Index: trunk/extensions/Wikidata/OmegaWiki/PropertyToColumnFilter.php |
— | — | @@ -4,6 +4,7 @@ |
5 | 5 | |
6 | 6 | interface AttributeIDFilter { |
7 | 7 | public function filter(array $attributeIDs); |
| 8 | + public function leavesOnlyOneOption(); |
8 | 9 | } |
9 | 10 | |
10 | 11 | class IncludeAttributeIDsFilter implements AttributeIDFilter { |
— | — | @@ -22,6 +23,10 @@ |
23 | 24 | |
24 | 25 | return $result; |
25 | 26 | } |
| 27 | + |
| 28 | + public function leavesOnlyOneOption() { |
| 29 | + return count($this->attributeIDsToInclude) == 1; |
| 30 | + } |
26 | 31 | } |
27 | 32 | |
28 | 33 | class ExcludeAttributeIDsFilter implements AttributeIDFilter { |
— | — | @@ -40,6 +45,10 @@ |
41 | 46 | |
42 | 47 | return $result; |
43 | 48 | } |
| 49 | + |
| 50 | + public function leavesOnlyOneOption() { |
| 51 | + return false; |
| 52 | + } |
44 | 53 | } |
45 | 54 | |
46 | 55 | /** |
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php |
— | — | @@ -24,12 +24,14 @@ |
25 | 25 | protected $valueAttribute; |
26 | 26 | protected $attributeIDFilter; |
27 | 27 | protected $levelName; |
| 28 | + protected $showPropertyColumn; |
28 | 29 | |
29 | 30 | public function __construct(Attribute $attribute, $propertyCaption, $valueCaption, ViewInformation $viewInformation, $levelName, AttributeIDFilter $attributeIDFilter) { |
30 | 31 | parent::__construct(new RecordUnorderedListEditor($attribute, 5)); |
31 | 32 | |
32 | 33 | $this->levelName = $levelName; |
33 | 34 | $this->attributeIDFilter = $attributeIDFilter; |
| 35 | + $this->showPropertyColumn = !$attributeIDFilter->leavesOnlyOneOption(); |
34 | 36 | |
35 | 37 | $this->recordSetTableEditor = new RecordSetTableEditor( |
36 | 38 | $attribute, |
— | — | @@ -153,24 +155,28 @@ |
154 | 156 | $this->wrappedEditor->addEditor($editor); |
155 | 157 | } |
156 | 158 | |
157 | | - protected function getVisibleStructureForEditor(Editor $editor, array &$suffixAttributes) { |
| 159 | + protected function getVisibleStructureForEditor(Editor $editor, $showPropertyColumn, array &$suffixAttributes) { |
158 | 160 | $leadingAttributes = array(); |
159 | 161 | $childEditors = $editor->getEditors(); |
160 | 162 | |
161 | | - for ($i = 0; $i < 2; $i++) |
| 163 | + for ($i = $showPropertyColumn ? 0 : 1; $i < 2; $i++) |
162 | 164 | $leadingAttributes[] = $childEditors[$i]->getAttribute(); |
163 | 165 | |
164 | 166 | return new Structure(array_merge($leadingAttributes, $suffixAttributes)); |
165 | 167 | } |
166 | 168 | |
167 | 169 | public function view(IdStack $idPath, $value) { |
| 170 | + $visibleAttributes = array(); |
| 171 | + |
| 172 | + if ($this->showPropertyColumn) |
| 173 | + $visibleAttributes[] = $this->propertyAttribute; |
| 174 | + |
| 175 | + $visibleAttributes[] = $this->valueAttribute; |
| 176 | + |
168 | 177 | $idPath->pushAnnotationAttribute($this->getAttribute()); |
169 | 178 | $visibleSuffixAttributes = $this->determineVisibleSuffixAttributes($idPath, $value); |
170 | 179 | |
171 | | - $visibleStructure = new Structure(array_merge( |
172 | | - array($this->propertyAttribute, $this->valueAttribute), |
173 | | - $visibleSuffixAttributes |
174 | | - )); |
| 180 | + $visibleStructure = new Structure(array_merge($visibleAttributes, $visibleSuffixAttributes)); |
175 | 181 | |
176 | 182 | $result = $this->recordSetTableEditor->viewHeader($idPath, $visibleStructure); |
177 | 183 | |
— | — | @@ -180,7 +186,7 @@ |
181 | 187 | $result .= $editor->viewRows( |
182 | 188 | $idPath, |
183 | 189 | $value->getAttributeValue($attribute), |
184 | | - $this->getVisibleStructureForEditor($editor, $visibleSuffixAttributes) |
| 190 | + $this->getVisibleStructureForEditor($editor, $this->showPropertyColumn, $visibleSuffixAttributes) |
185 | 191 | ); |
186 | 192 | $idPath->popAttribute(); |
187 | 193 | } |
— | — | @@ -214,12 +220,16 @@ |
215 | 221 | $idPath->popAnnotationAttribute(); |
216 | 222 | } |
217 | 223 | |
218 | | - public function showEditField(IdStack $idPath) { |
| 224 | + protected function getAttributeOptionCount(IdStack $idPath) { |
219 | 225 | $classAttributes = $idPath->getClassAttributes()->filterClassAttributesOnLevel($this->getLevelName()); |
220 | 226 | $classAttributes = $this->getAttributeIDFilter()->filter($classAttributes); |
221 | 227 | |
222 | | - return count($classAttributes) > 0; |
| 228 | + return count($classAttributes); |
223 | 229 | } |
| 230 | + |
| 231 | + public function showEditField(IdStack $idPath) { |
| 232 | + return $this->getAttributeOptionCount($idPath) > 0; |
| 233 | + } |
224 | 234 | } |
225 | 235 | |
226 | 236 | class ShowEditFieldForAttributeValuesChecker extends ShowEditFieldChecker { |
Index: trunk/extensions/Wikidata/OmegaWiki/Editor.php |
— | — | @@ -2333,8 +2333,14 @@ |
2334 | 2334 | |
2335 | 2335 | class DefinedMeaningContextEditor extends WrappingEditor { |
2336 | 2336 | public function view(IdStack $idPath, $value) { |
2337 | | - $idPath->pushDefinedMeaningId($value->definedMeaningId); |
| 2337 | + $definedMeaningId = (int) $value->definedMeaningId; |
| 2338 | + |
| 2339 | + $idPath->pushDefinedMeaningId($definedMeaningId); |
| 2340 | + $idPath->pushClassAttributes(new ClassAttributes($definedMeaningId)); |
| 2341 | + |
2338 | 2342 | $result = $this->wrappedEditor->view($idPath, $value); |
| 2343 | + |
| 2344 | + $idPath->popClassAttributes(); |
2339 | 2345 | $idPath->popDefinedMeaningId(); |
2340 | 2346 | |
2341 | 2347 | return $result; |