Index: trunk/extensions/Wikidata/OmegaWiki/Editor.php |
— | — | @@ -412,21 +412,82 @@ |
413 | 413 | $this->rowHTMLAttributes = $rowHTMLAttributes; |
414 | 414 | } |
415 | 415 | |
| 416 | + protected function columnShowsData($columnEditor, $value, $attributePath) { |
| 417 | + $result = false; |
| 418 | + $recordCount = $value->getRecordCount(); |
| 419 | + $i = 0; |
| 420 | + |
| 421 | + while (!$result && $i < $recordCount) { |
| 422 | + $recordOrScalar = $value->getRecord($i); |
| 423 | + |
| 424 | + foreach ($attributePath as $attribute) |
| 425 | + $recordOrScalar = $recordOrScalar->getAttributeValue($attribute); |
| 426 | + |
| 427 | + $result = $columnEditor->showsData($recordOrScalar); |
| 428 | + $i++; |
| 429 | + } |
| 430 | + |
| 431 | + return $result; |
| 432 | + } |
| 433 | + |
| 434 | + protected function getColumnEditorsShowingData($editor, $value, $attributePath = array()) { |
| 435 | + $result = array(); |
| 436 | + |
| 437 | + foreach ($editor->getEditors() as $childEditor) { |
| 438 | + array_push($attributePath, $childEditor->getAttribute()); |
| 439 | + |
| 440 | + if ($childEditor instanceof RecordTableCellEditor) { |
| 441 | + $visibleChildColumnEditors = $this->getColumnEditorsShowingData($childEditor, $value, $attributePath); |
| 442 | + |
| 443 | + if (count($visibleChildColumnEditors) > 0) { |
| 444 | + $result[] = $childEditor; |
| 445 | + $result = array_merge($result, $visibleChildColumnEditors); |
| 446 | + } |
| 447 | + } |
| 448 | + else if ($this->columnShowsData($childEditor, $value, $attributePath)) |
| 449 | + $result[] = $childEditor; |
| 450 | + |
| 451 | + array_pop($attributePath); |
| 452 | + } |
| 453 | + |
| 454 | + return $result; |
| 455 | + } |
| 456 | + |
| 457 | + protected function getAllColumnEditors($editor, $value) { |
| 458 | + $result = array(); |
| 459 | + |
| 460 | + foreach ($editor->getEditors() as $childEditor) { |
| 461 | + if ($childEditor instanceof RecordTableCellEditor) { |
| 462 | + $result[] = $childEditor; |
| 463 | + $result = array_merge($result, $this->getAllColumnEditors($childEditor, $value)); |
| 464 | + } |
| 465 | + else |
| 466 | + $result[] = $childEditor; |
| 467 | + } |
| 468 | + |
| 469 | + return $result; |
| 470 | + } |
| 471 | + |
416 | 472 | public function view($idPath, $value) { |
417 | 473 | $result = '<table id="'. $idPath->getId() .'" class="wiki-data-table">'; |
418 | 474 | $structure = $value->getStructure(); |
419 | 475 | $key = $value->getKey(); |
420 | 476 | $rowAttributes = $this->getRowAttributesText(); |
| 477 | + $visibleColumnEditors = $this->getColumnEditorsShowingData($this, $value); |
421 | 478 | |
422 | | - foreach(getStructureAsTableHeaderRows($this->getTableStructure($this), 0, $idPath) as $headerRow) |
| 479 | + foreach (getStructureAsTableHeaderRows($this->getTableStructure($this, $visibleColumnEditors), 0, $idPath) as $headerRow) |
423 | 480 | $result .= '<tr>' . $headerRow . '</tr>'.EOL; |
424 | 481 | |
425 | 482 | $recordCount = $value->getRecordCount(); |
426 | 483 | |
427 | | - for($i = 0; $i < $recordCount; $i++) { |
| 484 | + for ($i = 0; $i < $recordCount; $i++) { |
428 | 485 | $record = $value->getRecord($i); |
429 | 486 | $idPath->pushKey(project($record, $key)); |
430 | | - $result .= '<tr id="'. $idPath->getId() .'" '. $rowAttributes . '>' . getRecordAsTableCells($idPath, $this, $record) .'</tr>'.EOL; |
| 487 | + $result .= |
| 488 | + '<tr id="'. $idPath->getId() .'" '. $rowAttributes . '>' . |
| 489 | + getRecordAsTableCells($idPath, $this, $visibleColumnEditors, $record) . |
| 490 | + '</tr>'.EOL; |
| 491 | + |
431 | 492 | $idPath->popKey(); |
432 | 493 | } |
433 | 494 | |
— | — | @@ -442,15 +503,11 @@ |
443 | 504 | $result = '<table id="'. $idPath->getId() .'" class="wiki-data-table">'; |
444 | 505 | $key = $value->getKey(); |
445 | 506 | $rowAttributes = $this->getRowAttributesText(); |
| 507 | + $visibleColumnEditors = $this->getAllColumnEditors($this, $value); |
| 508 | + $columnOffset = $this->allowRemove ? 1 : 0; |
| 509 | + $headerRows = getStructureAsTableHeaderRows($this->getTableStructure($this, $visibleColumnEditors), $columnOffset, $idPath); |
446 | 510 | |
447 | 511 | if ($this->allowRemove) |
448 | | - $columnOffset = 1; |
449 | | - else |
450 | | - $columnOffset = 0; |
451 | | - |
452 | | - $headerRows = getStructureAsTableHeaderRows($this->getTableStructure($this), $columnOffset, $idPath); |
453 | | - |
454 | | - if ($this->allowRemove) |
455 | 512 | $headerRows[0] = '<th class="remove" rowspan="' . count($headerRows) . '"><img src="'.$wgStylePath.'/amethyst/delete.png" title="Mark rows to remove" alt="Remove"/></th>' . $headerRows[0]; |
456 | 513 | |
457 | 514 | if ($this->repeatInput) |
— | — | @@ -478,7 +535,7 @@ |
479 | 536 | if ($this->permissionController->allowUpdateOfValue($idPath, $record)) |
480 | 537 | $result .= getRecordAsEditTableCells($record, $idPath, $this); |
481 | 538 | else |
482 | | - $result .= getRecordAsTableCells($idPath, $this, $record); |
| 539 | + $result .= getRecordAsTableCells($idPath, $this, $visibleColumnEditors, $record); |
483 | 540 | |
484 | 541 | $idPath->popKey(); |
485 | 542 | |
— | — | @@ -539,18 +596,20 @@ |
540 | 597 | return $result . '</tr>' . EOL; |
541 | 598 | } |
542 | 599 | |
543 | | - public function getTableStructure($editor) { |
| 600 | + public function getTableStructure($editor, $visibleColumnEditors) { |
544 | 601 | $attributes = array(); |
545 | 602 | |
546 | 603 | foreach($editor->getEditors() as $childEditor) { |
547 | | - $childAttribute = $childEditor->getAttribute(); |
548 | | - |
549 | | - if ($childEditor instanceof RecordTableCellEditor) |
550 | | - $type = $this->getTableStructure($childEditor); |
551 | | - else |
552 | | - $type = 'short-text'; |
553 | | - |
554 | | - $attributes[] = new Attribute($childAttribute->id, $childAttribute->name, $type); |
| 604 | + if (in_array($childEditor, $visibleColumnEditors, true)) { |
| 605 | + $childAttribute = $childEditor->getAttribute(); |
| 606 | + |
| 607 | + if ($childEditor instanceof RecordTableCellEditor) |
| 608 | + $type = $this->getTableStructure($childEditor, $visibleColumnEditors); |
| 609 | + else |
| 610 | + $type = 'short-text'; |
| 611 | + |
| 612 | + $attributes[] = new Attribute($childAttribute->id, $childAttribute->name, $type); |
| 613 | + } |
555 | 614 | } |
556 | 615 | |
557 | 616 | return new Structure($attributes); |
— | — | @@ -632,7 +691,16 @@ |
633 | 692 | } |
634 | 693 | |
635 | 694 | public function showsData($value) { |
636 | | - return true; |
| 695 | + $result = true; |
| 696 | + $i = 0; |
| 697 | + |
| 698 | + while ($result && $i < count($this->editors)) { |
| 699 | + $editor = $this->editors[$i]; |
| 700 | + $result = $editor->showsData($value->getAttributeValue($editor->getAttribute())); |
| 701 | + $i++; |
| 702 | + } |
| 703 | + |
| 704 | + return $result; |
637 | 705 | } |
638 | 706 | |
639 | 707 | public function showEditField($idPath) { |
— | — | @@ -715,7 +783,7 @@ |
716 | 784 | } |
717 | 785 | |
718 | 786 | public function showsData($value) { |
719 | | - return true; |
| 787 | + return ($value != null) && (trim($value) != ""); |
720 | 788 | } |
721 | 789 | |
722 | 790 | public function showEditField($idPath) { |
— | — | @@ -725,7 +793,7 @@ |
726 | 794 | |
727 | 795 | class LanguageEditor extends ScalarEditor { |
728 | 796 | public function getViewHTML($idPath, $value) { |
729 | | - return languageIdAsText($value); |
| 797 | + return languageIdAsText($value); |
730 | 798 | } |
731 | 799 | |
732 | 800 | public function getEditHTML($idPath, $value) { |
— | — | @@ -742,6 +810,10 @@ |
743 | 811 | |
744 | 812 | return $wgRequest->getInt($id); |
745 | 813 | } |
| 814 | + |
| 815 | + public function showsData($value) { |
| 816 | + return ($value != null) && ($value != 0); |
| 817 | + } |
746 | 818 | } |
747 | 819 | |
748 | 820 | class SpellingEditor extends ScalarEditor { |
— | — | @@ -1161,16 +1233,18 @@ |
1162 | 1234 | } |
1163 | 1235 | |
1164 | 1236 | public function showsData($value) { |
1165 | | - $index = 0; |
1166 | | - $showsData = false; |
1167 | | - while($index < count($this->editors) && !$showsData) { |
1168 | | - $editor = $this->editors[$index]; |
| 1237 | + $i = 0; |
| 1238 | + $result = false; |
| 1239 | + |
| 1240 | + while(!$result && $i < count($this->editors)) { |
| 1241 | + $editor = $this->editors[$i]; |
1169 | 1242 | $attribute = $editor->getAttribute(); |
1170 | 1243 | $attributeValue = $value->getAttributeValue($attribute); |
1171 | | - $showsData = $editor->showsData($attributeValue); |
1172 | | - $index += 1; |
| 1244 | + $result = $editor->showsData($attributeValue); |
| 1245 | + $i++; |
1173 | 1246 | } |
1174 | | - return $showsData; |
| 1247 | + |
| 1248 | + return $result; |
1175 | 1249 | } |
1176 | 1250 | |
1177 | 1251 | public function view($idPath, $value) { |
Index: trunk/extensions/Wikidata/OmegaWiki/Wikidata.php |
— | — | @@ -593,8 +593,8 @@ |
594 | 594 | return $this->dataset; |
595 | 595 | } |
596 | 596 | |
597 | | - public function setLanguageId($langaugeId) { |
598 | | - $this->langaugeId=$languageId; |
| 597 | + public function setLanguageId($languageId) { |
| 598 | + $this->languageId = $languageId; |
599 | 599 | } |
600 | 600 | |
601 | 601 | public function getLanguageId() { |
Index: trunk/extensions/Wikidata/OmegaWiki/HTMLtable.php |
— | — | @@ -113,28 +113,27 @@ |
114 | 114 | return $type; |
115 | 115 | } |
116 | 116 | |
117 | | -function getRecordAsTableCells($idPath, $editor, $record, &$startColumn = 0) { |
| 117 | +function getRecordAsTableCells($idPath, $editor, $visibleColumnEditors, $record, &$startColumn = 0) { |
118 | 118 | $result = ''; |
119 | 119 | |
120 | | - foreach($editor->getEditors() as $childEditor) { |
121 | | - $attribute = $childEditor->getAttribute(); |
122 | | - $type = $attribute->type; |
123 | | - $value = $record->getAttributeValue($attribute); |
124 | | - $idPath->pushAttribute($attribute); |
125 | | - $attributeId = $idPath->getId(); |
126 | | - |
127 | | - if ($childEditor instanceof RecordTableCellEditor) |
128 | | - $result .= getRecordAsTableCells($idPath, $childEditor, $value, $startColumn); |
129 | | - else { |
130 | | - if($childEditor->showsData($value)) |
131 | | - $displayValue = $childEditor->view($idPath, $value); |
132 | | - else |
133 | | - $displayValue = ""; |
134 | | - $result .= '<td class="'. getHTMLClassForType($type,$attribute) .' column-'. parityClass($startColumn) . '">'. $displayValue . '</td>'; |
135 | | - $startColumn++; |
| 120 | + foreach ($editor->getEditors() as $childEditor) { |
| 121 | + if (in_array($childEditor, $visibleColumnEditors, true)) { |
| 122 | + $attribute = $childEditor->getAttribute(); |
| 123 | + $type = $attribute->type; |
| 124 | + $value = $record->getAttributeValue($attribute); |
| 125 | + $idPath->pushAttribute($attribute); |
| 126 | + $attributeId = $idPath->getId(); |
| 127 | + |
| 128 | + if ($childEditor instanceof RecordTableCellEditor) |
| 129 | + $result .= getRecordAsTableCells($idPath, $childEditor, $visibleColumnEditors, $value, $startColumn); |
| 130 | + else { |
| 131 | + $displayValue = $childEditor->showsData($value) ? $childEditor->view($idPath, $value) : ""; |
| 132 | + $result .= '<td class="'. getHTMLClassForType($type,$attribute) .' column-'. parityClass($startColumn) . '">'. $displayValue . '</td>'; |
| 133 | + $startColumn++; |
| 134 | + } |
| 135 | + |
| 136 | + $idPath->popAttribute(); |
136 | 137 | } |
137 | | - |
138 | | - $idPath->popAttribute(); |
139 | 138 | } |
140 | 139 | |
141 | 140 | return $result; |