Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php |
— | — | @@ -133,7 +133,7 @@ |
134 | 134 | global |
135 | 135 | $objectAttributesAttribute, $definedMeaningIdAttribute; |
136 | 136 | |
137 | | - $result = new RecordUnorderedListEditor($attribute, 5); |
| 137 | + $result = new ObjectAttributeValuesEditor($attribute); |
138 | 138 | |
139 | 139 | addObjectAttributesEditors( |
140 | 140 | $result, |
— | — | @@ -150,7 +150,7 @@ |
151 | 151 | global |
152 | 152 | $objectAttributesAttribute, $definedMeaningIdAttribute; |
153 | 153 | |
154 | | - $result = new RecordUnorderedListEditor($attribute, 5); |
| 154 | + $result = new ObjectAttributeValuesEditor($attribute); |
155 | 155 | |
156 | 156 | addObjectAttributesEditors( |
157 | 157 | $result, |
Index: trunk/extensions/Wikidata/OmegaWiki/Editor.php |
— | — | @@ -210,6 +210,7 @@ |
211 | 211 | } |
212 | 212 | |
213 | 213 | public function add(IdStack $idPath) { |
| 214 | + return ""; |
214 | 215 | } |
215 | 216 | |
216 | 217 | public function save(IdStack $idPath, $value) { |
— | — | @@ -493,13 +494,13 @@ |
494 | 495 | return $result; |
495 | 496 | } |
496 | 497 | |
497 | | - protected function getAllColumnEditors(Editor $editor, $value) { |
| 498 | + public function getAllColumnEditors(Editor $editor) { |
498 | 499 | $result = array(); |
499 | 500 | |
500 | 501 | foreach ($editor->getEditors() as $childEditor) { |
501 | 502 | if ($childEditor instanceof RecordTableCellEditor) { |
502 | 503 | $result[] = $childEditor; |
503 | | - $result = array_merge($result, $this->getAllColumnEditors($childEditor, $value)); |
| 504 | + $result = array_merge($result, $this->getAllColumnEditors($childEditor)); |
504 | 505 | } |
505 | 506 | else |
506 | 507 | $result[] = $childEditor; |
— | — | @@ -541,15 +542,15 @@ |
542 | 543 | return '</table>' . EOL; |
543 | 544 | } |
544 | 545 | |
545 | | - public function getVisibleColumnHeadersForView($value) { |
| 546 | + public function getVisibleColumnEditorsForView($value) { |
546 | 547 | if ($this->hideEmptyColumns) |
547 | 548 | return $this->getColumnEditorsShowingData($this, $value); |
548 | 549 | else |
549 | | - return $this->getAllColumnEditors($this, $value); |
| 550 | + return $this->getAllColumnEditors($this); |
550 | 551 | } |
551 | 552 | |
552 | 553 | public function view(IdStack $idPath, $value) { |
553 | | - $visibleColumnEditors = $this->getVisibleColumnHeadersForView($value); |
| 554 | + $visibleColumnEditors = $this->getVisibleColumnEditorsForView($value); |
554 | 555 | |
555 | 556 | $result = |
556 | 557 | $this->viewHeader($idPath, $visibleColumnEditors) . |
— | — | @@ -566,7 +567,7 @@ |
567 | 568 | $result = '<table id="'. $idPath->getId() .'" class="wiki-data-table">'; |
568 | 569 | $key = $value->getKey(); |
569 | 570 | $rowAttributes = $this->getRowAttributesText(); |
570 | | - $visibleColumnEditors = $this->getAllColumnEditors($this, $value); |
| 571 | + $visibleColumnEditors = $this->getAllColumnEditors($this); |
571 | 572 | $columnOffset = $this->allowRemove ? 1 : 0; |
572 | 573 | $headerRows = getStructureAsTableHeaderRows($this->getTableStructure($this, $visibleColumnEditors), $columnOffset, $idPath); |
573 | 574 | |
— | — | @@ -2170,4 +2171,73 @@ |
2171 | 2172 | } |
2172 | 2173 | } |
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 | + } |
2174 | 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 | +} |