Index: trunk/extensions/Wikidata/OmegaWiki/DefinedMeaning.php |
— | — | @@ -107,7 +107,9 @@ |
108 | 108 | $this->possiblySynonymousRelationTypeId, |
109 | 109 | $this->viewQueryTransactionInformation |
110 | 110 | ); |
111 | | - return $dmModel->getRecord(); |
| 111 | + $record=$dmModel->getRecord(); |
| 112 | + $record->finish("DefinedMeaning"); |
| 113 | + return $record; |
112 | 114 | } |
113 | 115 | |
114 | 116 | protected function save($referenceTransaction) { |
Index: trunk/extensions/Wikidata/OmegaWiki/RecordSet.php |
— | — | @@ -10,6 +10,8 @@ |
11 | 11 | public abstract function getKey(); |
12 | 12 | public abstract function getRecordCount(); |
13 | 13 | public abstract function getRecord($index); |
| 14 | + protected $type=null; |
| 15 | + protected $records; |
14 | 16 | # public function save(); # <- we first need to implement, then uncomment |
15 | 17 | /** |
16 | 18 | * @return carriage return separated list of values |
— | — | @@ -20,7 +22,8 @@ |
21 | 23 | |
22 | 24 | public function tostring_indent($depth=0,$key="",$myname="RecordSet") { |
23 | 25 | $rv="\n".str_pad("",$depth*8); |
24 | | - $rv.="$key:$myname {"; |
| 26 | + $type=$this->type; |
| 27 | + $rv.="$key:$myname(... $type) {"; |
25 | 28 | $rv2=$rv; |
26 | 29 | foreach ($this->records as $value) { |
27 | 30 | $rv=$rv2; |
— | — | @@ -39,8 +42,38 @@ |
40 | 43 | |
41 | 44 | return $rv; |
42 | 45 | } |
| 46 | + |
| 47 | + public function getType(){ |
| 48 | + return $this->type; |
| 49 | + } |
43 | 50 | |
| 51 | + public function setType($type) { |
| 52 | + $this->type=$type; |
| 53 | + } |
44 | 54 | |
| 55 | + /**only setType if it wasn't set yet |
| 56 | + * @param the type you would like to suggest |
| 57 | + * @returns the type this arrayset finally got |
| 58 | + */ |
| 59 | + public function suggestType($type) { |
| 60 | + if(is_null($this->type)) |
| 61 | + $this->setType($type); |
| 62 | + return $this->getType(); |
| 63 | + } |
| 64 | + |
| 65 | + public function finish($type) { |
| 66 | + $type=$this->suggestType($type); |
| 67 | + |
| 68 | + |
| 69 | + foreach ($this->records as $key=>$value) { |
| 70 | + $methods=get_class_methods(get_class($value)); |
| 71 | + if (!is_null($methods)) { |
| 72 | + if (in_array("finish",$methods)) { |
| 73 | + $value->finish($this->type); |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | + } |
45 | 78 | } |
46 | 79 | |
47 | 80 | class ArrayRecordSet extends RecordSet { |
Index: trunk/extensions/Wikidata/OmegaWiki/Record.php |
— | — | @@ -11,6 +11,7 @@ |
12 | 12 | class ArrayRecord implements Record { |
13 | 13 | protected $structure; |
14 | 14 | protected $values = array(); |
| 15 | + protected $type = null; |
15 | 16 | |
16 | 17 | public function __construct($structure) { |
17 | 18 | $this->structure = $structure; |
— | — | @@ -35,6 +36,36 @@ |
36 | 37 | $this->values[$attribute->id] = $value; |
37 | 38 | } |
38 | 39 | |
| 40 | + public function getType() { |
| 41 | + return $this->type; |
| 42 | + } |
| 43 | + |
| 44 | + public function setType($type) { |
| 45 | + $this->type=$type; |
| 46 | + } |
| 47 | + |
| 48 | + /**only setType if it wasn't set yet. |
| 49 | + *@param $type the type to set |
| 50 | + *@return the type that is actually used now. |
| 51 | + */ |
| 52 | + public function suggestType($type) { |
| 53 | + if(is_null($this->type)) |
| 54 | + $this->setType($type); |
| 55 | + return $this->getType(); |
| 56 | + } |
| 57 | + |
| 58 | + public function finish($type) { |
| 59 | + $type=$this->suggestType($type); |
| 60 | + |
| 61 | + foreach ($this->values as $key=>$value) { |
| 62 | + $methods=get_class_methods(get_class($value)); |
| 63 | + if (!is_null($methods)) { |
| 64 | + if (in_array("finish",$methods)) { |
| 65 | + $value->finish($key); |
| 66 | + } |
| 67 | + } |
| 68 | + } |
| 69 | + } |
39 | 70 | /** |
40 | 71 | * |
41 | 72 | * @param $values Array to write into the record, by order of the structure |
— | — | @@ -64,7 +95,8 @@ |
65 | 96 | |
66 | 97 | public function tostring_indent($depth=0,$key="") { |
67 | 98 | $rv="\n".str_pad("",$depth*8); |
68 | | - $rv.="$key:Record {"; |
| 99 | + $type=$this->type; |
| 100 | + $rv.="$key:ArrayRecord(..., $type) {"; |
69 | 101 | $rv2=$rv; |
70 | 102 | foreach ($this->values as $key=>$value) { |
71 | 103 | $rv=$rv2; |
— | — | @@ -73,8 +105,6 @@ |
74 | 106 | if (!is_null($methods)) { |
75 | 107 | if (in_array("tostring_indent",$methods)) { |
76 | 108 | $repr=$value->tostring_indent($depth+1,$key); |
77 | | - |
78 | | - |
79 | 109 | } |
80 | 110 | } |
81 | 111 | $rv.=$repr; |