Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like ORM often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ORM, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 42 | class ORM implements \ArrayAccess |
||
| 43 | { |
||
| 44 | |||
| 45 | // ----------------------- // |
||
| 46 | // --- CLASS CONSTANTS --- // |
||
| 47 | // ----------------------- // |
||
| 48 | |||
| 49 | // WHERE and HAVING condition array keys |
||
| 50 | const CONDITION_FRAGMENT = 0; |
||
| 51 | const CONDITION_VALUES = 1; |
||
| 52 | const DEFAULT_CONNECTION = 'default'; |
||
| 53 | |||
| 54 | // Limit clause style |
||
| 55 | const LIMIT_STYLE_TOP_N = 'top'; |
||
| 56 | const LIMIT_STYLE_LIMIT = 'limit'; |
||
| 57 | |||
| 58 | // ------------------------ // |
||
| 59 | // --- CLASS PROPERTIES --- // |
||
| 60 | // ------------------------ // |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Class configuration |
||
| 64 | * |
||
| 65 | * @var array |
||
| 66 | */ |
||
| 67 | protected static $_default_config = array( |
||
| 68 | 'connection_string' => 'sqlite::memory:', |
||
| 69 | 'id_column' => 'id', |
||
| 70 | 'id_column_overrides' => array(), |
||
| 71 | 'error_mode' => \PDO::ERRMODE_EXCEPTION, |
||
| 72 | 'username' => null, |
||
| 73 | 'password' => null, |
||
| 74 | 'driver_options' => null, |
||
| 75 | 'identifier_quote_character' => null, // if this is null, will be autodetected |
||
| 76 | 'limit_clause_style' => null, // if this is null, will be autodetected |
||
| 77 | 'logging' => false, |
||
| 78 | 'logger' => null, |
||
| 79 | 'caching' => false, |
||
| 80 | 'caching_auto_clear' => false, |
||
| 81 | 'return_result_sets' => false, |
||
| 82 | ); |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Map of configuration settings |
||
| 86 | * |
||
| 87 | * @var array |
||
| 88 | */ |
||
| 89 | protected static $_config = array(); |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Map of database connections, instances of the PDO class |
||
| 93 | * |
||
| 94 | * @var array |
||
| 95 | */ |
||
| 96 | protected static $_db = array(); |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Last query run, only populated if logging is enabled |
||
| 100 | * |
||
| 101 | * @var string |
||
| 102 | */ |
||
| 103 | protected static $_last_query; |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Log of all queries run, mapped by connection key, only populated if logging is enabled |
||
| 107 | * |
||
| 108 | * @var array |
||
| 109 | */ |
||
| 110 | protected static $_query_log = array(); |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Query cache, only used if query caching is enabled |
||
| 114 | * |
||
| 115 | * @var array |
||
| 116 | */ |
||
| 117 | protected static $_query_cache = array(); |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Reference to previously used PDOStatement object to enable low-level access, if needed |
||
| 121 | * |
||
| 122 | * @var null|\PDOStatement |
||
| 123 | */ |
||
| 124 | protected static $_last_statement = null; |
||
| 125 | |||
| 126 | // --------------------------- // |
||
| 127 | // --- INSTANCE PROPERTIES --- // |
||
| 128 | // --------------------------- // |
||
| 129 | |||
| 130 | /** |
||
| 131 | * Key name of the connections in static::$_db used by this instance |
||
| 132 | * |
||
| 133 | * @var string |
||
| 134 | */ |
||
| 135 | protected $_connection_name; |
||
| 136 | |||
| 137 | /** |
||
| 138 | * The name of the table the current ORM instance is associated with |
||
| 139 | * |
||
| 140 | * @var string |
||
| 141 | */ |
||
| 142 | protected $_table_name; |
||
| 143 | |||
| 144 | /** |
||
| 145 | * Alias for the table to be used in SELECT queries |
||
| 146 | * |
||
| 147 | * @var null|string |
||
| 148 | */ |
||
| 149 | protected $_table_alias = null; |
||
| 150 | |||
| 151 | /** |
||
| 152 | * Values to be bound to the query |
||
| 153 | * |
||
| 154 | * @var array |
||
| 155 | */ |
||
| 156 | protected $_values = array(); |
||
| 157 | |||
| 158 | /** |
||
| 159 | * Columns to select in the result |
||
| 160 | * |
||
| 161 | * @var array |
||
| 162 | */ |
||
| 163 | protected $_result_columns = array('*'); |
||
| 164 | |||
| 165 | /** |
||
| 166 | * Are we using the default result column or have these been manually changed? |
||
| 167 | * |
||
| 168 | * @var bool |
||
| 169 | */ |
||
| 170 | protected $_using_default_result_columns = true; |
||
| 171 | |||
| 172 | /** |
||
| 173 | * Join sources |
||
| 174 | * |
||
| 175 | * @var array |
||
| 176 | */ |
||
| 177 | protected $_join_sources = array(); |
||
| 178 | |||
| 179 | /** |
||
| 180 | * Should the query include a DISTINCT keyword? |
||
| 181 | * |
||
| 182 | * @var bool |
||
| 183 | */ |
||
| 184 | protected $_distinct = false; |
||
| 185 | |||
| 186 | /** |
||
| 187 | * Is this a raw query? |
||
| 188 | * |
||
| 189 | * @var bool |
||
| 190 | */ |
||
| 191 | protected $_is_raw_query = false; |
||
| 192 | |||
| 193 | /** |
||
| 194 | * The raw query |
||
| 195 | * |
||
| 196 | * @var string |
||
| 197 | */ |
||
| 198 | protected $_raw_query = ''; |
||
| 199 | |||
| 200 | /** |
||
| 201 | * The raw query parameters |
||
| 202 | * |
||
| 203 | * @var array |
||
| 204 | */ |
||
| 205 | protected $_raw_parameters = array(); |
||
| 206 | |||
| 207 | /** |
||
| 208 | * Array of WHERE clauses |
||
| 209 | * |
||
| 210 | * @var array |
||
| 211 | */ |
||
| 212 | protected $_where_conditions = array(); |
||
| 213 | |||
| 214 | /** |
||
| 215 | * LIMIT |
||
| 216 | * |
||
| 217 | * @var null|int |
||
| 218 | */ |
||
| 219 | protected $_limit = null; |
||
| 220 | |||
| 221 | /** |
||
| 222 | * OFFSET |
||
| 223 | * |
||
| 224 | * @var null|int |
||
| 225 | */ |
||
| 226 | protected $_offset = null; |
||
| 227 | |||
| 228 | /** |
||
| 229 | * ORDER BY |
||
| 230 | * |
||
| 231 | * @var array |
||
| 232 | */ |
||
| 233 | protected $_order_by = array(); |
||
| 234 | |||
| 235 | /** |
||
| 236 | * GROUP BY |
||
| 237 | * |
||
| 238 | * @var array |
||
| 239 | */ |
||
| 240 | protected $_group_by = array(); |
||
| 241 | |||
| 242 | /** |
||
| 243 | * HAVING |
||
| 244 | * |
||
| 245 | * @var array |
||
| 246 | */ |
||
| 247 | protected $_having_conditions = array(); |
||
| 248 | |||
| 249 | /** |
||
| 250 | * The data for a hydrated instance of the class |
||
| 251 | * |
||
| 252 | * @var array |
||
| 253 | */ |
||
| 254 | protected $_data = array(); |
||
| 255 | |||
| 256 | /** |
||
| 257 | * Fields that have been modified during the lifetime of the object |
||
| 258 | * |
||
| 259 | * @var array |
||
| 260 | */ |
||
| 261 | protected $_dirty_fields = array(); |
||
| 262 | |||
| 263 | /** |
||
| 264 | * Fields that are to be inserted in the DB raw |
||
| 265 | * |
||
| 266 | * @var array |
||
| 267 | */ |
||
| 268 | protected $_expr_fields = array(); |
||
| 269 | |||
| 270 | /** |
||
| 271 | * Is this a new object (has create() been called)? |
||
| 272 | * |
||
| 273 | * @var bool |
||
| 274 | */ |
||
| 275 | protected $_is_new = false; |
||
| 276 | |||
| 277 | /** |
||
| 278 | * Name of the column to use as the primary key for |
||
| 279 | * this instance only. Overrides the config settings. |
||
| 280 | * |
||
| 281 | * @var null|string |
||
| 282 | */ |
||
| 283 | protected $_instance_id_column = null; |
||
| 284 | |||
| 285 | /** |
||
| 286 | * Refresh cache for current query? |
||
| 287 | * |
||
| 288 | * @var bool |
||
| 289 | */ |
||
| 290 | protected $_refresh_cache = false; |
||
| 291 | |||
| 292 | /** |
||
| 293 | * Disable caching for current query? |
||
| 294 | * |
||
| 295 | * @var bool |
||
| 296 | */ |
||
| 297 | protected $_no_caching = false; |
||
| 298 | |||
| 299 | // ---------------------- // |
||
| 300 | // --- STATIC METHODS --- // |
||
| 301 | // ---------------------- // |
||
| 302 | |||
| 303 | /** |
||
| 304 | * Pass configuration settings to the class in the form of |
||
| 305 | * key/value pairs. As a shortcut, if the second argument |
||
| 306 | * is omitted and the key is a string, the setting is |
||
| 307 | * assumed to be the DSN string used by PDO to connect |
||
| 308 | * to the database (often, this will be the only configuration |
||
| 309 | * required to use Idiorm). If you have more than one setting |
||
| 310 | * you wish to configure, another shortcut is to pass an array |
||
| 311 | * of settings (and omit the second argument). |
||
| 312 | * |
||
| 313 | * @param string|array $key |
||
| 314 | * @param mixed $value |
||
| 315 | * @param string $connection_name Which connection to use |
||
| 316 | */ |
||
| 317 | 244 | public static function configure($key, $value = null, $connection_name = self::DEFAULT_CONNECTION) |
|
| 337 | |||
| 338 | /** |
||
| 339 | * Retrieve configuration options by key, or as whole array. |
||
| 340 | * |
||
| 341 | * @param string|null $key |
||
| 342 | * @param string $connection_name Which connection to use |
||
| 343 | * |
||
| 344 | * @return string|array |
||
| 345 | */ |
||
| 346 | 3 | public static function get_config($key = null, $connection_name = self::DEFAULT_CONNECTION) |
|
| 354 | |||
| 355 | /** |
||
| 356 | * Delete all configs in _config array. |
||
| 357 | */ |
||
| 358 | 156 | public static function reset_config() |
|
| 362 | |||
| 363 | /** |
||
| 364 | * Despite its slightly odd name, this is actually the factory |
||
| 365 | * method used to acquire instances of the class. It is named |
||
| 366 | * this way for the sake of a readable interface, ie |
||
| 367 | * ORM::for_table('table_name')->find_one()-> etc. As such, |
||
| 368 | * this will normally be the first method called in a chain. |
||
| 369 | * |
||
| 370 | * @param string $table_name |
||
| 371 | * @param string $connection_name Which connection to use |
||
| 372 | * |
||
| 373 | * @return static |
||
| 374 | */ |
||
| 375 | 229 | public static function for_table($table_name, $connection_name = self::DEFAULT_CONNECTION) |
|
| 381 | |||
| 382 | /** |
||
| 383 | * Set up the database connection used by the class |
||
| 384 | * |
||
| 385 | * @param string $connection_name Which connection to use |
||
| 386 | */ |
||
| 387 | 243 | protected static function _setup_db($connection_name = self::DEFAULT_CONNECTION) |
|
| 404 | |||
| 405 | /** |
||
| 406 | * Ensures configuration (multiple connections) is at least set to default. |
||
| 407 | * |
||
| 408 | * @param string $connection_name Which connection to use |
||
| 409 | */ |
||
| 410 | 244 | protected static function _setup_db_config($connection_name) |
|
| 416 | |||
| 417 | /** |
||
| 418 | * Set the PDO object used by Idiorm to communicate with the database. |
||
| 419 | * This is public in case the ORM should use a ready-instantiated |
||
| 420 | * PDO object as its database connection. Accepts an optional string key |
||
| 421 | * to identify the connection if multiple connections are used. |
||
| 422 | * |
||
| 423 | * @param \PDO $db |
||
| 424 | * @param string $connection_name Which connection to use |
||
| 425 | */ |
||
| 426 | 244 | public static function set_db($db, $connection_name = self::DEFAULT_CONNECTION) |
|
| 436 | |||
| 437 | /** |
||
| 438 | * Delete all registered PDO objects in _db array. |
||
| 439 | */ |
||
| 440 | 156 | public static function reset_db() |
|
| 444 | |||
| 445 | /** |
||
| 446 | * Detect and initialise the character used to quote identifiers |
||
| 447 | * (table names, column names etc). If this has been specified |
||
| 448 | * manually using ORM::configure('identifier_quote_character', 'some-char'), |
||
| 449 | * this will do nothing. |
||
| 450 | * |
||
| 451 | * @param string $connection_name Which connection to use |
||
| 452 | */ |
||
| 453 | 244 | protected static function _setup_identifier_quote_character($connection_name) |
|
| 459 | |||
| 460 | /** |
||
| 461 | * Detect and initialise the limit clause style ("SELECT TOP 5" / |
||
| 462 | * "... LIMIT 5"). If this has been specified manually using |
||
| 463 | * ORM::configure('limit_clause_style', 'top'), this will do nothing. |
||
| 464 | * |
||
| 465 | * @param string $connection_name Which connection to use |
||
| 466 | */ |
||
| 467 | 244 | public static function _setup_limit_clause_style($connection_name) |
|
| 473 | |||
| 474 | /** |
||
| 475 | * Return the correct character used to quote identifiers (table |
||
| 476 | * names, column names etc) by looking at the driver being used by PDO. |
||
| 477 | * |
||
| 478 | * @param string $connection_name Which connection to use |
||
| 479 | * |
||
| 480 | * @return string |
||
| 481 | */ |
||
| 482 | 156 | protected static function _detect_identifier_quote_character($connection_name) |
|
| 499 | |||
| 500 | /** |
||
| 501 | * Returns a constant after determining the appropriate limit clause |
||
| 502 | * style |
||
| 503 | * |
||
| 504 | * @param string $connection_name Which connection to use |
||
| 505 | * |
||
| 506 | * @return string Limit clause style keyword/constant |
||
| 507 | */ |
||
| 508 | 156 | protected static function _detect_limit_clause_style($connection_name) |
|
| 519 | |||
| 520 | /** |
||
| 521 | * Returns the PDO instance used by the the ORM to communicate with |
||
| 522 | * the database. This can be called if any low-level DB access is |
||
| 523 | * required outside the class. If multiple connections are used, |
||
| 524 | * accepts an optional key name for the connection. |
||
| 525 | * |
||
| 526 | * @param string $connection_name Which connection to use |
||
| 527 | * |
||
| 528 | * @return \PDO |
||
| 529 | */ |
||
| 530 | 243 | public static function get_db($connection_name = self::DEFAULT_CONNECTION) |
|
| 535 | |||
| 536 | /** |
||
| 537 | * Executes a raw query as a wrapper for PDOStatement::execute. |
||
| 538 | * Useful for queries that can't be accomplished through Idiorm, |
||
| 539 | * particularly those using engine-specific features. |
||
| 540 | * |
||
| 541 | * @example raw_execute('SELECT `name`, AVG(`order`) FROM `customer` GROUP BY `name` HAVING AVG(`order`) > 10') |
||
| 542 | * @example raw_execute('INSERT OR REPLACE INTO `widget` (`id`, `name`) SELECT `id`, `name` FROM `other_table`') |
||
| 543 | * |
||
| 544 | * @param string $query The raw SQL query |
||
| 545 | * @param array $parameters Optional bound parameters |
||
| 546 | * @param string $connection_name Which connection to use |
||
| 547 | * |
||
| 548 | * @return bool Success |
||
| 549 | */ |
||
| 550 | 1 | public static function raw_execute($query, $parameters = array(), $connection_name = self::DEFAULT_CONNECTION) |
|
| 556 | |||
| 557 | /** |
||
| 558 | * Returns the PDOStatement instance last used by any connection wrapped by the ORM. |
||
| 559 | * Useful for access to PDOStatement::rowCount() or error information |
||
| 560 | * |
||
| 561 | * @return \PDOStatement |
||
| 562 | */ |
||
| 563 | 207 | public static function get_last_statement() |
|
| 567 | |||
| 568 | /** |
||
| 569 | * Internal helper method for executing statements. Logs queries, and |
||
| 570 | * stores statement object in ::_last_statement, accessible publicly |
||
| 571 | * through ::get_last_statement() |
||
| 572 | * |
||
| 573 | * @param string $query |
||
| 574 | * @param array $parameters An array of parameters to be bound in to the query |
||
| 575 | * @param string $connection_name Which connection to use |
||
| 576 | * |
||
| 577 | * @return bool Response of PDOStatement::execute() |
||
| 578 | * |
||
| 579 | * @throws \Exception |
||
| 580 | */ |
||
| 581 | 219 | protected static function _execute($query, $parameters = array(), $connection_name = self::DEFAULT_CONNECTION) |
|
| 614 | |||
| 615 | /** |
||
| 616 | * Add a query to the internal query log. Only works if the |
||
| 617 | * 'logging' config option is set to true. |
||
| 618 | * |
||
| 619 | * This works by manually binding the parameters to the query - the |
||
| 620 | * query isn't executed like this (PDO normally passes the query and |
||
| 621 | * parameters to the database which takes care of the binding) but |
||
| 622 | * doing it this way makes the logged queries more readable. |
||
| 623 | * |
||
| 624 | * @param string $query |
||
| 625 | * @param array $parameters An array of parameters to be bound in to the query |
||
| 626 | * @param string $connection_name Which connection to use |
||
| 627 | * @param float $query_time Query time |
||
| 628 | * |
||
| 629 | * @return bool |
||
| 630 | */ |
||
| 631 | 219 | protected static function _log_query($query, $parameters, $connection_name, $query_time) |
|
| 680 | |||
| 681 | /** |
||
| 682 | * Get the last query executed. Only works if the |
||
| 683 | * 'logging' config option is set to true. Otherwise |
||
| 684 | * this will return null. Returns last query from all connections if |
||
| 685 | * no connection_name is specified |
||
| 686 | * |
||
| 687 | * @param null|string $connection_name Which connection to use |
||
| 688 | * |
||
| 689 | * @return string |
||
| 690 | */ |
||
| 691 | 208 | public static function get_last_query($connection_name = null) |
|
| 702 | |||
| 703 | /** |
||
| 704 | * Get an array containing all the queries run on a |
||
| 705 | * specified connection up to now. |
||
| 706 | * Only works if the 'logging' config option is |
||
| 707 | * set to true. Otherwise, returned array will be empty. |
||
| 708 | * |
||
| 709 | * @param string $connection_name Which connection to use |
||
| 710 | * |
||
| 711 | * @return array |
||
| 712 | */ |
||
| 713 | public static function get_query_log($connection_name = self::DEFAULT_CONNECTION) |
||
| 721 | |||
| 722 | /** |
||
| 723 | * Get a list of the available connection names |
||
| 724 | * |
||
| 725 | * @return array |
||
| 726 | */ |
||
| 727 | public static function get_connection_names() |
||
| 731 | |||
| 732 | // ------------------------ // |
||
| 733 | // --- INSTANCE METHODS --- // |
||
| 734 | // ------------------------ // |
||
| 735 | |||
| 736 | /** |
||
| 737 | * "Private" constructor; shouldn't be called directly. |
||
| 738 | * Use the ORM::for_table factory method instead. |
||
| 739 | * |
||
| 740 | * @param string $table_name |
||
| 741 | * @param array $data |
||
| 742 | * @param string $connection_name |
||
| 743 | */ |
||
| 744 | 229 | protected function __construct($table_name, $data = array(), $connection_name = self::DEFAULT_CONNECTION) |
|
| 752 | |||
| 753 | /** |
||
| 754 | * Create a new, empty instance of the class. Used |
||
| 755 | * to add a new row to your database. May optionally |
||
| 756 | * be passed an associative array of data to populate |
||
| 757 | * the instance. If so, all fields will be flagged as |
||
| 758 | * dirty so all will be saved to the database when |
||
| 759 | * save() is called. |
||
| 760 | * |
||
| 761 | * @param null|array $data |
||
| 762 | * |
||
| 763 | * @return $this |
||
| 764 | */ |
||
| 765 | 20 | public function create($data = null) |
|
| 774 | |||
| 775 | /** |
||
| 776 | * Specify the ID column to use for this instance or array of instances only. |
||
| 777 | * This overrides the id_column and id_column_overrides settings. |
||
| 778 | * |
||
| 779 | * This is mostly useful for libraries built on top of Idiorm, and will |
||
| 780 | * not normally be used in manually built queries. If you don't know why |
||
| 781 | * you would want to use this, you should probably just ignore it. |
||
| 782 | * |
||
| 783 | * @param string $id_column |
||
| 784 | * |
||
| 785 | * @return $this |
||
| 786 | */ |
||
| 787 | 208 | public function use_id_column($id_column) |
|
| 793 | |||
| 794 | /** |
||
| 795 | * Create an ORM instance from the given row (an associative |
||
| 796 | * array of data fetched from the database) |
||
| 797 | * |
||
| 798 | * @param array $row |
||
| 799 | * |
||
| 800 | * @return $this |
||
| 801 | */ |
||
| 802 | 204 | protected function _create_instance_from_row($row) |
|
| 810 | |||
| 811 | /** |
||
| 812 | * Tell the ORM that you are expecting a single result |
||
| 813 | * back from your query, and execute it. Will return |
||
| 814 | * a single instance of the ORM class, or false if no |
||
| 815 | * rows were returned. |
||
| 816 | * As a shortcut, you may supply an ID as a parameter |
||
| 817 | * to this method. This will perform a primary key |
||
| 818 | * lookup on the table. |
||
| 819 | * |
||
| 820 | * @param mixed $id |
||
| 821 | * |
||
| 822 | * @return false|ORM false on error |
||
| 823 | */ |
||
| 824 | 87 | public function find_one($id = null) |
|
| 838 | |||
| 839 | /** |
||
| 840 | * Tell the ORM that you are expecting multiple results |
||
| 841 | * from your query, and execute it. Will return an array |
||
| 842 | * of instances of the ORM class, or an empty array if |
||
| 843 | * no rows were returned. |
||
| 844 | * |
||
| 845 | * @return array|IdiormResultSet |
||
| 846 | */ |
||
| 847 | 117 | public function find_many() |
|
| 855 | |||
| 856 | /** |
||
| 857 | * Tell the ORM that you are expecting multiple results |
||
| 858 | * from your query, and execute it. Will return an array |
||
| 859 | * of instances of the ORM class, or an empty array if |
||
| 860 | * no rows were returned. |
||
| 861 | * |
||
| 862 | * @return array |
||
| 863 | */ |
||
| 864 | 119 | protected function _find_many() |
|
| 870 | |||
| 871 | /** |
||
| 872 | * Tell the ORM that you are expecting multiple results |
||
| 873 | * from your query, and execute it. Will return a result set object |
||
| 874 | * containing instances of the ORM class. |
||
| 875 | * |
||
| 876 | * @return IdiormResultSet |
||
| 877 | */ |
||
| 878 | 3 | public function find_result_set() |
|
| 882 | |||
| 883 | /** |
||
| 884 | * Tell the ORM that you are expecting multiple results |
||
| 885 | * from your query, and execute it. Will return an array, |
||
| 886 | * or an empty array if no rows were returned. |
||
| 887 | * |
||
| 888 | * @return array |
||
| 889 | */ |
||
| 890 | 1 | public function find_array() |
|
| 894 | |||
| 895 | /** |
||
| 896 | * Tell the ORM that you wish to execute a COUNT query. |
||
| 897 | * Will return an integer representing the number of |
||
| 898 | * rows returned. |
||
| 899 | * |
||
| 900 | * @param string $column |
||
| 901 | * |
||
| 902 | * @return int |
||
| 903 | */ |
||
| 904 | 4 | public function count($column = '*') |
|
| 908 | |||
| 909 | /** |
||
| 910 | * Tell the ORM that you wish to execute a MAX query. |
||
| 911 | * Will return the max value of the choosen column. |
||
| 912 | * |
||
| 913 | * @param string $column |
||
| 914 | * |
||
| 915 | * @return int |
||
| 916 | */ |
||
| 917 | 2 | public function max($column) |
|
| 921 | |||
| 922 | /** |
||
| 923 | * Tell the ORM that you wish to execute a MIN query. |
||
| 924 | * Will return the min value of the choosen column. |
||
| 925 | * |
||
| 926 | * @param string $column |
||
| 927 | * |
||
| 928 | * @return int|float |
||
| 929 | */ |
||
| 930 | 2 | public function min($column) |
|
| 934 | |||
| 935 | /** |
||
| 936 | * Tell the ORM that you wish to execute a AVG query. |
||
| 937 | * Will return the average value of the choosen column. |
||
| 938 | * |
||
| 939 | * @param string $column |
||
| 940 | * |
||
| 941 | * @return float |
||
| 942 | */ |
||
| 943 | 2 | public function avg($column) |
|
| 947 | |||
| 948 | /** |
||
| 949 | * Tell the ORM that you wish to execute a SUM query. |
||
| 950 | * Will return the sum of the choosen column. |
||
| 951 | * |
||
| 952 | * @param string $column |
||
| 953 | * |
||
| 954 | * @return int|float |
||
| 955 | */ |
||
| 956 | 2 | public function sum($column) |
|
| 960 | |||
| 961 | /** |
||
| 962 | * Execute an aggregate query on the current connection. |
||
| 963 | * |
||
| 964 | * @param string $sql_function The aggregate function to call eg. MIN, COUNT, etc |
||
| 965 | * @param string $column The column to execute the aggregate query against |
||
| 966 | * |
||
| 967 | * @return float|int|mixed |
||
| 968 | */ |
||
| 969 | 12 | protected function _call_aggregate_db_function($sql_function, $column) |
|
| 995 | |||
| 996 | /** |
||
| 997 | * This method can be called to hydrate (populate) this |
||
| 998 | * instance of the class from an associative array of data. |
||
| 999 | * This will usually be called only from inside the class, |
||
| 1000 | * but it's public in case you need to call it directly. |
||
| 1001 | * |
||
| 1002 | * @param array $data |
||
| 1003 | * |
||
| 1004 | * @return $this |
||
| 1005 | */ |
||
| 1006 | 209 | public function hydrate($data = array()) |
|
| 1012 | |||
| 1013 | /** |
||
| 1014 | * Force the ORM to flag all the fields in the $data array |
||
| 1015 | * as "dirty" and therefore update them when save() is called. |
||
| 1016 | * |
||
| 1017 | * @return $this |
||
| 1018 | */ |
||
| 1019 | 7 | public function force_all_dirty() |
|
| 1025 | |||
| 1026 | /** |
||
| 1027 | * Perform a raw query. The query can contain placeholders in |
||
| 1028 | * either named or question mark style. If placeholders are |
||
| 1029 | * used, the parameters should be an array of values which will |
||
| 1030 | * be bound to the placeholders in the query. If this method |
||
| 1031 | * is called, all other query building methods will be ignored. |
||
| 1032 | * |
||
| 1033 | * @param string $query |
||
| 1034 | * @param array $parameters |
||
| 1035 | * |
||
| 1036 | * @return $this |
||
| 1037 | */ |
||
| 1038 | 4 | public function raw_query($query, $parameters = array()) |
|
| 1046 | |||
| 1047 | /** |
||
| 1048 | * Add an alias for the main table to be used in SELECT queries |
||
| 1049 | * |
||
| 1050 | * @param string $alias |
||
| 1051 | * |
||
| 1052 | * @return $this |
||
| 1053 | */ |
||
| 1054 | 4 | public function table_alias($alias) |
|
| 1060 | |||
| 1061 | /** |
||
| 1062 | * Internal method to add an unquoted expression to the set |
||
| 1063 | * of columns returned by the SELECT query. The second optional |
||
| 1064 | * argument is the alias to return the expression as. |
||
| 1065 | * |
||
| 1066 | * @param string $expr |
||
| 1067 | * @param mixed $alias |
||
| 1068 | * |
||
| 1069 | * @return $this |
||
| 1070 | */ |
||
| 1071 | 34 | protected function _add_result_column($expr, $alias = null) |
|
| 1086 | |||
| 1087 | /** |
||
| 1088 | * Counts the number of columns that belong to the primary |
||
| 1089 | * key and their value is null. |
||
| 1090 | * |
||
| 1091 | * @return int |
||
| 1092 | */ |
||
| 1093 | 12 | public function count_null_id_columns() |
|
| 1101 | |||
| 1102 | /** |
||
| 1103 | * Add a column to the list of columns returned by the SELECT |
||
| 1104 | * query. This defaults to '*'. The second optional argument is |
||
| 1105 | * the alias to return the column as. |
||
| 1106 | * |
||
| 1107 | * @param string $column |
||
| 1108 | * @param mixed $alias |
||
| 1109 | * |
||
| 1110 | * @return $this |
||
| 1111 | */ |
||
| 1112 | 20 | public function select($column, $alias = null) |
|
| 1118 | |||
| 1119 | /** |
||
| 1120 | * Add an unquoted expression to the list of columns returned |
||
| 1121 | * by the SELECT query. The second optional argument is |
||
| 1122 | * the alias to return the column as. |
||
| 1123 | * |
||
| 1124 | * @param string $expr |
||
| 1125 | * @param mixed $alias |
||
| 1126 | * |
||
| 1127 | * @return $this |
||
| 1128 | */ |
||
| 1129 | 16 | public function select_expr($expr, $alias = null) |
|
| 1133 | |||
| 1134 | /** |
||
| 1135 | * Add columns to the list of columns returned by the SELECT |
||
| 1136 | * query. This defaults to '*'. Many columns can be supplied |
||
| 1137 | * as either an array or as a list of parameters to the method. |
||
| 1138 | * |
||
| 1139 | * Note that the alias must not be numeric - if you want a |
||
| 1140 | * numeric alias then prepend it with some alpha chars. eg. a1 |
||
| 1141 | * |
||
| 1142 | * @example select_many(array('alias' => 'column', 'column2', 'alias2' => 'column3'), 'column4', 'column5'); |
||
| 1143 | * @example select_many('column', 'column2', 'column3'); |
||
| 1144 | * @example select_many(array('column', 'column2', 'column3'), 'column4', 'column5'); |
||
| 1145 | * |
||
| 1146 | * @return $this |
||
| 1147 | */ |
||
| 1148 | 2 | View Code Duplication | public function select_many() |
| 1163 | |||
| 1164 | /** |
||
| 1165 | * Add an unquoted expression to the list of columns returned |
||
| 1166 | * by the SELECT query. Many columns can be supplied as either |
||
| 1167 | * an array or as a list of parameters to the method. |
||
| 1168 | * |
||
| 1169 | * Note that the alias must not be numeric - if you want a |
||
| 1170 | * numeric alias then prepend it with some alpha chars. eg. a1 |
||
| 1171 | * |
||
| 1172 | * @example select_many_expr(array('alias' => 'column', 'column2', 'alias2' => 'column3'), 'column4', 'column5') |
||
| 1173 | * @example select_many_expr('column', 'column2', 'column3') |
||
| 1174 | * @example select_many_expr(array('column', 'column2', 'column3'), 'column4', 'column5') |
||
| 1175 | * |
||
| 1176 | * @return $this |
||
| 1177 | */ |
||
| 1178 | 2 | View Code Duplication | public function select_many_expr() |
| 1193 | |||
| 1194 | /** |
||
| 1195 | * Take a column specification for the select many methods and convert it |
||
| 1196 | * into a normalised array of columns and aliases. |
||
| 1197 | * |
||
| 1198 | * It is designed to turn the following styles into a normalised array: |
||
| 1199 | * |
||
| 1200 | * array(array('alias' => 'column', 'column2', 'alias2' => 'column3'), 'column4', 'column5')) |
||
| 1201 | * |
||
| 1202 | * @param array $columns |
||
| 1203 | * |
||
| 1204 | * @return array |
||
| 1205 | */ |
||
| 1206 | 4 | protected function _normalise_select_many_columns($columns) |
|
| 1225 | |||
| 1226 | /** |
||
| 1227 | * Add a DISTINCT keyword before the list of columns in the SELECT query |
||
| 1228 | * |
||
| 1229 | * @return $this |
||
| 1230 | */ |
||
| 1231 | 2 | public function distinct() |
|
| 1237 | |||
| 1238 | /** |
||
| 1239 | * Internal method to add a JOIN source to the query. |
||
| 1240 | * |
||
| 1241 | * The join_operator should be one of INNER, LEFT OUTER, CROSS etc - this |
||
| 1242 | * will be prepended to JOIN. |
||
| 1243 | * |
||
| 1244 | * The table should be the name of the table to join to. |
||
| 1245 | * |
||
| 1246 | * The constraint may be either a string or an array with three elements. If it |
||
| 1247 | * is a string, it will be compiled into the query as-is, with no escaping. The |
||
| 1248 | * recommended way to supply the constraint is as an array with three elements: |
||
| 1249 | * |
||
| 1250 | * first_column, operator, second_column |
||
| 1251 | * |
||
| 1252 | * Example: array('user.id', '=', 'profile.user_id') |
||
| 1253 | * |
||
| 1254 | * will compile to |
||
| 1255 | * |
||
| 1256 | * ON `user`.`id` = `profile`.`user_id` |
||
| 1257 | * |
||
| 1258 | * The final (optional) argument specifies an alias for the joined table. |
||
| 1259 | * |
||
| 1260 | * @param string $join_operator |
||
| 1261 | * @param string $table |
||
| 1262 | * @param string $constraint |
||
| 1263 | * @param string|null $table_alias |
||
| 1264 | * |
||
| 1265 | * @return $this |
||
| 1266 | */ |
||
| 1267 | 20 | protected function _add_join_source($join_operator, $table, $constraint, $table_alias = null) |
|
| 1291 | |||
| 1292 | /** |
||
| 1293 | * Add a RAW JOIN source to the query |
||
| 1294 | * |
||
| 1295 | * @param string $table |
||
| 1296 | * @param string $constraint |
||
| 1297 | * @param string $table_alias |
||
| 1298 | * @param array $parameters |
||
| 1299 | * |
||
| 1300 | * @return $this |
||
| 1301 | */ |
||
| 1302 | 6 | public function raw_join($table, $constraint, $table_alias, $parameters = array()) |
|
| 1324 | |||
| 1325 | /** |
||
| 1326 | * Add a simple JOIN source to the query |
||
| 1327 | * |
||
| 1328 | * @param string $table |
||
| 1329 | * @param string $constraint |
||
| 1330 | * @param string|null $table_alias |
||
| 1331 | * |
||
| 1332 | * @return $this |
||
| 1333 | */ |
||
| 1334 | 12 | public function join($table, $constraint, $table_alias = null) |
|
| 1338 | |||
| 1339 | /** |
||
| 1340 | * Add an INNER JOIN souce to the query |
||
| 1341 | */ |
||
| 1342 | /** |
||
| 1343 | * @param string $table |
||
| 1344 | * @param string $constraint |
||
| 1345 | * @param null|string $table_alias |
||
| 1346 | * |
||
| 1347 | * @return $this |
||
| 1348 | */ |
||
| 1349 | 2 | public function inner_join($table, $constraint, $table_alias = null) |
|
| 1353 | |||
| 1354 | /** |
||
| 1355 | * Add an LEFT JOIN source to the query |
||
| 1356 | * |
||
| 1357 | * @param string $table |
||
| 1358 | * @param $constraint |
||
| 1359 | * @param null $table_alias |
||
| 1360 | * |
||
| 1361 | * @return $this |
||
| 1362 | */ |
||
| 1363 | public function left_join($table, $constraint, $table_alias = null) |
||
| 1367 | |||
| 1368 | /** |
||
| 1369 | * Add an RIGHT JOIN source to the query |
||
| 1370 | * |
||
| 1371 | * @param string $table |
||
| 1372 | * @param $constraint |
||
| 1373 | * @param null $table_alias |
||
| 1374 | * |
||
| 1375 | * @return $this |
||
| 1376 | */ |
||
| 1377 | public function right_join($table, $constraint, $table_alias = null) |
||
| 1381 | |||
| 1382 | /** |
||
| 1383 | * Add a LEFT OUTER JOIN souce to the query |
||
| 1384 | * |
||
| 1385 | * @param string $table |
||
| 1386 | * @param string $constraint |
||
| 1387 | * @param null|string $table_alias |
||
| 1388 | * |
||
| 1389 | * @return $this |
||
| 1390 | */ |
||
| 1391 | 2 | public function left_outer_join($table, $constraint, $table_alias = null) |
|
| 1395 | |||
| 1396 | /** |
||
| 1397 | * Add an RIGHT OUTER JOIN souce to the query |
||
| 1398 | * |
||
| 1399 | * @param string $table |
||
| 1400 | * @param string $constraint |
||
| 1401 | * @param null|string $table_alias |
||
| 1402 | * |
||
| 1403 | * @return $this |
||
| 1404 | */ |
||
| 1405 | 2 | public function right_outer_join($table, $constraint, $table_alias = null) |
|
| 1409 | |||
| 1410 | /** |
||
| 1411 | * Add an FULL OUTER JOIN souce to the query |
||
| 1412 | */ |
||
| 1413 | /** |
||
| 1414 | * @param string $table |
||
| 1415 | * @param string $constraint |
||
| 1416 | * @param null|string $table_alias |
||
| 1417 | * |
||
| 1418 | * @return $this |
||
| 1419 | */ |
||
| 1420 | 2 | public function full_outer_join($table, $constraint, $table_alias = null) |
|
| 1424 | |||
| 1425 | /** |
||
| 1426 | * Internal method to add a HAVING condition to the query |
||
| 1427 | */ |
||
| 1428 | /** |
||
| 1429 | * @param string $fragment |
||
| 1430 | * @param array $values |
||
| 1431 | * |
||
| 1432 | * @return $this |
||
| 1433 | */ |
||
| 1434 | 10 | protected function _add_having($fragment, $values = array()) |
|
| 1438 | |||
| 1439 | /** |
||
| 1440 | * Internal method to add a HAVING condition to the query |
||
| 1441 | */ |
||
| 1442 | /** |
||
| 1443 | * @param string|array $column_name |
||
| 1444 | * @param string $separator |
||
| 1445 | * @param mixed $value |
||
| 1446 | * |
||
| 1447 | * @return $this |
||
| 1448 | */ |
||
| 1449 | 14 | protected function _add_simple_having($column_name, $separator, $value) |
|
| 1453 | |||
| 1454 | /** |
||
| 1455 | * Internal method to add a HAVING clause with multiple values (like IN and NOT IN) |
||
| 1456 | */ |
||
| 1457 | /** |
||
| 1458 | * @param string|array $column_name |
||
| 1459 | * @param string $separator |
||
| 1460 | * @param mixed $values |
||
| 1461 | * |
||
| 1462 | * @return $this |
||
| 1463 | */ |
||
| 1464 | 4 | View Code Duplication | public function _add_having_placeholder($column_name, $separator, $values) |
| 1481 | |||
| 1482 | /** |
||
| 1483 | * Internal method to add a HAVING clause with no parameters(like IS NULL and IS NOT NULL) |
||
| 1484 | * |
||
| 1485 | * @param string|array $column_name |
||
| 1486 | * @param string $operator |
||
| 1487 | * |
||
| 1488 | * @return $this |
||
| 1489 | */ |
||
| 1490 | 4 | View Code Duplication | public function _add_having_no_value($column_name, $operator) |
| 1506 | |||
| 1507 | /** |
||
| 1508 | * Internal method to add a WHERE condition to the query |
||
| 1509 | * |
||
| 1510 | * @param string $fragment |
||
| 1511 | * @param array $values |
||
| 1512 | * |
||
| 1513 | * @return $this |
||
| 1514 | */ |
||
| 1515 | 29 | protected function _add_where($fragment, $values = array()) |
|
| 1519 | |||
| 1520 | /** |
||
| 1521 | * Internal method to add a WHERE condition to the query |
||
| 1522 | * |
||
| 1523 | * @param string|array $column_name |
||
| 1524 | * @param string $separator |
||
| 1525 | * @param mixed $value |
||
| 1526 | * |
||
| 1527 | * @return $this |
||
| 1528 | */ |
||
| 1529 | 65 | protected function _add_simple_where($column_name, $separator, $value) |
|
| 1533 | |||
| 1534 | /** |
||
| 1535 | * Add a WHERE clause with multiple values (like IN and NOT IN) |
||
| 1536 | * |
||
| 1537 | * @param string|array $column_name |
||
| 1538 | * @param string $separator |
||
| 1539 | * @param mixed $values |
||
| 1540 | * |
||
| 1541 | * @return $this |
||
| 1542 | */ |
||
| 1543 | 5 | View Code Duplication | public function _add_where_placeholder($column_name, $separator, $values) |
| 1560 | |||
| 1561 | /** |
||
| 1562 | * Add a WHERE clause with no parameters(like IS NULL and IS NOT NULL) |
||
| 1563 | * |
||
| 1564 | * @param string|array $column_name |
||
| 1565 | * @param string $operator |
||
| 1566 | * |
||
| 1567 | * @return $this |
||
| 1568 | */ |
||
| 1569 | 4 | View Code Duplication | public function _add_where_no_value($column_name, $operator) |
| 1585 | |||
| 1586 | /** |
||
| 1587 | * Internal method to add a HAVING or WHERE condition to the query |
||
| 1588 | * |
||
| 1589 | * @param string $type |
||
| 1590 | * @param string $fragment |
||
| 1591 | * @param mixed $values |
||
| 1592 | * |
||
| 1593 | * @return $this |
||
| 1594 | */ |
||
| 1595 | 119 | protected function _add_condition($type, $fragment, $values = array()) |
|
| 1613 | |||
| 1614 | /** |
||
| 1615 | * Helper method to compile a simple COLUMN SEPARATOR VALUE |
||
| 1616 | * style HAVING or WHERE condition into a string and value ready to |
||
| 1617 | * be passed to the _add_condition method. Avoids duplication |
||
| 1618 | * of the call to _quote_identifier |
||
| 1619 | * |
||
| 1620 | * If column_name is an associative array, it will add a condition for each column |
||
| 1621 | * |
||
| 1622 | * @param string $type |
||
| 1623 | * @param string|array $column_name |
||
| 1624 | * @param string $separator |
||
| 1625 | * @param string|int $value |
||
| 1626 | * |
||
| 1627 | * @return $this |
||
| 1628 | */ |
||
| 1629 | 79 | protected function _add_simple_condition($type, $column_name, $separator, $value) |
|
| 1656 | |||
| 1657 | /** |
||
| 1658 | * Add a WHERE clause width DATE |
||
| 1659 | * |
||
| 1660 | * If column_name is an associative array, it will add a condition for each column |
||
| 1661 | * |
||
| 1662 | * @param string $type |
||
| 1663 | * @param string|array $column_name |
||
| 1664 | * @param string $separator |
||
| 1665 | * @param string|int $value |
||
| 1666 | * |
||
| 1667 | * @return $this |
||
| 1668 | */ |
||
| 1669 | 5 | protected function _add_date_condition($type, $column_name, $separator, $value) |
|
| 1691 | |||
| 1692 | /** |
||
| 1693 | * Return a string containing the given number of question marks, |
||
| 1694 | * separated by commas. Eg "?, ?, ?" |
||
| 1695 | * |
||
| 1696 | * @param mixed $fields |
||
| 1697 | * |
||
| 1698 | * @return string |
||
| 1699 | */ |
||
| 1700 | 21 | protected function _create_placeholders($fields) |
|
| 1718 | |||
| 1719 | /** |
||
| 1720 | * Helper method that filters a column/value array returning only those |
||
| 1721 | * columns that belong to a compound primary key. |
||
| 1722 | * |
||
| 1723 | * If the key contains a column that does not exist in the given array, |
||
| 1724 | * a null value will be returned for it. |
||
| 1725 | * |
||
| 1726 | * @param mixed $value |
||
| 1727 | * |
||
| 1728 | * @return array |
||
| 1729 | */ |
||
| 1730 | 2 | protected function _get_compound_id_column_values($value) |
|
| 1739 | |||
| 1740 | /** |
||
| 1741 | * Helper method that filters an array containing compound column/value |
||
| 1742 | * arrays. |
||
| 1743 | * |
||
| 1744 | * @param array $values |
||
| 1745 | * |
||
| 1746 | * @return array |
||
| 1747 | */ |
||
| 1748 | 1 | protected function _get_compound_id_column_values_array($values) |
|
| 1757 | |||
| 1758 | /** |
||
| 1759 | * Add a WHERE column = value clause to your query. Each time |
||
| 1760 | * this is called in the chain, an additional WHERE will be |
||
| 1761 | * added, and these will be ANDed together when the final query |
||
| 1762 | * is built. |
||
| 1763 | * |
||
| 1764 | * If you use an array in $column_name, a new clause will be |
||
| 1765 | * added for each element. In this case, $value is ignored. |
||
| 1766 | * |
||
| 1767 | * @param string $column_name |
||
| 1768 | * @param mixed $value |
||
| 1769 | * |
||
| 1770 | * @return $this |
||
| 1771 | */ |
||
| 1772 | 51 | public function where($column_name, $value = null) |
|
| 1776 | |||
| 1777 | /** |
||
| 1778 | * More explicitly named version of for the where() method. |
||
| 1779 | * Can be used if preferred. |
||
| 1780 | * |
||
| 1781 | * @param string $column_name |
||
| 1782 | * @param mixed $value |
||
| 1783 | * |
||
| 1784 | * @return $this |
||
| 1785 | */ |
||
| 1786 | 55 | public function where_equal($column_name, $value = null) |
|
| 1790 | |||
| 1791 | /** |
||
| 1792 | * Add a WHERE column != value clause to your query. |
||
| 1793 | * |
||
| 1794 | * @param string $column_name |
||
| 1795 | * @param mixed $value |
||
| 1796 | * |
||
| 1797 | * @return $this |
||
| 1798 | */ |
||
| 1799 | 2 | public function where_not_equal($column_name, $value = null) |
|
| 1803 | |||
| 1804 | /** |
||
| 1805 | * Special method to query the table by its primary key |
||
| 1806 | * |
||
| 1807 | * If primary key is compound, only the columns that |
||
| 1808 | * belong to they key will be used for the query |
||
| 1809 | * |
||
| 1810 | * @param mixed $id |
||
| 1811 | * |
||
| 1812 | * @return $this |
||
| 1813 | */ |
||
| 1814 | 33 | View Code Duplication | public function where_id_is($id) |
| 1822 | |||
| 1823 | /** |
||
| 1824 | * Allows adding a WHERE clause that matches any of the conditions |
||
| 1825 | * specified in the array. Each element in the associative array will |
||
| 1826 | * be a different condition, where the key will be the column name. |
||
| 1827 | * |
||
| 1828 | * By default, an equal operator will be used against all columns, but |
||
| 1829 | * it can be overridden for any or every column using the second parameter. |
||
| 1830 | * |
||
| 1831 | * Each condition will be ORed together when added to the final query. |
||
| 1832 | * |
||
| 1833 | * @param array $values |
||
| 1834 | * @param string $operator |
||
| 1835 | * |
||
| 1836 | * @return $this |
||
| 1837 | */ |
||
| 1838 | 4 | public function where_any_is($values, $operator = '=') |
|
| 1874 | |||
| 1875 | /** |
||
| 1876 | * Similar to where_id_is() but allowing multiple primary keys. |
||
| 1877 | * |
||
| 1878 | * If primary key is compound, only the columns that |
||
| 1879 | * belong to they key will be used for the query |
||
| 1880 | * |
||
| 1881 | * @param mixed $ids |
||
| 1882 | * |
||
| 1883 | * @return $this |
||
| 1884 | */ |
||
| 1885 | 2 | public function where_id_in($ids) |
|
| 1893 | |||
| 1894 | /** |
||
| 1895 | * Add a WHERE ... LIKE clause to your query. |
||
| 1896 | * |
||
| 1897 | * @param string $column_name |
||
| 1898 | * @param mixed $value |
||
| 1899 | * |
||
| 1900 | * @return $this |
||
| 1901 | */ |
||
| 1902 | 2 | public function where_like($column_name, $value = null) |
|
| 1906 | |||
| 1907 | /** |
||
| 1908 | * Add where WHERE ... NOT LIKE clause to your query. |
||
| 1909 | * |
||
| 1910 | * @param string $column_name |
||
| 1911 | * @param mixed $value |
||
| 1912 | * |
||
| 1913 | * @return $this |
||
| 1914 | */ |
||
| 1915 | 2 | public function where_not_like($column_name, $value = null) |
|
| 1919 | |||
| 1920 | /** |
||
| 1921 | * Add a WHERE ... > clause to your query |
||
| 1922 | * |
||
| 1923 | * @param string $column_name |
||
| 1924 | * @param mixed $value |
||
| 1925 | * |
||
| 1926 | * @return $this |
||
| 1927 | */ |
||
| 1928 | 2 | public function where_gt($column_name, $value = null) |
|
| 1932 | |||
| 1933 | /** |
||
| 1934 | * Add a WHERE ... < clause to your query |
||
| 1935 | * |
||
| 1936 | * @param string $column_name |
||
| 1937 | * @param mixed $value |
||
| 1938 | * |
||
| 1939 | * @return $this |
||
| 1940 | */ |
||
| 1941 | 2 | public function where_lt($column_name, $value = null) |
|
| 1945 | |||
| 1946 | /** |
||
| 1947 | * Add a WHERE ... >= clause to your query |
||
| 1948 | * |
||
| 1949 | * @param string $column_name |
||
| 1950 | * @param mixed $value |
||
| 1951 | * |
||
| 1952 | * @return $this |
||
| 1953 | */ |
||
| 1954 | 2 | public function where_gte($column_name, $value = null) |
|
| 1958 | |||
| 1959 | /** |
||
| 1960 | * Add a WHERE ... <= clause to your query |
||
| 1961 | * |
||
| 1962 | * @param string $column_name |
||
| 1963 | * @param mixed $value |
||
| 1964 | * |
||
| 1965 | * @return $this |
||
| 1966 | */ |
||
| 1967 | 2 | public function where_lte($column_name, $value = null) |
|
| 1971 | |||
| 1972 | /** |
||
| 1973 | * Add a WHERE ... IN clause to your query |
||
| 1974 | * |
||
| 1975 | * @param string $column_name |
||
| 1976 | * @param mixed $values |
||
| 1977 | * |
||
| 1978 | * @return $this |
||
| 1979 | */ |
||
| 1980 | 3 | public function where_in($column_name, $values) |
|
| 1984 | |||
| 1985 | /** |
||
| 1986 | * Add a WHERE ... NOT IN clause to your query |
||
| 1987 | * |
||
| 1988 | * @param string $column_name |
||
| 1989 | * @param mixed $values |
||
| 1990 | * |
||
| 1991 | * @return $this |
||
| 1992 | */ |
||
| 1993 | 2 | public function where_not_in($column_name, $values) |
|
| 1997 | |||
| 1998 | /** |
||
| 1999 | * @param string $column_name |
||
| 2000 | * @param mixed $value |
||
| 2001 | * |
||
| 2002 | * @return $this |
||
| 2003 | */ |
||
| 2004 | 1 | public function where_date_eq($column_name, $value = null) |
|
| 2008 | |||
| 2009 | |||
| 2010 | /** |
||
| 2011 | * @param string $column_name |
||
| 2012 | * @param mixed $value |
||
| 2013 | * |
||
| 2014 | * @return $this |
||
| 2015 | */ |
||
| 2016 | 1 | public function where_date_lt($column_name, $value = null) |
|
| 2020 | |||
| 2021 | /** |
||
| 2022 | * @param string $column_name |
||
| 2023 | * @param mixed $value |
||
| 2024 | * |
||
| 2025 | * @return $this |
||
| 2026 | */ |
||
| 2027 | 1 | public function where_date_gt($column_name, $value = null) |
|
| 2031 | |||
| 2032 | /** |
||
| 2033 | * @param string $column_name |
||
| 2034 | * @param mixed $value |
||
| 2035 | * |
||
| 2036 | * @return $this |
||
| 2037 | */ |
||
| 2038 | 1 | public function where_date_le($column_name, $value = null) |
|
| 2042 | |||
| 2043 | /** |
||
| 2044 | * @param string $column_name |
||
| 2045 | * @param mixed $value |
||
| 2046 | * |
||
| 2047 | * @return $this |
||
| 2048 | */ |
||
| 2049 | 1 | public function where_date_ge($column_name, $value = null) |
|
| 2053 | |||
| 2054 | /** |
||
| 2055 | * Add a WHERE column IS NULL clause to your query. |
||
| 2056 | * |
||
| 2057 | * @param string $column_name |
||
| 2058 | * |
||
| 2059 | * @return $this |
||
| 2060 | */ |
||
| 2061 | 2 | public function where_null($column_name) |
|
| 2065 | |||
| 2066 | /** |
||
| 2067 | * Add a WHERE column IS NOT NULL clause to your query |
||
| 2068 | * |
||
| 2069 | * @param string $column_name |
||
| 2070 | * |
||
| 2071 | * @return $this |
||
| 2072 | */ |
||
| 2073 | 2 | public function where_not_null($column_name) |
|
| 2077 | |||
| 2078 | /** |
||
| 2079 | * Add a raw WHERE clause to the query. The clause should |
||
| 2080 | * contain question mark placeholders, which will be bound |
||
| 2081 | * to the parameters supplied in the second argument. |
||
| 2082 | * |
||
| 2083 | * @param string $clause |
||
| 2084 | * @param array $parameters |
||
| 2085 | * |
||
| 2086 | * @return $this |
||
| 2087 | */ |
||
| 2088 | 20 | public function where_raw($clause, $parameters = array()) |
|
| 2092 | |||
| 2093 | /** |
||
| 2094 | * Add a LIMIT to the query |
||
| 2095 | * |
||
| 2096 | * @param int $limit |
||
| 2097 | * |
||
| 2098 | * @return $this |
||
| 2099 | */ |
||
| 2100 | 96 | public function limit($limit) |
|
| 2106 | |||
| 2107 | /** |
||
| 2108 | * Add an OFFSET to the query |
||
| 2109 | * |
||
| 2110 | * @param $offset |
||
| 2111 | * |
||
| 2112 | * @return $this |
||
| 2113 | */ |
||
| 2114 | 4 | public function offset($offset) |
|
| 2120 | |||
| 2121 | /** |
||
| 2122 | * Add an ORDER BY clause to the query |
||
| 2123 | * |
||
| 2124 | * @param string $column_name |
||
| 2125 | * @param string $ordering |
||
| 2126 | * |
||
| 2127 | * @return $this |
||
| 2128 | */ |
||
| 2129 | 12 | protected function _add_order_by($column_name, $ordering) |
|
| 2136 | |||
| 2137 | /** |
||
| 2138 | * Add an ORDER BY column DESC clause |
||
| 2139 | * |
||
| 2140 | * @param string $column_name |
||
| 2141 | * |
||
| 2142 | * @return $this |
||
| 2143 | */ |
||
| 2144 | 8 | public function order_by_desc($column_name) |
|
| 2148 | |||
| 2149 | /** |
||
| 2150 | * Add an ORDER BY RAND clause |
||
| 2151 | */ |
||
| 2152 | 1 | public function order_by_rand() |
|
| 2158 | |||
| 2159 | /** |
||
| 2160 | * Add an ORDER BY column ASC clause |
||
| 2161 | * |
||
| 2162 | * @param string $column_name |
||
| 2163 | * |
||
| 2164 | * @return $this |
||
| 2165 | */ |
||
| 2166 | 6 | public function order_by_asc($column_name) |
|
| 2170 | |||
| 2171 | /** |
||
| 2172 | * Add an unquoted expression as an ORDER BY clause |
||
| 2173 | * |
||
| 2174 | * @param $clause |
||
| 2175 | * |
||
| 2176 | * @return $this |
||
| 2177 | */ |
||
| 2178 | 2 | public function order_by_expr($clause) |
|
| 2184 | |||
| 2185 | /** |
||
| 2186 | * Reset the ORDER BY clause |
||
| 2187 | */ |
||
| 2188 | 1 | public function reset_order_by() |
|
| 2194 | |||
| 2195 | /** |
||
| 2196 | * Add a column to the list of columns to GROUP BY |
||
| 2197 | * |
||
| 2198 | * @param string $column_name |
||
| 2199 | * |
||
| 2200 | * @return $this |
||
| 2201 | */ |
||
| 2202 | 28 | public function group_by($column_name) |
|
| 2209 | |||
| 2210 | /** |
||
| 2211 | * Add an unquoted expression to the list of columns to GROUP BY |
||
| 2212 | * |
||
| 2213 | * @param string $expr |
||
| 2214 | * |
||
| 2215 | * @return $this |
||
| 2216 | */ |
||
| 2217 | 2 | public function group_by_expr($expr) |
|
| 2223 | |||
| 2224 | /** |
||
| 2225 | * Add a HAVING column = value clause to your query. Each time |
||
| 2226 | * this is called in the chain, an additional HAVING will be |
||
| 2227 | * added, and these will be ANDed together when the final query |
||
| 2228 | * is built. |
||
| 2229 | * |
||
| 2230 | * If you use an array in $column_name, a new clause will be |
||
| 2231 | * added for each element. In this case, $value is ignored. |
||
| 2232 | * |
||
| 2233 | * @param string $column_name |
||
| 2234 | * @param null $value |
||
| 2235 | * |
||
| 2236 | * @return $this |
||
| 2237 | */ |
||
| 2238 | 4 | public function having($column_name, $value = null) |
|
| 2242 | |||
| 2243 | /** |
||
| 2244 | * More explicitly named version of for the having() method. |
||
| 2245 | * Can be used if preferred. |
||
| 2246 | * |
||
| 2247 | * @param string $column_name |
||
| 2248 | * @param null $value |
||
| 2249 | * |
||
| 2250 | * @return $this |
||
| 2251 | */ |
||
| 2252 | 4 | public function having_equal($column_name, $value = null) |
|
| 2256 | |||
| 2257 | /** |
||
| 2258 | * Add a HAVING column != value clause to your query. |
||
| 2259 | * |
||
| 2260 | * @param string $column_name |
||
| 2261 | * @param null $value |
||
| 2262 | * |
||
| 2263 | * @return $this |
||
| 2264 | */ |
||
| 2265 | 2 | public function having_not_equal($column_name, $value = null) |
|
| 2269 | |||
| 2270 | /** |
||
| 2271 | * Special method to query the table by its primary key. |
||
| 2272 | * |
||
| 2273 | * If primary key is compound, only the columns that |
||
| 2274 | * belong to they key will be used for the query |
||
| 2275 | * |
||
| 2276 | * @param $id |
||
| 2277 | * |
||
| 2278 | * @return $this |
||
| 2279 | */ |
||
| 2280 | View Code Duplication | public function having_id_is($id) |
|
| 2288 | |||
| 2289 | /** |
||
| 2290 | * Add a HAVING ... LIKE clause to your query. |
||
| 2291 | * |
||
| 2292 | * @param string $column_name |
||
| 2293 | * @param mixed $value |
||
| 2294 | * |
||
| 2295 | * @return $this |
||
| 2296 | */ |
||
| 2297 | 2 | public function having_like($column_name, $value = null) |
|
| 2301 | |||
| 2302 | /** |
||
| 2303 | * Add where HAVING ... NOT LIKE clause to your query. |
||
| 2304 | * |
||
| 2305 | * @param string $column_name |
||
| 2306 | * @param mixed $value |
||
| 2307 | * |
||
| 2308 | * @return $this |
||
| 2309 | */ |
||
| 2310 | 2 | public function having_not_like($column_name, $value = null) |
|
| 2314 | |||
| 2315 | /** |
||
| 2316 | * Add a HAVING ... > clause to your query |
||
| 2317 | * |
||
| 2318 | * @param string $column_name |
||
| 2319 | * @param mixed $value |
||
| 2320 | * |
||
| 2321 | * @return $this |
||
| 2322 | */ |
||
| 2323 | 2 | public function having_gt($column_name, $value = null) |
|
| 2327 | |||
| 2328 | /** |
||
| 2329 | * Add a HAVING ... < clause to your query |
||
| 2330 | * |
||
| 2331 | * @param string $column_name |
||
| 2332 | * @param mixed $value |
||
| 2333 | * |
||
| 2334 | * @return $this |
||
| 2335 | */ |
||
| 2336 | 2 | public function having_lt($column_name, $value = null) |
|
| 2340 | |||
| 2341 | /** |
||
| 2342 | * Add a HAVING ... >= clause to your query |
||
| 2343 | * |
||
| 2344 | * @param string $column_name |
||
| 2345 | * @param mixed $value |
||
| 2346 | * |
||
| 2347 | * @return $this |
||
| 2348 | */ |
||
| 2349 | 2 | public function having_gte($column_name, $value = null) |
|
| 2353 | |||
| 2354 | /** |
||
| 2355 | * Add a HAVING ... <= clause to your query |
||
| 2356 | * |
||
| 2357 | * @param string $column_name |
||
| 2358 | * @param mixed $value |
||
| 2359 | * |
||
| 2360 | * @return $this |
||
| 2361 | */ |
||
| 2362 | 2 | public function having_lte($column_name, $value = null) |
|
| 2366 | |||
| 2367 | /** |
||
| 2368 | * Add a HAVING ... IN clause to your query |
||
| 2369 | * |
||
| 2370 | * @param string $column_name |
||
| 2371 | * @param mixed $values |
||
| 2372 | * |
||
| 2373 | * @return $this |
||
| 2374 | */ |
||
| 2375 | 2 | public function having_in($column_name, $values = null) |
|
| 2379 | |||
| 2380 | /** |
||
| 2381 | * Add a HAVING ... NOT IN clause to your query |
||
| 2382 | * |
||
| 2383 | * @param string $column_name |
||
| 2384 | * @param mixed $values |
||
| 2385 | * |
||
| 2386 | * @return $this |
||
| 2387 | */ |
||
| 2388 | 2 | public function having_not_in($column_name, $values = null) |
|
| 2392 | |||
| 2393 | /** |
||
| 2394 | * Add a HAVING column IS NULL clause to your query |
||
| 2395 | * |
||
| 2396 | * @param string $column_name |
||
| 2397 | * |
||
| 2398 | * @return $this |
||
| 2399 | */ |
||
| 2400 | 2 | public function having_null($column_name) |
|
| 2404 | |||
| 2405 | /** |
||
| 2406 | * Add a HAVING column IS NOT NULL clause to your query |
||
| 2407 | * |
||
| 2408 | * @param string $column_name |
||
| 2409 | * |
||
| 2410 | * @return $this |
||
| 2411 | */ |
||
| 2412 | 2 | public function having_not_null($column_name) |
|
| 2416 | |||
| 2417 | /** |
||
| 2418 | * Add a raw HAVING clause to the query. The clause should |
||
| 2419 | * contain question mark placeholders, which will be bound |
||
| 2420 | * to the parameters supplied in the second argument. |
||
| 2421 | * |
||
| 2422 | * @param string $clause |
||
| 2423 | * @param array $parameters |
||
| 2424 | * |
||
| 2425 | * @return $this |
||
| 2426 | */ |
||
| 2427 | 2 | public function having_raw($clause, $parameters = array()) |
|
| 2431 | |||
| 2432 | /** |
||
| 2433 | * Activate cache refreshing for current query |
||
| 2434 | * |
||
| 2435 | * @return $this |
||
| 2436 | */ |
||
| 2437 | public function refreshCache() |
||
| 2443 | |||
| 2444 | /** |
||
| 2445 | * Disable caching for current query |
||
| 2446 | * |
||
| 2447 | * @return $this |
||
| 2448 | */ |
||
| 2449 | public function noCaching() |
||
| 2455 | |||
| 2456 | /** |
||
| 2457 | * Build a SELECT statement based on the clauses that have |
||
| 2458 | * been passed to this instance by chaining method calls. |
||
| 2459 | */ |
||
| 2460 | 207 | protected function _build_select() |
|
| 2486 | |||
| 2487 | /** |
||
| 2488 | * Build the start of the SELECT statement |
||
| 2489 | * |
||
| 2490 | * @return string |
||
| 2491 | */ |
||
| 2492 | 203 | protected function _build_select_start() |
|
| 2517 | |||
| 2518 | /** |
||
| 2519 | * Build the JOIN sources |
||
| 2520 | * |
||
| 2521 | * @return string |
||
| 2522 | */ |
||
| 2523 | 203 | protected function _build_join() |
|
| 2531 | |||
| 2532 | /** |
||
| 2533 | * Build the WHERE clause(s) |
||
| 2534 | * |
||
| 2535 | * @return string |
||
| 2536 | */ |
||
| 2537 | 205 | protected function _build_where() |
|
| 2541 | |||
| 2542 | /** |
||
| 2543 | * Build the HAVING clause(s) |
||
| 2544 | * |
||
| 2545 | * @return string |
||
| 2546 | */ |
||
| 2547 | 203 | protected function _build_having() |
|
| 2551 | |||
| 2552 | /** |
||
| 2553 | * Build GROUP BY |
||
| 2554 | * |
||
| 2555 | * @return string |
||
| 2556 | */ |
||
| 2557 | 203 | protected function _build_group_by() |
|
| 2565 | |||
| 2566 | /** |
||
| 2567 | * Build a WHERE or HAVING clause |
||
| 2568 | * |
||
| 2569 | * @param string $type |
||
| 2570 | * |
||
| 2571 | * @return string |
||
| 2572 | */ |
||
| 2573 | 205 | protected function _build_conditions($type) |
|
| 2590 | |||
| 2591 | /** |
||
| 2592 | * Build ORDER BY |
||
| 2593 | * |
||
| 2594 | * @return string |
||
| 2595 | */ |
||
| 2596 | 203 | protected function _build_order_by() |
|
| 2606 | |||
| 2607 | /** |
||
| 2608 | * Build LIMIT |
||
| 2609 | * |
||
| 2610 | * @return string |
||
| 2611 | */ |
||
| 2612 | 203 | protected function _build_limit() |
|
| 2635 | |||
| 2636 | /** |
||
| 2637 | * Build OFFSET |
||
| 2638 | * |
||
| 2639 | * @return string |
||
| 2640 | */ |
||
| 2641 | 203 | protected function _build_offset() |
|
| 2656 | |||
| 2657 | /** |
||
| 2658 | * Wrapper around PHP's join function which |
||
| 2659 | * only adds the pieces if they are not empty. |
||
| 2660 | * |
||
| 2661 | * @param string $glue |
||
| 2662 | * @param array $pieces |
||
| 2663 | * |
||
| 2664 | * @return string |
||
| 2665 | */ |
||
| 2666 | 205 | protected function _join_if_not_empty($glue, $pieces) |
|
| 2680 | |||
| 2681 | /** |
||
| 2682 | * Quote a string that is used as an identifier |
||
| 2683 | * (table names, column names etc). This method can |
||
| 2684 | * also deal with dot-separated identifiers eg table.column |
||
| 2685 | * |
||
| 2686 | * @param string $identifier |
||
| 2687 | * |
||
| 2688 | * @return string |
||
| 2689 | */ |
||
| 2690 | 215 | protected function _quote_one_identifier($identifier) |
|
| 2697 | |||
| 2698 | /** |
||
| 2699 | * Quote a string that is used as an identifier |
||
| 2700 | * (table names, column names etc) or an array containing |
||
| 2701 | * multiple identifiers. This method can also deal with |
||
| 2702 | * dot-separated identifiers eg table.column |
||
| 2703 | * |
||
| 2704 | * @param array|string $identifier |
||
| 2705 | * |
||
| 2706 | * @return string |
||
| 2707 | */ |
||
| 2708 | 215 | protected function _quote_identifier($identifier) |
|
| 2718 | |||
| 2719 | /** |
||
| 2720 | * This method performs the actual quoting of a single |
||
| 2721 | * part of an identifier, using the identifier quote |
||
| 2722 | * character specified in the config (or autodetected). |
||
| 2723 | * |
||
| 2724 | * @param string $part |
||
| 2725 | * |
||
| 2726 | * @return string |
||
| 2727 | */ |
||
| 2728 | 215 | protected function _quote_identifier_part($part) |
|
| 2739 | |||
| 2740 | /** |
||
| 2741 | * Create a cache key for the given query and parameters. |
||
| 2742 | * |
||
| 2743 | * @param string $query |
||
| 2744 | * @param array $parameters |
||
| 2745 | * @param null|string $table_name |
||
| 2746 | * @param string $connection_name |
||
| 2747 | * |
||
| 2748 | * @return mixed|string |
||
| 2749 | */ |
||
| 2750 | 3 | protected static function _create_cache_key($query, $parameters, $table_name = null, $connection_name = self::DEFAULT_CONNECTION) |
|
| 2772 | |||
| 2773 | /** |
||
| 2774 | * Check the query cache for the given cache key. If a value |
||
| 2775 | * is cached for the key, return the value. Otherwise, return false. |
||
| 2776 | * |
||
| 2777 | * @param string $cache_key |
||
| 2778 | * @param null|string $table_name |
||
| 2779 | * @param string $connection_name |
||
| 2780 | * |
||
| 2781 | * @return bool|mixed |
||
| 2782 | */ |
||
| 2783 | 3 | protected static function _check_query_cache($cache_key, $table_name = null, $connection_name = self::DEFAULT_CONNECTION) |
|
| 2804 | |||
| 2805 | /** |
||
| 2806 | * Clear the query cache |
||
| 2807 | * |
||
| 2808 | * @param null|string $table_name |
||
| 2809 | * @param string $connection_name |
||
| 2810 | * |
||
| 2811 | * @return bool|mixed |
||
| 2812 | */ |
||
| 2813 | 1 | public static function clear_cache($table_name = null, $connection_name = self::DEFAULT_CONNECTION) |
|
| 2834 | |||
| 2835 | /** |
||
| 2836 | * Add the given value to the query cache. |
||
| 2837 | * |
||
| 2838 | * @param string $cache_key |
||
| 2839 | * @param string $value |
||
| 2840 | * @param null|string $table_name |
||
| 2841 | * @param string $connection_name |
||
| 2842 | * |
||
| 2843 | * @return bool|mixed |
||
| 2844 | */ |
||
| 2845 | 3 | protected static function _cache_query_result($cache_key, $value, $table_name = null, $connection_name = self::DEFAULT_CONNECTION) |
|
| 2871 | |||
| 2872 | /** |
||
| 2873 | * Execute the SELECT query that has been built up by chaining methods |
||
| 2874 | * on this class. Return an array of rows as associative arrays. |
||
| 2875 | */ |
||
| 2876 | 207 | protected function _run() |
|
| 2916 | |||
| 2917 | /** |
||
| 2918 | * Return the raw data wrapped by this ORM |
||
| 2919 | * instance as an associative array. Column |
||
| 2920 | * names may optionally be supplied as arguments, |
||
| 2921 | * if so, only those keys will be returned. |
||
| 2922 | */ |
||
| 2923 | 3 | public function as_array() |
|
| 2932 | |||
| 2933 | /** |
||
| 2934 | * Return the raw data wrapped by this ORM |
||
| 2935 | * instance as an json. |
||
| 2936 | * |
||
| 2937 | * @param int $options |
||
| 2938 | * |
||
| 2939 | * @return string |
||
| 2940 | */ |
||
| 2941 | 1 | public function as_json($options = 0) |
|
| 2945 | |||
| 2946 | /** |
||
| 2947 | * Return the value of a property of this object (database row) |
||
| 2948 | * or null if not present. |
||
| 2949 | * |
||
| 2950 | * If a column-names array is passed, it will return a associative array |
||
| 2951 | * with the value of each column or null if it is not present. |
||
| 2952 | * |
||
| 2953 | * @param mixed $key |
||
| 2954 | * |
||
| 2955 | * @return mixed |
||
| 2956 | */ |
||
| 2957 | 35 | public function get($key) |
|
| 2970 | |||
| 2971 | /** |
||
| 2972 | * Return the name of the column in the database table which contains |
||
| 2973 | * the primary key ID of the row. |
||
| 2974 | */ |
||
| 2975 | 50 | protected function _get_id_column_name() |
|
| 2987 | |||
| 2988 | /** |
||
| 2989 | * Get the primary key ID of this object. |
||
| 2990 | * |
||
| 2991 | * @param bool $disallow_null |
||
| 2992 | * |
||
| 2993 | * @return mixed |
||
| 2994 | * |
||
| 2995 | * @throws \Exception |
||
| 2996 | */ |
||
| 2997 | 33 | public function id($disallow_null = false) |
|
| 3015 | |||
| 3016 | /** |
||
| 3017 | * Set a property to a particular value on this object. |
||
| 3018 | * To set multiple properties at once, pass an associative array |
||
| 3019 | * as the first parameter and leave out the second parameter. |
||
| 3020 | * Flags the properties as 'dirty' so they will be saved to the |
||
| 3021 | * database when save() is called. |
||
| 3022 | * |
||
| 3023 | * @param mixed $key |
||
| 3024 | * @param mixed $value |
||
| 3025 | * |
||
| 3026 | * @return $this |
||
| 3027 | */ |
||
| 3028 | 27 | public function set($key, $value = null) |
|
| 3032 | |||
| 3033 | /** |
||
| 3034 | * Set a property to a particular value on this object. |
||
| 3035 | * To set multiple properties at once, pass an associative array |
||
| 3036 | * as the first parameter and leave out the second parameter. |
||
| 3037 | * Flags the properties as 'dirty' so they will be saved to the |
||
| 3038 | * database when save() is called. |
||
| 3039 | * |
||
| 3040 | * @param string|array $key |
||
| 3041 | * @param string|null $value |
||
| 3042 | * |
||
| 3043 | * @return $this |
||
| 3044 | */ |
||
| 3045 | 10 | public function set_expr($key, $value = null) |
|
| 3049 | |||
| 3050 | /** |
||
| 3051 | * Set a property on the ORM object. |
||
| 3052 | * |
||
| 3053 | * @param string|array $key |
||
| 3054 | * @param string|null $value |
||
| 3055 | * @param bool $expr |
||
| 3056 | * |
||
| 3057 | * @return $this |
||
| 3058 | */ |
||
| 3059 | 29 | protected function _set_orm_property($key, $value = null, $expr = false) |
|
| 3078 | |||
| 3079 | /** |
||
| 3080 | * Check whether the given field has been changed since this |
||
| 3081 | * object was saved. |
||
| 3082 | * |
||
| 3083 | * @param string $key |
||
| 3084 | * |
||
| 3085 | * @return bool |
||
| 3086 | */ |
||
| 3087 | 1 | public function is_dirty($key) |
|
| 3091 | |||
| 3092 | /** |
||
| 3093 | * Check whether the model was the result of a call to create() or not |
||
| 3094 | * |
||
| 3095 | * @return bool |
||
| 3096 | */ |
||
| 3097 | 2 | public function is_new() |
|
| 3101 | |||
| 3102 | /** |
||
| 3103 | * Save any fields which have been modified on this object |
||
| 3104 | * to the database. |
||
| 3105 | * |
||
| 3106 | * @return bool |
||
| 3107 | * |
||
| 3108 | * @throws \Exception |
||
| 3109 | */ |
||
| 3110 | 28 | public function save() |
|
| 3182 | |||
| 3183 | /** |
||
| 3184 | * Add a WHERE clause for every column that belongs to the primary key |
||
| 3185 | * |
||
| 3186 | * @param array $query warning: this is a reference |
||
| 3187 | */ |
||
| 3188 | 21 | public function _add_id_column_conditions(&$query) |
|
| 3211 | |||
| 3212 | /** |
||
| 3213 | * Build an UPDATE query |
||
| 3214 | * |
||
| 3215 | * @return string |
||
| 3216 | */ |
||
| 3217 | 17 | protected function _build_update() |
|
| 3237 | |||
| 3238 | /** |
||
| 3239 | * Build an INSERT query |
||
| 3240 | * |
||
| 3241 | * @return string |
||
| 3242 | */ |
||
| 3243 | 12 | protected function _build_insert() |
|
| 3260 | |||
| 3261 | /** |
||
| 3262 | * Delete this record from the database |
||
| 3263 | * |
||
| 3264 | * @return bool |
||
| 3265 | */ |
||
| 3266 | 4 | public function delete() |
|
| 3280 | |||
| 3281 | /** |
||
| 3282 | * Delete many records from the database |
||
| 3283 | * |
||
| 3284 | * @return bool |
||
| 3285 | */ |
||
| 3286 | 2 | public function delete_many() |
|
| 3301 | |||
| 3302 | // --------------------- // |
||
| 3303 | // --- ArrayAccess --- // |
||
| 3304 | // --------------------- // |
||
| 3305 | |||
| 3306 | /** |
||
| 3307 | * @param mixed $key |
||
| 3308 | * |
||
| 3309 | * @return bool |
||
| 3310 | */ |
||
| 3311 | 14 | public function offsetExists($key) |
|
| 3315 | |||
| 3316 | /** |
||
| 3317 | * @param mixed $key |
||
| 3318 | * |
||
| 3319 | * @return mixed |
||
| 3320 | */ |
||
| 3321 | 4 | public function offsetGet($key) |
|
| 3325 | |||
| 3326 | /** |
||
| 3327 | * @param mixed $key |
||
| 3328 | * @param mixed $value |
||
| 3329 | */ |
||
| 3330 | 16 | public function offsetSet($key, $value) |
|
| 3337 | |||
| 3338 | /** |
||
| 3339 | * @param mixed $key |
||
| 3340 | */ |
||
| 3341 | 1 | public function offsetUnset($key) |
|
| 3346 | |||
| 3347 | // --------------------- // |
||
| 3348 | // --- MAGIC METHODS --- // |
||
| 3349 | // --------------------- // |
||
| 3350 | |||
| 3351 | /** |
||
| 3352 | * @param $key |
||
| 3353 | * |
||
| 3354 | * @return mixed |
||
| 3355 | */ |
||
| 3356 | 1 | public function __get($key) |
|
| 3360 | |||
| 3361 | /** |
||
| 3362 | * @param $key |
||
| 3363 | * @param $value |
||
| 3364 | */ |
||
| 3365 | 13 | public function __set($key, $value) |
|
| 3369 | |||
| 3370 | /** |
||
| 3371 | * @param $key |
||
| 3372 | */ |
||
| 3373 | public function __unset($key) |
||
| 3377 | |||
| 3378 | /** |
||
| 3379 | * @param $key |
||
| 3380 | * |
||
| 3381 | * @return bool |
||
| 3382 | */ |
||
| 3383 | 13 | public function __isset($key) |
|
| 3387 | |||
| 3388 | /** |
||
| 3389 | * Magic method to capture calls to undefined class methods. |
||
| 3390 | * In this case we are attempting to convert camel case formatted |
||
| 3391 | * methods into underscore formatted methods. |
||
| 3392 | * |
||
| 3393 | * This allows us to call ORM methods using camel case and remain |
||
| 3394 | * backwards compatible. |
||
| 3395 | * |
||
| 3396 | * @param string $name |
||
| 3397 | * @param array $arguments |
||
| 3398 | * |
||
| 3399 | * @return $this |
||
| 3400 | * |
||
| 3401 | * @throws IdiormMethodMissingException |
||
| 3402 | */ |
||
| 3403 | 81 | public function __call($name, $arguments) |
|
| 3413 | |||
| 3414 | /** |
||
| 3415 | * Magic method to capture calls to undefined static class methods. |
||
| 3416 | * In this case we are attempting to convert camel case formatted |
||
| 3417 | * methods into underscore formatted methods. |
||
| 3418 | * |
||
| 3419 | * This allows us to call ORM methods using camel case and remain |
||
| 3420 | * backwards compatible. |
||
| 3421 | * |
||
| 3422 | * @param string $name |
||
| 3423 | * @param array $arguments |
||
| 3424 | * |
||
| 3425 | * @return $this |
||
| 3426 | */ |
||
| 3427 | 88 | public static function __callStatic($name, $arguments) |
|
| 3433 | |||
| 3434 | } |
||
| 3435 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: