Localisation updates from http://translatewiki.net.
[mediawiki.git] / includes / db / IORMTable.php
blob853e8cd253efa05d4c197740037acc8397a952e1
1 <?php
2 /**
3 * Interface for objects representing a single database table.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @since 1.20
22 * @file
23 * @ingroup ORM
25 * @licence GNU GPL v2 or later
26 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
29 interface IORMTable {
31 /**
32 * Returns the name of the database table objects of this type are stored in.
34 * @since 1.20
36 * @return string
38 public function getName();
40 /**
41 * Returns the name of a IORMRow implementing class that
42 * represents single rows in this table.
44 * @since 1.20
46 * @return string
48 public function getRowClass();
50 /**
51 * Returns an array with the fields and their types this object contains.
52 * This corresponds directly to the fields in the database, without prefix.
54 * field name => type
56 * Allowed types:
57 * * id
58 * * str
59 * * int
60 * * float
61 * * bool
62 * * array
63 * * blob
65 * @since 1.20
67 * @return array
69 public function getFields();
71 /**
72 * Returns a list of default field values.
73 * field name => field value
75 * @since 1.20
77 * @return array
79 public function getDefaults();
81 /**
82 * Returns a list of the summary fields.
83 * These are fields that cache computed values, such as the amount of linked objects of $type.
84 * This is relevant as one might not want to do actions such as log changes when these get updated.
86 * @since 1.20
88 * @return array
90 public function getSummaryFields();
92 /**
93 * Selects the the specified fields of the records matching the provided
94 * conditions and returns them as DBDataObject. Field names get prefixed.
96 * @since 1.20
98 * @param array|string|null $fields
99 * @param array $conditions
100 * @param array $options
101 * @param string|null $functionName
103 * @return ORMResult
105 public function select( $fields = null, array $conditions = array(),
106 array $options = array(), $functionName = null );
109 * Selects the the specified fields of the records matching the provided
110 * conditions and returns them as DBDataObject. Field names get prefixed.
112 * @since 1.20
114 * @param array|string|null $fields
115 * @param array $conditions
116 * @param array $options
117 * @param string|null $functionName
119 * @return array of self
121 public function selectObjects( $fields = null, array $conditions = array(),
122 array $options = array(), $functionName = null );
125 * Do the actual select.
127 * @since 1.20
129 * @param null|string|array $fields
130 * @param array $conditions
131 * @param array $options
132 * @param null|string $functionName
134 * @return ResultWrapper
136 public function rawSelect( $fields = null, array $conditions = array(),
137 array $options = array(), $functionName = null );
140 * Selects the the specified fields of the records matching the provided
141 * conditions and returns them as associative arrays.
142 * Provided field names get prefixed.
143 * Returned field names will not have a prefix.
145 * When $collapse is true:
146 * If one field is selected, each item in the result array will be this field.
147 * If two fields are selected, each item in the result array will have as key
148 * the first field and as value the second field.
149 * If more then two fields are selected, each item will be an associative array.
151 * @since 1.20
153 * @param array|string|null $fields
154 * @param array $conditions
155 * @param array $options
156 * @param boolean $collapse Set to false to always return each result row as associative array.
157 * @param string|null $functionName
159 * @return array of array
161 public function selectFields( $fields = null, array $conditions = array(),
162 array $options = array(), $collapse = true, $functionName = null );
165 * Selects the the specified fields of the first matching record.
166 * Field names get prefixed.
168 * @since 1.20
170 * @param array|string|null $fields
171 * @param array $conditions
172 * @param array $options
173 * @param string|null $functionName
175 * @return IORMRow|bool False on failure
177 public function selectRow( $fields = null, array $conditions = array(),
178 array $options = array(), $functionName = null );
181 * Selects the the specified fields of the records matching the provided
182 * conditions. Field names do NOT get prefixed.
184 * @since 1.20
186 * @param array $fields
187 * @param array $conditions
188 * @param array $options
189 * @param string|null $functionName
191 * @return ResultWrapper
193 public function rawSelectRow( array $fields, array $conditions = array(),
194 array $options = array(), $functionName = null );
197 * Selects the the specified fields of the first record matching the provided
198 * conditions and returns it as an associative array, or false when nothing matches.
199 * This method makes use of selectFields and expects the same parameters and
200 * returns the same results (if there are any, if there are none, this method returns false).
201 * @see IORMTable::selectFields
203 * @since 1.20
205 * @param array|string|null $fields
206 * @param array $conditions
207 * @param array $options
208 * @param boolean $collapse Set to false to always return each result row as associative array.
209 * @param string|null $functionName
211 * @return mixed|array|bool False on failure
213 public function selectFieldsRow( $fields = null, array $conditions = array(),
214 array $options = array(), $collapse = true, $functionName = null );
217 * Returns if there is at least one record matching the provided conditions.
218 * Condition field names get prefixed.
220 * @since 1.20
222 * @param array $conditions
224 * @return boolean
226 public function has( array $conditions = array() );
229 * Returns the amount of matching records.
230 * Condition field names get prefixed.
232 * Note that this can be expensive on large tables.
233 * In such cases you might want to use DatabaseBase::estimateRowCount instead.
235 * @since 1.20
237 * @param array $conditions
238 * @param array $options
240 * @return integer
242 public function count( array $conditions = array(), array $options = array() );
245 * Removes the object from the database.
247 * @since 1.20
249 * @param array $conditions
250 * @param string|null $functionName
252 * @return boolean Success indicator
254 public function delete( array $conditions, $functionName = null );
257 * Get API parameters for the fields supported by this object.
259 * @since 1.20
261 * @param boolean $requireParams
262 * @param boolean $setDefaults
264 * @return array
266 public function getAPIParams( $requireParams = false, $setDefaults = false );
269 * Returns an array with the fields and their descriptions.
271 * field name => field description
273 * @since 1.20
275 * @return array
277 public function getFieldDescriptions();
280 * Get the database type used for read operations.
282 * @since 1.20
284 * @return integer DB_ enum
286 public function getReadDb();
289 * Set the database type to use for read operations.
291 * @param integer $db
293 * @since 1.20
295 public function setReadDb( $db );
298 * Update the records matching the provided conditions by
299 * setting the fields that are keys in the $values param to
300 * their corresponding values.
302 * @since 1.20
304 * @param array $values
305 * @param array $conditions
307 * @return boolean Success indicator
309 public function update( array $values, array $conditions = array() );
312 * Computes the values of the summary fields of the objects matching the provided conditions.
314 * @since 1.20
316 * @param array|string|null $summaryFields
317 * @param array $conditions
319 public function updateSummaryFields( $summaryFields = null, array $conditions = array() );
322 * Takes in an associative array with field names as keys and
323 * their values as value. The field names are prefixed with the
324 * db field prefix.
326 * @since 1.20
328 * @param array $values
330 * @return array
332 public function getPrefixedValues( array $values );
335 * Takes in a field or array of fields and returns an
336 * array with their prefixed versions, ready for db usage.
338 * @since 1.20
340 * @param array|string $fields
342 * @return array
344 public function getPrefixedFields( array $fields );
347 * Takes in a field and returns an it's prefixed version, ready for db usage.
349 * @since 1.20
351 * @param string|array $field
353 * @return string
355 public function getPrefixedField( $field );
358 * Takes an array of field names with prefix and returns the unprefixed equivalent.
360 * @since 1.20
362 * @param array $fieldNames
364 * @return array
366 public function unprefixFieldNames( array $fieldNames );
369 * Takes a field name with prefix and returns the unprefixed equivalent.
371 * @since 1.20
373 * @param string $fieldName
375 * @return string
377 public function unprefixFieldName( $fieldName );
380 * Get an instance of this class.
382 * @since 1.20
384 * @return IORMTable
386 public static function singleton();
389 * Get an array with fields from a database result,
390 * that can be fed directly to the constructor or
391 * to setFields.
393 * @since 1.20
395 * @param stdClass $result
397 * @return array
399 public function getFieldsFromDBResult( stdClass $result );
402 * Get a new instance of the class from a database result.
404 * @since 1.20
406 * @param stdClass $result
408 * @return IORMRow
410 public function newFromDBResult( stdClass $result );
413 * Get a new instance of the class from an array.
415 * @since 1.20
417 * @param array $data
418 * @param boolean $loadDefaults
420 * @return IORMRow
422 public function newFromArray( array $data, $loadDefaults = false );
425 * Return the names of the fields.
427 * @since 1.20
429 * @return array
431 public function getFieldNames();
434 * Gets if the object can take a certain field.
436 * @since 1.20
438 * @param string $name
440 * @return boolean
442 public function canHaveField( $name );