Index: trunk/extensions/Wikidata/OmegaWiki/RecordSet.php |
— | — | @@ -5,15 +5,45 @@ |
6 | 6 | require_once('Attribute.php'); |
7 | 7 | require_once('Record.php'); |
8 | 8 | |
9 | | -interface RecordSet { |
10 | | - public function getStructure(); |
11 | | - public function getKey(); |
12 | | - public function getRecordCount(); |
13 | | - public function getRecord($index); |
| 9 | +abstract class RecordSet { |
| 10 | + public abstract function getStructure(); |
| 11 | + public abstract function getKey(); |
| 12 | + public abstract function getRecordCount(); |
| 13 | + public abstract function getRecord($index); |
14 | 14 | # public function save(); # <- we first need to implement, then uncomment |
| 15 | +/** |
| 16 | + * @return carriage return separated list of values |
| 17 | + */ |
| 18 | + public function __tostring() { |
| 19 | + return $this->tostring_indent(); |
| 20 | + } |
| 21 | + |
| 22 | + public function tostring_indent($depth=0,$key="",$myname="RecordSet") { |
| 23 | + $rv="\n".str_pad("",$depth*8); |
| 24 | + $rv.="$key:$myname {"; |
| 25 | + $rv2=$rv; |
| 26 | + foreach ($this->records as $value) { |
| 27 | + $rv=$rv2; |
| 28 | + $methods=get_class_methods(get_class($value)); |
| 29 | + if (!is_null($methods)) { |
| 30 | + if (in_array("tostring_indent",$methods)) { |
| 31 | + $value=$value->tostring_indent($depth+1); |
| 32 | + } |
| 33 | + } |
| 34 | + $rv.="$value"; |
| 35 | + |
| 36 | + $rv2=$rv; |
| 37 | + $rv2.=", "; |
| 38 | + } |
| 39 | + $rv.="}"; |
| 40 | + |
| 41 | + return $rv; |
| 42 | + } |
| 43 | + |
| 44 | + |
15 | 45 | } |
16 | 46 | |
17 | | -class ArrayRecordSet implements RecordSet { |
| 47 | +class ArrayRecordSet extends RecordSet { |
18 | 48 | protected $structure; |
19 | 49 | protected $key; |
20 | 50 | protected $records = array(); |
— | — | @@ -49,38 +79,14 @@ |
50 | 80 | public function getRecord($index) { |
51 | 81 | return $this->records[$index]; |
52 | 82 | } |
53 | | - |
54 | | - /** |
55 | | - * @return carriage return separated list of values |
56 | | - */ |
57 | | - public function __tostring() { |
58 | | - return $this->tostring_indent(); |
| 83 | + |
| 84 | + public function tostring_indent($depth=0,$key="",$myname="") { |
| 85 | + return parent::tostring_indent($depth,$key,$myname."_ArrayRecordSet"); |
59 | 86 | } |
60 | | - |
61 | | - public function tostring_indent($depth=0,$key="") { |
62 | | - $rv="\n".str_pad("",$depth*8); |
63 | | - $rv.="$key:ArrayRecordSet {"; |
64 | | - $rv2=$rv; |
65 | | - foreach ($this->records as $value) { |
66 | | - $rv=$rv2; |
67 | | - $methods=get_class_methods(get_class($value)); |
68 | | - if (!is_null($methods)) { |
69 | | - if (in_array("tostring_indent",$methods)) { |
70 | | - $value=$value->tostring_indent($depth+1); |
71 | | - } |
72 | | - } |
73 | | - $rv.="$value"; |
74 | 87 | |
75 | | - $rv2=$rv; |
76 | | - $rv2.=", "; |
77 | | - } |
78 | | - $rv.="}"; |
79 | | - |
80 | | - return $rv; |
81 | | - } |
82 | 88 | } |
83 | 89 | |
84 | | -class ConvertingRecordSet implements RecordSet { |
| 90 | +class ConvertingRecordSet extends RecordSet { |
85 | 91 | protected $relation; |
86 | 92 | protected $converters; |
87 | 93 | protected $structure; |
— | — | @@ -121,6 +127,10 @@ |
122 | 128 | |
123 | 129 | return new Structure($attributes); |
124 | 130 | } |
| 131 | + |
| 132 | + public function tostring_indent($depth=0,$key="",$myname="") { |
| 133 | + return parent::tostring_indent($depth,$key,$myname."_ConvertingRecordSet"); |
| 134 | + } |
125 | 135 | } |
126 | 136 | |
127 | 137 | function getRelationAsHTMLList($relation) { |