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 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * http://www.gnu.org/copyleft/gpl.html
28 * @licence GNU GPL v2 or later
29 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
40 * @param IORMTable $table
41 * @param array|null $fields
42 * @param boolean $loadDefaults
44 public function __construct( IORMTable
$table, $fields = null, $loadDefaults = false );
47 * Load the specified fields from the database.
51 * @param array|null $fields
52 * @param boolean $override
53 * @param boolean $skipLoaded
55 * @return bool Success indicator
57 public function loadFields( $fields = null, $override = true, $skipLoaded = false );
60 * Gets the value of a field.
65 * @param mixed $default
70 public function getField( $name, $default = null );
73 * Gets the value of a field but first loads it if not done so already.
81 public function loadAndGetField( $name );
90 public function removeField( $name );
93 * Returns the objects database id.
97 * @return integer|null
99 public function getId();
102 * Sets the objects database id.
106 * @param integer|null $id
108 public function setId( $id );
111 * Gets if a certain field is set.
115 * @param string $name
119 public function hasField( $name );
122 * Gets if the id field is set.
128 public function hasIdField();
131 * Sets multiple fields.
135 * @param array $fields The fields to set
136 * @param boolean $override Override already set fields with the provided values?
138 public function setFields( array $fields, $override = true );
141 * Serializes the object to an associative array which
142 * can then easily be converted into JSON or similar.
146 * @param null|array $fields
147 * @param boolean $incNullId
151 public function toArray( $fields = null, $incNullId = false );
154 * Load the default values, via getDefaults.
158 * @param boolean $override
160 public function loadDefaults( $override = true );
163 * Writes the answer to the database, either updating it
164 * when it already exists, or inserting it when it doesn't.
168 * @param string|null $functionName
170 * @return boolean Success indicator
172 public function save( $functionName = null );
175 * Removes the object from the database.
179 * @return boolean Success indicator
181 public function remove();
184 * Return the names and values of the fields.
190 public function getFields();
193 * Return the names of the fields.
199 public function getSetFieldNames();
202 * Sets the value of a field.
203 * Strings can be provided for other types,
204 * so this method can be called from unserialization handlers.
208 * @param string $name
209 * @param mixed $value
211 * @throws MWException
213 public function setField( $name, $value );
216 * Add an amount (can be negative) to the specified field (needs to be numeric).
217 * TODO: most off this stuff makes more sense in the table class
221 * @param string $field
222 * @param integer $amount
224 * @return boolean Success indicator
226 public function addToField( $field, $amount );
229 * Return the names of the fields.
235 public function getFieldNames();
238 * Computes and updates the values of the summary fields.
242 * @param array|string|null $summaryFields
244 public function loadSummaryFields( $summaryFields = null );
247 * Sets the value for the @see $updateSummaries field.
251 * @param boolean $update
253 public function setUpdateSummaries( $update );
256 * Sets the value for the @see $inSummaryMode field.
260 * @param boolean $summaryMode
262 public function setSummaryMode( $summaryMode );
265 * Returns the table this IORMRow is a row in.
271 public function getTable();