Index: trunk/extensions/Wikidata/OmegaWiki/Controller.php |
— | — | @@ -367,27 +367,30 @@ |
368 | 368 | |
369 | 369 | class ObjectAttributeValuesController extends DefaultUpdateController { |
370 | 370 | protected $objectIdFetcher; |
| 371 | + protected $attributeIDFilter; |
| 372 | + protected $levelName; |
371 | 373 | |
372 | | - public function __construct(ContextFetcher $objectIdFetcher) { |
| 374 | + public function __construct(ContextFetcher $objectIdFetcher, $levelName, AttributeIDFilter $attributeIDFilter) { |
373 | 375 | $this->objectIdFetcher = $objectIdFetcher; |
| 376 | + $this->attributeIDFilter = $attributeIDFilter; |
| 377 | + $this->levelName = $levelName; |
374 | 378 | } |
| 379 | + |
| 380 | + protected function determineAttributeId(IdStack $idPath, $annotationType, $attributeIdFromRecord) { |
| 381 | + $classAttributes = $idPath->getClassAttributes()->filterClassAttributesOnLevelAndType($this->levelName, $annotationType); |
| 382 | + $classAttributes = $this->attributeIDFilter->filter($classAttributes); |
| 383 | + |
| 384 | + if (count($classAttributes) == 1) |
| 385 | + return $classAttributes[0]; |
| 386 | + else |
| 387 | + return $attributeIdFromRecord; |
| 388 | + } |
375 | 389 | } |
376 | 390 | |
377 | 391 | class DefinedMeaningAttributeValuesController extends ObjectAttributeValuesController { |
378 | | - protected $attributeIDFilter; |
379 | | - |
380 | | - public function __construct(ContextFetcher $objectIdFetcher, AttributeIDFilter $attributeIDFilter) { |
381 | | - parent::__construct($objectIdFetcher); |
382 | | - |
383 | | - $this->attributeIDFilter = $attributeIDFilter; |
384 | | - } |
385 | | - |
386 | 392 | public function add(IdStack $idPath, $record) { |
387 | | -// if ($this->allowedAttributeIDs != null && count($this->allowedAttributeIDs) == 1) |
388 | | -// echo "Allowed attribute: " . $this->allowedAttributeIDs[0]; |
389 | | - |
390 | 393 | $objectId = $this->objectIdFetcher->fetch($idPath->getKeyStack()); |
391 | | - $definedMeaningAttributeId = $record->relationType; |
| 394 | + $definedMeaningAttributeId = $this->determineAttributeId($idPath, "DM", $record->relationType); |
392 | 395 | $definedMeaningValue = $record->otherDefinedMeaning; |
393 | 396 | |
394 | 397 | if ($definedMeaningAttributeId != 0 && $definedMeaningValue != 0) |
— | — | @@ -403,7 +406,7 @@ |
404 | 407 | class TextAttributeValuesController extends ObjectAttributeValuesController { |
405 | 408 | public function add(IdStack $idPath, $record) { |
406 | 409 | $objectId = $this->objectIdFetcher->fetch($idPath->getKeyStack()); |
407 | | - $textAttributeId = $record->textAttribute; |
| 410 | + $textAttributeId = $this->determineAttributeId($idPath, "TEXT", $record->textAttribute); |
408 | 411 | $text = $record->text; |
409 | 412 | |
410 | 413 | if ($textAttributeId != 0 && $text != '') |
— | — | @@ -435,7 +438,7 @@ |
436 | 439 | |
437 | 440 | public function add(IdStack $idPath, $record) { |
438 | 441 | $objectId = $this->objectIdFetcher->fetch($idPath->getKeyStack()); |
439 | | - $linkAttributeId = $record->linkAttribute; |
| 442 | + $linkAttributeId = $this->determineAttributeId($idPath, "URL", $record->linkAttribute); |
440 | 443 | $linkValue = $record->link; |
441 | 444 | $label = $linkValue->linkLabel; |
442 | 445 | $url = $linkValue->linkURL; |
— | — | @@ -463,8 +466,8 @@ |
464 | 467 | class TranslatedTextAttributeValuesController extends ObjectAttributeValuesController { |
465 | 468 | protected $filterLanguageId; |
466 | 469 | |
467 | | - public function __construct($objectIdFetcher, $filterLanguageId) { |
468 | | - parent::__construct($objectIdFetcher); |
| 470 | + public function __construct(ContextFetcher $objectIdFetcher, $levelName, AttributeIDFilter $attributeIDFilter, $filterLanguageId) { |
| 471 | + parent::__construct($objectIdFetcher, $levelName, $attributeIDFilter); |
469 | 472 | |
470 | 473 | $this->filterLanguageId = $filterLanguageId; |
471 | 474 | } |
— | — | @@ -472,7 +475,7 @@ |
473 | 476 | public function add(IdStack $idPath, $record) { |
474 | 477 | $objectId = $this->objectIdFetcher->fetch($idPath->getKeyStack()); |
475 | 478 | $textValue = $record->translatedTextValue; |
476 | | - $textAttributeId = $record->translatedTextAttribute; |
| 479 | + $textAttributeId = $this->determineAttributeId($idPath, "TRNS", $record->translatedTextAttribute); |
477 | 480 | |
478 | 481 | if ($textAttributeId != 0) { |
479 | 482 | if ($this->filterLanguageId == 0) { |
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php |
— | — | @@ -426,11 +426,11 @@ |
427 | 427 | $attributeIDFilter = $objectAttributesEditor->getAttributeIDfilter(); |
428 | 428 | $annotationLevelName = $objectAttributesEditor->getLevelName(); |
429 | 429 | |
430 | | - $objectAttributesEditor->addEditor(getDefinedMeaningAttributeValuesEditor($viewInformation, new DefinedMeaningAttributeValuesController($annotatedObjectIdFetcher, $attributeIDFilter), $annotationLevelName, $attributeIDFilter)); |
431 | | - $objectAttributesEditor->addEditor(getTextAttributeValuesEditor($viewInformation, new TextAttributeValuesController($annotatedObjectIdFetcher), $annotationLevelName, $attributeIDFilter)); |
432 | | - $objectAttributesEditor->addEditor(getTranslatedTextAttributeValuesEditor($viewInformation, new TranslatedTextAttributeValuesController($annotatedObjectIdFetcher, $viewInformation->filterLanguageId), $annotationLevelName, $attributeIDFilter)); |
433 | | - $objectAttributesEditor->addEditor(getLinkAttributeValuesEditor($viewInformation, new LinkAttributeValuesController($annotatedObjectIdFetcher), $annotationLevelName, $attributeIDFilter)); |
434 | | - $objectAttributesEditor->addEditor(getOptionAttributeValuesEditor($viewInformation, new OptionAttributeValuesController($annotatedObjectIdFetcher), $annotationLevelName, $attributeIDFilter)); |
| 430 | + $objectAttributesEditor->addEditor(getDefinedMeaningAttributeValuesEditor($viewInformation, new DefinedMeaningAttributeValuesController($annotatedObjectIdFetcher, $annotationLevelName, $attributeIDFilter), $annotationLevelName, $attributeIDFilter)); |
| 431 | + $objectAttributesEditor->addEditor(getTextAttributeValuesEditor($viewInformation, new TextAttributeValuesController($annotatedObjectIdFetcher, $annotationLevelName, $attributeIDFilter), $annotationLevelName, $attributeIDFilter)); |
| 432 | + $objectAttributesEditor->addEditor(getTranslatedTextAttributeValuesEditor($viewInformation, new TranslatedTextAttributeValuesController($annotatedObjectIdFetcher, $annotationLevelName, $attributeIDFilter, $viewInformation->filterLanguageId), $annotationLevelName, $attributeIDFilter)); |
| 433 | + $objectAttributesEditor->addEditor(getLinkAttributeValuesEditor($viewInformation, new LinkAttributeValuesController($annotatedObjectIdFetcher, $annotationLevelName, $attributeIDFilter), $annotationLevelName, $attributeIDFilter)); |
| 434 | + $objectAttributesEditor->addEditor(getOptionAttributeValuesEditor($viewInformation, new OptionAttributeValuesController($annotatedObjectIdFetcher, $annotationLevelName, $attributeIDFilter), $annotationLevelName, $attributeIDFilter)); |
435 | 435 | } |
436 | 436 | |
437 | 437 | function createObjectAttributesEditor(ViewInformation $viewInformation, Attribute $attribute, $propertyCaption, $valueCaption, Attribute $idAttribute, $levelName, AttributeIDFilter $attributeIDFilter) { |
Index: trunk/extensions/Wikidata/OmegaWiki/Editor.php |
— | — | @@ -2355,8 +2355,14 @@ |
2356 | 2356 | } |
2357 | 2357 | |
2358 | 2358 | public function save(IdStack $idPath, $value) { |
2359 | | - $idPath->pushDefinedMeaningId($value->definedMeaningId); |
| 2359 | + $definedMeaningId = (int) $value->definedMeaningId; |
| 2360 | + |
| 2361 | + $idPath->pushDefinedMeaningId($definedMeaningId); |
| 2362 | + $idPath->pushClassAttributes(new ClassAttributes($definedMeaningId)); |
| 2363 | + |
2360 | 2364 | $this->wrappedEditor->save($idPath, $value); |
| 2365 | + |
| 2366 | + $idPath->popClassAttributes(); |
2361 | 2367 | $idPath->popDefinedMeaningId(); |
2362 | 2368 | } |
2363 | 2369 | } |