1 | <?php |
||
14 | class Record { |
||
15 | |||
16 | /** |
||
17 | * The table that this record belongs to. |
||
18 | * |
||
19 | * @var Table |
||
20 | */ |
||
21 | protected $table; |
||
22 | |||
23 | /** |
||
24 | * The raw data of this database row. |
||
25 | * |
||
26 | * @var \stdClass |
||
27 | */ |
||
28 | protected $data; |
||
29 | |||
30 | /** |
||
31 | * The suffix that is added to foreign keys when we want to get their |
||
32 | * 'title' value instead of their raw integer (or whatever) form. |
||
33 | */ |
||
34 | const FKTITLE = 'FKTITLE'; |
||
35 | |||
36 | /** |
||
37 | * Create a new Record object. |
||
38 | * |
||
39 | * @param Table $table The table object. |
||
40 | * @param array $data The data of this record. |
||
41 | */ |
||
42 | public function __construct( $table, $data = array() ) { |
||
46 | |||
47 | /** |
||
48 | * Magic method to set one item in the data object. |
||
49 | * |
||
50 | * @param string $name The name of the column. |
||
51 | * @param mixed $value The value to set. |
||
52 | */ |
||
53 | public function __set( $name, $value ) { |
||
56 | |||
57 | /** |
||
58 | * Set multiple columns' values. |
||
59 | * |
||
60 | * @param mixed[] $data An array of column names to data values. |
||
61 | */ |
||
62 | public function set_multiple( $data ) { |
||
70 | |||
71 | /** |
||
72 | * Get a column's value. If suffixed with 'FKTITLE', then get the title of |
||
73 | * the foreign record (where applicable). |
||
74 | * |
||
75 | * @param string $name The column name. |
||
76 | * @param mixed [] $args Parameter not used. |
||
77 | * @return string|boolean |
||
78 | * @throws Exception If any arguments are passed (as there should never be any). |
||
79 | */ |
||
80 | public function __call( $name, $args ) { |
||
121 | |||
122 | /** |
||
123 | * Get a column of this record's table, optionally throwing an Exception if |
||
124 | * it doesn't exist. |
||
125 | * |
||
126 | * @param string $name The name of the column. |
||
127 | * @param boolean $required True if this should throw an Exception. |
||
128 | * @return \WordPress\Tabulate\DB\Column The column. |
||
129 | * @throws \Exception If the column named doesn't exist. |
||
130 | */ |
||
131 | protected function get_col( $name, $required = true ) { |
||
138 | |||
139 | /** |
||
140 | * Get a string representation of this record. |
||
141 | * |
||
142 | * @return string |
||
143 | */ |
||
144 | public function __toString() { |
||
147 | |||
148 | /** |
||
149 | * Get the value of this record's primary key, or false if it doesn't have |
||
150 | * one. |
||
151 | * |
||
152 | * @return string|false |
||
153 | */ |
||
154 | public function get_primary_key() { |
||
163 | |||
164 | /** |
||
165 | * Get the value of this Record's title column. |
||
166 | * |
||
167 | * @return string |
||
168 | */ |
||
169 | public function get_title() { |
||
183 | |||
184 | /** |
||
185 | * Get the record that is referenced by this one from the column given. |
||
186 | * |
||
187 | * @param string $column_name The name of the column. |
||
188 | * @return boolean|\WordPress\Tabulate\DB\Record |
||
189 | */ |
||
190 | public function get_referenced_record( $column_name ) { |
||
199 | |||
200 | /** |
||
201 | * Get a list of records that reference this record in one of their columns. |
||
202 | * |
||
203 | * @param string|\WordPress\Tabulate\DB\Table $foreign_table The foreign table. |
||
204 | * @param string|\WordPress\Tabulate\DB\Column $foreign_column The column in the foreign table that references this record's table. |
||
205 | * @param boolean $with_pagination Whether to only return the top N records. |
||
206 | * @return \WordPress\Tabulate\DB\Record[] |
||
207 | */ |
||
208 | public function get_referencing_records( $foreign_table, $foreign_column, $with_pagination = true ) { |
||
213 | |||
214 | /** |
||
215 | * Get an Admin Area URL. |
||
216 | * |
||
217 | * @param string $action The action. |
||
218 | * @param boolean $include_ident Whether to include the record Primary Key. |
||
219 | * @param string[] $extra_params Other parameters to append to the URL. |
||
220 | * @return string The URL. |
||
221 | */ |
||
222 | public function get_url( $action = 'index', $include_ident = true, $extra_params = false ) { |
||
237 | |||
238 | /** |
||
239 | * Get most recent changes. |
||
240 | * |
||
241 | * @return string[] |
||
242 | */ |
||
243 | public function get_changes() { |
||
257 | } |
||
258 |