Index: trunk/extensions/Wikidata/OmegaWiki/HTMLtable.php |
— | — | @@ -23,7 +23,7 @@ |
24 | 24 | public $childNodes = array(); |
25 | 25 | } |
26 | 26 | |
27 | | -function getTableHeaderNode($structure, &$currentColumn=0) { |
| 27 | +function getTableHeaderNode(Structure $structure, &$currentColumn=0) { |
28 | 28 | $tableHeaderNode = new TableHeaderNode(); |
29 | 29 | |
30 | 30 | foreach($structure->getAttributes() as $attribute) { |
— | — | @@ -50,7 +50,7 @@ |
51 | 51 | return $tableHeaderNode; |
52 | 52 | } |
53 | 53 | |
54 | | -function addChildNodesToRows($headerNode, &$rows, $currentDepth, $columnOffset, $idPath, $leftmost=True) { |
| 54 | +function addChildNodesToRows(TableHeaderNode $headerNode, &$rows, $currentDepth, $columnOffset, IdStack $idPath, $leftmost=True) { |
55 | 55 | $height = $headerNode->height; |
56 | 56 | foreach($headerNode->childNodes as $childNode) { |
57 | 57 | $attribute = $childNode->attribute; |
— | — | @@ -91,7 +91,7 @@ |
92 | 92 | } |
93 | 93 | } |
94 | 94 | |
95 | | -function getStructureAsTableHeaderRows($structure, $columnOffset, $idPath) { |
| 95 | +function getStructureAsTableHeaderRows(Structure $structure, $columnOffset, IdStack $idPath) { |
96 | 96 | $rootNode = getTableHeaderNode($structure); |
97 | 97 | $result = array(); |
98 | 98 | |
— | — | @@ -103,18 +103,21 @@ |
104 | 104 | return $result; |
105 | 105 | } |
106 | 106 | |
107 | | -function getHTMLClassForType($type,$attribute) { |
| 107 | +function getHTMLClassForType($type, Attribute $attribute) { |
108 | 108 | if ($type instanceof Structure) |
109 | 109 | return $attribute->id; |
110 | 110 | else |
111 | 111 | return $type; |
112 | 112 | } |
113 | 113 | |
114 | | -function getRecordAsTableCells($idPath, $editor, $visibleColumnEditors, $record, &$startColumn = 0) { |
| 114 | +function getRecordAsTableCells(IdStack $idPath, Editor $editor, Structure $visibleStructure, Record $record, &$startColumn = 0) { |
115 | 115 | $result = ''; |
| 116 | + $childEditorMap = $editor->getAttributeEditorMap(); |
116 | 117 | |
117 | | - foreach ($editor->getEditors() as $childEditor) { |
118 | | - if (in_array($childEditor, $visibleColumnEditors, true)) { |
| 118 | + foreach ($visibleStructure->getAttributes() as $visibleAttribute) { |
| 119 | + $childEditor = $childEditorMap->getEditorForAttribute($visibleAttribute); |
| 120 | + |
| 121 | + if ($childEditor != null) { |
119 | 122 | $attribute = $childEditor->getAttribute(); |
120 | 123 | $type = $attribute->type; |
121 | 124 | $value = $record->getAttributeValue($attribute); |
— | — | @@ -122,7 +125,7 @@ |
123 | 126 | $attributeId = $idPath->getId(); |
124 | 127 | |
125 | 128 | if ($childEditor instanceof RecordTableCellEditor) |
126 | | - $result .= getRecordAsTableCells($idPath, $childEditor, $visibleColumnEditors, $value, $startColumn); |
| 129 | + $result .= getRecordAsTableCells($idPath, $childEditor, $visibleAttribute->type, $value, $startColumn); |
127 | 130 | else { |
128 | 131 | $displayValue = $childEditor->showsData($value) ? $childEditor->view($idPath, $value) : ""; |
129 | 132 | $result .= '<td class="'. getHTMLClassForType($type,$attribute) .' column-'. parityClass($startColumn) . '">'. $displayValue . '</td>'; |
— | — | @@ -131,12 +134,14 @@ |
132 | 135 | |
133 | 136 | $idPath->popAttribute(); |
134 | 137 | } |
| 138 | + else |
| 139 | + $result .= '<td/>'; |
135 | 140 | } |
136 | 141 | |
137 | 142 | return $result; |
138 | 143 | } |
139 | 144 | |
140 | | -function getRecordAsEditTableCells($record, $idPath, $editor, &$startColumn = 0) { |
| 145 | +function getRecordAsEditTableCells(Record $record, IdStack $idPath, Editor $editor, &$startColumn = 0) { |
141 | 146 | $result = ''; |
142 | 147 | |
143 | 148 | foreach($editor->getEditors() as $childEditor) { |
— | — | @@ -164,7 +169,7 @@ |
165 | 170 | return $result; |
166 | 171 | } |
167 | 172 | |
168 | | -function getStructureAsAddCells($idPath, $editor, &$startColumn = 0) { |
| 173 | +function getStructureAsAddCells(IdStack $idPath, Editor $editor, &$startColumn = 0) { |
169 | 174 | $result = ''; |
170 | 175 | |
171 | 176 | foreach($editor->getEditors() as $childEditor) { |
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php |
— | — | @@ -8,6 +8,165 @@ |
9 | 9 | require_once('GotoSourceTemplate.php'); |
10 | 10 | require_once('ViewInformation.php'); |
11 | 11 | |
| 12 | +class ObjectAttributeValuesEditor extends WrappingEditor { |
| 13 | + protected $recordSetTableEditor; |
| 14 | + protected $propertyAttribute; |
| 15 | + protected $valueAttribute; |
| 16 | + protected $suffixAttributes; |
| 17 | + |
| 18 | + public function __construct(Attribute $attribute, ViewInformation $viewInformation) { |
| 19 | + parent::__construct(new RecordUnorderedListEditor($attribute, 5)); |
| 20 | + |
| 21 | + $this->recordSetTableEditor = new RecordSetTableEditor( |
| 22 | + $attribute, |
| 23 | + new SimplePermissionController(false), |
| 24 | + new ShowEditFieldChecker(true), |
| 25 | + new AllowAddController(false), |
| 26 | + false, |
| 27 | + false, |
| 28 | + null |
| 29 | + ); |
| 30 | + |
| 31 | + $this->propertyAttribute = new Attribute("property", "Property", "short-text"); |
| 32 | + $this->valueAttribute = new Attribute("value", "Value", "short-text"); |
| 33 | + |
| 34 | + $this->suffixAttributes = array(); |
| 35 | + |
| 36 | +// foreach ($viewInformation->getPropertyToColumnFilters() as $propertyToColumnFilter) |
| 37 | +// $this->suffixAttributes[] = $propertyToColumnFilter->getAttribute(); |
| 38 | + |
| 39 | + global |
| 40 | + $wgRequest, $objectAttributesAttribute, $recordLifeSpanAttribute; |
| 41 | + |
| 42 | +// $this->suffixAttributes[] = $objectAttributesAttribute; |
| 43 | + |
| 44 | + if ($wgRequest->getText('action') == 'history' && $viewInformation->showRecordLifeSpan) |
| 45 | + $this->suffixAttributes[] = $recordLifeSpanAttribute; |
| 46 | + } |
| 47 | + |
| 48 | + protected function attributeInStructure(Attribute $attribute, Structure $structure) { |
| 49 | + $result = false; |
| 50 | + $attributes = $structure->getAttributes(); |
| 51 | + $i = 0; |
| 52 | + |
| 53 | + while (!$result && $i < count($attributes)) { |
| 54 | + $result = $attribute->id == $attributes[$i]->id; |
| 55 | + $i++; |
| 56 | + } |
| 57 | + |
| 58 | + |
| 59 | + return $result; |
| 60 | + } |
| 61 | + |
| 62 | + protected function attributeInStructures(Attribute $attribute, array &$structures) { |
| 63 | + $result = false; |
| 64 | + $i = 0; |
| 65 | + |
| 66 | + while (!$result && $i < count($structures)) { |
| 67 | + $result = $this->attributeInStructure($attribute, $structures[$i]); |
| 68 | + $i++; |
| 69 | + } |
| 70 | + |
| 71 | + return $result; |
| 72 | + } |
| 73 | + |
| 74 | + protected function getSubStructureForAttribute(Structure $structure, Attribute $attribute) { |
| 75 | + $attributes = $structure->getAttributes(); |
| 76 | + $result = null; |
| 77 | + $i = 0; |
| 78 | + |
| 79 | + while ($result == null && $i < count($attributes)) |
| 80 | + if ($attribute->id == $attributes[$i]->id) |
| 81 | + $result = $attributes[$i]->type; |
| 82 | + else |
| 83 | + $i++; |
| 84 | + |
| 85 | + return $result; |
| 86 | + } |
| 87 | + |
| 88 | + protected function filterStructuresOnAttribute(array &$structures, Attribute $attribute) { |
| 89 | + $result = array(); |
| 90 | + |
| 91 | + foreach ($structures as $structure) { |
| 92 | + $subStructure = $this->getSubStructureForAttribute($structure, $attribute); |
| 93 | + |
| 94 | + if ($subStructure != null) |
| 95 | + $result[] = $subStructure; |
| 96 | + } |
| 97 | + |
| 98 | + return $result; |
| 99 | + } |
| 100 | + |
| 101 | + protected function filterAttributesByStructures(array &$attributes, array &$structures) { |
| 102 | + $result = array(); |
| 103 | + |
| 104 | + foreach ($attributes as $attribute) { |
| 105 | + if ($attribute->type instanceof Structure) { |
| 106 | + $filteredAttributes = $this->filterAttributesByStructures( |
| 107 | + $attribute->type->getAttributes(), |
| 108 | + $this->filterStructuresOnAttribute($structures, $attribute) |
| 109 | + ); |
| 110 | + |
| 111 | + if (count($filteredAttributes) > 0) |
| 112 | + $result[] = new Attribute($attribute->id, $attribute->name, new Structure($filteredAttributes)); |
| 113 | + } |
| 114 | + else if ($this->attributeInStructures($attribute, $structures)) |
| 115 | + $result[] = $attribute; |
| 116 | + } |
| 117 | + |
| 118 | + return $result; |
| 119 | + } |
| 120 | + |
| 121 | + public function determineVisibleSuffixAttributes($value) { |
| 122 | + $visibleStructures = array(); |
| 123 | + |
| 124 | + foreach ($this->getEditors() as $editor) |
| 125 | + $visibleStructures[] = $editor->getTableStructureForView($value->getAttributeValue($editor->getAttribute())); |
| 126 | + |
| 127 | + return $this->filterAttributesByStructures($this->suffixAttributes, $visibleStructures); |
| 128 | + } |
| 129 | + |
| 130 | + public function addEditor(Editor $editor) { |
| 131 | + $this->wrappedEditor->addEditor($editor); |
| 132 | + } |
| 133 | + |
| 134 | + protected function getVisibleStructureForEditor(Editor $editor, array &$suffixAttributes) { |
| 135 | + $leadingAttributes = array(); |
| 136 | + $childEditors = $editor->getEditors(); |
| 137 | + |
| 138 | + for ($i = 0; $i < 2; $i++) |
| 139 | + $leadingAttributes[] = $childEditors[$i]->getAttribute(); |
| 140 | + |
| 141 | + return new Structure(array_merge($leadingAttributes, $suffixAttributes)); |
| 142 | + } |
| 143 | + |
| 144 | + public function view(IdStack $idPath, $value) { |
| 145 | + $visibleSuffixAttributes = $this->determineVisibleSuffixAttributes($value); |
| 146 | + |
| 147 | + $visibleStructure = new Structure(array_merge( |
| 148 | + array($this->propertyAttribute, $this->valueAttribute), |
| 149 | + $visibleSuffixAttributes |
| 150 | + )); |
| 151 | + |
| 152 | + $result = $this->recordSetTableEditor->viewHeader($idPath, $visibleStructure); |
| 153 | + |
| 154 | + foreach ($this->getEditors() as $editor) { |
| 155 | + $attribute = $editor->getAttribute(); |
| 156 | + $idPath->pushAttribute($attribute); |
| 157 | + $result .= $editor->viewRows( |
| 158 | + $idPath, |
| 159 | + $value->getAttributeValue($attribute), |
| 160 | + $this->getVisibleStructureForEditor($editor, $visibleSuffixAttributes) |
| 161 | + ); |
| 162 | + $idPath->popAttribute(); |
| 163 | + } |
| 164 | + |
| 165 | + $result .= $this->recordSetTableEditor->viewFooter($idPath, $visibleStructure); |
| 166 | + |
| 167 | + return $result; |
| 168 | + } |
| 169 | +} |
| 170 | + |
12 | 171 | function initializeObjectAttributeEditors(ViewInformation $viewInformation) { |
13 | 172 | global |
14 | 173 | $objectAttributesAttribute, $definedMeaningIdAttribute, |
— | — | @@ -49,16 +208,27 @@ |
50 | 209 | return $result; |
51 | 210 | } |
52 | 211 | |
53 | | -function addTableLifeSpanEditor(Editor $editor, $showRecordLifeSpan) { |
| 212 | +function getTableLifeSpanEditor($showRecordLifeSpan) { |
54 | 213 | global |
55 | 214 | $recordLifeSpanAttribute, $addTransactionAttribute, $removeTransactionAttribute, $wgRequest; |
56 | 215 | |
| 216 | + $result = array(); |
| 217 | + |
57 | 218 | if ($wgRequest->getText('action') == 'history' && $showRecordLifeSpan) |
58 | | - $editor->addEditor(createTableLifeSpanEditor($recordLifeSpanAttribute)); |
| 219 | + $result[] = createTableLifeSpanEditor($recordLifeSpanAttribute); |
| 220 | + |
| 221 | + return $result; |
59 | 222 | } |
60 | 223 | |
| 224 | +function getTableMetadataEditors(ViewInformation $viewInformation) { |
| 225 | + return getTableLifeSpanEditor($viewInformation->showRecordLifeSpan); |
| 226 | +} |
| 227 | + |
61 | 228 | function addTableMetadataEditors($editor, ViewInformation $viewInformation) { |
62 | | - addTableLifeSpanEditor($editor, $viewInformation->showRecordLifeSpan); |
| 229 | + $metadataEditors = getTableMetadataEditors($viewInformation); |
| 230 | + |
| 231 | + foreach ($metadataEditors as $metadataEditor) |
| 232 | + $editor->addEditor($metadataEditor); |
63 | 233 | } |
64 | 234 | |
65 | 235 | function getDefinitionEditor(ViewInformation $viewInformation) { |
— | — | @@ -137,7 +307,7 @@ |
138 | 308 | global |
139 | 309 | $objectAttributesAttribute, $definedMeaningIdAttribute; |
140 | 310 | |
141 | | - $result = new ObjectAttributeValuesEditor($attribute); |
| 311 | + $result = new ObjectAttributeValuesEditor($attribute, $viewInformation); |
142 | 312 | |
143 | 313 | addObjectAttributesEditors( |
144 | 314 | $result, |
— | — | @@ -154,7 +324,7 @@ |
155 | 325 | global |
156 | 326 | $objectAttributesAttribute, $definedMeaningIdAttribute; |
157 | 327 | |
158 | | - $result = new ObjectAttributeValuesEditor($attribute); |
| 328 | + $result = new ObjectAttributeValuesEditor($attribute, $viewInformation); |
159 | 329 | |
160 | 330 | addObjectAttributesEditors( |
161 | 331 | $result, |
— | — | @@ -502,20 +672,6 @@ |
503 | 673 | return $expressionsEditor; |
504 | 674 | } |
505 | 675 | |
506 | | -class AttributeEditorMap { |
507 | | - protected $attributeEditorMap = array(); |
508 | | - |
509 | | - public function addEditor($editor) { |
510 | | - $attributeId = $editor->getAttribute()->id; |
511 | | - $this->attributeEditorMap[$attributeId] = $editor; |
512 | | - } |
513 | | - |
514 | | - public function getEditorForAttributeId($attributeId) { |
515 | | - # FIXME: check if this actually exists |
516 | | - return @$this->attributeEditorMap[$attributeId]; |
517 | | - } |
518 | | -} |
519 | | - |
520 | 676 | function getDefinedMeaningEditor(ViewInformation $viewInformation) { |
521 | 677 | global |
522 | 678 | $wdDefinedMeaningAttributesOrder, $definedMeaningIdAttribute, $definedMeaningMeaningName, |
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiRecordSets.php |
— | — | @@ -659,21 +659,19 @@ |
660 | 660 | $translatedContentTable, |
661 | 661 | $translatedTextStructure, $omegaWikiAttributes; |
662 | 662 | |
663 | | - $o=$omegaWikiAttributes; |
664 | | - |
665 | 663 | $recordSet = queryRecordSet( |
666 | 664 | $translatedTextStructure->getStructureType(), |
667 | 665 | $viewInformation->queryTransactionInformation, |
668 | | - $o->language, |
| 666 | + $omegaWikiAttributes->language, |
669 | 667 | new TableColumnsToAttributesMapping( |
670 | | - new TableColumnsToAttribute(array('language_id'), $o->language), |
671 | | - new TableColumnsToAttribute(array('text_id'), $o->text) |
| 668 | + new TableColumnsToAttribute(array('language_id'), $omegaWikiAttributes->language), |
| 669 | + new TableColumnsToAttribute(array('text_id'), $omegaWikiAttributes->text) |
672 | 670 | ), |
673 | 671 | $translatedContentTable, |
674 | 672 | array("translated_content_id=$translatedContentId") |
675 | 673 | ); |
676 | 674 | |
677 | | - expandTextReferencesInRecordSet($recordSet, array($o->text)); |
| 675 | + expandTextReferencesInRecordSet($recordSet, array($omegaWikiAttributes->text)); |
678 | 676 | |
679 | 677 | return $recordSet; |
680 | 678 | } |
— | — | @@ -682,15 +680,13 @@ |
683 | 681 | global |
684 | 682 | $translatedContentTable, $omegaWikiAttributes ; |
685 | 683 | |
686 | | - $o=$omegaWikiAttributes; |
687 | | - |
688 | 684 | $recordSet = queryRecordSet( |
689 | 685 | null, |
690 | 686 | $viewInformation->queryTransactionInformation, |
691 | 687 | $o->language, |
692 | 688 | new TableColumnsToAttributesMapping( |
693 | | - new TableColumnsToAttribute(array('language_id'), $o->language), |
694 | | - new TableColumnsToAttribute(array('text_id'), $o->text) |
| 689 | + new TableColumnsToAttribute(array('language_id'), $omegaWikiAttributes->language), |
| 690 | + new TableColumnsToAttribute(array('text_id'), $omegaWikiAttributes->text) |
695 | 691 | ), |
696 | 692 | $translatedContentTable, |
697 | 693 | array( |
— | — | @@ -699,7 +695,7 @@ |
700 | 696 | ) |
701 | 697 | ); |
702 | 698 | |
703 | | - expandTextReferencesInRecordSet($recordSet, array($textAttribute)); |
| 699 | + expandTextReferencesInRecordSet($recordSet, array($omegaWikiAttributes->textAttribute)); |
704 | 700 | |
705 | 701 | return $recordSet; |
706 | 702 | } |
Index: trunk/extensions/Wikidata/OmegaWiki/Editor.php |
— | — | @@ -145,19 +145,44 @@ |
146 | 146 | public function getAddValue(IdStack $idPath); |
147 | 147 | |
148 | 148 | public function getEditors(); |
| 149 | + public function getAttributeEditorMap(); |
149 | 150 | } |
150 | 151 | |
| 152 | +class AttributeEditorMap { |
| 153 | + protected $attributeEditorMap = array(); |
| 154 | + |
| 155 | + public function addEditor($editor) { |
| 156 | + $attributeId = $editor->getAttribute()->id; |
| 157 | + $this->attributeEditorMap[$attributeId] = $editor; |
| 158 | + } |
| 159 | + |
| 160 | + public function getEditorForAttributeId($attributeId) { |
| 161 | + if (isset($this->attributeEditorMap[$attributeId])) |
| 162 | + return $this->attributeEditorMap[$attributeId]; |
| 163 | + else |
| 164 | + return null; |
| 165 | + } |
| 166 | + |
| 167 | + public function getEditorForAttribute(Attribute $attribute) { |
| 168 | + return $this->getEditorForAttributeId($attribute->id); |
| 169 | + } |
| 170 | +} |
| 171 | + |
151 | 172 | /* XXX: Basic Editor class. */ |
152 | 173 | abstract class DefaultEditor implements Editor { |
153 | | - protected $editors = array(); |
| 174 | + protected $editors; |
| 175 | + protected $attributeEditorMap; |
154 | 176 | protected $attribute; |
155 | 177 | |
156 | 178 | public function __construct(Attribute $attribute = null) { |
157 | 179 | $this->attribute = $attribute; |
| 180 | + $this->editors = array(); |
| 181 | + $this->attributeEditorMap = new AttributeEditorMap(); |
158 | 182 | } |
159 | 183 | |
160 | 184 | public function addEditor(Editor $editor) { |
161 | 185 | $this->editors[] = $editor; |
| 186 | + $this->attributeEditorMap->addEditor($editor); |
162 | 187 | } |
163 | 188 | |
164 | 189 | public function getAttribute() { |
— | — | @@ -167,6 +192,10 @@ |
168 | 193 | public function getEditors() { |
169 | 194 | return $this->editors; |
170 | 195 | } |
| 196 | + |
| 197 | + public function getAttributeEditorMap() { |
| 198 | + return $this->attributeEditorMap; |
| 199 | + } |
171 | 200 | |
172 | 201 | public function getExpansionPrefix($class, $elementId) { |
173 | 202 | return '<span id="prefix-collapsed-' . $elementId . '" class="collapse-' . $class . '">+</span><span id="prefix-expanded-' . $elementId . '" class="expand-' . $class . '">–</span>' . EOL; |
— | — | @@ -255,7 +284,7 @@ |
256 | 285 | $relation = new ArrayRecordSet($addStructure, $addStructure); // TODO Determine real key |
257 | 286 | $values = array(); |
258 | 287 | |
259 | | - foreach($this->editors as $editor) |
| 288 | + foreach($this->getEditors() as $editor) |
260 | 289 | if ($attribute = $editor->getAddAttribute()) { |
261 | 290 | $idPath->pushAttribute($attribute); |
262 | 291 | $values[] = $editor->getAddValue($idPath); |
— | — | @@ -271,7 +300,7 @@ |
272 | 301 | } |
273 | 302 | |
274 | 303 | protected function saveRecord(IdStack $idPath, Record $record) { |
275 | | - foreach($this->editors as $editor) { |
| 304 | + foreach($this->getEditors() as $editor) { |
276 | 305 | $attribute = $editor->getAttribute(); |
277 | 306 | $value = $record->getAttributeValue($attribute); |
278 | 307 | $idPath->pushAttribute($attribute); |
— | — | @@ -304,7 +333,7 @@ |
305 | 334 | public function getStructure() { |
306 | 335 | $attributes = array(); |
307 | 336 | |
308 | | - foreach($this->editors as $editor) |
| 337 | + foreach($this->getEditors() as $editor) |
309 | 338 | $attributes[] = $editor->getAttribute(); |
310 | 339 | |
311 | 340 | return new Structure($attributes); |
— | — | @@ -317,7 +346,7 @@ |
318 | 347 | protected function getUpdateStructure() { |
319 | 348 | $attributes = array(); |
320 | 349 | |
321 | | - foreach($this->editors as $editor) |
| 350 | + foreach($this->getEditors() as $editor) |
322 | 351 | if ($updateAttribute = $editor->getUpdateAttribute()) |
323 | 352 | $attributes[] = $updateAttribute; |
324 | 353 | |
— | — | @@ -327,7 +356,7 @@ |
328 | 357 | protected function getAddStructure() { |
329 | 358 | $attributes = array(); |
330 | 359 | |
331 | | - foreach($this->editors as $editor) |
| 360 | + foreach($this->getEditors() as $editor) |
332 | 361 | if ($addAttribute = $editor->getAddAttribute()) |
333 | 362 | $attributes[] = $addAttribute; |
334 | 363 | |
— | — | @@ -337,7 +366,7 @@ |
338 | 367 | protected function getUpdateEditors() { |
339 | 368 | $updateEditors = array(); |
340 | 369 | |
341 | | - foreach($this->editors as $editor) |
| 370 | + foreach($this->getEditors() as $editor) |
342 | 371 | if ($editor->getUpdateAttribute()) |
343 | 372 | $updateEditors[] = $editor; |
344 | 373 | |
— | — | @@ -347,7 +376,7 @@ |
348 | 377 | protected function getAddEditors() { |
349 | 378 | $addEditors = array(); |
350 | 379 | |
351 | | - foreach($this->editors as $editor) |
| 380 | + foreach($this->getEditors() as $editor) |
352 | 381 | if ($editor->getAddAttribute()) |
353 | 382 | $addEditors[] = $editor; |
354 | 383 | |
— | — | @@ -470,55 +499,56 @@ |
471 | 500 | |
472 | 501 | return $result; |
473 | 502 | } |
| 503 | + |
| 504 | + public function getTableStructure(Editor $editor) { |
| 505 | + $attributes = array(); |
474 | 506 | |
475 | | - protected function getColumnEditorsShowingData(Editor $editor, $value, $attributePath = array()) { |
476 | | - $result = array(); |
477 | | - |
| 507 | + foreach($editor->getEditors() as $childEditor) { |
| 508 | + $childAttribute = $childEditor->getAttribute(); |
| 509 | + |
| 510 | + if ($childEditor instanceof RecordTableCellEditor) |
| 511 | + $type = $this->getTableStructure($childEditor); |
| 512 | + else |
| 513 | + $type = 'short-text'; |
| 514 | + |
| 515 | + $attributes[] = new Attribute($childAttribute->id, $childAttribute->name, $type); |
| 516 | + } |
| 517 | + |
| 518 | + return new Structure($attributes); |
| 519 | + } |
| 520 | + |
| 521 | + protected function getTableStructureShowingData(Editor $editor, $value, $attributePath = array()) { |
| 522 | + $attributes = array(); |
| 523 | + |
478 | 524 | foreach ($editor->getEditors() as $childEditor) { |
479 | | - array_push($attributePath, $childEditor->getAttribute()); |
| 525 | + $childAttribute = $childEditor->getAttribute(); |
| 526 | + array_push($attributePath, $childAttribute); |
480 | 527 | |
481 | | - if ($childEditor instanceof RecordTableCellEditor) { |
482 | | - $visibleChildColumnEditors = $this->getColumnEditorsShowingData($childEditor, $value, $attributePath); |
| 528 | + if ($childEditor instanceof RecordTableCellEditor) { |
| 529 | + $type = $this->getTableStructureShowingData($childEditor, $value, $attributePath); |
483 | 530 | |
484 | | - if (count($visibleChildColumnEditors) > 0) { |
485 | | - $result[] = $childEditor; |
486 | | - $result = array_merge($result, $visibleChildColumnEditors); |
487 | | - } |
| 531 | + if (count($type->getAttributes()) > 0) |
| 532 | + $attributes[] = new Attribute($childAttribute->id, $childAttribute->name, $type); |
488 | 533 | } |
489 | 534 | else if ($this->columnShowsData($childEditor, $value, $attributePath)) |
490 | | - $result[] = $childEditor; |
491 | | - |
| 535 | + $attributes[] = new Attribute($childAttribute->id, $childAttribute->name, 'short-text'); |
| 536 | + |
492 | 537 | array_pop($attributePath); |
493 | | - } |
494 | | - |
495 | | - return $result; |
| 538 | + } |
| 539 | + |
| 540 | + return new Structure($attributes); |
496 | 541 | } |
497 | | - |
498 | | - public function getAllColumnEditors(Editor $editor) { |
499 | | - $result = array(); |
500 | | - |
501 | | - foreach ($editor->getEditors() as $childEditor) { |
502 | | - if ($childEditor instanceof RecordTableCellEditor) { |
503 | | - $result[] = $childEditor; |
504 | | - $result = array_merge($result, $this->getAllColumnEditors($childEditor)); |
505 | | - } |
506 | | - else |
507 | | - $result[] = $childEditor; |
508 | | - } |
509 | | - |
510 | | - return $result; |
511 | | - } |
512 | 542 | |
513 | | - public function viewHeader(IdStack $idPath, array $visibleColumnEditors) { |
| 543 | + public function viewHeader(IdStack $idPath, Structure $visibleStructure) { |
514 | 544 | $result = '<table id="'. $idPath->getId() .'" class="wiki-data-table">'; |
515 | 545 | |
516 | | - foreach (getStructureAsTableHeaderRows($this->getTableStructure($this, $visibleColumnEditors), 0, $idPath) as $headerRow) |
| 546 | + foreach (getStructureAsTableHeaderRows($visibleStructure, 0, $idPath) as $headerRow) |
517 | 547 | $result .= '<tr>' . $headerRow . '</tr>'.EOL; |
518 | 548 | |
519 | 549 | return $result; |
520 | 550 | } |
521 | 551 | |
522 | | - public function viewRows(IdStack $idPath, $value, array $visibleColumnEditors) { |
| 552 | + public function viewRows(IdStack $idPath, $value, Structure $visibleStructure) { |
523 | 553 | $result = ""; |
524 | 554 | $rowAttributes = $this->getRowAttributesText(); |
525 | 555 | $key = $value->getKey(); |
— | — | @@ -529,7 +559,7 @@ |
530 | 560 | $idPath->pushKey(project($record, $key)); |
531 | 561 | $result .= |
532 | 562 | '<tr id="'. $idPath->getId() .'" '. $rowAttributes . '>' . |
533 | | - getRecordAsTableCells($idPath, $this, $visibleColumnEditors, $record) . |
| 563 | + getRecordAsTableCells($idPath, $this, $visibleStructure, $record) . |
534 | 564 | '</tr>'.EOL; |
535 | 565 | |
536 | 566 | $idPath->popKey(); |
— | — | @@ -538,24 +568,24 @@ |
539 | 569 | return $result; |
540 | 570 | } |
541 | 571 | |
542 | | - public function viewFooter(IdStack $idPath, array $visibleColumnEditors) { |
| 572 | + public function viewFooter(IdStack $idPath, Structure $visibleStructure) { |
543 | 573 | return '</table>' . EOL; |
544 | 574 | } |
545 | 575 | |
546 | | - public function getVisibleColumnEditorsForView($value) { |
| 576 | + public function getTableStructureForView($value) { |
547 | 577 | if ($this->hideEmptyColumns) |
548 | | - return $this->getColumnEditorsShowingData($this, $value); |
| 578 | + return $this->getTableStructureShowingData($this, $value); |
549 | 579 | else |
550 | | - return $this->getAllColumnEditors($this); |
| 580 | + return $this->getTableStructure($this); |
551 | 581 | } |
552 | 582 | |
553 | 583 | public function view(IdStack $idPath, $value) { |
554 | | - $visibleColumnEditors = $this->getVisibleColumnEditorsForView($value); |
| 584 | + $visibleStructure = $this->getTableStructureForView($value); |
555 | 585 | |
556 | 586 | $result = |
557 | | - $this->viewHeader($idPath, $visibleColumnEditors) . |
558 | | - $this->viewRows($idPath, $value, $visibleColumnEditors) . |
559 | | - $this->viewFooter($idPath, $visibleColumnEditors); |
| 587 | + $this->viewHeader($idPath, $visibleStructure) . |
| 588 | + $this->viewRows($idPath, $value, $visibleStructure) . |
| 589 | + $this->viewFooter($idPath, $visibleStructure); |
560 | 590 | |
561 | 591 | return $result; |
562 | 592 | } |
— | — | @@ -567,9 +597,9 @@ |
568 | 598 | $result = '<table id="'. $idPath->getId() .'" class="wiki-data-table">'; |
569 | 599 | $key = $value->getKey(); |
570 | 600 | $rowAttributes = $this->getRowAttributesText(); |
571 | | - $visibleColumnEditors = $this->getAllColumnEditors($this); |
| 601 | + $visibleStructure = $this->getTableStructure($this); |
572 | 602 | $columnOffset = $this->allowRemove ? 1 : 0; |
573 | | - $headerRows = getStructureAsTableHeaderRows($this->getTableStructure($this, $visibleColumnEditors), $columnOffset, $idPath); |
| 603 | + $headerRows = getStructureAsTableHeaderRows($this->getTableStructure($this), $columnOffset, $idPath); |
574 | 604 | |
575 | 605 | if ($this->allowRemove) |
576 | 606 | $headerRows[0] = '<th class="remove" rowspan="' . count($headerRows) . '"><img src="'.$wgStylePath.'/amethyst/delete.png" title="Mark rows to remove" alt="Remove"/></th>' . $headerRows[0]; |
— | — | @@ -599,7 +629,7 @@ |
600 | 630 | if ($this->permissionController->allowUpdateOfValue($idPath, $record)) |
601 | 631 | $result .= getRecordAsEditTableCells($record, $idPath, $this); |
602 | 632 | else |
603 | | - $result .= getRecordAsTableCells($idPath, $this, $visibleColumnEditors, $record); |
| 633 | + $result .= getRecordAsTableCells($idPath, $this, $visibleStructure, $record); |
604 | 634 | |
605 | 635 | $idPath->popKey(); |
606 | 636 | |
— | — | @@ -660,25 +690,6 @@ |
661 | 691 | return $result . '</tr>' . EOL; |
662 | 692 | } |
663 | 693 | |
664 | | - public function getTableStructure(Editor $editor, $visibleColumnEditors) { |
665 | | - $attributes = array(); |
666 | | - |
667 | | - foreach($editor->getEditors() as $childEditor) { |
668 | | - if (in_array($childEditor, $visibleColumnEditors, true)) { |
669 | | - $childAttribute = $childEditor->getAttribute(); |
670 | | - |
671 | | - if ($childEditor instanceof RecordTableCellEditor) |
672 | | - $type = $this->getTableStructure($childEditor, $visibleColumnEditors); |
673 | | - else |
674 | | - $type = 'short-text'; |
675 | | - |
676 | | - $attributes[] = new Attribute($childAttribute->id, $childAttribute->name, $type); |
677 | | - } |
678 | | - } |
679 | | - |
680 | | - return new Structure($attributes); |
681 | | - } |
682 | | - |
683 | 694 | public function setHideEmptyColumns($hideEmptyColumns) { |
684 | 695 | $this->hideEmptyColumns = $hideEmptyColumns; |
685 | 696 | } |
— | — | @@ -688,7 +699,7 @@ |
689 | 700 | protected function getUpdateStructure() { |
690 | 701 | $attributes = array(); |
691 | 702 | |
692 | | - foreach($this->editors as $editor) |
| 703 | + foreach($this->getEditors() as $editor) |
693 | 704 | if ($updateAttribute = $editor->getUpdateAttribute()) |
694 | 705 | $attributes[] = $updateAttribute; |
695 | 706 | |
— | — | @@ -698,7 +709,7 @@ |
699 | 710 | protected function getAddStructure() { |
700 | 711 | $attributes = array(); |
701 | 712 | |
702 | | - foreach($this->editors as $editor) |
| 713 | + foreach($this->getEditors() as $editor) |
703 | 714 | if ($addAttribute = $editor->getAddAttribute()) |
704 | 715 | $attributes[] = $addAttribute; |
705 | 716 | |
— | — | @@ -708,7 +719,7 @@ |
709 | 720 | public function getUpdateValue(IdStack $idPath) { |
710 | 721 | $result = new ArrayRecord($this->getUpdateStructure()); |
711 | 722 | |
712 | | - foreach($this->editors as $editor) |
| 723 | + foreach($this->getEditors() as $editor) |
713 | 724 | if ($attribute = $editor->getUpdateAttribute()) { |
714 | 725 | $idPath->pushAttribute($attribute); |
715 | 726 | $result->setAttributeValue($attribute, $editor->getUpdateValue($idPath)); |
— | — | @@ -721,7 +732,7 @@ |
722 | 733 | public function getAddValue(IdStack $idPath) { |
723 | 734 | $result = new ArrayRecord($this->getAddStructure()); |
724 | 735 | |
725 | | - foreach($this->editors as $editor) |
| 736 | + foreach($this->getEditors() as $editor) |
726 | 737 | if ($attribute = $editor->getAddAttribute()) { |
727 | 738 | $idPath->pushAttribute($attribute); |
728 | 739 | $result->setAttributeValue($attribute, $editor->getAddValue($idPath)); |
— | — | @@ -750,7 +761,7 @@ |
751 | 762 | } |
752 | 763 | |
753 | 764 | public function save(IdStack $idPath, $value) { |
754 | | - foreach($this->editors as $editor) { |
| 765 | + foreach($this->getEditors() as $editor) { |
755 | 766 | $attribute = $editor->getAttribute(); |
756 | 767 | $idPath->pushAttribute($attribute); |
757 | 768 | $editor->save($idPath, $value->getAttributeValue($attribute)); |
— | — | @@ -761,9 +772,10 @@ |
762 | 773 | public function showsData($value) { |
763 | 774 | $result = true; |
764 | 775 | $i = 0; |
| 776 | + $childEditors = $this->getEditors(); |
765 | 777 | |
766 | | - while ($result && $i < count($this->editors)) { |
767 | | - $editor = $this->editors[$i]; |
| 778 | + while ($result && $i < count($childEditors)) { |
| 779 | + $editor = $childEditors[$i]; |
768 | 780 | $result = $editor->showsData($value->getAttributeValue($editor->getAttribute())); |
769 | 781 | $i++; |
770 | 782 | } |
— | — | @@ -1316,9 +1328,10 @@ |
1317 | 1329 | public function showsData($value) { |
1318 | 1330 | $i = 0; |
1319 | 1331 | $result = false; |
| 1332 | + $childEditors = $this->getEditors(); |
1320 | 1333 | |
1321 | | - while(!$result && $i < count($this->editors)) { |
1322 | | - $editor = $this->editors[$i]; |
| 1334 | + while(!$result && $i < count($childEditors)) { |
| 1335 | + $editor = $childEditors[$i]; |
1323 | 1336 | $attribute = $editor->getAttribute(); |
1324 | 1337 | $attributeValue = $value->getAttributeValue($attribute); |
1325 | 1338 | $result = $editor->showsData($attributeValue); |
— | — | @@ -1330,7 +1343,8 @@ |
1331 | 1344 | |
1332 | 1345 | public function view(IdStack $idPath, $value) { |
1333 | 1346 | $result = ''; |
1334 | | - foreach ($this->editors as $editor) { |
| 1347 | + |
| 1348 | + foreach ($this->getEditors() as $editor) { |
1335 | 1349 | $attribute = $editor->getAttribute(); |
1336 | 1350 | $idPath->pushAttribute($attribute); |
1337 | 1351 | $class = $idPath->getClass(); |
— | — | @@ -1353,7 +1367,7 @@ |
1354 | 1368 | |
1355 | 1369 | public function edit(IdStack $idPath, $value) { |
1356 | 1370 | $result = ''; |
1357 | | - foreach ($this->editors as $editor) { |
| 1371 | + foreach ($this->getEditors() as $editor) { |
1358 | 1372 | $attribute = $editor->getAttribute(); |
1359 | 1373 | $idPath->pushAttribute($attribute); |
1360 | 1374 | |
— | — | @@ -1373,7 +1387,7 @@ |
1374 | 1388 | |
1375 | 1389 | public function add(IdStack $idPath) { |
1376 | 1390 | $result = ''; |
1377 | | - foreach($this->editors as $editor) { |
| 1391 | + foreach($this->getEditors() as $editor) { |
1378 | 1392 | if ($attribute = $editor->getAddAttribute()) { |
1379 | 1393 | $idPath->pushAttribute($attribute); |
1380 | 1394 | $class = $idPath->getClass(); |
— | — | @@ -1524,6 +1538,10 @@ |
1525 | 1539 | public function getEditors() { |
1526 | 1540 | return $this->wrappedEditor->getEditors(); |
1527 | 1541 | } |
| 1542 | + |
| 1543 | + public function getAttributeEditorMap() { |
| 1544 | + return $this->wrappedEditor->getAttributeEditorMap(); |
| 1545 | + } |
1528 | 1546 | } |
1529 | 1547 | |
1530 | 1548 | class PopUpEditor extends WrappingEditor { |
— | — | @@ -1746,7 +1764,7 @@ |
1747 | 1765 | public function view(IdStack $idPath, $value) { |
1748 | 1766 | $fields = array(); |
1749 | 1767 | |
1750 | | - foreach($this->editors as $editor) { |
| 1768 | + foreach($this->getEditors() as $editor) { |
1751 | 1769 | $attribute = $editor->getAttribute(); |
1752 | 1770 | $idPath->pushAttribute($attribute); |
1753 | 1771 | $attributeValue = $editor->view($idPath, $value->getAttributeValue($attribute)); |
— | — | @@ -1768,7 +1786,7 @@ |
1769 | 1787 | public function add(IdStack $idPath) { |
1770 | 1788 | $fields = array(); |
1771 | 1789 | |
1772 | | - foreach($this->editors as $editor) { |
| 1790 | + foreach($this->getEditors() as $editor) { |
1773 | 1791 | if ($attribute = $editor->getAddAttribute()) { |
1774 | 1792 | $attribute = $editor->getAttribute(); |
1775 | 1793 | $idPath->pushAttribute($attribute); |
— | — | @@ -1785,7 +1803,7 @@ |
1786 | 1804 | public function edit(IdStack $idPath, $value) { |
1787 | 1805 | $fields = array(); |
1788 | 1806 | |
1789 | | - foreach($this->editors as $editor) { |
| 1807 | + foreach($this->getEditors() as $editor) { |
1790 | 1808 | $attribute = $editor->getAttribute(); |
1791 | 1809 | $idPath->pushAttribute($attribute); |
1792 | 1810 | $fields[] = $attribute->name . $this->valueSeparator. $editor->view($idPath, $value->getAttributeValue($attribute)); |
— | — | @@ -2169,75 +2187,4 @@ |
2170 | 2188 | public function showsData($value) { |
2171 | 2189 | return true; |
2172 | 2190 | } |
2173 | | -} |
2174 | | - |
2175 | | -class ObjectAttributeValuesEditor extends WrappingEditor { |
2176 | | - protected $recordSetTableEditor; |
2177 | | - protected $propertyEditor; |
2178 | | - protected $vslueEditor; |
2179 | | - |
2180 | | - public function __construct(Attribute $attribute = null) { |
2181 | | - parent::__construct(new RecordUnorderedListEditor($attribute, 5)); |
2182 | | - |
2183 | | - $this->recordSetTableEditor = new RecordSetTableEditor( |
2184 | | - $attribute, |
2185 | | - new SimplePermissionController(false), |
2186 | | - new ShowEditFieldChecker(true), |
2187 | | - new AllowAddController(false), |
2188 | | - false, |
2189 | | - false, |
2190 | | - null |
2191 | | - ); |
2192 | | - |
2193 | | - $propertyAttribute = new Attribute("property", "Property", "short-text"); |
2194 | | - $valueAttribute = new Attribute("value", "Value", "short-text"); |
2195 | | - |
2196 | | - $this->propertyEditor = new ShortTextEditor($propertyAttribute, new SimplePermissionController(false), false); |
2197 | | - $this->valueEditor = new ShortTextEditor($valueAttribute, new SimplePermissionController(false), false); |
2198 | | - |
2199 | | - $this->recordSetTableEditor->addEditor($this->propertyEditor); |
2200 | | - $this->recordSetTableEditor->addEditor($this->valueEditor); |
2201 | | - } |
2202 | | - |
2203 | | - public function addEditor(Editor $editor) { |
2204 | | - $this->wrappedEditor->addEditor($editor); |
2205 | | - $childEditors = $editor->getEditors(); |
2206 | | - |
2207 | | - for ($i = count($this->recordSetTableEditor->getEditors()); $i < count($childEditors); $i++) |
2208 | | - $this->recordSetTableEditor->addEditor($childEditors[$i]); |
2209 | | - } |
2210 | | - |
2211 | | - public function determineVisibleHeaders($value) { |
2212 | | - $result = array($this->propertyEditor, $this->valueEditor); |
2213 | | - |
2214 | | - foreach ($this->wrappedEditor->getEditors() as $editor) { |
2215 | | - $visibleEditors = $editor->getVisibleColumnEditorsForView($value->getAttributeValue($editor->getAttribute())); |
2216 | | - |
2217 | | - foreach ($visibleEditors as $visibleEditor) |
2218 | | - if (!in_array($visibleEditor, $result, true)) |
2219 | | - $result[] = $visibleEditor; |
2220 | | - } |
2221 | | - |
2222 | | - return $result; |
2223 | | - } |
2224 | | - |
2225 | | - public function view(IdStack $idPath, $value) { |
2226 | | - $visibleColumnEditors = $this->determineVisibleHeaders($value); |
2227 | | - $result = $this->recordSetTableEditor->viewHeader($idPath, $visibleColumnEditors); |
2228 | | - |
2229 | | - foreach ($this->wrappedEditor->getEditors() as $editor) { |
2230 | | - $attribute = $editor->getAttribute(); |
2231 | | - $idPath->pushAttribute($attribute); |
2232 | | - $result .= $editor->viewRows( |
2233 | | - $idPath, |
2234 | | - $value->getAttributeValue($attribute), |
2235 | | - $visibleColumnEditors |
2236 | | - ); |
2237 | | - $idPath->popAttribute(); |
2238 | | - } |
2239 | | - |
2240 | | - $result .= $this->recordSetTableEditor->viewFooter($idPath, $visibleColumnEditors); |
2241 | | - |
2242 | | - return $result; |
2243 | | - } |
2244 | | -} |
| 2191 | +} |
\ No newline at end of file |