Index: trunk/extensions/Wikidata/OmegaWiki/Controller.php |
— | — | @@ -3,7 +3,7 @@ |
4 | 4 | require_once("OmegaWikiAttributes.php"); |
5 | 5 | |
6 | 6 | interface UpdateController { |
7 | | - public function add($keyPath, $record); |
| 7 | + public function add(IdStack $idPath, $record); |
8 | 8 | public function remove($keyPath); |
9 | 9 | public function update($keyPath, $record); |
10 | 10 | } |
— | — | @@ -40,9 +40,20 @@ |
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
44 | | -class DefinedMeaningDefinitionController implements UpdateController { |
45 | | - public function add($keyPath, $record) { |
46 | | - $definedMeaningId = $keyPath->peek(0)->definedMeaningId; |
| 44 | +class DefaultUpdateController implements UpdateController { |
| 45 | + public function add(IdStack $idPath, $record) { |
| 46 | + } |
| 47 | + |
| 48 | + public function remove($keyPath) { |
| 49 | + } |
| 50 | + |
| 51 | + public function update($keyPath, $record) { |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +class DefinedMeaningDefinitionController extends DefaultUpdateController { |
| 56 | + public function add(IdStack $idPath, $record) { |
| 57 | + $definedMeaningId = $idPath->getKeyStack()->peek(0)->definedMeaningId; |
47 | 58 | $languageId = $record->language; |
48 | 59 | $text = $record->text; |
49 | 60 | |
— | — | @@ -81,15 +92,15 @@ |
82 | 93 | } |
83 | 94 | } |
84 | 95 | |
85 | | -class DefinedMeaningAlternativeDefinitionsController implements UpdateController { |
| 96 | +class DefinedMeaningAlternativeDefinitionsController extends DefaultUpdateController { |
86 | 97 | protected $filterLanguageId; |
87 | 98 | |
88 | 99 | public function __construct($filterLanguageId) { |
89 | 100 | $this->filterLanguageId = $filterLanguageId; |
90 | 101 | } |
91 | 102 | |
92 | | - public function add($keyPath, $record) { |
93 | | - $definedMeaningId = $keyPath->peek(0)->definedMeaningId; |
| 103 | + public function add(IdStack $idPath, $record) { |
| 104 | + $definedMeaningId = $idPath->getKeyStack()->peek(0)->definedMeaningId; |
94 | 105 | $alternativeDefinition = $record->alternativeDefinition; |
95 | 106 | $sourceId = $record->source; |
96 | 107 | |
— | — | @@ -113,14 +124,11 @@ |
114 | 125 | $definitionId = $keyPath->peek(0)->definitionId; |
115 | 126 | removeDefinedMeaningAlternativeDefinition($definedMeaningId, $definitionId); |
116 | 127 | } |
117 | | - |
118 | | - public function update($keyPath, $record) { |
119 | | - } |
120 | 128 | } |
121 | 129 | |
122 | | -class DefinedMeaningAlternativeDefinitionController implements UpdateController { |
123 | | - public function add($keyPath, $record) { |
124 | | - $definitionId = $keyPath->peek(0)->definitionId; |
| 130 | +class DefinedMeaningAlternativeDefinitionController extends DefaultUpdateController { |
| 131 | + public function add(IdStack $idPath, $record) { |
| 132 | + $definitionId = $idPath->getKeyStack()->peek(0)->definitionId; |
125 | 133 | $languageId = $record->language; |
126 | 134 | $text = $record->text; |
127 | 135 | |
— | — | @@ -160,15 +168,15 @@ |
161 | 169 | } |
162 | 170 | } |
163 | 171 | |
164 | | -class SynonymTranslationController implements UpdateController { |
| 172 | +class SynonymTranslationController extends DefaultUpdateController { |
165 | 173 | protected $filterLanguageId; |
166 | 174 | |
167 | 175 | public function __construct($filterLanguageId) { |
168 | 176 | $this->filterLanguageId = $filterLanguageId; |
169 | 177 | } |
170 | 178 | |
171 | | - public function add($keyPath, $record) { |
172 | | - $definedMeaningId = $keyPath->peek(0)->definedMeaningId; |
| 179 | + public function add(IdStack $idPath, $record) { |
| 180 | + $definedMeaningId = $idPath->getKeyStack()->peek(0)->definedMeaningId; |
173 | 181 | $expressionValue = $record->expression; |
174 | 182 | |
175 | 183 | if ($this->filterLanguageId == 0) { |
— | — | @@ -202,9 +210,9 @@ |
203 | 211 | } |
204 | 212 | } |
205 | 213 | |
206 | | -class ClassAttributesController implements UpdateController { |
207 | | - public function add($keyPath, $record) { |
208 | | - $definedMeaningId = $keyPath->peek(0)->definedMeaningId; |
| 214 | +class ClassAttributesController extends DefaultUpdateController { |
| 215 | + public function add(IdStack $idPath, $record) { |
| 216 | + $definedMeaningId = $idPath->getKeyStack()->peek(0)->definedMeaningId; |
209 | 217 | $attributeLevelId = $record->classAttributeLevel; |
210 | 218 | $attributeMeaningId = $record->classAttributeAttribute; |
211 | 219 | $attributeType = $record->classAttributeType; |
— | — | @@ -217,12 +225,9 @@ |
218 | 226 | $classAttributeId = $keyPath->peek(0)->classAttributeId; |
219 | 227 | removeClassAttributeWithId($classAttributeId); |
220 | 228 | } |
221 | | - |
222 | | - public function update($keyPath, $record) { |
223 | | - } |
224 | 229 | } |
225 | 230 | |
226 | | -class GroupedRelationTypeController implements UpdateController { |
| 231 | +class GroupedRelationTypeController extends DefaultUpdateController { |
227 | 232 | protected $relationTypeId; |
228 | 233 | protected $groupedRelationIdAttribute; |
229 | 234 | protected $otherDefinedMeaningAttribute; |
— | — | @@ -233,8 +238,8 @@ |
234 | 239 | $this->otherDefinedMeaningAttribute = $otherDefinedMeaningAttribute; |
235 | 240 | } |
236 | 241 | |
237 | | - public function add($keyPath, $record) { |
238 | | - $definedMeaningId = $keyPath->peek(0)->definedMeaningId; |
| 242 | + public function add(IdStack $idPath, $record) { |
| 243 | + $definedMeaningId = $idPath->getKeyStack()->peek(0)->definedMeaningId; |
239 | 244 | $otherDefinedMeaningId = $record->getAttributeValue($this->otherDefinedMeaningAttribute); |
240 | 245 | |
241 | 246 | if ($otherDefinedMeaningId != 0) |
— | — | @@ -245,14 +250,11 @@ |
246 | 251 | $relationId = $keyPath->peek(0)->getAttributeValue($this->groupedRelationIdAttribute); |
247 | 252 | removeRelationWithId($relationId); |
248 | 253 | } |
249 | | - |
250 | | - public function update($keyPath, $record) { |
251 | | - } |
252 | 254 | } |
253 | 255 | |
254 | | -class DefinedMeaningClassMembershipController implements UpdateController { |
255 | | - public function add($keyPath, $record) { |
256 | | - $definedMeaningId = $keyPath->peek(0)->definedMeaningId; |
| 256 | +class DefinedMeaningClassMembershipController extends DefaultUpdateController { |
| 257 | + public function add(IdStack $idPath, $record) { |
| 258 | + $definedMeaningId = $idPath->getKeyStack()->peek(0)->definedMeaningId; |
257 | 259 | $classId = $record->class; |
258 | 260 | |
259 | 261 | if ($classId != 0) |
— | — | @@ -262,14 +264,11 @@ |
263 | 265 | public function remove($keyPath) { |
264 | 266 | removeClassMembershipWithId($keyPath->peek(0)->classMembershipId); |
265 | 267 | } |
266 | | - |
267 | | - public function update($keyPath, $record) { |
268 | | - } |
269 | 268 | } |
270 | 269 | |
271 | | -class DefinedMeaningCollectionController implements UpdateController { |
272 | | - public function add($keyPath, $record) { |
273 | | - $definedMeaningId = $keyPath->peek(0)->definedMeaningId; |
| 270 | +class DefinedMeaningCollectionController extends DefaultUpdateController { |
| 271 | + public function add(IdStack $idPath, $record) { |
| 272 | + $definedMeaningId = $idPath->getKeyStack()->peek(0)->definedMeaningId; |
274 | 273 | $collectionMeaningId = $record->collectionMeaning; |
275 | 274 | $internalId = $record->sourceIdentifier; |
276 | 275 | |
— | — | @@ -294,17 +293,17 @@ |
295 | 294 | } |
296 | 295 | } |
297 | 296 | |
298 | | -class ExpressionMeaningController implements UpdateController { |
| 297 | +class ExpressionMeaningController extends DefaultUpdateController { |
299 | 298 | protected $filterLanguageId; |
300 | 299 | |
301 | 300 | public function __construct($filterLanguageId) { |
302 | 301 | $this->filterLanguageId = $filterLanguageId; |
303 | 302 | } |
304 | 303 | |
305 | | - public function add($keyPath, $record) { |
| 304 | + public function add(IdStack $idPath, $record) { |
306 | 305 | $definition = $record->definedMeaning->definition; |
307 | 306 | $translatedContent = $definition->translatedText; |
308 | | - $expressionId = $keyPath->peek(0)->expressionId; |
| 307 | + $expressionId = $idPath->getKeyStack()->peek(0)->expressionId; |
309 | 308 | |
310 | 309 | if ($this->filterLanguageId == 0) { |
311 | 310 | if ($translatedContent->getRecordCount() > 0) { |
— | — | @@ -320,15 +319,9 @@ |
321 | 320 | else if ($translatedContent != "") |
322 | 321 | createNewDefinedMeaning($expressionId, $this->filterLanguageId, $translatedContent); |
323 | 322 | } |
324 | | - |
325 | | - public function remove($keyPath) { |
326 | | - } |
327 | | - |
328 | | - public function update($keyPath, $record) { |
329 | | - } |
330 | 323 | } |
331 | 324 | |
332 | | -class ExpressionController implements UpdateController { |
| 325 | +class ExpressionController extends DefaultUpdateController { |
333 | 326 | protected $spelling; |
334 | 327 | protected $filterLanguageId; |
335 | 328 | |
— | — | @@ -337,7 +330,7 @@ |
338 | 331 | $this->filterLanguageId = $filterLanguageId; |
339 | 332 | } |
340 | 333 | |
341 | | - public function add($keyPath, $record) { |
| 334 | + public function add(IdStack $idPath, $record) { |
342 | 335 | if ($this->filterLanguageId == 0) |
343 | 336 | $expressionLanguageId = $record->expression->language; |
344 | 337 | else |
— | — | @@ -370,25 +363,30 @@ |
371 | 364 | } |
372 | 365 | } |
373 | 366 | } |
374 | | - |
375 | | - public function remove($keyPath) { |
376 | | - } |
377 | | - |
378 | | - public function update($keyPath, $record) { |
379 | | - } |
380 | 367 | } |
381 | 368 | |
382 | | -abstract class ObjectAttributeValuesController implements UpdateController { |
| 369 | +class ObjectAttributeValuesController extends DefaultUpdateController { |
383 | 370 | protected $objectIdFetcher; |
384 | 371 | |
385 | | - public function __construct($objectIdFetcher) { |
| 372 | + public function __construct(ContextFetcher $objectIdFetcher) { |
386 | 373 | $this->objectIdFetcher = $objectIdFetcher; |
387 | 374 | } |
388 | 375 | } |
389 | 376 | |
390 | 377 | class DefinedMeaningAttributeValuesController extends ObjectAttributeValuesController { |
391 | | - public function add($keyPath, $record) { |
392 | | - $objectId = $this->objectIdFetcher->fetch($keyPath); |
| 378 | + protected $attributeIDFilter; |
| 379 | + |
| 380 | + public function __construct(ContextFetcher $objectIdFetcher, AttributeIDFilter $attributeIDFilter) { |
| 381 | + parent::__construct($objectIdFetcher); |
| 382 | + |
| 383 | + $this->attributeIDFilter = $attributeIDFilter; |
| 384 | + } |
| 385 | + |
| 386 | + public function add(IdStack $idPath, $record) { |
| 387 | +// if ($this->allowedAttributeIDs != null && count($this->allowedAttributeIDs) == 1) |
| 388 | +// echo "Allowed attribute: " . $this->allowedAttributeIDs[0]; |
| 389 | + |
| 390 | + $objectId = $this->objectIdFetcher->fetch($idPath->getKeyStack()); |
393 | 391 | $definedMeaningAttributeId = $record->relationType; |
394 | 392 | $definedMeaningValue = $record->otherDefinedMeaning; |
395 | 393 | |
— | — | @@ -400,16 +398,14 @@ |
401 | 399 | $valueId = $keyPath->peek(0)->relationId; |
402 | 400 | removeRelationWithId($valueId); |
403 | 401 | } |
404 | | - |
405 | | - public function update($keyPath, $record) { |
406 | | - } |
407 | 402 | } |
408 | 403 | |
409 | 404 | class TextAttributeValuesController extends ObjectAttributeValuesController { |
410 | | - public function add($keyPath, $record) { |
411 | | - $objectId = $this->objectIdFetcher->fetch($keyPath); |
| 405 | + public function add(IdStack $idPath, $record) { |
| 406 | + $objectId = $this->objectIdFetcher->fetch($idPath->getKeyStack()); |
412 | 407 | $textAttributeId = $record->textAttribute; |
413 | 408 | $text = $record->text; |
| 409 | + |
414 | 410 | if ($textAttributeId != 0 && $text != '') |
415 | 411 | addTextAttributeValue($objectId, $textAttributeId, $text); |
416 | 412 | } |
— | — | @@ -437,8 +433,8 @@ |
438 | 434 | return $url; |
439 | 435 | } |
440 | 436 | |
441 | | - public function add($keyPath, $record) { |
442 | | - $objectId = $this->objectIdFetcher->fetch($keyPath); |
| 437 | + public function add(IdStack $idPath, $record) { |
| 438 | + $objectId = $this->objectIdFetcher->fetch($idPath->getKeyStack()); |
443 | 439 | $linkAttributeId = $record->linkAttribute; |
444 | 440 | $linkValue = $record->link; |
445 | 441 | $label = $linkValue->linkLabel; |
— | — | @@ -473,8 +469,8 @@ |
474 | 470 | $this->filterLanguageId = $filterLanguageId; |
475 | 471 | } |
476 | 472 | |
477 | | - public function add($keyPath, $record) { |
478 | | - $objectId = $this->objectIdFetcher->fetch($keyPath); |
| 473 | + public function add(IdStack $idPath, $record) { |
| 474 | + $objectId = $this->objectIdFetcher->fetch($idPath->getKeyStack()); |
479 | 475 | $textValue = $record->translatedTextValue; |
480 | 476 | $textAttributeId = $record->translatedTextAttribute; |
481 | 477 | |
— | — | @@ -499,14 +495,11 @@ |
500 | 496 | $valueId = $keyPath->peek(0)->translatedTextAttributeId; |
501 | 497 | removeTranslatedTextAttributeValue($valueId); |
502 | 498 | } |
503 | | - |
504 | | - public function update($keyPath, $record) { |
505 | | - } |
506 | 499 | } |
507 | 500 | |
508 | | -class TranslatedTextAttributeValueController implements UpdateController { |
509 | | - public function add($keyPath, $record) { |
510 | | - $valueId = $keyPath->peek(0)->translatedTextAttributeId; |
| 501 | +class TranslatedTextAttributeValueController extends DefaultUpdateController { |
| 502 | + public function add(IdStack $idPath, $record) { |
| 503 | + $valueId = $idPath->getKeyStack()->peek(0)->translatedTextAttributeId; |
511 | 504 | $languageId = $record->language; |
512 | 505 | $text = $record->text; |
513 | 506 | $translatedTextAttribute = getTranslatedTextAttribute($valueId); |
— | — | @@ -551,8 +544,8 @@ |
552 | 545 | } |
553 | 546 | |
554 | 547 | class OptionAttributeValuesController extends ObjectAttributeValuesController { |
555 | | - public function add($keyPath, $record) { |
556 | | - $objectId = $this->objectIdFetcher->fetch($keyPath); |
| 548 | + public function add(IdStack $idPath, $record) { |
| 549 | + $objectId = $this->objectIdFetcher->fetch($idPath->getKeyStack()); |
557 | 550 | $optionId = $record->optionAttributeOption; |
558 | 551 | |
559 | 552 | if ($optionId) |
— | — | @@ -563,13 +556,11 @@ |
564 | 557 | $valueId = $keyPath->peek(0)->optionAttributeId; |
565 | 558 | removeOptionAttributeValue($valueId); |
566 | 559 | } |
567 | | - |
568 | | - public function update($keyPath, $record) {} |
569 | 560 | } |
570 | 561 | |
571 | | -class OptionAttributeOptionsController implements UpdateController { |
572 | | - public function add($keyPath, $record) { |
573 | | - $attributeId = $keyPath->peek(0)->classAttributeId; |
| 562 | +class OptionAttributeOptionsController extends DefaultUpdateController { |
| 563 | + public function add(IdStack $idPath, $record) { |
| 564 | + $attributeId = $idPath->getKeyStack()->peek(0)->classAttributeId; |
574 | 565 | $optionMeaningId = $record->optionAttributeOption; |
575 | 566 | $languageId = $record->language; |
576 | 567 | |
— | — | @@ -581,9 +572,6 @@ |
582 | 573 | $optionId = $keyPath->peek(0)->optionAttributeOptionId; |
583 | 574 | removeOptionAttributeOption($optionId); |
584 | 575 | } |
585 | | - |
586 | | - public function update($keyPath, $record) { |
587 | | - } |
588 | 576 | } |
589 | 577 | |
590 | 578 | class AlternativeDefinitionsPermissionController implements PermissionController { |
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php |
— | — | @@ -426,7 +426,7 @@ |
427 | 427 | $attributeIDFilter = $objectAttributesEditor->getAttributeIDfilter(); |
428 | 428 | $annotationLevelName = $objectAttributesEditor->getLevelName(); |
429 | 429 | |
430 | | - $objectAttributesEditor->addEditor(getDefinedMeaningAttributeValuesEditor($viewInformation, new DefinedMeaningAttributeValuesController($annotatedObjectIdFetcher), $annotationLevelName, $attributeIDFilter)); |
| 430 | + $objectAttributesEditor->addEditor(getDefinedMeaningAttributeValuesEditor($viewInformation, new DefinedMeaningAttributeValuesController($annotatedObjectIdFetcher, $attributeIDFilter), $annotationLevelName, $attributeIDFilter)); |
431 | 431 | $objectAttributesEditor->addEditor(getTextAttributeValuesEditor($viewInformation, new TextAttributeValuesController($annotatedObjectIdFetcher), $annotationLevelName, $attributeIDFilter)); |
432 | 432 | $objectAttributesEditor->addEditor(getTranslatedTextAttributeValuesEditor($viewInformation, new TranslatedTextAttributeValuesController($annotatedObjectIdFetcher, $viewInformation->filterLanguageId), $annotationLevelName, $attributeIDFilter)); |
433 | 433 | $objectAttributesEditor->addEditor(getLinkAttributeValuesEditor($viewInformation, new LinkAttributeValuesController($annotatedObjectIdFetcher), $annotationLevelName, $attributeIDFilter)); |
Index: trunk/extensions/Wikidata/OmegaWiki/Editor.php |
— | — | @@ -482,7 +482,7 @@ |
483 | 483 | if (count($addStructure->getAttributes()) > 0) { |
484 | 484 | $addEditors = $this->getAddEditors(); |
485 | 485 | $record = $this->getAddRecord($idPath, $addStructure, $addEditors); |
486 | | - $this->controller->add($idPath->getKeyStack(), $record); |
| 486 | + $this->controller->add($idPath, $record); |
487 | 487 | } |
488 | 488 | } |
489 | 489 | |
— | — | @@ -2181,7 +2181,7 @@ |
2182 | 2182 | $idPath->popKey(); |
2183 | 2183 | } |
2184 | 2184 | else |
2185 | | - $this->controller->add($idPath->getKeyStack(), $this->recordEditor->getAddValue($idPath)); |
| 2185 | + $this->controller->add($idPath, $this->recordEditor->getAddValue($idPath)); |
2186 | 2186 | } |
2187 | 2187 | |
2188 | 2188 | public function setRecordEditor(Editor $recordEditor) { |