3 * Interface for representing objects that are stored in some DB table.
4 * This is basically an ORM-like wrapper around rows in database tables that
5 * aims to be both simple and very flexible. It is centered around an associative
6 * array of fields and various methods to do common interaction with the database.
8 * Documentation inline and at https://www.mediawiki.org/wiki/Manual:ORMTable
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 * http://www.gnu.org/copyleft/gpl.html
30 * @licence GNU GPL v2 or later
31 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
42 * @param IORMTable $table
43 * @param array|null $fields
44 * @param boolean $loadDefaults
46 public function __construct( IORMTable
$table, $fields = null, $loadDefaults = false );
49 * Load the specified fields from the database.
53 * @param array|null $fields
54 * @param boolean $override
55 * @param boolean $skipLoaded
57 * @return bool Success indicator
59 public function loadFields( $fields = null, $override = true, $skipLoaded = false );
62 * Gets the value of a field.
67 * @param mixed $default
72 public function getField( $name, $default = null );
75 * Gets the value of a field but first loads it if not done so already.
83 public function loadAndGetField( $name );
92 public function removeField( $name );
95 * Returns the objects database id.
99 * @return integer|null
101 public function getId();
104 * Sets the objects database id.
108 * @param integer|null $id
110 public function setId( $id );
113 * Gets if a certain field is set.
117 * @param string $name
121 public function hasField( $name );
124 * Gets if the id field is set.
130 public function hasIdField();
133 * Sets multiple fields.
137 * @param array $fields The fields to set
138 * @param boolean $override Override already set fields with the provided values?
140 public function setFields( array $fields, $override = true );
143 * Serializes the object to an associative array which
144 * can then easily be converted into JSON or similar.
148 * @param null|array $fields
149 * @param boolean $incNullId
153 public function toArray( $fields = null, $incNullId = false );
156 * Load the default values, via getDefaults.
160 * @param boolean $override
162 public function loadDefaults( $override = true );
165 * Writes the answer to the database, either updating it
166 * when it already exists, or inserting it when it doesn't.
170 * @param string|null $functionName
172 * @return boolean Success indicator
174 public function save( $functionName = null );
177 * Removes the object from the database.
181 * @return boolean Success indicator
183 public function remove();
186 * Return the names and values of the fields.
192 public function getFields();
195 * Return the names of the fields.
201 public function getSetFieldNames();
204 * Sets the value of a field.
205 * Strings can be provided for other types,
206 * so this method can be called from unserialization handlers.
210 * @param string $name
211 * @param mixed $value
213 * @throws MWException
215 public function setField( $name, $value );
218 * Add an amount (can be negative) to the specified field (needs to be numeric).
219 * TODO: most off this stuff makes more sense in the table class
223 * @param string $field
224 * @param integer $amount
226 * @return boolean Success indicator
228 public function addToField( $field, $amount );
231 * Return the names of the fields.
237 public function getFieldNames();
240 * Computes and updates the values of the summary fields.
244 * @param array|string|null $summaryFields
246 public function loadSummaryFields( $summaryFields = null );
249 * Sets the value for the @see $updateSummaries field.
253 * @param boolean $update
255 public function setUpdateSummaries( $update );
258 * Sets the value for the @see $inSummaryMode field.
262 * @param boolean $summaryMode
264 public function setSummaryMode( $summaryMode );
267 * Returns the table this IORMRow is a row in.
273 public function getTable();