Complex classes like FluentPdoModel 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 FluentPdoModel, and based on these observations, apply Extract Interface, too.
| 1 | <?php declare(strict_types=1); |
||
| 34 | class FluentPdoModel |
||
| 35 | { |
||
| 36 | const ACTIVE = 1; |
||
| 37 | const INACTIVE = 0; |
||
| 38 | const ARCHIVED = -1; |
||
| 39 | const GZIP_PREFIX = 'gzipped|'; |
||
| 40 | const OPERATOR_AND = ' AND '; |
||
| 41 | const OPERATOR_OR = ' OR '; |
||
| 42 | const ORDERBY_ASC = 'ASC'; |
||
| 43 | const ORDERBY_DESC = 'DESC'; |
||
| 44 | const SAVE_INSERT = 'INSERT'; |
||
| 45 | const SAVE_UPDATE = 'UPDATE'; |
||
| 46 | const LEFT_JOIN = 'LEFT'; |
||
| 47 | const INNER_JOIN = 'INNER'; |
||
| 48 | const ONE_DAY = 86400; |
||
| 49 | const ONE_WEEK = 60480060; |
||
| 50 | const ONE_HOUR = 3600; |
||
| 51 | const TEN_MINS = 600; |
||
| 52 | const CACHE_NO = -1; |
||
| 53 | const CACHE_DEFAULT = 0; |
||
| 54 | |||
| 55 | const CREATOR_ID_FIELD = 'created_by_id'; |
||
| 56 | const CREATOR_FIELD = 'creator'; |
||
| 57 | const CREATED_TS_FIELD = 'created_ts'; |
||
| 58 | const MODIFIER_ID_FIELD = 'modified_by_id'; |
||
| 59 | const MODIFIER_FIELD = 'modifier'; |
||
| 60 | const MODIFIED_TS_FIELD = 'modified_ts'; |
||
| 61 | const DELETER_ID_FIELD = 'deleted_by_id'; |
||
| 62 | const DELETER_FIELD = 'deleter'; |
||
| 63 | const DELETED_TS_FIELD = 'deleted_ts'; |
||
| 64 | const STATUS_FIELD = 'status'; |
||
| 65 | |||
| 66 | /** @var AbstractPdo $_connection */ |
||
| 67 | protected $_connection = null; |
||
| 68 | |||
| 69 | /** @var string */ |
||
| 70 | protected $_primary_key = 'id'; |
||
| 71 | |||
| 72 | /** @var array */ |
||
| 73 | protected $_where_parameters = []; |
||
| 74 | |||
| 75 | /** @var array */ |
||
| 76 | protected $_select_fields = []; |
||
| 77 | |||
| 78 | /** @var array */ |
||
| 79 | protected $_join_sources = []; |
||
| 80 | |||
| 81 | /** @var array */ |
||
| 82 | protected $_join_aliases = []; |
||
| 83 | |||
| 84 | /** @var array $_associations */ |
||
| 85 | protected $_associations = [ |
||
| 86 | 'belongsTo' => [], |
||
| 87 | ]; |
||
| 88 | |||
| 89 | /** @var array */ |
||
| 90 | protected $_where_conditions = []; |
||
| 91 | |||
| 92 | protected $_raw_sql = ''; |
||
| 93 | |||
| 94 | /** @var int */ |
||
| 95 | protected $_limit = 0; |
||
| 96 | |||
| 97 | /** @var int */ |
||
| 98 | protected $_offset = 0; |
||
| 99 | |||
| 100 | /** @var array */ |
||
| 101 | protected $_order_by = []; |
||
| 102 | |||
| 103 | /** @var array */ |
||
| 104 | protected $_group_by = []; |
||
| 105 | |||
| 106 | /** @var string */ |
||
| 107 | protected $_and_or_operator = self::OPERATOR_AND; |
||
| 108 | |||
| 109 | /** @var array */ |
||
| 110 | protected $_having = []; |
||
| 111 | |||
| 112 | /** @var bool */ |
||
| 113 | protected $_wrap_open = false; |
||
| 114 | |||
| 115 | /** @var int */ |
||
| 116 | protected $_last_wrap_position = 0; |
||
| 117 | |||
| 118 | /** @var PDOStatement $_pdo_stmt */ |
||
| 119 | protected $_pdo_stmt = null; |
||
| 120 | |||
| 121 | /** @var bool */ |
||
| 122 | protected $_distinct = false; |
||
| 123 | |||
| 124 | /** @var null */ |
||
| 125 | protected $_requested_fields = []; |
||
| 126 | |||
| 127 | /** @var null */ |
||
| 128 | protected $_filter_meta = []; |
||
| 129 | |||
| 130 | /** @var bool */ |
||
| 131 | protected $_log_queries = false; |
||
| 132 | |||
| 133 | /** @var array */ |
||
| 134 | protected $_timer = []; |
||
| 135 | |||
| 136 | /** @var int */ |
||
| 137 | protected $_slow_query_secs = 5; |
||
| 138 | |||
| 139 | /** @var array */ |
||
| 140 | protected $_pagination_attribs = [ |
||
| 141 | '_limit', |
||
| 142 | '_offset', |
||
| 143 | '_order', |
||
| 144 | '_fields', |
||
| 145 | '_search' |
||
| 146 | ]; |
||
| 147 | |||
| 148 | /** @var string $_table_name */ |
||
| 149 | protected $_table_name = ''; |
||
| 150 | |||
| 151 | /** @var string $_table_alias */ |
||
| 152 | protected $_table_alias = ''; |
||
| 153 | |||
| 154 | /** @var string $_display_column */ |
||
| 155 | protected $_display_column = ''; |
||
| 156 | |||
| 157 | /** @var string $_connection_name */ |
||
| 158 | protected $_connection_name = ''; |
||
| 159 | |||
| 160 | /** @var array $_schema */ |
||
| 161 | protected $_schema = []; |
||
| 162 | |||
| 163 | /** @var array $_virtual_fields */ |
||
| 164 | protected $_virtual_fields = []; |
||
| 165 | |||
| 166 | /** @var array $_errors */ |
||
| 167 | protected $_errors = []; |
||
| 168 | |||
| 169 | /** |
||
| 170 | * @var int - true = connection default x days |
||
| 171 | * - false = no cache |
||
| 172 | * - int = a specific amount |
||
| 173 | */ |
||
| 174 | protected $_cache_ttl = self::CACHE_NO; |
||
| 175 | |||
| 176 | /** @var array */ |
||
| 177 | protected $_flush_cache_tables = []; |
||
| 178 | |||
| 179 | /** @var string */ |
||
| 180 | protected $_tmp_table_prefix = 'tmp_'; |
||
| 181 | |||
| 182 | /** @var null|string */ |
||
| 183 | protected $_built_query = ''; |
||
| 184 | |||
| 185 | /** @var array */ |
||
| 186 | protected $_handlers = []; |
||
| 187 | |||
| 188 | /** @var bool User want to directly specify the fields */ |
||
| 189 | protected $_explicit_select_mode = false; |
||
| 190 | |||
| 191 | /** @var string[] */ |
||
| 192 | protected $_update_raw = []; |
||
| 193 | |||
| 194 | protected $_max_callback_failures = -1; |
||
| 195 | |||
| 196 | protected $_num_callback_failures = 0; |
||
| 197 | |||
| 198 | protected $_filter_on_fetch = false; |
||
| 199 | |||
| 200 | protected $_log_filter_changes = true; |
||
| 201 | |||
| 202 | protected $_include_count = false; |
||
| 203 | |||
| 204 | /** @var string */ |
||
| 205 | static protected $_model_namespace = ''; |
||
| 206 | |||
| 207 | /** @var bool */ |
||
| 208 | protected $_validation_exceptions = true; |
||
| 209 | |||
| 210 | /** @var array */ |
||
| 211 | protected $_paging_meta = []; |
||
| 212 | |||
| 213 | /** @var bool */ |
||
| 214 | protected $_soft_deletes = true; |
||
| 215 | |||
| 216 | |||
| 217 | /** @var bool */ |
||
| 218 | protected $_allow_meta_override = false; |
||
| 219 | |||
| 220 | /** @var bool */ |
||
| 221 | protected $_skip_meta_updates = false; |
||
| 222 | |||
| 223 | /** @var bool */ |
||
| 224 | protected $_add_update_alias = false; |
||
| 225 | |||
| 226 | /** @var int */ |
||
| 227 | protected $_default_max = 250; |
||
| 228 | |||
| 229 | /** @var array */ |
||
| 230 | protected $removeUnauthorisedFields = []; |
||
| 231 | |||
| 232 | protected $_can_generic_update = true; |
||
| 233 | protected $_can_generic_add = true; |
||
| 234 | protected $_can_generic_delete = true; |
||
| 235 | |||
| 236 | /** @var array */ |
||
| 237 | protected $row_meta_data = []; |
||
| 238 | |||
| 239 | protected $excluded_search_cols = []; |
||
| 240 | |||
| 241 | |||
| 242 | /** @var array */ |
||
| 243 | protected $globalRemoveUnauthorisedFields = [ |
||
| 244 | '/global_table_meta#view' => [ |
||
| 245 | self::CREATOR_ID_FIELD, |
||
| 246 | self::CREATOR_FIELD, |
||
| 247 | self::CREATED_TS_FIELD, |
||
| 248 | self::MODIFIER_ID_FIELD, |
||
| 249 | self::MODIFIER_FIELD, |
||
| 250 | self::MODIFIED_TS_FIELD, |
||
| 251 | self::STATUS_FIELD, |
||
| 252 | ], |
||
| 253 | ]; |
||
| 254 | |||
| 255 | |||
| 256 | /** |
||
| 257 | * @param AbstractPdo|null $connection |
||
| 258 | */ |
||
| 259 | public function __construct(AbstractPdo $connection=null) |
||
| 266 | |||
| 267 | public function init() |
||
| 269 | |||
| 270 | /** |
||
| 271 | * @return AbstractPdo |
||
| 272 | * @throws Exception |
||
| 273 | */ |
||
| 274 | public function getPdo() : AbstractPdo |
||
| 278 | |||
| 279 | /** |
||
| 280 | * @return LoggerInterface |
||
| 281 | */ |
||
| 282 | public function getLogger() : LoggerInterface |
||
| 286 | |||
| 287 | /** |
||
| 288 | * @return CacheInterface |
||
| 289 | */ |
||
| 290 | public function getCache() : CacheInterface |
||
| 294 | |||
| 295 | /** |
||
| 296 | * Define the working table and create a new instance |
||
| 297 | * |
||
| 298 | * @param string $tableName - Table name |
||
| 299 | * @param string $alias - The table alias name |
||
| 300 | * @param string $displayColumn |
||
| 301 | * @param string $primaryKeyName |
||
| 302 | * |
||
| 303 | * @return FluentPdoModel|$this |
||
| 304 | */ |
||
| 305 | public function table(string $tableName, string $alias='', string $displayColumn='', string $primaryKeyName='id') : FluentPdoModel |
||
| 313 | |||
| 314 | /** |
||
| 315 | * @param string $primaryKeyName |
||
| 316 | * @return FluentPdoModel|$this |
||
| 317 | */ |
||
| 318 | public function primaryKeyName(string $primaryKeyName) : FluentPdoModel |
||
| 324 | |||
| 325 | /** |
||
| 326 | * @param string $tableName |
||
| 327 | * |
||
| 328 | * @return FluentPdoModel|$this |
||
| 329 | */ |
||
| 330 | public function tableName(string $tableName) : FluentPdoModel |
||
| 336 | |||
| 337 | /** |
||
| 338 | * @param $explicitSelect |
||
| 339 | * |
||
| 340 | * @return FluentPdoModel|$this |
||
| 341 | */ |
||
| 342 | public function explicitSelectMode(bool $explicitSelect=true) : FluentPdoModel |
||
| 348 | |||
| 349 | /** |
||
| 350 | * @param bool $filterOnFetch |
||
| 351 | * |
||
| 352 | * @return FluentPdoModel|$this |
||
| 353 | */ |
||
| 354 | public function filterOnFetch(bool $filterOnFetch=true) : FluentPdoModel |
||
| 360 | |||
| 361 | /** |
||
| 362 | * @param bool $logFilterChanges |
||
| 363 | * |
||
| 364 | * @return FluentPdoModel|$this |
||
| 365 | */ |
||
| 366 | public function logFilterChanges(bool $logFilterChanges=true) : FluentPdoModel |
||
| 372 | |||
| 373 | /** |
||
| 374 | * Return the name of the table |
||
| 375 | * |
||
| 376 | * @return string |
||
| 377 | */ |
||
| 378 | public function getTableName() : string |
||
| 382 | |||
| 383 | /** |
||
| 384 | * @return string |
||
| 385 | */ |
||
| 386 | public function getDisplayColumn() : string |
||
| 390 | |||
| 391 | /** |
||
| 392 | * Set the display column |
||
| 393 | * |
||
| 394 | * @param string $column |
||
| 395 | * |
||
| 396 | * @return FluentPdoModel|$this |
||
| 397 | */ |
||
| 398 | public function displayColumn(string $column) : FluentPdoModel |
||
| 404 | /** |
||
| 405 | * Set the table alias |
||
| 406 | * |
||
| 407 | * @param string $alias |
||
| 408 | * |
||
| 409 | * @return FluentPdoModel|$this |
||
| 410 | */ |
||
| 411 | public function tableAlias(string $alias) : FluentPdoModel |
||
| 417 | |||
| 418 | /** |
||
| 419 | * @param int $cacheTtl |
||
| 420 | * @return FluentPdoModel|$this |
||
| 421 | * @throws Exception |
||
| 422 | */ |
||
| 423 | protected function _cacheTtl(int $cacheTtl) : FluentPdoModel |
||
| 434 | |||
| 435 | /** |
||
| 436 | * @return string |
||
| 437 | */ |
||
| 438 | public function getTableAlias() : string |
||
| 442 | |||
| 443 | /** |
||
| 444 | * @param array $associations |
||
| 445 | * |
||
| 446 | * @return FluentPdoModel|$this |
||
| 447 | */ |
||
| 448 | public function associations(array $associations) : FluentPdoModel |
||
| 454 | |||
| 455 | /** |
||
| 456 | * @param string $alias |
||
| 457 | * @param array $definition |
||
| 458 | * @return FluentPdoModel|$this |
||
| 459 | */ |
||
| 460 | public function setBelongsTo(string $alias, array $definition) : FluentPdoModel |
||
| 469 | |||
| 470 | /** |
||
| 471 | * @param $alias |
||
| 472 | * @param $displayField |
||
| 473 | * @return FluentPdoModel|$this |
||
| 474 | * @throws \Terah\Assert\AssertionFailedException |
||
| 475 | */ |
||
| 476 | public function setBelongsToDisplayField(string $alias, string $displayField) : FluentPdoModel |
||
| 486 | |||
| 487 | /** |
||
| 488 | * @param PDOStatement $stmt |
||
| 489 | * |
||
| 490 | * @param PDOStatement $stmt |
||
| 491 | * @param Closure $fnCallback |
||
| 492 | * @return bool|stdClass |
||
| 493 | */ |
||
| 494 | public function fetchRow(PDOStatement $stmt, Closure $fnCallback=null) |
||
| 517 | |||
| 518 | /** |
||
| 519 | * @param PDOStatement $stmt |
||
| 520 | * @param $record |
||
| 521 | * @return array |
||
| 522 | */ |
||
| 523 | protected function getColumnMeta(PDOStatement $stmt, $record) : array |
||
| 542 | |||
| 543 | /** |
||
| 544 | * @param array $schema |
||
| 545 | * |
||
| 546 | * @return FluentPdoModel|$this |
||
| 547 | */ |
||
| 548 | public function schema(array $schema) : FluentPdoModel |
||
| 554 | |||
| 555 | /** |
||
| 556 | * @param string|array $field |
||
| 557 | * @param $type |
||
| 558 | * @return FluentPdoModel|$this |
||
| 559 | */ |
||
| 560 | public function addSchema($field, string $type) : FluentPdoModel |
||
| 576 | |||
| 577 | /** |
||
| 578 | * @param $keysOnly |
||
| 579 | * @return array |
||
| 580 | */ |
||
| 581 | public function getColumns(bool $keysOnly=true) : array |
||
| 585 | |||
| 586 | /** |
||
| 587 | * Get the primary key name |
||
| 588 | * |
||
| 589 | * @return string |
||
| 590 | */ |
||
| 591 | public function getPrimaryKeyName() : string |
||
| 595 | |||
| 596 | /** |
||
| 597 | * @param string $query |
||
| 598 | * @param array $parameters |
||
| 599 | * |
||
| 600 | * @return bool |
||
| 601 | * @throws Exception |
||
| 602 | */ |
||
| 603 | public function execute(string $query, array $parameters=[]) : bool |
||
| 628 | |||
| 629 | /** |
||
| 630 | * @param string $query |
||
| 631 | * @param array $params |
||
| 632 | * @return FluentPdoModel|$this |
||
| 633 | */ |
||
| 634 | public function query(string $query, array $params=[]) : FluentPdoModel |
||
| 641 | |||
| 642 | /** |
||
| 643 | * @param string $sql |
||
| 644 | * @param array $params |
||
| 645 | * |
||
| 646 | * @return string |
||
| 647 | */ |
||
| 648 | public function buildQuery(string $sql, array $params=[]) : string |
||
| 676 | |||
| 677 | /** |
||
| 678 | * @param stdClass $record |
||
| 679 | * |
||
| 680 | * @return stdClass |
||
| 681 | */ |
||
| 682 | protected function _trimAndLowerCaseKeys(stdClass $record) : stdClass |
||
| 692 | |||
| 693 | /** |
||
| 694 | * Return the number of affected row by the last statement |
||
| 695 | * |
||
| 696 | * @return int |
||
| 697 | */ |
||
| 698 | public function rowCount() : int |
||
| 704 | |||
| 705 | /** |
||
| 706 | * @return PDOStatement |
||
| 707 | * @throws PDOException |
||
| 708 | */ |
||
| 709 | public function fetchStmt() |
||
| 718 | |||
| 719 | /** |
||
| 720 | * @return array |
||
| 721 | */ |
||
| 722 | public function fetchSqlQuery() : array |
||
| 732 | |||
| 733 | /** |
||
| 734 | * @param string $tableName |
||
| 735 | * @param bool $dropIfExists |
||
| 736 | * @param array $indexes |
||
| 737 | * @return boolean |
||
| 738 | * @throws Exception |
||
| 739 | */ |
||
| 740 | public function fetchIntoMemoryTable(string $tableName, bool $dropIfExists=true, array $indexes=[]) : bool |
||
| 762 | |||
| 763 | /** |
||
| 764 | * @param string $keyedOn |
||
| 765 | * @param int $cacheTtl |
||
| 766 | * @return stdClass[] |
||
| 767 | */ |
||
| 768 | public function fetch(string $keyedOn='', int $cacheTtl=self::CACHE_NO) : array |
||
| 806 | |||
| 807 | /** |
||
| 808 | * @return string |
||
| 809 | */ |
||
| 810 | protected function _parseWhereForPrimaryLookup() : string |
||
| 826 | |||
| 827 | /** |
||
| 828 | * @param string $cacheKey |
||
| 829 | * @param Closure $func |
||
| 830 | * @param int $cacheTtl - 0 for default ttl, -1 for no cache or int for custom ttl |
||
| 831 | * @return mixed |
||
| 832 | */ |
||
| 833 | protected function _cacheData(string $cacheKey, Closure $func, int $cacheTtl=self::CACHE_DEFAULT) |
||
| 871 | |||
| 872 | /** |
||
| 873 | * @param string $cacheKey |
||
| 874 | * @return bool |
||
| 875 | */ |
||
| 876 | public function clearCache(string $cacheKey) : bool |
||
| 880 | |||
| 881 | /** |
||
| 882 | * @param string $table |
||
| 883 | * @return bool |
||
| 884 | */ |
||
| 885 | public function clearCacheByTable(string $table='') : bool |
||
| 895 | |||
| 896 | /** |
||
| 897 | * @return string[] |
||
| 898 | */ |
||
| 899 | public function getFlushCacheTables() : array |
||
| 903 | |||
| 904 | /** |
||
| 905 | * @param Closure $fnCallback |
||
| 906 | * @return int |
||
| 907 | */ |
||
| 908 | public function fetchCallback(Closure $fnCallback) : int |
||
| 917 | |||
| 918 | /** |
||
| 919 | * @param Closure $fnCallback |
||
| 920 | * @param string $keyedOn |
||
| 921 | * @return array |
||
| 922 | */ |
||
| 923 | public function fetchObjectsByCallback(Closure $fnCallback, string $keyedOn='') : array |
||
| 940 | |||
| 941 | /** |
||
| 942 | * @param $numFailures |
||
| 943 | * @return FluentPdoModel|$this |
||
| 944 | */ |
||
| 945 | public function maxCallbackFailures(int $numFailures) : FluentPdoModel |
||
| 952 | |||
| 953 | /** |
||
| 954 | * @param PDOStatement $stmt |
||
| 955 | * @param Closure $fnCallback |
||
| 956 | * @param int $successCnt |
||
| 957 | * @return bool|null|stdClass |
||
| 958 | */ |
||
| 959 | protected function _tallySuccessCount(PDOStatement $stmt, Closure $fnCallback, int &$successCnt) |
||
| 992 | |||
| 993 | /** |
||
| 994 | * @return bool |
||
| 995 | */ |
||
| 996 | public function canGenericUpdate() : bool |
||
| 1000 | |||
| 1001 | /** |
||
| 1002 | * @return bool |
||
| 1003 | */ |
||
| 1004 | public function canGenericAdd() : bool |
||
| 1008 | |||
| 1009 | /** |
||
| 1010 | * @return bool |
||
| 1011 | */ |
||
| 1012 | public function canGenericDelete() : bool |
||
| 1016 | |||
| 1017 | /** |
||
| 1018 | * @param string $keyedOn |
||
| 1019 | * @param string $valueField |
||
| 1020 | * @param int $cacheTtl |
||
| 1021 | * @return mixed |
||
| 1022 | */ |
||
| 1023 | public function fetchList(string $keyedOn='', string $valueField='', int $cacheTtl=self::CACHE_NO) : array |
||
| 1085 | |||
| 1086 | /** |
||
| 1087 | * @param string $column |
||
| 1088 | * @param int $cacheTtl |
||
| 1089 | * @param bool|true $unique |
||
| 1090 | * @return array |
||
| 1091 | */ |
||
| 1092 | public function fetchColumn(string $column, int $cacheTtl=self::CACHE_NO, bool $unique=true) : array |
||
| 1102 | |||
| 1103 | /** |
||
| 1104 | * @param string $field |
||
| 1105 | * @param int $itemId |
||
| 1106 | * @param int $cacheTtl |
||
| 1107 | * @return mixed|null |
||
| 1108 | */ |
||
| 1109 | public function fetchField(string $field='', int $itemId=0, int $cacheTtl=self::CACHE_NO) |
||
| 1132 | |||
| 1133 | /** |
||
| 1134 | * @param string $field |
||
| 1135 | * @param int $itemId |
||
| 1136 | * @param int $cacheTtl |
||
| 1137 | * @return string |
||
| 1138 | */ |
||
| 1139 | public function fetchStr(string $field='', $itemId=0, int $cacheTtl=self::CACHE_NO) : string |
||
| 1143 | |||
| 1144 | /** |
||
| 1145 | * @param int $cacheTtl |
||
| 1146 | * @return int |
||
| 1147 | */ |
||
| 1148 | public function fetchId(int $cacheTtl=self::CACHE_NO) : int |
||
| 1152 | |||
| 1153 | /** |
||
| 1154 | * @param string $field |
||
| 1155 | * @param int $itemId |
||
| 1156 | * @param int $cacheTtl |
||
| 1157 | * @return int |
||
| 1158 | */ |
||
| 1159 | public function fetchInt(string $field='', int $itemId=0, int $cacheTtl=self::CACHE_NO) : int |
||
| 1163 | |||
| 1164 | /** |
||
| 1165 | * @param string $field |
||
| 1166 | * @param int $itemId |
||
| 1167 | * @param int $cacheTtl |
||
| 1168 | * @return float |
||
| 1169 | */ |
||
| 1170 | public function fetchFloat(string $field='', int $itemId=0, int $cacheTtl=self::CACHE_NO) : float |
||
| 1174 | |||
| 1175 | /** |
||
| 1176 | * @param string $field |
||
| 1177 | * @param int $itemId |
||
| 1178 | * @param int $cacheTtl |
||
| 1179 | * @return bool |
||
| 1180 | */ |
||
| 1181 | public function fetchBool(string $field='', int $itemId=0, int $cacheTtl=self::CACHE_NO) : bool |
||
| 1185 | |||
| 1186 | /** |
||
| 1187 | * @param int|null $id |
||
| 1188 | * @param int $cacheTtl |
||
| 1189 | * @return stdClass|bool |
||
| 1190 | */ |
||
| 1191 | public function fetchOne(int $id=0, int $cacheTtl=self::CACHE_NO) |
||
| 1202 | |||
| 1203 | /** |
||
| 1204 | * @param int|null $id |
||
| 1205 | * @param int $cacheTtl |
||
| 1206 | * @return boolean |
||
| 1207 | */ |
||
| 1208 | public function fetchExists(int $id=0, int $cacheTtl=self::CACHE_NO) : bool |
||
| 1218 | |||
| 1219 | /*------------------------------------------------------------------------------ |
||
| 1220 | Fluent Query Builder |
||
| 1221 | *-----------------------------------------------------------------------------*/ |
||
| 1222 | |||
| 1223 | /** |
||
| 1224 | * Create the select clause |
||
| 1225 | * |
||
| 1226 | * @param mixed $columns - the column to select. Can be string or array of fields |
||
| 1227 | * @param string $alias - an alias to the column |
||
| 1228 | * @param boolean $explicitSelect |
||
| 1229 | * @return FluentPdoModel|$this |
||
| 1230 | */ |
||
| 1231 | public function select($columns='*', string $alias='', bool $explicitSelect=true) : FluentPdoModel |
||
| 1273 | |||
| 1274 | /** |
||
| 1275 | * @param string $select |
||
| 1276 | * @return FluentPdoModel|$this |
||
| 1277 | */ |
||
| 1278 | public function selectRaw(string $select) : FluentPdoModel |
||
| 1284 | |||
| 1285 | /** |
||
| 1286 | * @param bool $logQueries |
||
| 1287 | * |
||
| 1288 | * @return FluentPdoModel|$this |
||
| 1289 | */ |
||
| 1290 | public function logQueries(bool $logQueries=true) : FluentPdoModel |
||
| 1296 | |||
| 1297 | /** |
||
| 1298 | * @param bool $includeCnt |
||
| 1299 | * |
||
| 1300 | * @return FluentPdoModel|$this |
||
| 1301 | */ |
||
| 1302 | public function includeCount(bool $includeCnt=true) : FluentPdoModel |
||
| 1308 | |||
| 1309 | /** |
||
| 1310 | * @param bool $distinct |
||
| 1311 | * |
||
| 1312 | * @return FluentPdoModel|$this |
||
| 1313 | */ |
||
| 1314 | public function distinct(bool $distinct=true) : FluentPdoModel |
||
| 1320 | |||
| 1321 | /** |
||
| 1322 | * @param array $fields |
||
| 1323 | * @return FluentPdoModel|$this |
||
| 1324 | */ |
||
| 1325 | public function withBelongsTo(array $fields=[]) : FluentPdoModel |
||
| 1338 | |||
| 1339 | /** |
||
| 1340 | * @param string $alias |
||
| 1341 | * @param bool $addSelectField |
||
| 1342 | * @return FluentPdoModel |
||
| 1343 | */ |
||
| 1344 | public function autoInnerJoin(string $alias, bool $addSelectField=true) : FluentPdoModel |
||
| 1348 | |||
| 1349 | /** |
||
| 1350 | * @param string $alias |
||
| 1351 | * @param string $type |
||
| 1352 | * @param bool $addSelectField |
||
| 1353 | * @return FluentPdoModel|$this |
||
| 1354 | */ |
||
| 1355 | public function autoJoin(string $alias, string $type=self::LEFT_JOIN, bool $addSelectField=true) : FluentPdoModel |
||
| 1384 | |||
| 1385 | /** |
||
| 1386 | * @param array $conditions |
||
| 1387 | * @return FluentPdoModel |
||
| 1388 | */ |
||
| 1389 | public function whereArr(array $conditions) : FluentPdoModel |
||
| 1398 | /** |
||
| 1399 | * Add where condition, more calls appends with AND |
||
| 1400 | * |
||
| 1401 | * @param string $condition possibly containing ? or :name |
||
| 1402 | * @param mixed $parameters accepted by PDOStatement::execute or a scalar value |
||
| 1403 | * @param mixed ... |
||
| 1404 | * @return FluentPdoModel|$this |
||
| 1405 | */ |
||
| 1406 | public function where($condition, $parameters=[]) : FluentPdoModel |
||
| 1455 | |||
| 1456 | /** |
||
| 1457 | * Create an AND operator in the where clause |
||
| 1458 | * |
||
| 1459 | * @return FluentPdoModel|$this |
||
| 1460 | */ |
||
| 1461 | public function _and() : FluentPdoModel |
||
| 1475 | |||
| 1476 | |||
| 1477 | /** |
||
| 1478 | * Create an OR operator in the where clause |
||
| 1479 | * |
||
| 1480 | * @return FluentPdoModel|$this |
||
| 1481 | */ |
||
| 1482 | public function _or() : FluentPdoModel |
||
| 1496 | |||
| 1497 | /** |
||
| 1498 | * To group multiple where clauses together. |
||
| 1499 | * |
||
| 1500 | * @return FluentPdoModel|$this |
||
| 1501 | */ |
||
| 1502 | public function wrap() : FluentPdoModel |
||
| 1512 | |||
| 1513 | /** |
||
| 1514 | * Where Primary key |
||
| 1515 | * |
||
| 1516 | * @param int $id |
||
| 1517 | * @param bool $addAlias |
||
| 1518 | * |
||
| 1519 | * @return FluentPdoModel|$this |
||
| 1520 | */ |
||
| 1521 | public function wherePk(int $id, bool $addAlias=true) : FluentPdoModel |
||
| 1527 | |||
| 1528 | /** |
||
| 1529 | * @param string $name |
||
| 1530 | * @param bool $addAlias |
||
| 1531 | * @return FluentPdoModel |
||
| 1532 | */ |
||
| 1533 | public function whereDisplayName(string $name, bool $addAlias=true) : FluentPdoModel |
||
| 1539 | |||
| 1540 | /** |
||
| 1541 | * WHERE $columnName != $value |
||
| 1542 | * |
||
| 1543 | * @param string $columnName |
||
| 1544 | * @param mixed $value |
||
| 1545 | * @return FluentPdoModel|$this |
||
| 1546 | */ |
||
| 1547 | public function whereNot(string $columnName, $value) : FluentPdoModel |
||
| 1551 | /** |
||
| 1552 | * WHERE $columnName != $value |
||
| 1553 | * |
||
| 1554 | * @param string $columnName |
||
| 1555 | * @param mixed $value |
||
| 1556 | * @return FluentPdoModel|$this |
||
| 1557 | */ |
||
| 1558 | public function whereCoercedNot(string $columnName, $value) : FluentPdoModel |
||
| 1562 | |||
| 1563 | /** |
||
| 1564 | * WHERE $columnName LIKE $value |
||
| 1565 | * |
||
| 1566 | * @param string $columnName |
||
| 1567 | * @param mixed $value |
||
| 1568 | * @return FluentPdoModel|$this |
||
| 1569 | */ |
||
| 1570 | public function whereLike(string $columnName, $value) : FluentPdoModel |
||
| 1574 | |||
| 1575 | /** |
||
| 1576 | * @param string $columnName |
||
| 1577 | * @param mixed $value1 |
||
| 1578 | * @param mixed $value2 |
||
| 1579 | * @return FluentPdoModel|$this |
||
| 1580 | */ |
||
| 1581 | public function whereBetween(string $columnName, $value1, $value2) : FluentPdoModel |
||
| 1588 | |||
| 1589 | /** |
||
| 1590 | * @param string $columnName |
||
| 1591 | * @param mixed $value1 |
||
| 1592 | * @param mixed $value2 |
||
| 1593 | * @return FluentPdoModel|$this |
||
| 1594 | */ |
||
| 1595 | public function whereNotBetween(string $columnName, $value1, $value2) : FluentPdoModel |
||
| 1602 | |||
| 1603 | /** |
||
| 1604 | * @param string $columnName |
||
| 1605 | * @param string $regex |
||
| 1606 | * @return FluentPdoModel|$this |
||
| 1607 | */ |
||
| 1608 | public function whereRegex(string $columnName, string $regex) : FluentPdoModel |
||
| 1612 | |||
| 1613 | /** |
||
| 1614 | * @param string $columnName |
||
| 1615 | * @param string $regex |
||
| 1616 | * @return FluentPdoModel|$this |
||
| 1617 | */ |
||
| 1618 | public function whereNotRegex(string $columnName, string $regex) : FluentPdoModel |
||
| 1622 | |||
| 1623 | /** |
||
| 1624 | * WHERE $columnName NOT LIKE $value |
||
| 1625 | * |
||
| 1626 | * @param string $columnName |
||
| 1627 | * @param string $value |
||
| 1628 | * @return FluentPdoModel|$this |
||
| 1629 | */ |
||
| 1630 | public function whereNotLike(string $columnName, string $value) : FluentPdoModel |
||
| 1634 | |||
| 1635 | /** |
||
| 1636 | * WHERE $columnName > $value |
||
| 1637 | * |
||
| 1638 | * @param string $columnName |
||
| 1639 | * @param mixed $value |
||
| 1640 | * @return FluentPdoModel|$this |
||
| 1641 | */ |
||
| 1642 | public function whereGt(string $columnName, $value) : FluentPdoModel |
||
| 1646 | |||
| 1647 | /** |
||
| 1648 | * WHERE $columnName >= $value |
||
| 1649 | * |
||
| 1650 | * @param string $columnName |
||
| 1651 | * @param mixed $value |
||
| 1652 | * @return FluentPdoModel|$this |
||
| 1653 | */ |
||
| 1654 | public function whereGte(string $columnName, $value) : FluentPdoModel |
||
| 1658 | |||
| 1659 | /** |
||
| 1660 | * WHERE $columnName < $value |
||
| 1661 | * |
||
| 1662 | * @param string $columnName |
||
| 1663 | * @param mixed $value |
||
| 1664 | * @return FluentPdoModel|$this |
||
| 1665 | */ |
||
| 1666 | public function whereLt(string $columnName, $value) : FluentPdoModel |
||
| 1670 | |||
| 1671 | /** |
||
| 1672 | * WHERE $columnName <= $value |
||
| 1673 | * |
||
| 1674 | * @param string $columnName |
||
| 1675 | * @param mixed $value |
||
| 1676 | * @return FluentPdoModel|$this |
||
| 1677 | */ |
||
| 1678 | public function whereLte(string $columnName, $value) : FluentPdoModel |
||
| 1682 | |||
| 1683 | /** |
||
| 1684 | * WHERE $columnName IN (?,?,?,...) |
||
| 1685 | * |
||
| 1686 | * @param string $columnName |
||
| 1687 | * @param array $values |
||
| 1688 | * @return FluentPdoModel|$this |
||
| 1689 | */ |
||
| 1690 | public function whereIn(string $columnName, array $values) : FluentPdoModel |
||
| 1694 | |||
| 1695 | /** |
||
| 1696 | * WHERE $columnName NOT IN (?,?,?,...) |
||
| 1697 | * |
||
| 1698 | * @param string $columnName |
||
| 1699 | * @param array $values |
||
| 1700 | * @return FluentPdoModel|$this |
||
| 1701 | */ |
||
| 1702 | public function whereNotIn(string $columnName, array $values) : FluentPdoModel |
||
| 1708 | |||
| 1709 | /** |
||
| 1710 | * WHERE $columnName IS NULL |
||
| 1711 | * |
||
| 1712 | * @param string $columnName |
||
| 1713 | * @return FluentPdoModel|$this |
||
| 1714 | */ |
||
| 1715 | public function whereNull(string $columnName) : FluentPdoModel |
||
| 1719 | |||
| 1720 | /** |
||
| 1721 | * WHERE $columnName IS NOT NULL |
||
| 1722 | * |
||
| 1723 | * @param string $columnName |
||
| 1724 | * @return FluentPdoModel|$this |
||
| 1725 | */ |
||
| 1726 | public function whereNotNull(string $columnName) : FluentPdoModel |
||
| 1730 | |||
| 1731 | /** |
||
| 1732 | * @param string $statement |
||
| 1733 | * @param string $operator |
||
| 1734 | * @return FluentPdoModel|$this |
||
| 1735 | */ |
||
| 1736 | public function having(string $statement, string $operator=self::OPERATOR_AND) : FluentPdoModel |
||
| 1745 | |||
| 1746 | /** |
||
| 1747 | * ORDER BY $columnName (ASC | DESC) |
||
| 1748 | * |
||
| 1749 | * @param string $columnName - The name of the column or an expression |
||
| 1750 | * @param string $ordering (DESC | ASC) |
||
| 1751 | * @return FluentPdoModel|$this |
||
| 1752 | */ |
||
| 1753 | public function orderBy(string $columnName='', string $ordering='ASC') : FluentPdoModel |
||
| 1767 | |||
| 1768 | /** |
||
| 1769 | * GROUP BY $columnName |
||
| 1770 | * |
||
| 1771 | * @param string $columnName |
||
| 1772 | * @return FluentPdoModel|$this |
||
| 1773 | */ |
||
| 1774 | public function groupBy(string $columnName) : FluentPdoModel |
||
| 1784 | |||
| 1785 | |||
| 1786 | /** |
||
| 1787 | * LIMIT $limit |
||
| 1788 | * |
||
| 1789 | * @param int $limit |
||
| 1790 | * @param int|null $offset |
||
| 1791 | * @return FluentPdoModel|$this |
||
| 1792 | */ |
||
| 1793 | public function limit(int $limit, int $offset=0) : FluentPdoModel |
||
| 1802 | |||
| 1803 | /** |
||
| 1804 | * Return the limit |
||
| 1805 | * |
||
| 1806 | * @return integer |
||
| 1807 | */ |
||
| 1808 | public function getLimit() : int |
||
| 1812 | |||
| 1813 | /** |
||
| 1814 | * OFFSET $offset |
||
| 1815 | * |
||
| 1816 | * @param int $offset |
||
| 1817 | * @return FluentPdoModel|$this |
||
| 1818 | */ |
||
| 1819 | public function offset(int $offset) : FluentPdoModel |
||
| 1825 | |||
| 1826 | /** |
||
| 1827 | * Return the offset |
||
| 1828 | * |
||
| 1829 | * @return integer |
||
| 1830 | */ |
||
| 1831 | public function getOffset() : int |
||
| 1835 | |||
| 1836 | /** |
||
| 1837 | * Build a join |
||
| 1838 | * |
||
| 1839 | * @param string $table - The table name |
||
| 1840 | * @param string $constraint -> id = profile.user_id |
||
| 1841 | * @param string $tableAlias - The alias of the table name |
||
| 1842 | * @param string $joinOperator - LEFT | INNER | etc... |
||
| 1843 | * @return FluentPdoModel|$this |
||
| 1844 | */ |
||
| 1845 | public function join(string $table, string $constraint='', string $tableAlias='', string $joinOperator='') : FluentPdoModel |
||
| 1864 | |||
| 1865 | /** |
||
| 1866 | * Create a left join |
||
| 1867 | * |
||
| 1868 | * @param string $table |
||
| 1869 | * @param string $constraint |
||
| 1870 | * @param string $tableAlias |
||
| 1871 | * @return FluentPdoModel|$this |
||
| 1872 | */ |
||
| 1873 | public function leftJoin(string $table, string $constraint, string $tableAlias='') : FluentPdoModel |
||
| 1877 | |||
| 1878 | |||
| 1879 | /** |
||
| 1880 | * Return the build select query |
||
| 1881 | * |
||
| 1882 | * @return string |
||
| 1883 | */ |
||
| 1884 | public function getSelectQuery() : string |
||
| 1927 | |||
| 1928 | /** |
||
| 1929 | * @param string $field |
||
| 1930 | * @param string $column |
||
| 1931 | * @return string |
||
| 1932 | */ |
||
| 1933 | public function getFieldComment(string $field, string $column) : string |
||
| 1937 | |||
| 1938 | /** |
||
| 1939 | * Prepare columns to include the table alias name |
||
| 1940 | * @param array $columns |
||
| 1941 | * @return array |
||
| 1942 | */ |
||
| 1943 | protected function _prepareColumns(array $columns) : array |
||
| 1973 | |||
| 1974 | /** |
||
| 1975 | * Build the WHERE clause(s) |
||
| 1976 | * |
||
| 1977 | * @param bool $purgeAliases |
||
| 1978 | * @return string |
||
| 1979 | */ |
||
| 1980 | protected function _getWhereString(bool $purgeAliases=false) : string |
||
| 2013 | |||
| 2014 | /** |
||
| 2015 | * Return the HAVING clause |
||
| 2016 | * |
||
| 2017 | * @return string |
||
| 2018 | */ |
||
| 2019 | protected function _getHavingString() : string |
||
| 2038 | |||
| 2039 | /** |
||
| 2040 | * Return the values to be bound for where |
||
| 2041 | * |
||
| 2042 | * @param bool $purgeAliases |
||
| 2043 | * @return array |
||
| 2044 | */ |
||
| 2045 | protected function _getWhereParameters(bool $purgeAliases=false) : array |
||
| 2051 | |||
| 2052 | /** |
||
| 2053 | * @param array $record |
||
| 2054 | * @return stdClass |
||
| 2055 | */ |
||
| 2056 | public function insertArr(array $record) : stdClass |
||
| 2060 | |||
| 2061 | /** |
||
| 2062 | * Insert new rows |
||
| 2063 | * $records can be a stdClass or an array of stdClass to add a bulk insert |
||
| 2064 | * If a single row is inserted, it will return it's row instance |
||
| 2065 | * |
||
| 2066 | * @param stdClass $record |
||
| 2067 | * @return stdClass |
||
| 2068 | * @throws Exception |
||
| 2069 | */ |
||
| 2070 | public function insert(stdClass $record) : stdClass |
||
| 2093 | |||
| 2094 | /** |
||
| 2095 | * @param string $name |
||
| 2096 | * @return int |
||
| 2097 | */ |
||
| 2098 | public function getLastInsertId(string $name='') : int |
||
| 2102 | |||
| 2103 | /** |
||
| 2104 | * @param stdClass[] $records |
||
| 2105 | * @return stdClass[] |
||
| 2106 | */ |
||
| 2107 | public function insertSqlQuery(array $records) : array |
||
| 2127 | |||
| 2128 | /** |
||
| 2129 | * @param $data |
||
| 2130 | * @param array $matchOn |
||
| 2131 | * @param bool $returnObj |
||
| 2132 | * @return bool|int|stdClass |
||
| 2133 | */ |
||
| 2134 | public function upsert($data, array $matchOn=[], $returnObj=false) |
||
| 2156 | |||
| 2157 | /** |
||
| 2158 | * @param stdClass $object |
||
| 2159 | * @param array $matchOn |
||
| 2160 | * @param bool $returnObj |
||
| 2161 | * @return bool|int|stdClass |
||
| 2162 | */ |
||
| 2163 | public function upsertOne(stdClass $object, array $matchOn=[], $returnObj=false) |
||
| 2203 | |||
| 2204 | /** |
||
| 2205 | * @param array $data |
||
| 2206 | * @param array $matchOn |
||
| 2207 | * @param bool|false $returnObj |
||
| 2208 | * @return bool|int|stdClass |
||
| 2209 | */ |
||
| 2210 | public function upsertArr(array $data, array $matchOn=[], bool $returnObj=false) |
||
| 2214 | |||
| 2215 | /** |
||
| 2216 | * Update entries |
||
| 2217 | * Use the query builder to create the where clause |
||
| 2218 | * |
||
| 2219 | * @param stdClass $record |
||
| 2220 | * @param bool $updateAll |
||
| 2221 | * @return int |
||
| 2222 | * @throws Exception |
||
| 2223 | */ |
||
| 2224 | public function update(stdClass $record, $updateAll=false) : int |
||
| 2247 | |||
| 2248 | /** |
||
| 2249 | * @param array $record |
||
| 2250 | * @param bool|false $updateAll |
||
| 2251 | * @return int |
||
| 2252 | * @throws Exception |
||
| 2253 | */ |
||
| 2254 | public function updateArr(array $record, $updateAll=false) : int |
||
| 2258 | |||
| 2259 | |||
| 2260 | /** |
||
| 2261 | * @param string $field |
||
| 2262 | * @param mixed $value |
||
| 2263 | * @param int $id |
||
| 2264 | * @param bool|false $updateAll |
||
| 2265 | * @return int |
||
| 2266 | * @throws Exception |
||
| 2267 | */ |
||
| 2268 | public function updateField(string $field, $value, int $id=0, bool $updateAll=false) : int |
||
| 2277 | |||
| 2278 | /** |
||
| 2279 | * @param stdClass $record |
||
| 2280 | * @return bool|int |
||
| 2281 | * @throws Exception |
||
| 2282 | */ |
||
| 2283 | public function updateChanged(stdClass $record) : int |
||
| 2297 | |||
| 2298 | /** |
||
| 2299 | * @param string $expression |
||
| 2300 | * @param array $params |
||
| 2301 | * @return FluentPdoModel|$this |
||
| 2302 | */ |
||
| 2303 | public function updateByExpression(string $expression, array $params) : FluentPdoModel |
||
| 2309 | |||
| 2310 | /** |
||
| 2311 | * @param array $data |
||
| 2312 | * @return int |
||
| 2313 | * @throws Exception |
||
| 2314 | */ |
||
| 2315 | public function rawUpdate(array $data=[]) : int |
||
| 2324 | |||
| 2325 | /** |
||
| 2326 | * @param stdClass $record |
||
| 2327 | * @return array |
||
| 2328 | */ |
||
| 2329 | public function updateSqlQuery(stdClass $record) : array |
||
| 2339 | |||
| 2340 | /** |
||
| 2341 | * @param $record |
||
| 2342 | * @return array |
||
| 2343 | */ |
||
| 2344 | protected function updateSql(array $record) : array |
||
| 2377 | |||
| 2378 | /** |
||
| 2379 | * @param bool $deleteAll |
||
| 2380 | * @param bool $force |
||
| 2381 | * @return int |
||
| 2382 | * @throws Exception |
||
| 2383 | */ |
||
| 2384 | public function delete(bool $deleteAll=false, bool $force=false) : int |
||
| 2400 | |||
| 2401 | /** |
||
| 2402 | * @return bool |
||
| 2403 | */ |
||
| 2404 | public function isSoftDelete() : bool |
||
| 2408 | |||
| 2409 | /** |
||
| 2410 | * @param bool|false $force |
||
| 2411 | * @return FluentPdoModel|$this |
||
| 2412 | * @throws Exception |
||
| 2413 | */ |
||
| 2414 | public function truncate(bool $force=false) : FluentPdoModel |
||
| 2428 | |||
| 2429 | /** |
||
| 2430 | * @return array |
||
| 2431 | */ |
||
| 2432 | public function deleteSqlQuery() : array |
||
| 2444 | |||
| 2445 | |||
| 2446 | /** |
||
| 2447 | * Return the aggregate count of column |
||
| 2448 | * |
||
| 2449 | * @param string $column |
||
| 2450 | * @param int $cacheTtl |
||
| 2451 | * @return float |
||
| 2452 | */ |
||
| 2453 | public function count(string $column='*', int $cacheTtl=self::CACHE_NO) : float |
||
| 2473 | |||
| 2474 | |||
| 2475 | /** |
||
| 2476 | * Return the aggregate max count of column |
||
| 2477 | * |
||
| 2478 | * @param string $column |
||
| 2479 | * @param int $cacheTtl |
||
| 2480 | * @return int|float|string|null |
||
| 2481 | */ |
||
| 2482 | public function max(string $column, int $cacheTtl=self::CACHE_NO) |
||
| 2488 | |||
| 2489 | |||
| 2490 | /** |
||
| 2491 | * Return the aggregate min count of column |
||
| 2492 | * |
||
| 2493 | * @param string $column |
||
| 2494 | * @param int $cacheTtl |
||
| 2495 | * @return int|float|string|null |
||
| 2496 | */ |
||
| 2497 | public function min(string $column, int $cacheTtl=self::CACHE_NO) |
||
| 2503 | |||
| 2504 | /** |
||
| 2505 | * Return the aggregate sum count of column |
||
| 2506 | * |
||
| 2507 | * @param string $column |
||
| 2508 | * @param int $cacheTtl |
||
| 2509 | * @return int|float|string|null |
||
| 2510 | */ |
||
| 2511 | public function sum(string $column, int $cacheTtl=self::CACHE_NO) |
||
| 2517 | |||
| 2518 | /** |
||
| 2519 | * Return the aggregate average count of column |
||
| 2520 | * |
||
| 2521 | * @param string $column |
||
| 2522 | * @param int $cacheTtl |
||
| 2523 | * @return int|float|string|null |
||
| 2524 | */ |
||
| 2525 | public function avg(string $column, int $cacheTtl=self::CACHE_NO) |
||
| 2531 | |||
| 2532 | /*******************************************************************************/ |
||
| 2533 | // Utilities methods |
||
| 2534 | |||
| 2535 | /** |
||
| 2536 | * Reset fields |
||
| 2537 | * |
||
| 2538 | * @return FluentPdoModel|$this |
||
| 2539 | */ |
||
| 2540 | public function reset() : FluentPdoModel |
||
| 2568 | |||
| 2569 | |||
| 2570 | /** |
||
| 2571 | * @return FluentPdoModel|$this |
||
| 2572 | */ |
||
| 2573 | public function removeUnauthorisedFields() : FluentPdoModel |
||
| 2577 | |||
| 2578 | /** |
||
| 2579 | * @return Closure[] |
||
| 2580 | */ |
||
| 2581 | protected function _getFieldHandlers() : array |
||
| 2649 | |||
| 2650 | /** |
||
| 2651 | * @return bool |
||
| 2652 | */ |
||
| 2653 | public function begin() : bool |
||
| 2667 | |||
| 2668 | /** |
||
| 2669 | * @return bool |
||
| 2670 | */ |
||
| 2671 | public function commit() : bool |
||
| 2689 | |||
| 2690 | /** |
||
| 2691 | * @return bool |
||
| 2692 | */ |
||
| 2693 | public function rollback() : bool |
||
| 2707 | |||
| 2708 | /** |
||
| 2709 | * @param stdClass $record |
||
| 2710 | * @param string $type |
||
| 2711 | * @return stdClass |
||
| 2712 | */ |
||
| 2713 | public function applyGlobalModifiers(stdClass $record, string $type) : stdClass |
||
| 2726 | |||
| 2727 | /** |
||
| 2728 | * @param stdClass $record |
||
| 2729 | * @param string $type |
||
| 2730 | * @return stdClass |
||
| 2731 | */ |
||
| 2732 | public function removeUnneededFields(stdClass $record, string $type) : stdClass |
||
| 2761 | |||
| 2762 | |||
| 2763 | /** |
||
| 2764 | * @param array $ids |
||
| 2765 | * @param array $values |
||
| 2766 | * @param int $batch |
||
| 2767 | * @return bool |
||
| 2768 | */ |
||
| 2769 | public function setById(array $ids, array $values, int $batch=1000) : bool |
||
| 2789 | |||
| 2790 | |||
| 2791 | /** |
||
| 2792 | * @param string $displayColumnValue |
||
| 2793 | * @return int |
||
| 2794 | */ |
||
| 2795 | public function resolveId(string $displayColumnValue) : int |
||
| 2806 | |||
| 2807 | /** |
||
| 2808 | * @param int $resourceId |
||
| 2809 | * @param array $query |
||
| 2810 | * @param array $extraFields |
||
| 2811 | * @param int $cacheTtl |
||
| 2812 | * @return array |
||
| 2813 | */ |
||
| 2814 | public function fetchApiResource(int $resourceId, array $query=[], array $extraFields=[], int $cacheTtl=self::CACHE_NO) : array |
||
| 2827 | |||
| 2828 | /** |
||
| 2829 | * @param array $query |
||
| 2830 | * @param array $extraFields |
||
| 2831 | * @param int $cacheTtl |
||
| 2832 | * @param string $permEntity |
||
| 2833 | * @return array |
||
| 2834 | */ |
||
| 2835 | public function fetchApiResources(array $query=[], array $extraFields=[], int $cacheTtl=self::CACHE_NO, string $permEntity='') : array |
||
| 2857 | |||
| 2858 | |||
| 2859 | /** |
||
| 2860 | * @return array |
||
| 2861 | */ |
||
| 2862 | public function getSearchableAssociations() : array |
||
| 2869 | |||
| 2870 | /** |
||
| 2871 | * @param array $fields |
||
| 2872 | */ |
||
| 2873 | public function removeUnrequestedFields(array $fields) |
||
| 2884 | |||
| 2885 | /** |
||
| 2886 | * @param array $removeFields |
||
| 2887 | */ |
||
| 2888 | public function removeFields(array $removeFields=[]) |
||
| 2913 | |||
| 2914 | /** |
||
| 2915 | * @return FluentPdoModel|$this |
||
| 2916 | */ |
||
| 2917 | public function defaultFilters() : FluentPdoModel |
||
| 2921 | |||
| 2922 | /** |
||
| 2923 | * @param bool $allow |
||
| 2924 | * |
||
| 2925 | * @return FluentPdoModel|$this |
||
| 2926 | */ |
||
| 2927 | public function allowMetaColumnOverride(bool $allow=false) : FluentPdoModel |
||
| 2933 | |||
| 2934 | /** |
||
| 2935 | * @param bool $skip |
||
| 2936 | * |
||
| 2937 | * @return FluentPdoModel|$this |
||
| 2938 | */ |
||
| 2939 | public function skipMetaUpdates(bool $skip=true) : FluentPdoModel |
||
| 2945 | |||
| 2946 | /** |
||
| 2947 | * @param bool $add |
||
| 2948 | * |
||
| 2949 | * @return FluentPdoModel|$this |
||
| 2950 | */ |
||
| 2951 | public function addUpdateAlias(bool $add=true) : FluentPdoModel |
||
| 2957 | |||
| 2958 | /** |
||
| 2959 | * @param stdClass $record |
||
| 2960 | * @return stdClass |
||
| 2961 | */ |
||
| 2962 | public function onFetch(stdClass $record) : stdClass |
||
| 2974 | |||
| 2975 | /** |
||
| 2976 | * @param $value |
||
| 2977 | * @return string |
||
| 2978 | */ |
||
| 2979 | public function gzEncodeData(string $value) : string |
||
| 2988 | |||
| 2989 | /** |
||
| 2990 | * @param $value |
||
| 2991 | * @return mixed|string |
||
| 2992 | */ |
||
| 2993 | public function gzDecodeData(string $value) : string |
||
| 3003 | |||
| 3004 | /** |
||
| 3005 | * @param $value |
||
| 3006 | * @return bool |
||
| 3007 | */ |
||
| 3008 | protected function _hasGzipPrefix(string $value) : bool |
||
| 3012 | |||
| 3013 | /** |
||
| 3014 | * @param stdClass $record |
||
| 3015 | * @return stdClass |
||
| 3016 | */ |
||
| 3017 | public function fixTimestamps(stdClass $record) : stdClass |
||
| 3029 | |||
| 3030 | /** |
||
| 3031 | * @param int $max |
||
| 3032 | * @return FluentPdoModel|$this |
||
| 3033 | */ |
||
| 3034 | public function setMaxRecords(int $max) : FluentPdoModel |
||
| 3041 | |||
| 3042 | |||
| 3043 | /** |
||
| 3044 | * @param stdClass $record |
||
| 3045 | * @param string $type |
||
| 3046 | * @return stdClass |
||
| 3047 | */ |
||
| 3048 | public function afterSave(stdClass $record, string $type) : stdClass |
||
| 3069 | |||
| 3070 | /** |
||
| 3071 | * @param stdClass $record |
||
| 3072 | * @param string $type |
||
| 3073 | * @return stdClass |
||
| 3074 | */ |
||
| 3075 | public function addDefaultFields(stdClass $record, string $type) : stdClass |
||
| 3108 | |||
| 3109 | |||
| 3110 | /** |
||
| 3111 | * @return bool |
||
| 3112 | */ |
||
| 3113 | public function createTable() : bool |
||
| 3117 | |||
| 3118 | /** |
||
| 3119 | * @param bool|false $force |
||
| 3120 | * @return FluentPdoModel|$this |
||
| 3121 | * @throws Exception |
||
| 3122 | */ |
||
| 3123 | public function dropTable(bool $force=false) : FluentPdoModel |
||
| 3127 | |||
| 3128 | protected function _compileHandlers() |
||
| 3137 | |||
| 3138 | /** |
||
| 3139 | * @param string $viewName |
||
| 3140 | * @param int $cacheTtl |
||
| 3141 | * @return array |
||
| 3142 | */ |
||
| 3143 | public function getViewColumns($viewName, $cacheTtl=self::CACHE_NO) |
||
| 3147 | |||
| 3148 | /** |
||
| 3149 | * @param int $id |
||
| 3150 | * @return string |
||
| 3151 | */ |
||
| 3152 | public function getDisplayNameById(int $id) : string |
||
| 3162 | |||
| 3163 | /** |
||
| 3164 | * @param int $id |
||
| 3165 | * @param string $displayColumnValue |
||
| 3166 | * @return bool |
||
| 3167 | */ |
||
| 3168 | public function validIdDisplayNameCombo(int $id, $displayColumnValue) : bool |
||
| 3172 | |||
| 3173 | /** |
||
| 3174 | * @param array $toPopulate |
||
| 3175 | * @return stdClass |
||
| 3176 | */ |
||
| 3177 | protected function getEmptyObject(array $toPopulate=[]) : stdClass |
||
| 3183 | |||
| 3184 | /** |
||
| 3185 | * @param array $toPopulate |
||
| 3186 | * @return stdClass |
||
| 3187 | */ |
||
| 3188 | protected static function emptyObject(array $toPopulate=[]) : stdClass |
||
| 3194 | |||
| 3195 | /** |
||
| 3196 | * @param int $id |
||
| 3197 | * @return bool |
||
| 3198 | */ |
||
| 3199 | public static function isId(int $id) : bool |
||
| 3203 | |||
| 3204 | /** |
||
| 3205 | * @param int $cacheTtl |
||
| 3206 | * @return int |
||
| 3207 | */ |
||
| 3208 | public function activeCount(int $cacheTtl=self::CACHE_NO) : int |
||
| 3212 | |||
| 3213 | /** |
||
| 3214 | * @param string $tableAlias |
||
| 3215 | * @param string $columnName |
||
| 3216 | * @return FluentPdoModel|$this |
||
| 3217 | */ |
||
| 3218 | public function whereActive(string $tableAlias='', string $columnName=self::STATUS_FIELD) : FluentPdoModel |
||
| 3222 | |||
| 3223 | /** |
||
| 3224 | * @param string $tableAlias |
||
| 3225 | * @param string $columnName |
||
| 3226 | * @return FluentPdoModel|$this |
||
| 3227 | */ |
||
| 3228 | public function whereInactive(string $tableAlias='', string $columnName=self::STATUS_FIELD) : FluentPdoModel |
||
| 3232 | |||
| 3233 | /** |
||
| 3234 | * @param string $tableAlias |
||
| 3235 | * @param string $columnName |
||
| 3236 | * @return FluentPdoModel|$this |
||
| 3237 | */ |
||
| 3238 | public function whereArchived(string $tableAlias='', string $columnName='status') : FluentPdoModel |
||
| 3242 | |||
| 3243 | /** |
||
| 3244 | * @param int $status |
||
| 3245 | * @param string $tableAlias |
||
| 3246 | * @param string $columnName |
||
| 3247 | * @return FluentPdoModel|$this |
||
| 3248 | */ |
||
| 3249 | public function whereStatus(int $status, string $tableAlias='', string $columnName=self::STATUS_FIELD) : FluentPdoModel |
||
| 3258 | |||
| 3259 | /** |
||
| 3260 | * @param int $id |
||
| 3261 | * @return int |
||
| 3262 | */ |
||
| 3263 | public function updateActive(int $id=0) : int |
||
| 3273 | |||
| 3274 | /** |
||
| 3275 | * @param int $id |
||
| 3276 | * @return int |
||
| 3277 | */ |
||
| 3278 | public function updateInactive(int $id=0) : int |
||
| 3287 | |||
| 3288 | /** |
||
| 3289 | * @param string $field |
||
| 3290 | * @param int $id |
||
| 3291 | * @return int |
||
| 3292 | */ |
||
| 3293 | public function updateNow(string $field, int $id=0) : int |
||
| 3299 | |||
| 3300 | /** |
||
| 3301 | * @param string $field |
||
| 3302 | * @param int $id |
||
| 3303 | * @return int |
||
| 3304 | */ |
||
| 3305 | public function updateToday($field, int $id=0) : int |
||
| 3311 | |||
| 3312 | /** |
||
| 3313 | * @param int $id |
||
| 3314 | * @return int |
||
| 3315 | */ |
||
| 3316 | public function updateDeleted(int $id=0) : int |
||
| 3329 | |||
| 3330 | /** |
||
| 3331 | * @param int $id |
||
| 3332 | * @return int |
||
| 3333 | */ |
||
| 3334 | public function updateArchived(int $id=0) : int |
||
| 3344 | |||
| 3345 | /** |
||
| 3346 | * @param int $status |
||
| 3347 | * @return int |
||
| 3348 | * @throws \Exception |
||
| 3349 | */ |
||
| 3350 | public function updateStatus(int $status) |
||
| 3356 | |||
| 3357 | /** |
||
| 3358 | * Return a YYYY-MM-DD HH:II:SS date format |
||
| 3359 | * |
||
| 3360 | * @param string $datetime - An english textual datetime description |
||
| 3361 | * now, yesterday, 3 days ago, +1 week |
||
| 3362 | * http://php.net/manual/en/function.strtotime.php |
||
| 3363 | * @return string YYYY-MM-DD HH:II:SS |
||
| 3364 | */ |
||
| 3365 | public static function NOW(string $datetime='now') : string |
||
| 3369 | |||
| 3370 | /** |
||
| 3371 | * Return a string containing the given number of question marks, |
||
| 3372 | * separated by commas. Eg '?, ?, ?' |
||
| 3373 | * |
||
| 3374 | * @param int - total of placeholder to insert |
||
| 3375 | * @return string |
||
| 3376 | */ |
||
| 3377 | protected function _makePlaceholders(int $numberOfPlaceholders=1) : string |
||
| 3381 | |||
| 3382 | /** |
||
| 3383 | * Format the table{Primary|Foreign}KeyName |
||
| 3384 | * |
||
| 3385 | * @param string $pattern |
||
| 3386 | * @param string $tableName |
||
| 3387 | * @return string |
||
| 3388 | */ |
||
| 3389 | protected function _formatKeyName(string $pattern, string $tableName) : string |
||
| 3393 | |||
| 3394 | /** |
||
| 3395 | * @param array $query |
||
| 3396 | * @param array $extraFields |
||
| 3397 | * @return array |
||
| 3398 | * @throws \Exception |
||
| 3399 | */ |
||
| 3400 | protected function _prepareApiResource(array $query=[], array $extraFields=[]) : array |
||
| 3421 | |||
| 3422 | /** |
||
| 3423 | * @param string $query |
||
| 3424 | * @param array $parameters |
||
| 3425 | * |
||
| 3426 | * @return array |
||
| 3427 | */ |
||
| 3428 | protected function _logQuery(string $query, array $parameters) : array |
||
| 3441 | |||
| 3442 | /** |
||
| 3443 | * @param string $ident |
||
| 3444 | * @param string $builtQuery |
||
| 3445 | */ |
||
| 3446 | protected function _logSlowQueries(string $ident, string $builtQuery) |
||
| 3459 | |||
| 3460 | /** |
||
| 3461 | * @return float |
||
| 3462 | */ |
||
| 3463 | public function getTimeTaken() : float |
||
| 3469 | |||
| 3470 | /** |
||
| 3471 | * @param $secs |
||
| 3472 | * @return FluentPdoModel|$this |
||
| 3473 | */ |
||
| 3474 | public function slowQuerySeconds(int $secs) : FluentPdoModel |
||
| 3481 | |||
| 3482 | |||
| 3483 | /** |
||
| 3484 | * @param $field |
||
| 3485 | * @param array $values |
||
| 3486 | * @param string $placeholderPrefix |
||
| 3487 | * |
||
| 3488 | * @return array |
||
| 3489 | */ |
||
| 3490 | public function getNamedWhereIn(string $field, array $values, string $placeholderPrefix='') : array |
||
| 3514 | |||
| 3515 | /** |
||
| 3516 | * @param string $field |
||
| 3517 | * @param string $delimiter |
||
| 3518 | * |
||
| 3519 | * @return array |
||
| 3520 | */ |
||
| 3521 | protected function _getColumnAliasParts(string $field, string $delimiter=':') : array |
||
| 3536 | |||
| 3537 | /** |
||
| 3538 | * @param string $column |
||
| 3539 | * @param string $term |
||
| 3540 | * @return FluentPdoModel|$this |
||
| 3541 | */ |
||
| 3542 | protected function _addWhereClause(string $column, string $term) : FluentPdoModel |
||
| 3611 | |||
| 3612 | public function destroy() |
||
| 3621 | |||
| 3622 | public function __destruct() |
||
| 3626 | |||
| 3627 | /** |
||
| 3628 | * Load a model |
||
| 3629 | * |
||
| 3630 | * @param string $modelName |
||
| 3631 | * @param AbstractPdo $connection |
||
| 3632 | * @return FluentPdoModel|$this |
||
| 3633 | * @throws ModelNotFoundException |
||
| 3634 | */ |
||
| 3635 | public static function loadModel(string $modelName, AbstractPdo $connection=null) : FluentPdoModel |
||
| 3645 | |||
| 3646 | /** |
||
| 3647 | * Load a model |
||
| 3648 | * |
||
| 3649 | * @param string $tableName |
||
| 3650 | * @param AbstractPdo $connection |
||
| 3651 | * @return FluentPdoModel|$this |
||
| 3652 | */ |
||
| 3653 | public static function loadTable(string $tableName, AbstractPdo $connection=null) : FluentPdoModel |
||
| 3660 | |||
| 3661 | /** |
||
| 3662 | * @param string $columnName |
||
| 3663 | * @param int $cacheTtl |
||
| 3664 | * @param bool $flushCache |
||
| 3665 | * @return bool |
||
| 3666 | */ |
||
| 3667 | public function columnExists(string $columnName, int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : bool |
||
| 3673 | |||
| 3674 | /** |
||
| 3675 | * @param string $foreignKeyName |
||
| 3676 | * @param int $cacheTtl |
||
| 3677 | * @param bool $flushCache |
||
| 3678 | * @return bool |
||
| 3679 | */ |
||
| 3680 | public function foreignKeyExists(string $foreignKeyName, int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : bool |
||
| 3686 | |||
| 3687 | /** |
||
| 3688 | * @param string $indexName |
||
| 3689 | * @param int $cacheTtl |
||
| 3690 | * @param bool $flushCache |
||
| 3691 | * @return bool |
||
| 3692 | */ |
||
| 3693 | public function indexExists(string $indexName, int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : bool |
||
| 3715 | |||
| 3716 | |||
| 3717 | |||
| 3718 | /** |
||
| 3719 | * @param int $cacheTtl |
||
| 3720 | * @param bool $flushCache |
||
| 3721 | * @return FluentPdoModel|$this |
||
| 3722 | */ |
||
| 3723 | public function loadSchemaFromDb(int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : FluentPdoModel |
||
| 3730 | |||
| 3731 | /** |
||
| 3732 | * @param int $cacheTtl |
||
| 3733 | * @param bool $flushCache |
||
| 3734 | * @return array |
||
| 3735 | */ |
||
| 3736 | public function getSchemaFromDb(int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : array |
||
| 3749 | |||
| 3750 | /** |
||
| 3751 | * @param int $cacheTtl |
||
| 3752 | * @param bool $flushCache |
||
| 3753 | * @return array |
||
| 3754 | */ |
||
| 3755 | public function getForeignKeysFromDb(int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : array |
||
| 3768 | |||
| 3769 | /** |
||
| 3770 | * @param string $table |
||
| 3771 | * @param int $cacheTtl |
||
| 3772 | * @param bool $flushCache |
||
| 3773 | * @return Column[][] |
||
| 3774 | */ |
||
| 3775 | protected function _getColumnsByTableFromDb(string $table, int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : array |
||
| 3791 | |||
| 3792 | /** |
||
| 3793 | * @param string $table |
||
| 3794 | * @param int $cacheTtl |
||
| 3795 | * @param bool $flushCache |
||
| 3796 | * @return Column[][] |
||
| 3797 | */ |
||
| 3798 | protected function _getForeignKeysByTableFromDb(string $table, int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : array |
||
| 3814 | |||
| 3815 | /** |
||
| 3816 | * @param string $table |
||
| 3817 | * @return bool |
||
| 3818 | */ |
||
| 3819 | public function clearSchemaCache(string $table) : bool |
||
| 3823 | |||
| 3824 | /** |
||
| 3825 | * @param stdClass $record |
||
| 3826 | * @return stdClass |
||
| 3827 | */ |
||
| 3828 | public function cleanseRecord(stdClass $record) : stdClass |
||
| 3845 | |||
| 3846 | /** |
||
| 3847 | * @param stdClass $record |
||
| 3848 | * @param string $type |
||
| 3849 | * @return stdClass |
||
| 3850 | */ |
||
| 3851 | public function beforeSave(stdClass $record, string $type) : stdClass |
||
| 3860 | |||
| 3861 | /** |
||
| 3862 | * @param array $data |
||
| 3863 | * @param string $saveType |
||
| 3864 | * @return array |
||
| 3865 | */ |
||
| 3866 | public function cleanseWebData(array $data, string $saveType) : array |
||
| 3881 | |||
| 3882 | /** |
||
| 3883 | * @return array |
||
| 3884 | */ |
||
| 3885 | public function skeleton() : array |
||
| 3896 | |||
| 3897 | /** |
||
| 3898 | * @param bool $toString |
||
| 3899 | * @return array |
||
| 3900 | */ |
||
| 3901 | public function getErrors(bool $toString=false) : array |
||
| 3916 | |||
| 3917 | /** |
||
| 3918 | * @param bool $throw |
||
| 3919 | * @return FluentPdoModel|$this |
||
| 3920 | */ |
||
| 3921 | public function validationExceptions(bool $throw=true) : FluentPdoModel |
||
| 3927 | |||
| 3928 | /** |
||
| 3929 | * @param array $query array('_limit' => int, '_offset' => int, '_order' => string, '_fields' => string, _search) |
||
| 3930 | * |
||
| 3931 | * @return FluentPdoModel|$this |
||
| 3932 | * @throws Exception |
||
| 3933 | */ |
||
| 3934 | public function paginate(array $query=[]) : FluentPdoModel |
||
| 3948 | |||
| 3949 | /** |
||
| 3950 | * @param int $limit |
||
| 3951 | * @param int $offset |
||
| 3952 | * @return FluentPdoModel|$this |
||
| 3953 | */ |
||
| 3954 | protected function _setLimit(int $limit=0, int $offset=0) : FluentPdoModel |
||
| 3969 | |||
| 3970 | /** |
||
| 3971 | * @param array $fields |
||
| 3972 | * @return FluentPdoModel|$this |
||
| 3973 | * @throws Exception |
||
| 3974 | */ |
||
| 3975 | protected function _setFields(array $fields=[]) : FluentPdoModel |
||
| 4023 | |||
| 4024 | /** |
||
| 4025 | * @param string $orderBy |
||
| 4026 | * @return FluentPdoModel|$this|FluentPdoModel |
||
| 4027 | */ |
||
| 4028 | protected function _setOrderBy(string $orderBy='') : FluentPdoModel |
||
| 4065 | |||
| 4066 | /** |
||
| 4067 | * @return array |
||
| 4068 | */ |
||
| 4069 | public function getPagingMeta() |
||
| 4078 | |||
| 4079 | /** |
||
| 4080 | * @return FluentPdoModel|$this |
||
| 4081 | */ |
||
| 4082 | public function setPagingMeta() : FluentPdoModel |
||
| 4104 | |||
| 4105 | /** |
||
| 4106 | * Take a web request and format a query |
||
| 4107 | * |
||
| 4108 | * @param array $query |
||
| 4109 | * |
||
| 4110 | * @return FluentPdoModel|$this |
||
| 4111 | * @throws Exception |
||
| 4112 | */ |
||
| 4113 | public function filter(array $query=[]) : FluentPdoModel |
||
| 4183 | |||
| 4184 | /** |
||
| 4185 | * @param string $column |
||
| 4186 | * @param string $displayCol |
||
| 4187 | * @return string|null |
||
| 4188 | */ |
||
| 4189 | protected function _findFieldByQuery(string $column, string $displayCol) |
||
| 4236 | |||
| 4237 | /** |
||
| 4238 | * @param $keysOnly |
||
| 4239 | * @return array |
||
| 4240 | */ |
||
| 4241 | |||
| 4242 | public function columns(bool $keysOnly=true) : array |
||
| 4246 | |||
| 4247 | /** |
||
| 4248 | * @param string $field |
||
| 4249 | * @param mixed $value |
||
| 4250 | * @param array $pdoMetaData |
||
| 4251 | * @return float|int |
||
| 4252 | * @throws Exception |
||
| 4253 | */ |
||
| 4254 | protected function _fixTypeToSentinel(string $field, $value, array $pdoMetaData=[]) |
||
| 4306 | |||
| 4307 | /** |
||
| 4308 | * @param string $field |
||
| 4309 | * @param mixed $value |
||
| 4310 | * @param bool|false $permissive |
||
| 4311 | * @return float|int|null|string |
||
| 4312 | */ |
||
| 4313 | protected function _fixType(string $field, $value, bool $permissive=false) |
||
| 4364 | |||
| 4365 | /** |
||
| 4366 | * @param stdClass $record |
||
| 4367 | * @param string $type |
||
| 4368 | * @return stdClass |
||
| 4369 | */ |
||
| 4370 | public function fixTypesToSentinel(stdClass $record, string $type='') : stdClass |
||
| 4397 | |||
| 4398 | /** |
||
| 4399 | * @param stdClass $record |
||
| 4400 | * @param string $type |
||
| 4401 | * @return stdClass |
||
| 4402 | * @throws Exception |
||
| 4403 | */ |
||
| 4404 | public function applyHandlers(stdClass $record, string $type='INSERT') : stdClass |
||
| 4432 | |||
| 4433 | |||
| 4434 | /** |
||
| 4435 | * @param stdClass $record |
||
| 4436 | * @param array $fields |
||
| 4437 | * @param string $type |
||
| 4438 | * @return bool |
||
| 4439 | */ |
||
| 4440 | protected function uniqueCheck(stdClass $record, array $fields, string $type) : bool |
||
| 4453 | |||
| 4454 | /** |
||
| 4455 | * @param string $field |
||
| 4456 | * @param mixed $value |
||
| 4457 | * @param string $type |
||
| 4458 | * @param stdClass $record |
||
| 4459 | * @return null |
||
| 4460 | * @throws Exception |
||
| 4461 | */ |
||
| 4462 | protected function applyHandler(string $field, $value, string $type='', stdClass $record=null) |
||
| 4486 | |||
| 4487 | /** |
||
| 4488 | * @param string $start |
||
| 4489 | * @param string $end |
||
| 4490 | * @param string $hayStack |
||
| 4491 | * @return mixed |
||
| 4492 | */ |
||
| 4493 | public static function between(string $start, string $end, string $hayStack) : string |
||
| 4497 | |||
| 4498 | /** |
||
| 4499 | * @param string $needle |
||
| 4500 | * @param string $hayStack |
||
| 4501 | * @param bool $returnOrigIfNeedleNotExists |
||
| 4502 | * @return mixed |
||
| 4503 | */ |
||
| 4504 | public static function before(string $needle, string $hayStack, bool $returnOrigIfNeedleNotExists=false) : string |
||
| 4514 | |||
| 4515 | /** |
||
| 4516 | * @param string $needle |
||
| 4517 | * @param string $hayStack |
||
| 4518 | * @param bool $returnOrigIfNeedleNotExists |
||
| 4519 | * @return string |
||
| 4520 | */ |
||
| 4521 | public static function after(string $needle, string $hayStack, bool $returnOrigIfNeedleNotExists=false) : string |
||
| 4530 | |||
| 4531 | /** |
||
| 4532 | * @return int |
||
| 4533 | */ |
||
| 4534 | public function getUserId() |
||
| 4538 | |||
| 4539 | /** |
||
| 4540 | * @param string $entity |
||
| 4541 | * @param int $id |
||
| 4542 | * @return int |
||
| 4543 | */ |
||
| 4544 | public function getMaskByResourceAndId(string $entity, int $id) : int |
||
| 4548 | |||
| 4549 | /** |
||
| 4550 | * @param string|int|null $time |
||
| 4551 | * @return string |
||
| 4552 | */ |
||
| 4553 | public static function date($time=null) : string |
||
| 4557 | |||
| 4558 | /** |
||
| 4559 | * @param string|int|null $time |
||
| 4560 | * @return string |
||
| 4561 | */ |
||
| 4562 | public static function dateTime($time=null) : string |
||
| 4566 | |||
| 4567 | /** |
||
| 4568 | * @param string|int|null $time |
||
| 4569 | * @return string |
||
| 4570 | */ |
||
| 4571 | public static function atom($time=null) : string |
||
| 4575 | |||
| 4576 | /** |
||
| 4577 | * @param string|int|null $time |
||
| 4578 | * @return int |
||
| 4579 | */ |
||
| 4580 | public static function getTime($time=null) : int |
||
| 4593 | |||
| 4594 | /** |
||
| 4595 | * @param int $id |
||
| 4596 | * @param int $cacheTtl |
||
| 4597 | * @return string |
||
| 4598 | */ |
||
| 4599 | public function getCodeById(int $id, int $cacheTtl=self::ONE_DAY) : string |
||
| 4607 | |||
| 4608 | /** |
||
| 4609 | * @param array $authUserRoles |
||
| 4610 | * @param int $authUserId |
||
| 4611 | * @return FluentPdoModel |
||
| 4612 | */ |
||
| 4613 | public function applyRoleFilter(array $authUserRoles, int $authUserId) : FluentPdoModel |
||
| 4617 | |||
| 4618 | /** |
||
| 4619 | * @param int $id |
||
| 4620 | * @param string[] $authUserRoles |
||
| 4621 | * @param int $authUserId |
||
| 4622 | * @return bool |
||
| 4623 | */ |
||
| 4624 | public function canAccessIdWithRole(int $id, array $authUserRoles, int $authUserId) : bool |
||
| 4628 | } |
||
| 4629 |