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 = 'creator_id'; |
||
| 56 | const CREATOR_FIELD = 'creator'; |
||
| 57 | const CREATED_TS_FIELD = 'created_ts'; |
||
| 58 | const MODIFIER_ID_FIELD = 'modifier_id'; |
||
| 59 | const MODIFIER_FIELD = 'modifier'; |
||
| 60 | const MODIFIED_TS_FIELD = 'modified_ts'; |
||
| 61 | const DELETER_ID_FIELD = 'deleter_id'; |
||
| 62 | const DELETER_FIELD = 'deleter'; |
||
| 63 | const DELETED_TS_FIELD = 'deleted_ts'; |
||
| 64 | const STATUS_FIELD = 'active'; |
||
| 65 | const ACTIVE_FIELD = 'active'; |
||
| 66 | |||
| 67 | /** @var AbstractPdo $connection */ |
||
| 68 | protected $connection = null; |
||
| 69 | |||
| 70 | /** @var string */ |
||
| 71 | protected $primaryKey = 'id'; |
||
| 72 | |||
| 73 | /** @var array */ |
||
| 74 | protected $whereParameters = []; |
||
| 75 | |||
| 76 | /** @var array */ |
||
| 77 | protected $selectFields = []; |
||
| 78 | |||
| 79 | /** @var array */ |
||
| 80 | protected $joinSources = []; |
||
| 81 | |||
| 82 | /** @var array */ |
||
| 83 | protected $joinAliases = []; |
||
| 84 | |||
| 85 | /** @var array $associations */ |
||
| 86 | protected $associations = [ |
||
| 87 | 'belongsTo' => [], |
||
| 88 | ]; |
||
| 89 | |||
| 90 | /** @var array */ |
||
| 91 | protected $whereConditions = []; |
||
| 92 | |||
| 93 | /** @var string */ |
||
| 94 | protected $rawSql = ''; |
||
| 95 | |||
| 96 | /** @var int */ |
||
| 97 | protected $limit = 0; |
||
| 98 | |||
| 99 | /** @var int */ |
||
| 100 | protected $offset = 0; |
||
| 101 | |||
| 102 | /** @var array */ |
||
| 103 | protected $orderBy = []; |
||
| 104 | |||
| 105 | /** @var array */ |
||
| 106 | protected $groupBy = []; |
||
| 107 | |||
| 108 | /** @var string */ |
||
| 109 | protected $andOrOperator = self::OPERATOR_AND; |
||
| 110 | |||
| 111 | /** @var array */ |
||
| 112 | protected $having = []; |
||
| 113 | |||
| 114 | /** @var bool */ |
||
| 115 | protected $wrapOpen = false; |
||
| 116 | |||
| 117 | /** @var int */ |
||
| 118 | protected $lastWrapPosition = 0; |
||
| 119 | |||
| 120 | /** @var PDOStatement $pdoStmt */ |
||
| 121 | protected $pdoStmt = null; |
||
| 122 | |||
| 123 | /** @var bool */ |
||
| 124 | protected $distinct = false; |
||
| 125 | |||
| 126 | /** @var null */ |
||
| 127 | protected $requestedFields = []; |
||
| 128 | |||
| 129 | /** @var null */ |
||
| 130 | protected $filterMeta = []; |
||
| 131 | |||
| 132 | /** @var bool */ |
||
| 133 | protected $logQueries = false; |
||
| 134 | |||
| 135 | /** @var array */ |
||
| 136 | protected $timer = []; |
||
| 137 | |||
| 138 | /** @var int */ |
||
| 139 | protected $slowQuerySecs = 5; |
||
| 140 | |||
| 141 | /** @var array */ |
||
| 142 | protected $paginationAttribs = [ |
||
| 143 | '_limit', |
||
| 144 | '_offset', |
||
| 145 | '_order', |
||
| 146 | '_fields', |
||
| 147 | '_search' |
||
| 148 | ]; |
||
| 149 | |||
| 150 | /** @var string $tableName */ |
||
| 151 | protected $tableName = ''; |
||
| 152 | |||
| 153 | /** @var string $tableAlias */ |
||
| 154 | protected $tableAlias = ''; |
||
| 155 | |||
| 156 | /** @var string $displayColumn */ |
||
| 157 | protected $displayColumn = ''; |
||
| 158 | |||
| 159 | /** @var string $connectionName */ |
||
| 160 | protected $connectionName = ''; |
||
| 161 | |||
| 162 | /** @var array $schema */ |
||
| 163 | protected $schema = []; |
||
| 164 | |||
| 165 | /** @var array $virtualFields */ |
||
| 166 | protected $virtualFields = []; |
||
| 167 | |||
| 168 | /** @var array $errors */ |
||
| 169 | protected $errors = []; |
||
| 170 | |||
| 171 | /** |
||
| 172 | * @var int - true = connection default x days |
||
| 173 | * - false = no cache |
||
| 174 | * - int = a specific amount |
||
| 175 | */ |
||
| 176 | protected $cacheTtl = self::CACHE_NO; |
||
| 177 | |||
| 178 | /** @var array */ |
||
| 179 | protected $flushCacheTables = []; |
||
| 180 | |||
| 181 | /** @var string */ |
||
| 182 | protected $tmpTablePrefix = 'tmp_'; |
||
| 183 | |||
| 184 | /** @var null|string */ |
||
| 185 | protected $builtQuery = ''; |
||
| 186 | |||
| 187 | /** @var array */ |
||
| 188 | protected $handlers = []; |
||
| 189 | |||
| 190 | /** @var bool User want to directly specify the fields */ |
||
| 191 | protected $explicitSelectMode = false; |
||
| 192 | |||
| 193 | /** @var string[] */ |
||
| 194 | protected $updateRaw = []; |
||
| 195 | |||
| 196 | /** @var int */ |
||
| 197 | protected $maxCallbackFails = -1; |
||
| 198 | |||
| 199 | /** @var int */ |
||
| 200 | protected $numCallbackFails = 0; |
||
| 201 | |||
| 202 | /** @var bool */ |
||
| 203 | protected $filterOnFetch = false; |
||
| 204 | |||
| 205 | /** @var bool */ |
||
| 206 | protected $logFilterChanges = true; |
||
| 207 | |||
| 208 | /** @var bool */ |
||
| 209 | protected $includeCount = false; |
||
| 210 | |||
| 211 | /** @var string */ |
||
| 212 | static protected $modelNamespace = ''; |
||
| 213 | |||
| 214 | /** @var bool */ |
||
| 215 | protected $validationExceptions = true; |
||
| 216 | |||
| 217 | /** @var array */ |
||
| 218 | protected $pagingMeta = []; |
||
| 219 | |||
| 220 | /** @var bool */ |
||
| 221 | protected $softDeletes = true; |
||
| 222 | |||
| 223 | /** @var bool */ |
||
| 224 | protected $allowMetaOverride = false; |
||
| 225 | |||
| 226 | /** @var bool */ |
||
| 227 | protected $skipMetaUpdates = false; |
||
| 228 | |||
| 229 | /** @var bool */ |
||
| 230 | protected $addUpdateAlias = false; |
||
| 231 | |||
| 232 | /** @var int */ |
||
| 233 | protected $defaultMax = 250; |
||
| 234 | |||
| 235 | /** @var array */ |
||
| 236 | protected $removeUnauthorisedFields = []; |
||
| 237 | |||
| 238 | /** @var bool */ |
||
| 239 | protected $canGenericUpdate = true; |
||
| 240 | |||
| 241 | /** @var bool */ |
||
| 242 | protected $canGenericCreate = true; |
||
| 243 | |||
| 244 | /** @var bool */ |
||
| 245 | protected $canGenericDelete = true; |
||
| 246 | |||
| 247 | /** @var array */ |
||
| 248 | protected $rowMetaData = []; |
||
| 249 | |||
| 250 | /** @var array */ |
||
| 251 | protected $excludedSearchCols = []; |
||
| 252 | |||
| 253 | |||
| 254 | /** @var array */ |
||
| 255 | protected $globalRemoveUnauthorisedFields = [ |
||
| 256 | '/global_table_meta#view' => [ |
||
| 257 | self::CREATOR_ID_FIELD, |
||
| 258 | self::CREATOR_FIELD, |
||
| 259 | self::CREATED_TS_FIELD, |
||
| 260 | self::MODIFIER_ID_FIELD, |
||
| 261 | self::MODIFIER_FIELD, |
||
| 262 | self::MODIFIED_TS_FIELD, |
||
| 263 | self::STATUS_FIELD, |
||
| 264 | ], |
||
| 265 | ]; |
||
| 266 | |||
| 267 | |||
| 268 | /** |
||
| 269 | * @param AbstractPdo|null $connection |
||
| 270 | */ |
||
| 271 | public function __construct(AbstractPdo $connection=null) |
||
| 278 | |||
| 279 | public function init() |
||
| 281 | |||
| 282 | /** |
||
| 283 | * @return AbstractPdo |
||
| 284 | * @throws Exception |
||
| 285 | */ |
||
| 286 | public function getPdo() : AbstractPdo |
||
| 290 | |||
| 291 | /** |
||
| 292 | * @return LoggerInterface |
||
| 293 | */ |
||
| 294 | public function getLogger() : LoggerInterface |
||
| 298 | |||
| 299 | /** |
||
| 300 | * @return CacheInterface |
||
| 301 | */ |
||
| 302 | public function getCache() : CacheInterface |
||
| 306 | |||
| 307 | /** |
||
| 308 | * Define the working table and create a new instance |
||
| 309 | * |
||
| 310 | * @param string $tableName - Table name |
||
| 311 | * @param string $alias - The table alias name |
||
| 312 | * @param string $displayColumn |
||
| 313 | * @param string $primaryKeyName |
||
| 314 | * |
||
| 315 | * @return FluentPdoModel|$this |
||
| 316 | */ |
||
| 317 | public function table(string $tableName, string $alias='', string $displayColumn='', string $primaryKeyName='id') : FluentPdoModel |
||
| 325 | |||
| 326 | /** |
||
| 327 | * @param string $primaryKeyName |
||
| 328 | * @return FluentPdoModel|$this |
||
| 329 | */ |
||
| 330 | public function primaryKeyName(string $primaryKeyName) : FluentPdoModel |
||
| 336 | |||
| 337 | /** |
||
| 338 | * @param string $tableName |
||
| 339 | * |
||
| 340 | * @return FluentPdoModel|$this |
||
| 341 | */ |
||
| 342 | public function tableName(string $tableName) : FluentPdoModel |
||
| 348 | |||
| 349 | /** |
||
| 350 | * @param $explicitSelect |
||
| 351 | * |
||
| 352 | * @return FluentPdoModel|$this |
||
| 353 | */ |
||
| 354 | public function explicitSelectMode(bool $explicitSelect=true) : FluentPdoModel |
||
| 360 | |||
| 361 | /** |
||
| 362 | * @param bool $filterOnFetch |
||
| 363 | * |
||
| 364 | * @return FluentPdoModel|$this |
||
| 365 | */ |
||
| 366 | public function filterOnFetch(bool $filterOnFetch=true) : FluentPdoModel |
||
| 372 | |||
| 373 | /** |
||
| 374 | * @param bool $logFilterChanges |
||
| 375 | * |
||
| 376 | * @return FluentPdoModel|$this |
||
| 377 | */ |
||
| 378 | public function logFilterChanges(bool $logFilterChanges=true) : FluentPdoModel |
||
| 384 | |||
| 385 | /** |
||
| 386 | * Return the name of the table |
||
| 387 | * |
||
| 388 | * @return string |
||
| 389 | */ |
||
| 390 | public function getTableName() : string |
||
| 394 | |||
| 395 | /** |
||
| 396 | * @return string |
||
| 397 | */ |
||
| 398 | public function getDisplayColumn() : string |
||
| 402 | |||
| 403 | /** |
||
| 404 | * Set the display column |
||
| 405 | * |
||
| 406 | * @param string $column |
||
| 407 | * |
||
| 408 | * @return FluentPdoModel|$this |
||
| 409 | */ |
||
| 410 | public function displayColumn(string $column) : FluentPdoModel |
||
| 416 | /** |
||
| 417 | * Set the table alias |
||
| 418 | * |
||
| 419 | * @param string $alias |
||
| 420 | * |
||
| 421 | * @return FluentPdoModel|$this |
||
| 422 | */ |
||
| 423 | public function tableAlias(string $alias) : FluentPdoModel |
||
| 429 | |||
| 430 | /** |
||
| 431 | * @param int $cacheTtl |
||
| 432 | * @return FluentPdoModel|$this |
||
| 433 | * @throws Exception |
||
| 434 | */ |
||
| 435 | protected function cacheTtl(int $cacheTtl) : FluentPdoModel |
||
| 446 | |||
| 447 | /** |
||
| 448 | * @return string |
||
| 449 | */ |
||
| 450 | public function getTableAlias() : string |
||
| 454 | |||
| 455 | /** |
||
| 456 | * @param array $associations |
||
| 457 | * |
||
| 458 | * @return FluentPdoModel|$this |
||
| 459 | */ |
||
| 460 | public function associations(array $associations) : FluentPdoModel |
||
| 466 | |||
| 467 | /** |
||
| 468 | * @param string $alias |
||
| 469 | * @param array $definition |
||
| 470 | * @return FluentPdoModel|$this |
||
| 471 | */ |
||
| 472 | public function setBelongsTo(string $alias, array $definition) : FluentPdoModel |
||
| 481 | |||
| 482 | /** |
||
| 483 | * @param $alias |
||
| 484 | * @param $displayField |
||
| 485 | * @return FluentPdoModel|$this |
||
| 486 | * @throws \Terah\Assert\AssertionFailedException |
||
| 487 | */ |
||
| 488 | public function setBelongsToDisplayField(string $alias, string $displayField) : FluentPdoModel |
||
| 498 | |||
| 499 | /** |
||
| 500 | * @param PDOStatement $stmt |
||
| 501 | * @param Closure $fnCallback |
||
| 502 | * @return bool|stdClass |
||
| 503 | */ |
||
| 504 | public function fetchRow(PDOStatement $stmt, Closure $fnCallback=null) |
||
| 527 | |||
| 528 | /** |
||
| 529 | * @param PDOStatement $stmt |
||
| 530 | * @param $record |
||
| 531 | * @return array |
||
| 532 | */ |
||
| 533 | protected function getColumnMeta(PDOStatement $stmt, $record) : array |
||
| 552 | |||
| 553 | /** |
||
| 554 | * @param array $schema |
||
| 555 | * |
||
| 556 | * @return FluentPdoModel|$this |
||
| 557 | */ |
||
| 558 | public function schema(array $schema) : FluentPdoModel |
||
| 564 | |||
| 565 | /** |
||
| 566 | * @param string|array $field |
||
| 567 | * @param $type |
||
| 568 | * @return FluentPdoModel|$this |
||
| 569 | */ |
||
| 570 | public function addSchema($field, string $type) : FluentPdoModel |
||
| 586 | |||
| 587 | /** |
||
| 588 | * @param bool $getForeign |
||
| 589 | * @return array |
||
| 590 | */ |
||
| 591 | public function getSchema(bool $getForeign=false) : array |
||
| 602 | |||
| 603 | /** |
||
| 604 | * @param $keysOnly |
||
| 605 | * @return array |
||
| 606 | */ |
||
| 607 | public function getColumns(bool $keysOnly=true) : array |
||
| 613 | |||
| 614 | /** |
||
| 615 | * Get the primary key name |
||
| 616 | * |
||
| 617 | * @return string |
||
| 618 | */ |
||
| 619 | public function getPrimaryKeyName() : string |
||
| 623 | |||
| 624 | /** |
||
| 625 | * @param string $query |
||
| 626 | * @param array $parameters |
||
| 627 | * |
||
| 628 | * @return bool |
||
| 629 | * @throws Exception |
||
| 630 | */ |
||
| 631 | public function execute(string $query, array $parameters=[]) : bool |
||
| 667 | |||
| 668 | /** |
||
| 669 | * @param string $query |
||
| 670 | * @param array $params |
||
| 671 | * @return FluentPdoModel|$this |
||
| 672 | */ |
||
| 673 | public function query(string $query, array $params=[]) : FluentPdoModel |
||
| 680 | |||
| 681 | /** |
||
| 682 | * @param string $sql |
||
| 683 | * @param array $params |
||
| 684 | * |
||
| 685 | * @return string |
||
| 686 | */ |
||
| 687 | public function buildQuery(string $sql, array $params=[]) : string |
||
| 715 | |||
| 716 | /** |
||
| 717 | * @param stdClass $record |
||
| 718 | * |
||
| 719 | * @return stdClass |
||
| 720 | */ |
||
| 721 | protected function trimAndLowerCaseKeys(stdClass $record) : stdClass |
||
| 732 | |||
| 733 | /** |
||
| 734 | * Return the number of affected row by the last statement |
||
| 735 | * |
||
| 736 | * @return int |
||
| 737 | */ |
||
| 738 | public function rowCount() : int |
||
| 744 | |||
| 745 | /** |
||
| 746 | * @return PDOStatement |
||
| 747 | * @throws PDOException |
||
| 748 | */ |
||
| 749 | public function fetchStmt() |
||
| 758 | |||
| 759 | /** |
||
| 760 | * @return array |
||
| 761 | */ |
||
| 762 | public function fetchSqlQuery() : array |
||
| 772 | |||
| 773 | /** |
||
| 774 | * @param string $tableName |
||
| 775 | * @param bool $dropIfExists |
||
| 776 | * @param array $indexes |
||
| 777 | * @return boolean |
||
| 778 | * @throws Exception |
||
| 779 | */ |
||
| 780 | public function fetchIntoMemoryTable(string $tableName, bool $dropIfExists=true, array $indexes=[]) : bool |
||
| 802 | |||
| 803 | /** |
||
| 804 | * @param string $keyedOn |
||
| 805 | * @param int $cacheTtl |
||
| 806 | * @return stdClass[] |
||
| 807 | */ |
||
| 808 | public function fetch(string $keyedOn='', int $cacheTtl=self::CACHE_NO) : array |
||
| 846 | |||
| 847 | /** |
||
| 848 | * @return string |
||
| 849 | */ |
||
| 850 | protected function parseWhereForPrimaryLookup() : string |
||
| 866 | |||
| 867 | /** |
||
| 868 | * @param string $cacheKey |
||
| 869 | * @param Closure $func |
||
| 870 | * @param int $cacheTtl - 0 for default ttl, -1 for no cache or int for custom ttl |
||
| 871 | * @return mixed |
||
| 872 | */ |
||
| 873 | protected function cacheData(string $cacheKey, Closure $func, int $cacheTtl=self::CACHE_DEFAULT) |
||
| 911 | |||
| 912 | /** |
||
| 913 | * @param string $cacheKey |
||
| 914 | * @return bool |
||
| 915 | */ |
||
| 916 | public function clearCache(string $cacheKey) : bool |
||
| 920 | |||
| 921 | /** |
||
| 922 | * @param string $table |
||
| 923 | * @return bool |
||
| 924 | */ |
||
| 925 | public function clearCacheByTable(string $table='') : bool |
||
| 935 | |||
| 936 | /** |
||
| 937 | * @return string[] |
||
| 938 | */ |
||
| 939 | public function getFlushCacheTables() : array |
||
| 943 | |||
| 944 | /** |
||
| 945 | * @param Closure $fnCallback |
||
| 946 | * @return int |
||
| 947 | */ |
||
| 948 | public function fetchCallback(Closure $fnCallback) : int |
||
| 959 | |||
| 960 | /** |
||
| 961 | * @param Closure $fnCallback |
||
| 962 | * @param string $keyedOn |
||
| 963 | * @return array |
||
| 964 | */ |
||
| 965 | public function fetchObjectsByCallback(Closure $fnCallback, string $keyedOn='') : array |
||
| 983 | |||
| 984 | /** |
||
| 985 | * @param $numFailures |
||
| 986 | * @return FluentPdoModel|$this |
||
| 987 | */ |
||
| 988 | public function maxCallbackFailures(int $numFailures) : FluentPdoModel |
||
| 995 | |||
| 996 | /** |
||
| 997 | * @param PDOStatement $stmt |
||
| 998 | * @param Closure $fnCallback |
||
| 999 | * @param int $successCnt |
||
| 1000 | * @return bool|null|stdClass |
||
| 1001 | */ |
||
| 1002 | protected function tallySuccessCount(PDOStatement $stmt, Closure $fnCallback, int &$successCnt) |
||
| 1035 | |||
| 1036 | /** |
||
| 1037 | * @return bool |
||
| 1038 | */ |
||
| 1039 | public function canGenericUpdate() : bool |
||
| 1043 | |||
| 1044 | /** |
||
| 1045 | * @return bool |
||
| 1046 | */ |
||
| 1047 | public function canGenericCreate() : bool |
||
| 1051 | |||
| 1052 | /** |
||
| 1053 | * @return bool |
||
| 1054 | */ |
||
| 1055 | public function canGenericDelete() : bool |
||
| 1059 | |||
| 1060 | /** |
||
| 1061 | * @param string $keyedOn |
||
| 1062 | * @param string $valueField |
||
| 1063 | * @param int $cacheTtl |
||
| 1064 | * @return mixed |
||
| 1065 | */ |
||
| 1066 | public function fetchList(string $keyedOn='', string $valueField='', int $cacheTtl=self::CACHE_NO) : array |
||
| 1128 | |||
| 1129 | /** |
||
| 1130 | * @param string $column |
||
| 1131 | * @param int $cacheTtl |
||
| 1132 | * @param bool|true $unique |
||
| 1133 | * @return array |
||
| 1134 | */ |
||
| 1135 | public function fetchColumn(string $column, int $cacheTtl=self::CACHE_NO, bool $unique=true) : array |
||
| 1145 | |||
| 1146 | /** |
||
| 1147 | * @param string $field |
||
| 1148 | * @param int $itemId |
||
| 1149 | * @param int $cacheTtl |
||
| 1150 | * @return mixed|null |
||
| 1151 | */ |
||
| 1152 | public function fetchField(string $field='', int $itemId=0, int $cacheTtl=self::CACHE_NO) |
||
| 1173 | |||
| 1174 | /** |
||
| 1175 | * @param string $field |
||
| 1176 | * @param int $itemId |
||
| 1177 | * @param int $cacheTtl |
||
| 1178 | * @return string |
||
| 1179 | */ |
||
| 1180 | public function fetchStr(string $field='', $itemId=0, int $cacheTtl=self::CACHE_NO) : string |
||
| 1184 | |||
| 1185 | /** |
||
| 1186 | * @param int $cacheTtl |
||
| 1187 | * @return int |
||
| 1188 | */ |
||
| 1189 | public function fetchId(int $cacheTtl=self::CACHE_NO) : int |
||
| 1193 | |||
| 1194 | /** |
||
| 1195 | * @param string $field |
||
| 1196 | * @param int $itemId |
||
| 1197 | * @param int $cacheTtl |
||
| 1198 | * @return int |
||
| 1199 | */ |
||
| 1200 | public function fetchInt(string $field='', int $itemId=0, int $cacheTtl=self::CACHE_NO) : int |
||
| 1204 | |||
| 1205 | /** |
||
| 1206 | * @param string $field |
||
| 1207 | * @param int $itemId |
||
| 1208 | * @param int $cacheTtl |
||
| 1209 | * @return float |
||
| 1210 | */ |
||
| 1211 | public function fetchFloat(string $field='', int $itemId=0, int $cacheTtl=self::CACHE_NO) : float |
||
| 1215 | |||
| 1216 | /** |
||
| 1217 | * @param string $field |
||
| 1218 | * @param int $itemId |
||
| 1219 | * @param int $cacheTtl |
||
| 1220 | * @return bool |
||
| 1221 | */ |
||
| 1222 | public function fetchBool(string $field='', int $itemId=0, int $cacheTtl=self::CACHE_NO) : bool |
||
| 1226 | |||
| 1227 | /** |
||
| 1228 | * @param int|null $id |
||
| 1229 | * @param int $cacheTtl |
||
| 1230 | * @return stdClass|null |
||
| 1231 | */ |
||
| 1232 | public function fetchOne(int $id=0, int $cacheTtl=self::CACHE_NO) |
||
| 1244 | |||
| 1245 | /** |
||
| 1246 | * @param int|null $id |
||
| 1247 | * @param int $cacheTtl |
||
| 1248 | * @return boolean |
||
| 1249 | */ |
||
| 1250 | public function fetchExists(int $id=0, int $cacheTtl=self::CACHE_NO) : bool |
||
| 1260 | |||
| 1261 | /*------------------------------------------------------------------------------ |
||
| 1262 | Fluent Query Builder |
||
| 1263 | *-----------------------------------------------------------------------------*/ |
||
| 1264 | |||
| 1265 | /** |
||
| 1266 | * Create the select clause |
||
| 1267 | * |
||
| 1268 | * @param mixed $columns - the column to select. Can be string or array of fields |
||
| 1269 | * @param string $alias - an alias to the column |
||
| 1270 | * @param boolean $explicitSelect |
||
| 1271 | * @return FluentPdoModel|$this |
||
| 1272 | */ |
||
| 1273 | public function select($columns='*', string $alias='', bool $explicitSelect=true) : FluentPdoModel |
||
| 1316 | |||
| 1317 | /** |
||
| 1318 | * @param string $select |
||
| 1319 | * @return FluentPdoModel|$this |
||
| 1320 | */ |
||
| 1321 | public function selectRaw(string $select) : FluentPdoModel |
||
| 1327 | |||
| 1328 | /** |
||
| 1329 | * @param bool $logQueries |
||
| 1330 | * |
||
| 1331 | * @return FluentPdoModel|$this |
||
| 1332 | */ |
||
| 1333 | public function logQueries(bool $logQueries=true) : FluentPdoModel |
||
| 1339 | |||
| 1340 | /** |
||
| 1341 | * @param bool $includeCnt |
||
| 1342 | * |
||
| 1343 | * @return FluentPdoModel|$this |
||
| 1344 | */ |
||
| 1345 | public function includeCount(bool $includeCnt=true) : FluentPdoModel |
||
| 1351 | |||
| 1352 | /** |
||
| 1353 | * @param bool $distinct |
||
| 1354 | * |
||
| 1355 | * @return FluentPdoModel|$this |
||
| 1356 | */ |
||
| 1357 | public function distinct(bool $distinct=true) : FluentPdoModel |
||
| 1363 | |||
| 1364 | /** |
||
| 1365 | * @param array $fields |
||
| 1366 | * @return FluentPdoModel|$this |
||
| 1367 | */ |
||
| 1368 | public function withBelongsTo(array $fields=[]) : FluentPdoModel |
||
| 1382 | |||
| 1383 | /** |
||
| 1384 | * @param string $alias |
||
| 1385 | * @param bool $addSelectField |
||
| 1386 | * @return FluentPdoModel |
||
| 1387 | */ |
||
| 1388 | public function autoInnerJoin(string $alias, bool $addSelectField=true) : FluentPdoModel |
||
| 1392 | |||
| 1393 | /** |
||
| 1394 | * @param string $alias |
||
| 1395 | * @param string $type |
||
| 1396 | * @param bool $addSelectField |
||
| 1397 | * @return FluentPdoModel|$this |
||
| 1398 | */ |
||
| 1399 | public function autoJoin(string $alias, string $type=self::LEFT_JOIN, bool $addSelectField=true) : FluentPdoModel |
||
| 1426 | |||
| 1427 | /** |
||
| 1428 | * @param array $conditions |
||
| 1429 | * @return FluentPdoModel |
||
| 1430 | */ |
||
| 1431 | public function whereArr(array $conditions) : FluentPdoModel |
||
| 1440 | /** |
||
| 1441 | * Add where condition, more calls appends with AND |
||
| 1442 | * |
||
| 1443 | * @param string $condition possibly containing ? or :name |
||
| 1444 | * @param mixed $parameters accepted by PDOStatement::execute or a scalar value |
||
| 1445 | * @param mixed ... |
||
| 1446 | * @return FluentPdoModel|$this |
||
| 1447 | */ |
||
| 1448 | public function where($condition, $parameters=[]) : FluentPdoModel |
||
| 1497 | |||
| 1498 | /** |
||
| 1499 | * Create an AND operator in the where clause |
||
| 1500 | * |
||
| 1501 | * @return FluentPdoModel|$this |
||
| 1502 | */ |
||
| 1503 | public function _and() : FluentPdoModel |
||
| 1517 | |||
| 1518 | |||
| 1519 | /** |
||
| 1520 | * Create an OR operator in the where clause |
||
| 1521 | * |
||
| 1522 | * @return FluentPdoModel|$this |
||
| 1523 | */ |
||
| 1524 | public function _or() : FluentPdoModel |
||
| 1538 | |||
| 1539 | /** |
||
| 1540 | * To group multiple where clauses together. |
||
| 1541 | * |
||
| 1542 | * @return FluentPdoModel|$this |
||
| 1543 | */ |
||
| 1544 | public function wrap() : FluentPdoModel |
||
| 1554 | |||
| 1555 | /** |
||
| 1556 | * Where Primary key |
||
| 1557 | * |
||
| 1558 | * @param int $id |
||
| 1559 | * @param bool $addAlias |
||
| 1560 | * |
||
| 1561 | * @return FluentPdoModel|$this |
||
| 1562 | */ |
||
| 1563 | public function wherePk(int $id, bool $addAlias=true) : FluentPdoModel |
||
| 1569 | |||
| 1570 | /** |
||
| 1571 | * @param string $name |
||
| 1572 | * @param bool $addAlias |
||
| 1573 | * @return FluentPdoModel |
||
| 1574 | */ |
||
| 1575 | public function whereDisplayName(string $name, bool $addAlias=true) : FluentPdoModel |
||
| 1581 | |||
| 1582 | /** |
||
| 1583 | * WHERE $columnName != $value |
||
| 1584 | * |
||
| 1585 | * @param string $columnName |
||
| 1586 | * @param mixed $value |
||
| 1587 | * @return FluentPdoModel|$this |
||
| 1588 | */ |
||
| 1589 | public function whereNot(string $columnName, $value) : FluentPdoModel |
||
| 1593 | /** |
||
| 1594 | * WHERE $columnName != $value |
||
| 1595 | * |
||
| 1596 | * @param string $columnName |
||
| 1597 | * @param mixed $value |
||
| 1598 | * @return FluentPdoModel|$this |
||
| 1599 | */ |
||
| 1600 | public function whereCoercedNot(string $columnName, $value) : FluentPdoModel |
||
| 1604 | |||
| 1605 | /** |
||
| 1606 | * WHERE $columnName LIKE $value |
||
| 1607 | * |
||
| 1608 | * @param string $columnName |
||
| 1609 | * @param mixed $value |
||
| 1610 | * @return FluentPdoModel|$this |
||
| 1611 | */ |
||
| 1612 | public function whereLike(string $columnName, $value) : FluentPdoModel |
||
| 1616 | |||
| 1617 | /** |
||
| 1618 | * @param string $columnName |
||
| 1619 | * @param mixed $value1 |
||
| 1620 | * @param mixed $value2 |
||
| 1621 | * @return FluentPdoModel|$this |
||
| 1622 | */ |
||
| 1623 | public function whereBetween(string $columnName, $value1, $value2) : FluentPdoModel |
||
| 1630 | |||
| 1631 | /** |
||
| 1632 | * @param string $columnName |
||
| 1633 | * @param mixed $value1 |
||
| 1634 | * @param mixed $value2 |
||
| 1635 | * @return FluentPdoModel|$this |
||
| 1636 | */ |
||
| 1637 | public function whereNotBetween(string $columnName, $value1, $value2) : FluentPdoModel |
||
| 1644 | |||
| 1645 | /** |
||
| 1646 | * @param string $columnName |
||
| 1647 | * @param string $regex |
||
| 1648 | * @return FluentPdoModel|$this |
||
| 1649 | */ |
||
| 1650 | public function whereRegex(string $columnName, string $regex) : FluentPdoModel |
||
| 1654 | |||
| 1655 | /** |
||
| 1656 | * @param string $columnName |
||
| 1657 | * @param string $regex |
||
| 1658 | * @return FluentPdoModel|$this |
||
| 1659 | */ |
||
| 1660 | public function whereNotRegex(string $columnName, string $regex) : FluentPdoModel |
||
| 1664 | |||
| 1665 | /** |
||
| 1666 | * WHERE $columnName NOT LIKE $value |
||
| 1667 | * |
||
| 1668 | * @param string $columnName |
||
| 1669 | * @param string $value |
||
| 1670 | * @return FluentPdoModel|$this |
||
| 1671 | */ |
||
| 1672 | public function whereNotLike(string $columnName, string $value) : FluentPdoModel |
||
| 1676 | |||
| 1677 | /** |
||
| 1678 | * WHERE $columnName > $value |
||
| 1679 | * |
||
| 1680 | * @param string $columnName |
||
| 1681 | * @param mixed $value |
||
| 1682 | * @return FluentPdoModel|$this |
||
| 1683 | */ |
||
| 1684 | public function whereGt(string $columnName, $value) : FluentPdoModel |
||
| 1688 | |||
| 1689 | /** |
||
| 1690 | * WHERE $columnName >= $value |
||
| 1691 | * |
||
| 1692 | * @param string $columnName |
||
| 1693 | * @param mixed $value |
||
| 1694 | * @return FluentPdoModel|$this |
||
| 1695 | */ |
||
| 1696 | public function whereGte(string $columnName, $value) : FluentPdoModel |
||
| 1700 | |||
| 1701 | /** |
||
| 1702 | * WHERE $columnName < $value |
||
| 1703 | * |
||
| 1704 | * @param string $columnName |
||
| 1705 | * @param mixed $value |
||
| 1706 | * @return FluentPdoModel|$this |
||
| 1707 | */ |
||
| 1708 | public function whereLt(string $columnName, $value) : FluentPdoModel |
||
| 1712 | |||
| 1713 | /** |
||
| 1714 | * WHERE $columnName <= $value |
||
| 1715 | * |
||
| 1716 | * @param string $columnName |
||
| 1717 | * @param mixed $value |
||
| 1718 | * @return FluentPdoModel|$this |
||
| 1719 | */ |
||
| 1720 | public function whereLte(string $columnName, $value) : FluentPdoModel |
||
| 1724 | |||
| 1725 | /** |
||
| 1726 | * WHERE $columnName IN (?,?,?,...) |
||
| 1727 | * |
||
| 1728 | * @param string $columnName |
||
| 1729 | * @param array $values |
||
| 1730 | * @return FluentPdoModel|$this |
||
| 1731 | */ |
||
| 1732 | public function whereIn(string $columnName, array $values) : FluentPdoModel |
||
| 1736 | |||
| 1737 | /** |
||
| 1738 | * WHERE $columnName NOT IN (?,?,?,...) |
||
| 1739 | * |
||
| 1740 | * @param string $columnName |
||
| 1741 | * @param array $values |
||
| 1742 | * @return FluentPdoModel|$this |
||
| 1743 | */ |
||
| 1744 | public function whereNotIn(string $columnName, array $values) : FluentPdoModel |
||
| 1750 | |||
| 1751 | /** |
||
| 1752 | * WHERE $columnName IS NULL |
||
| 1753 | * |
||
| 1754 | * @param string $columnName |
||
| 1755 | * @return FluentPdoModel|$this |
||
| 1756 | */ |
||
| 1757 | public function whereNull(string $columnName) : FluentPdoModel |
||
| 1761 | |||
| 1762 | /** |
||
| 1763 | * WHERE $columnName IS NOT NULL |
||
| 1764 | * |
||
| 1765 | * @param string $columnName |
||
| 1766 | * @return FluentPdoModel|$this |
||
| 1767 | */ |
||
| 1768 | public function whereNotNull(string $columnName) : FluentPdoModel |
||
| 1772 | |||
| 1773 | /** |
||
| 1774 | * @param string $statement |
||
| 1775 | * @param string $operator |
||
| 1776 | * @return FluentPdoModel|$this |
||
| 1777 | */ |
||
| 1778 | public function having(string $statement, string $operator=self::OPERATOR_AND) : FluentPdoModel |
||
| 1787 | |||
| 1788 | /** |
||
| 1789 | * ORDER BY $columnName (ASC | DESC) |
||
| 1790 | * |
||
| 1791 | * @param string $columnName - The name of the column or an expression |
||
| 1792 | * @param string $ordering (DESC | ASC) |
||
| 1793 | * @return FluentPdoModel|$this |
||
| 1794 | */ |
||
| 1795 | public function orderBy(string $columnName='', string $ordering='ASC') : FluentPdoModel |
||
| 1809 | |||
| 1810 | /** |
||
| 1811 | * GROUP BY $columnName |
||
| 1812 | * |
||
| 1813 | * @param string $columnName |
||
| 1814 | * @return FluentPdoModel|$this |
||
| 1815 | */ |
||
| 1816 | public function groupBy(string $columnName) : FluentPdoModel |
||
| 1826 | |||
| 1827 | |||
| 1828 | /** |
||
| 1829 | * LIMIT $limit |
||
| 1830 | * |
||
| 1831 | * @param int $limit |
||
| 1832 | * @param int|null $offset |
||
| 1833 | * @return FluentPdoModel|$this |
||
| 1834 | */ |
||
| 1835 | public function limit(int $limit, int $offset=0) : FluentPdoModel |
||
| 1844 | |||
| 1845 | /** |
||
| 1846 | * Return the limit |
||
| 1847 | * |
||
| 1848 | * @return integer |
||
| 1849 | */ |
||
| 1850 | public function getLimit() : int |
||
| 1854 | |||
| 1855 | /** |
||
| 1856 | * OFFSET $offset |
||
| 1857 | * |
||
| 1858 | * @param int $offset |
||
| 1859 | * @return FluentPdoModel|$this |
||
| 1860 | */ |
||
| 1861 | public function offset(int $offset) : FluentPdoModel |
||
| 1867 | |||
| 1868 | /** |
||
| 1869 | * Return the offset |
||
| 1870 | * |
||
| 1871 | * @return integer |
||
| 1872 | */ |
||
| 1873 | public function getOffset() : int |
||
| 1877 | |||
| 1878 | /** |
||
| 1879 | * Build a join |
||
| 1880 | * |
||
| 1881 | * @param string $table - The table name |
||
| 1882 | * @param string $constraint -> id = profile.user_id |
||
| 1883 | * @param string $tableAlias - The alias of the table name |
||
| 1884 | * @param string $joinOperator - LEFT | INNER | etc... |
||
| 1885 | * @return FluentPdoModel|$this |
||
| 1886 | */ |
||
| 1887 | public function join(string $table, string $constraint='', string $tableAlias='', string $joinOperator='') : FluentPdoModel |
||
| 1906 | |||
| 1907 | /** |
||
| 1908 | * Create a left join |
||
| 1909 | * |
||
| 1910 | * @param string $table |
||
| 1911 | * @param string $constraint |
||
| 1912 | * @param string $tableAlias |
||
| 1913 | * @return FluentPdoModel|$this |
||
| 1914 | */ |
||
| 1915 | public function leftJoin(string $table, string $constraint, string $tableAlias='') : FluentPdoModel |
||
| 1919 | |||
| 1920 | |||
| 1921 | /** |
||
| 1922 | * Return the build select query |
||
| 1923 | * |
||
| 1924 | * @return string |
||
| 1925 | */ |
||
| 1926 | public function getSelectQuery() : string |
||
| 1969 | |||
| 1970 | /** |
||
| 1971 | * @param string $field |
||
| 1972 | * @param string $column |
||
| 1973 | * @return string |
||
| 1974 | */ |
||
| 1975 | public function getFieldComment(string $field, string $column) : string |
||
| 1979 | |||
| 1980 | /** |
||
| 1981 | * Prepare columns to include the table alias name |
||
| 1982 | * @param array $columns |
||
| 1983 | * @return array |
||
| 1984 | */ |
||
| 1985 | protected function prepareColumns(array $columns) : array |
||
| 2015 | |||
| 2016 | /** |
||
| 2017 | * Build the WHERE clause(s) |
||
| 2018 | * |
||
| 2019 | * @param bool $purgeAliases |
||
| 2020 | * @return string |
||
| 2021 | */ |
||
| 2022 | protected function getWhereString(bool $purgeAliases=false) : string |
||
| 2055 | |||
| 2056 | /** |
||
| 2057 | * Return the HAVING clause |
||
| 2058 | * |
||
| 2059 | * @return string |
||
| 2060 | */ |
||
| 2061 | protected function getHavingString() : string |
||
| 2080 | |||
| 2081 | /** |
||
| 2082 | * Return the values to be bound for where |
||
| 2083 | * |
||
| 2084 | * @param bool $purgeAliases |
||
| 2085 | * @return array |
||
| 2086 | */ |
||
| 2087 | protected function getWhereParameters(bool $purgeAliases=false) : array |
||
| 2093 | |||
| 2094 | /** |
||
| 2095 | * @param array $record |
||
| 2096 | * @return stdClass |
||
| 2097 | */ |
||
| 2098 | public function insertArr(array $record) : stdClass |
||
| 2102 | |||
| 2103 | /** |
||
| 2104 | * Insert new rows |
||
| 2105 | * $records can be a stdClass or an array of stdClass to add a bulk insert |
||
| 2106 | * If a single row is inserted, it will return it's row instance |
||
| 2107 | * |
||
| 2108 | * @param stdClass $rec |
||
| 2109 | * @return stdClass |
||
| 2110 | * @throws Exception |
||
| 2111 | */ |
||
| 2112 | public function insert(stdClass $rec) : stdClass |
||
| 2135 | |||
| 2136 | /** |
||
| 2137 | * @param string $name |
||
| 2138 | * @return int |
||
| 2139 | */ |
||
| 2140 | public function getLastInsertId(string $name='') : int |
||
| 2144 | |||
| 2145 | /** |
||
| 2146 | * @param stdClass[] $records |
||
| 2147 | * @return stdClass[] |
||
| 2148 | */ |
||
| 2149 | public function insertSqlQuery(array $records) : array |
||
| 2169 | |||
| 2170 | /** |
||
| 2171 | * @param $data |
||
| 2172 | * @param array $matchOn |
||
| 2173 | * @param bool $returnObj |
||
| 2174 | * @return bool|int|stdClass |
||
| 2175 | */ |
||
| 2176 | public function upsert($data, array $matchOn=[], $returnObj=false) |
||
| 2198 | |||
| 2199 | /** |
||
| 2200 | * @param stdClass $object |
||
| 2201 | * @param array $matchOn |
||
| 2202 | * @param bool $returnObj |
||
| 2203 | * @return bool|int|stdClass |
||
| 2204 | */ |
||
| 2205 | public function upsertOne(stdClass $object, array $matchOn=[], $returnObj=false) |
||
| 2245 | |||
| 2246 | /** |
||
| 2247 | * @param array $data |
||
| 2248 | * @param array $matchOn |
||
| 2249 | * @param bool|false $returnObj |
||
| 2250 | * @return bool|int|stdClass |
||
| 2251 | */ |
||
| 2252 | public function upsertArr(array $data, array $matchOn=[], bool $returnObj=false) |
||
| 2256 | |||
| 2257 | /** |
||
| 2258 | * Update entries |
||
| 2259 | * Use the query builder to create the where clause |
||
| 2260 | * |
||
| 2261 | * @param stdClass $record |
||
| 2262 | * @param bool $updateAll |
||
| 2263 | * @return int |
||
| 2264 | * @throws Exception |
||
| 2265 | */ |
||
| 2266 | public function update(stdClass $record, $updateAll=false) : int |
||
| 2289 | |||
| 2290 | /** |
||
| 2291 | * @param array $record |
||
| 2292 | * @param bool|false $updateAll |
||
| 2293 | * @return int |
||
| 2294 | * @throws Exception |
||
| 2295 | */ |
||
| 2296 | public function updateArr(array $record, $updateAll=false) : int |
||
| 2300 | |||
| 2301 | /** |
||
| 2302 | * @param string $field |
||
| 2303 | * @param mixed $value |
||
| 2304 | * @param int $id |
||
| 2305 | * @param bool|false $updateAll |
||
| 2306 | * @return int |
||
| 2307 | * @throws Exception |
||
| 2308 | */ |
||
| 2309 | public function updateField(string $field, $value, int $id=0, bool $updateAll=false) : int |
||
| 2323 | |||
| 2324 | /** |
||
| 2325 | * @param stdClass $record |
||
| 2326 | * @return bool|int |
||
| 2327 | * @throws Exception |
||
| 2328 | */ |
||
| 2329 | public function updateChanged(stdClass $record) : int |
||
| 2343 | |||
| 2344 | /** |
||
| 2345 | * @param string $expression |
||
| 2346 | * @param array $params |
||
| 2347 | * @return FluentPdoModel|$this |
||
| 2348 | */ |
||
| 2349 | public function updateByExpression(string $expression, array $params) : FluentPdoModel |
||
| 2355 | |||
| 2356 | /** |
||
| 2357 | * @param array $data |
||
| 2358 | * @return int |
||
| 2359 | * @throws Exception |
||
| 2360 | */ |
||
| 2361 | public function rawUpdate(array $data=[]) : int |
||
| 2370 | |||
| 2371 | /** |
||
| 2372 | * @param stdClass $record |
||
| 2373 | * @return array |
||
| 2374 | */ |
||
| 2375 | public function updateSqlQuery(stdClass $record) : array |
||
| 2384 | |||
| 2385 | /** |
||
| 2386 | * @param $record |
||
| 2387 | * @return array |
||
| 2388 | */ |
||
| 2389 | protected function updateSql(array $record) : array |
||
| 2422 | |||
| 2423 | /** |
||
| 2424 | * @param bool $deleteAll |
||
| 2425 | * @param bool $force |
||
| 2426 | * @return int |
||
| 2427 | * @throws Exception |
||
| 2428 | */ |
||
| 2429 | public function delete(bool $deleteAll=false, bool $force=false) : int |
||
| 2450 | |||
| 2451 | /** |
||
| 2452 | * @return bool |
||
| 2453 | */ |
||
| 2454 | public function isSoftDelete() : bool |
||
| 2458 | |||
| 2459 | /** |
||
| 2460 | * @param bool|false $force |
||
| 2461 | * @return FluentPdoModel|$this |
||
| 2462 | * @throws Exception |
||
| 2463 | */ |
||
| 2464 | public function truncate(bool $force=false) : FluentPdoModel |
||
| 2478 | |||
| 2479 | /** |
||
| 2480 | * @return array |
||
| 2481 | */ |
||
| 2482 | public function deleteSqlQuery() : array |
||
| 2494 | |||
| 2495 | |||
| 2496 | /** |
||
| 2497 | * Return the aggregate count of column |
||
| 2498 | * |
||
| 2499 | * @param string $column |
||
| 2500 | * @param int $cacheTtl |
||
| 2501 | * @return float |
||
| 2502 | */ |
||
| 2503 | public function count(string $column='*', int $cacheTtl=self::CACHE_NO) : float |
||
| 2523 | |||
| 2524 | |||
| 2525 | /** |
||
| 2526 | * Return the aggregate max count of column |
||
| 2527 | * |
||
| 2528 | * @param string $column |
||
| 2529 | * @param int $cacheTtl |
||
| 2530 | * @return int|float|string|null |
||
| 2531 | */ |
||
| 2532 | public function max(string $column, int $cacheTtl=self::CACHE_NO) |
||
| 2538 | |||
| 2539 | |||
| 2540 | /** |
||
| 2541 | * Return the aggregate min count of column |
||
| 2542 | * |
||
| 2543 | * @param string $column |
||
| 2544 | * @param int $cacheTtl |
||
| 2545 | * @return int|float|string|null |
||
| 2546 | */ |
||
| 2547 | public function min(string $column, int $cacheTtl=self::CACHE_NO) |
||
| 2553 | |||
| 2554 | /** |
||
| 2555 | * Return the aggregate sum count of column |
||
| 2556 | * |
||
| 2557 | * @param string $column |
||
| 2558 | * @param int $cacheTtl |
||
| 2559 | * @return int|float|string|null |
||
| 2560 | */ |
||
| 2561 | public function sum(string $column, int $cacheTtl=self::CACHE_NO) |
||
| 2567 | |||
| 2568 | /** |
||
| 2569 | * Return the aggregate average count of column |
||
| 2570 | * |
||
| 2571 | * @param string $column |
||
| 2572 | * @param int $cacheTtl |
||
| 2573 | * @return int|float|string|null |
||
| 2574 | */ |
||
| 2575 | public function avg(string $column, int $cacheTtl=self::CACHE_NO) |
||
| 2581 | |||
| 2582 | /*******************************************************************************/ |
||
| 2583 | // Utilities methods |
||
| 2584 | |||
| 2585 | /** |
||
| 2586 | * Reset fields |
||
| 2587 | * |
||
| 2588 | * @return FluentPdoModel|$this |
||
| 2589 | */ |
||
| 2590 | public function reset() : FluentPdoModel |
||
| 2618 | |||
| 2619 | |||
| 2620 | /** |
||
| 2621 | * @return FluentPdoModel|$this |
||
| 2622 | */ |
||
| 2623 | public function removeUnauthorisedFields() : FluentPdoModel |
||
| 2627 | |||
| 2628 | /** |
||
| 2629 | * @return Closure[] |
||
| 2630 | */ |
||
| 2631 | protected function getFieldHandlers() : array |
||
| 2731 | |||
| 2732 | /** |
||
| 2733 | * @return bool |
||
| 2734 | */ |
||
| 2735 | public function begin() : bool |
||
| 2749 | |||
| 2750 | /** |
||
| 2751 | * @return bool |
||
| 2752 | */ |
||
| 2753 | public function commit() : bool |
||
| 2771 | |||
| 2772 | /** |
||
| 2773 | * @return bool |
||
| 2774 | */ |
||
| 2775 | public function rollback() : bool |
||
| 2789 | |||
| 2790 | /** |
||
| 2791 | * @param stdClass $record |
||
| 2792 | * @param string $type |
||
| 2793 | * @return stdClass |
||
| 2794 | */ |
||
| 2795 | public function applyGlobalModifiers(stdClass $record, string $type) : stdClass |
||
| 2808 | |||
| 2809 | /** |
||
| 2810 | * @param stdClass $record |
||
| 2811 | * @param string $type |
||
| 2812 | * @return stdClass |
||
| 2813 | */ |
||
| 2814 | public function removeUnneededFields(stdClass $record, string $type) : stdClass |
||
| 2845 | |||
| 2846 | |||
| 2847 | /** |
||
| 2848 | * @param array $ids |
||
| 2849 | * @param array $values |
||
| 2850 | * @param int $batch |
||
| 2851 | * @return bool |
||
| 2852 | */ |
||
| 2853 | public function setById(array $ids, array $values, int $batch=1000) : bool |
||
| 2873 | |||
| 2874 | |||
| 2875 | /** |
||
| 2876 | * @param string $displayColumnValue |
||
| 2877 | * @return int |
||
| 2878 | */ |
||
| 2879 | public function resolveId(string $displayColumnValue) : int |
||
| 2890 | |||
| 2891 | /** |
||
| 2892 | * @param int $resourceId |
||
| 2893 | * @param array $query |
||
| 2894 | * @param array $extraFields |
||
| 2895 | * @param int $cacheTtl |
||
| 2896 | * @return array |
||
| 2897 | */ |
||
| 2898 | public function fetchApiResource(int $resourceId, array $query=[], array $extraFields=[], int $cacheTtl=self::CACHE_NO) : array |
||
| 2911 | |||
| 2912 | /** |
||
| 2913 | * @param array $query |
||
| 2914 | * @param array $extraFields |
||
| 2915 | * @param int $cacheTtl |
||
| 2916 | * @param string $permEntity |
||
| 2917 | * @return array |
||
| 2918 | */ |
||
| 2919 | public function fetchApiResources(array $query=[], array $extraFields=[], int $cacheTtl=self::CACHE_NO, string $permEntity='') : array |
||
| 2941 | |||
| 2942 | |||
| 2943 | /** |
||
| 2944 | * @return array |
||
| 2945 | */ |
||
| 2946 | public function getSearchableAssociations() : array |
||
| 2953 | |||
| 2954 | /** |
||
| 2955 | * @param array $fields |
||
| 2956 | */ |
||
| 2957 | public function removeUnrequestedFields(array $fields) |
||
| 2968 | |||
| 2969 | /** |
||
| 2970 | * @param array $removeFields |
||
| 2971 | */ |
||
| 2972 | public function removeFields(array $removeFields=[]) |
||
| 2998 | |||
| 2999 | /** |
||
| 3000 | * @return FluentPdoModel|$this |
||
| 3001 | */ |
||
| 3002 | public function defaultFilters() : FluentPdoModel |
||
| 3006 | |||
| 3007 | /** |
||
| 3008 | * @param bool $allow |
||
| 3009 | * |
||
| 3010 | * @return FluentPdoModel|$this |
||
| 3011 | */ |
||
| 3012 | public function allowMetaColumnOverride(bool $allow=false) : FluentPdoModel |
||
| 3018 | |||
| 3019 | /** |
||
| 3020 | * @param bool $skip |
||
| 3021 | * |
||
| 3022 | * @return FluentPdoModel|$this |
||
| 3023 | */ |
||
| 3024 | public function skipMetaUpdates(bool $skip=true) : FluentPdoModel |
||
| 3030 | |||
| 3031 | /** |
||
| 3032 | * @param bool $add |
||
| 3033 | * |
||
| 3034 | * @return FluentPdoModel|$this |
||
| 3035 | */ |
||
| 3036 | public function addUpdateAlias(bool $add=true) : FluentPdoModel |
||
| 3042 | |||
| 3043 | /** |
||
| 3044 | * @param stdClass $record |
||
| 3045 | * @return stdClass |
||
| 3046 | */ |
||
| 3047 | public function onFetch(stdClass $record) : stdClass |
||
| 3059 | |||
| 3060 | /** |
||
| 3061 | * @param $value |
||
| 3062 | * @return string |
||
| 3063 | */ |
||
| 3064 | public function gzEncodeData(string $value) : string |
||
| 3073 | |||
| 3074 | /** |
||
| 3075 | * @param $value |
||
| 3076 | * @return mixed|string |
||
| 3077 | */ |
||
| 3078 | public function gzDecodeData(string $value) : string |
||
| 3088 | |||
| 3089 | /** |
||
| 3090 | * @param $value |
||
| 3091 | * @return bool |
||
| 3092 | */ |
||
| 3093 | protected function hasGzipPrefix(string $value) : bool |
||
| 3097 | |||
| 3098 | /** |
||
| 3099 | * @param stdClass $record |
||
| 3100 | * @return stdClass |
||
| 3101 | */ |
||
| 3102 | public function fixTimestamps(stdClass $record) : stdClass |
||
| 3114 | |||
| 3115 | /** |
||
| 3116 | * @param int $max |
||
| 3117 | * @return FluentPdoModel|$this |
||
| 3118 | */ |
||
| 3119 | public function setMaxRecords(int $max) : FluentPdoModel |
||
| 3126 | |||
| 3127 | |||
| 3128 | /** |
||
| 3129 | * @param stdClass $record |
||
| 3130 | * @param string $type |
||
| 3131 | * @return stdClass |
||
| 3132 | */ |
||
| 3133 | public function afterSave(stdClass $record, string $type) : stdClass |
||
| 3154 | |||
| 3155 | /** |
||
| 3156 | * @param stdClass $record |
||
| 3157 | * @param string $type |
||
| 3158 | * @return stdClass |
||
| 3159 | */ |
||
| 3160 | public function addDefaultFields(stdClass $record, string $type) : stdClass |
||
| 3193 | |||
| 3194 | |||
| 3195 | /** |
||
| 3196 | * @return bool |
||
| 3197 | */ |
||
| 3198 | public function createTable() : bool |
||
| 3202 | |||
| 3203 | /** |
||
| 3204 | * @param bool|false $force |
||
| 3205 | * @return FluentPdoModel|$this |
||
| 3206 | * @throws Exception |
||
| 3207 | */ |
||
| 3208 | public function dropTable(bool $force=false) : FluentPdoModel |
||
| 3212 | |||
| 3213 | protected function compileHandlers() |
||
| 3222 | |||
| 3223 | /** |
||
| 3224 | * @param string $viewName |
||
| 3225 | * @param int $cacheTtl |
||
| 3226 | * @return array |
||
| 3227 | */ |
||
| 3228 | public function getViewColumns($viewName, $cacheTtl=self::CACHE_NO) |
||
| 3232 | |||
| 3233 | /** |
||
| 3234 | * @param int $id |
||
| 3235 | * @return string |
||
| 3236 | */ |
||
| 3237 | public function getDisplayNameById(int $id) : string |
||
| 3247 | |||
| 3248 | /** |
||
| 3249 | * @param int $id |
||
| 3250 | * @param string $displayColumnValue |
||
| 3251 | * @return bool |
||
| 3252 | */ |
||
| 3253 | public function validIdDisplayNameCombo(int $id, $displayColumnValue) : bool |
||
| 3257 | |||
| 3258 | /** |
||
| 3259 | * @param array $toPopulate |
||
| 3260 | * @return stdClass |
||
| 3261 | */ |
||
| 3262 | protected function getEmptyObject(array $toPopulate=[]) : stdClass |
||
| 3268 | |||
| 3269 | /** |
||
| 3270 | * @param array $toPopulate |
||
| 3271 | * @return stdClass |
||
| 3272 | */ |
||
| 3273 | protected static function emptyObject(array $toPopulate=[]) : stdClass |
||
| 3279 | |||
| 3280 | /** |
||
| 3281 | * @param int $id |
||
| 3282 | * @return bool |
||
| 3283 | */ |
||
| 3284 | public static function isId(int $id) : bool |
||
| 3288 | |||
| 3289 | /** |
||
| 3290 | * @param int $cacheTtl |
||
| 3291 | * @return int |
||
| 3292 | */ |
||
| 3293 | public function activeCount(int $cacheTtl=self::CACHE_NO) : int |
||
| 3297 | |||
| 3298 | /** |
||
| 3299 | * @param string $tableAlias |
||
| 3300 | * @param string $columnName |
||
| 3301 | * @return FluentPdoModel|$this |
||
| 3302 | */ |
||
| 3303 | public function whereActive(string $tableAlias='', string $columnName=self::STATUS_FIELD) : FluentPdoModel |
||
| 3307 | |||
| 3308 | /** |
||
| 3309 | * @param string $tableAlias |
||
| 3310 | * @param string $columnName |
||
| 3311 | * @return FluentPdoModel|$this |
||
| 3312 | */ |
||
| 3313 | public function whereInactive(string $tableAlias='', string $columnName=self::STATUS_FIELD) : FluentPdoModel |
||
| 3317 | |||
| 3318 | /** |
||
| 3319 | * @param string $tableAlias |
||
| 3320 | * @param string $columnName |
||
| 3321 | * @return FluentPdoModel|$this |
||
| 3322 | */ |
||
| 3323 | public function whereArchived(string $tableAlias='', string $columnName='status') : FluentPdoModel |
||
| 3327 | |||
| 3328 | /** |
||
| 3329 | * @param int $status |
||
| 3330 | * @param string $tableAlias |
||
| 3331 | * @param string $columnName |
||
| 3332 | * @return FluentPdoModel|$this |
||
| 3333 | */ |
||
| 3334 | public function whereStatus(int $status, string $tableAlias='', string $columnName=self::STATUS_FIELD) : FluentPdoModel |
||
| 3343 | |||
| 3344 | /** |
||
| 3345 | * @param int $id |
||
| 3346 | * @return int |
||
| 3347 | */ |
||
| 3348 | public function updateActive(int $id=0) : int |
||
| 3358 | |||
| 3359 | /** |
||
| 3360 | * @param int $id |
||
| 3361 | * @return int |
||
| 3362 | */ |
||
| 3363 | public function updateInactive(int $id=0) : int |
||
| 3372 | |||
| 3373 | /** |
||
| 3374 | * @param string $field |
||
| 3375 | * @param int $id |
||
| 3376 | * @return int |
||
| 3377 | */ |
||
| 3378 | public function updateNow(string $field, int $id=0) : int |
||
| 3384 | |||
| 3385 | /** |
||
| 3386 | * @param string $field |
||
| 3387 | * @param int $id |
||
| 3388 | * @return int |
||
| 3389 | */ |
||
| 3390 | public function updateToday($field, int $id=0) : int |
||
| 3396 | |||
| 3397 | /** |
||
| 3398 | * @param int $id |
||
| 3399 | * @return int |
||
| 3400 | */ |
||
| 3401 | public function updateDeleted(int $id=0) : int |
||
| 3414 | |||
| 3415 | /** |
||
| 3416 | * @return bool |
||
| 3417 | */ |
||
| 3418 | public function isDeleterTableType() : bool |
||
| 3428 | |||
| 3429 | /** |
||
| 3430 | * @param int $id |
||
| 3431 | * @return int |
||
| 3432 | */ |
||
| 3433 | public function updateArchived(int $id=0) : int |
||
| 3443 | |||
| 3444 | /** |
||
| 3445 | * @param int $status |
||
| 3446 | * @return int |
||
| 3447 | * @throws \Exception |
||
| 3448 | */ |
||
| 3449 | public function updateStatus(int $status) |
||
| 3455 | |||
| 3456 | /** |
||
| 3457 | * Return a YYYY-MM-DD HH:II:SS date format |
||
| 3458 | * |
||
| 3459 | * @param string $datetime - An english textual datetime description |
||
| 3460 | * now, yesterday, 3 days ago, +1 week |
||
| 3461 | * http://php.net/manual/en/function.strtotime.php |
||
| 3462 | * @return string YYYY-MM-DD HH:II:SS |
||
| 3463 | */ |
||
| 3464 | public static function NOW(string $datetime='now') : string |
||
| 3468 | |||
| 3469 | /** |
||
| 3470 | * Return a string containing the given number of question marks, |
||
| 3471 | * separated by commas. Eg '?, ?, ?' |
||
| 3472 | * |
||
| 3473 | * @param int - total of placeholder to insert |
||
| 3474 | * @return string |
||
| 3475 | */ |
||
| 3476 | protected function makePlaceholders(int $numberOfPlaceholders=1) : string |
||
| 3480 | |||
| 3481 | /** |
||
| 3482 | * Format the table{Primary|Foreign}KeyName |
||
| 3483 | * |
||
| 3484 | * @param string $pattern |
||
| 3485 | * @param string $tableName |
||
| 3486 | * @return string |
||
| 3487 | */ |
||
| 3488 | protected function formatKeyName(string $pattern, string $tableName) : string |
||
| 3492 | |||
| 3493 | /** |
||
| 3494 | * @param array $query |
||
| 3495 | * @param array $extraFields |
||
| 3496 | * @return array |
||
| 3497 | * @throws \Exception |
||
| 3498 | */ |
||
| 3499 | protected function prepareApiResource(array $query=[], array $extraFields=[]) : array |
||
| 3520 | |||
| 3521 | /** |
||
| 3522 | * @param string $query |
||
| 3523 | * @param array $parameters |
||
| 3524 | * |
||
| 3525 | * @return array |
||
| 3526 | */ |
||
| 3527 | protected function logQuery(string $query, array $parameters) : array |
||
| 3540 | |||
| 3541 | /** |
||
| 3542 | * @param string $ident |
||
| 3543 | * @param string $builtQuery |
||
| 3544 | */ |
||
| 3545 | protected function logSlowQueries(string $ident, string $builtQuery) |
||
| 3558 | |||
| 3559 | /** |
||
| 3560 | * @return float |
||
| 3561 | */ |
||
| 3562 | public function getTimeTaken() : float |
||
| 3568 | |||
| 3569 | /** |
||
| 3570 | * @param $secs |
||
| 3571 | * @return FluentPdoModel|$this |
||
| 3572 | */ |
||
| 3573 | public function slowQuerySeconds(int $secs) : FluentPdoModel |
||
| 3580 | |||
| 3581 | |||
| 3582 | /** |
||
| 3583 | * @param $field |
||
| 3584 | * @param array $values |
||
| 3585 | * @param string $placeholderPrefix |
||
| 3586 | * |
||
| 3587 | * @return array |
||
| 3588 | */ |
||
| 3589 | public function getNamedWhereIn(string $field, array $values, string $placeholderPrefix='') : array |
||
| 3613 | |||
| 3614 | /** |
||
| 3615 | * @param string $field |
||
| 3616 | * @param string $delimiter |
||
| 3617 | * |
||
| 3618 | * @return array |
||
| 3619 | */ |
||
| 3620 | protected function getColumnAliasParts(string $field, string $delimiter=':') : array |
||
| 3635 | |||
| 3636 | /** |
||
| 3637 | * @param string $column |
||
| 3638 | * @param string $term |
||
| 3639 | * @return FluentPdoModel|$this |
||
| 3640 | */ |
||
| 3641 | protected function addWhereClause(string $column, string $term) : FluentPdoModel |
||
| 3693 | |||
| 3694 | /** |
||
| 3695 | * @param string $term |
||
| 3696 | * @return array |
||
| 3697 | */ |
||
| 3698 | public function parseWhereClause(string $term) : array |
||
| 3723 | |||
| 3724 | public function destroy() |
||
| 3733 | |||
| 3734 | public function __destruct() |
||
| 3738 | |||
| 3739 | /** |
||
| 3740 | * Load a model |
||
| 3741 | * |
||
| 3742 | * @param string $modelName |
||
| 3743 | * @param AbstractPdo $connection |
||
| 3744 | * @return FluentPdoModel|$this |
||
| 3745 | * @throws ModelNotFoundException |
||
| 3746 | */ |
||
| 3747 | public static function loadModel(string $modelName, AbstractPdo $connection=null) : FluentPdoModel |
||
| 3757 | |||
| 3758 | /** |
||
| 3759 | * Load a model |
||
| 3760 | * |
||
| 3761 | * @param string $tableName |
||
| 3762 | * @param AbstractPdo $connection |
||
| 3763 | * @return FluentPdoModel|$this |
||
| 3764 | */ |
||
| 3765 | public static function loadTable(string $tableName, AbstractPdo $connection=null) : FluentPdoModel |
||
| 3772 | |||
| 3773 | /** |
||
| 3774 | * @param string $columnName |
||
| 3775 | * @param int $cacheTtl |
||
| 3776 | * @param bool $flushCache |
||
| 3777 | * @return bool |
||
| 3778 | */ |
||
| 3779 | public function columnExists(string $columnName, int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : bool |
||
| 3785 | |||
| 3786 | /** |
||
| 3787 | * @param string $typeName |
||
| 3788 | * @return bool |
||
| 3789 | */ |
||
| 3790 | public function typeExists(string $typeName) : bool |
||
| 3794 | |||
| 3795 | /** |
||
| 3796 | * @param string $foreignKeyName |
||
| 3797 | * @param int $cacheTtl |
||
| 3798 | * @param bool $flushCache |
||
| 3799 | * @return bool |
||
| 3800 | */ |
||
| 3801 | public function foreignKeyExists(string $foreignKeyName, int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : bool |
||
| 3807 | |||
| 3808 | /** |
||
| 3809 | * @param string $indexName |
||
| 3810 | * @param int $cacheTtl |
||
| 3811 | * @param bool $flushCache |
||
| 3812 | * @return bool |
||
| 3813 | */ |
||
| 3814 | public function indexExists(string $indexName, int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : bool |
||
| 3836 | |||
| 3837 | |||
| 3838 | |||
| 3839 | /** |
||
| 3840 | * @param int $cacheTtl |
||
| 3841 | * @param bool $flushCache |
||
| 3842 | * @return FluentPdoModel|$this |
||
| 3843 | */ |
||
| 3844 | public function loadSchemaFromDb(int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : FluentPdoModel |
||
| 3851 | |||
| 3852 | /** |
||
| 3853 | * @param int $cacheTtl |
||
| 3854 | * @param bool $flushCache |
||
| 3855 | * @return Column[][] |
||
| 3856 | */ |
||
| 3857 | public function getSchemaFromDb(int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : array |
||
| 3871 | |||
| 3872 | /** |
||
| 3873 | * @param int $cacheTtl |
||
| 3874 | * @param bool $flushCache |
||
| 3875 | * @return array |
||
| 3876 | */ |
||
| 3877 | public function getForeignKeysFromDb(int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : array |
||
| 3890 | |||
| 3891 | /** |
||
| 3892 | * @param string $table |
||
| 3893 | * @param int $cacheTtl |
||
| 3894 | * @param bool $flushCache |
||
| 3895 | * @return Column[][] |
||
| 3896 | */ |
||
| 3897 | protected function getColumnsByTableFromDb(string $table, int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : array |
||
| 3913 | |||
| 3914 | /** |
||
| 3915 | * @param string $table |
||
| 3916 | * @param int $cacheTtl |
||
| 3917 | * @param bool $flushCache |
||
| 3918 | * @return Column[][] |
||
| 3919 | */ |
||
| 3920 | protected function getForeignKeysByTableFromDb(string $table, int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : array |
||
| 3936 | |||
| 3937 | /** |
||
| 3938 | * @param string $table |
||
| 3939 | * @return bool |
||
| 3940 | */ |
||
| 3941 | public function clearSchemaCache(string $table) : bool |
||
| 3945 | |||
| 3946 | /** |
||
| 3947 | * @param stdClass $record |
||
| 3948 | * @return stdClass |
||
| 3949 | */ |
||
| 3950 | public function cleanseRecord(stdClass $record) : stdClass |
||
| 3968 | |||
| 3969 | /** |
||
| 3970 | * @param stdClass $record |
||
| 3971 | * @param string $type |
||
| 3972 | * @return stdClass |
||
| 3973 | */ |
||
| 3974 | public function beforeSave(stdClass $record, string $type) : stdClass |
||
| 3983 | |||
| 3984 | /** |
||
| 3985 | * @param array $data |
||
| 3986 | * @param string $saveType |
||
| 3987 | * @param array $preserve |
||
| 3988 | * @return array |
||
| 3989 | * @throws \Terah\Assert\AssertionFailedException |
||
| 3990 | */ |
||
| 3991 | public function cleanseWebData(array $data, string $saveType, array $preserve=[]) : array |
||
| 4007 | |||
| 4008 | /** |
||
| 4009 | * @return array |
||
| 4010 | */ |
||
| 4011 | public function skeleton() : array |
||
| 4022 | |||
| 4023 | /** |
||
| 4024 | * @param bool $toString |
||
| 4025 | * @return array |
||
| 4026 | */ |
||
| 4027 | public function getErrors(bool $toString=false) : array |
||
| 4041 | |||
| 4042 | /** |
||
| 4043 | * @param bool $throw |
||
| 4044 | * @return FluentPdoModel|$this |
||
| 4045 | */ |
||
| 4046 | public function validationExceptions(bool $throw=true) : FluentPdoModel |
||
| 4052 | |||
| 4053 | /** |
||
| 4054 | * @param array $query array('_limit' => int, '_offset' => int, '_order' => string, '_fields' => string, _search) |
||
| 4055 | * |
||
| 4056 | * @return FluentPdoModel|$this |
||
| 4057 | * @throws Exception |
||
| 4058 | */ |
||
| 4059 | public function paginate(array $query=[]) : FluentPdoModel |
||
| 4076 | |||
| 4077 | /** |
||
| 4078 | * @param int $limit |
||
| 4079 | * @param int $offset |
||
| 4080 | * @return FluentPdoModel|$this |
||
| 4081 | */ |
||
| 4082 | protected function setLimit(int $limit=0, int $offset=0) : FluentPdoModel |
||
| 4097 | |||
| 4098 | /** |
||
| 4099 | * @param array $fields |
||
| 4100 | * @return FluentPdoModel|$this |
||
| 4101 | * @throws Exception |
||
| 4102 | */ |
||
| 4103 | protected function setFields(array $fields=[]) : FluentPdoModel |
||
| 4154 | |||
| 4155 | /** |
||
| 4156 | * @param string $orderBy |
||
| 4157 | * @return FluentPdoModel|$this|FluentPdoModel |
||
| 4158 | */ |
||
| 4159 | protected function setOrderBy(string $orderBy='') : FluentPdoModel |
||
| 4196 | |||
| 4197 | /** |
||
| 4198 | * @return array |
||
| 4199 | */ |
||
| 4200 | public function getPagingMeta() |
||
| 4209 | |||
| 4210 | /** |
||
| 4211 | * @return FluentPdoModel|$this |
||
| 4212 | */ |
||
| 4213 | public function setPagingMeta() : FluentPdoModel |
||
| 4235 | |||
| 4236 | /** |
||
| 4237 | * Take a web request and format a query |
||
| 4238 | * |
||
| 4239 | * @param array $query |
||
| 4240 | * |
||
| 4241 | * @return FluentPdoModel|$this |
||
| 4242 | * @throws Exception |
||
| 4243 | */ |
||
| 4244 | public function filter(array $query=[]) : FluentPdoModel |
||
| 4314 | |||
| 4315 | /** |
||
| 4316 | * @param string $column |
||
| 4317 | * @param string $displayCol |
||
| 4318 | * @return string|null |
||
| 4319 | */ |
||
| 4320 | protected function findFieldByQuery(string $column, string $displayCol) |
||
| 4367 | |||
| 4368 | /** |
||
| 4369 | * @param string $field |
||
| 4370 | * @param mixed $value |
||
| 4371 | * @param array $pdoMetaData |
||
| 4372 | * @return float|int |
||
| 4373 | * @throws Exception |
||
| 4374 | */ |
||
| 4375 | protected function fixTypeToSentinel(string $field, $value, array $pdoMetaData=[]) |
||
| 4431 | |||
| 4432 | /** |
||
| 4433 | * @param string $field |
||
| 4434 | * @param mixed $value |
||
| 4435 | * @param bool|false $permissive |
||
| 4436 | * @return float|int|null|string |
||
| 4437 | */ |
||
| 4438 | protected function fixType(string $field, $value, bool $permissive=false) |
||
| 4490 | |||
| 4491 | /** |
||
| 4492 | * @param stdClass $record |
||
| 4493 | * @param string $type |
||
| 4494 | * @return stdClass |
||
| 4495 | */ |
||
| 4496 | public function fixTypesToSentinel(stdClass $record, string $type='') : stdClass |
||
| 4523 | |||
| 4524 | /** |
||
| 4525 | * @param stdClass $record |
||
| 4526 | * @param string $type |
||
| 4527 | * @return stdClass |
||
| 4528 | * @throws Exception |
||
| 4529 | */ |
||
| 4530 | public function applyHandlers(stdClass $record, string $type='INSERT') : stdClass |
||
| 4558 | |||
| 4559 | |||
| 4560 | /** |
||
| 4561 | * @param stdClass $record |
||
| 4562 | * @param array $fields |
||
| 4563 | * @param string $type |
||
| 4564 | * @return bool |
||
| 4565 | */ |
||
| 4566 | protected function uniqueCheck(stdClass $record, array $fields, string $type) : bool |
||
| 4579 | |||
| 4580 | /** |
||
| 4581 | * @param string $field |
||
| 4582 | * @param mixed $value |
||
| 4583 | * @param string $type |
||
| 4584 | * @param stdClass $record |
||
| 4585 | * @return null |
||
| 4586 | * @throws Exception |
||
| 4587 | */ |
||
| 4588 | protected function applyHandler(string $field, $value, string $type='', stdClass $record=null) |
||
| 4612 | |||
| 4613 | /** |
||
| 4614 | * @param string $start |
||
| 4615 | * @param string $end |
||
| 4616 | * @param string $hayStack |
||
| 4617 | * @return mixed |
||
| 4618 | */ |
||
| 4619 | public static function between(string $start, string $end, string $hayStack) : string |
||
| 4623 | |||
| 4624 | /** |
||
| 4625 | * @param string $needle |
||
| 4626 | * @param string $hayStack |
||
| 4627 | * @param bool $returnOrigIfNeedleNotExists |
||
| 4628 | * @return mixed |
||
| 4629 | */ |
||
| 4630 | public static function before(string $needle, string $hayStack, bool $returnOrigIfNeedleNotExists=false) : string |
||
| 4640 | |||
| 4641 | /** |
||
| 4642 | * @param string $needle |
||
| 4643 | * @param string $hayStack |
||
| 4644 | * @param bool $returnOrigIfNeedleNotExists |
||
| 4645 | * @return string |
||
| 4646 | */ |
||
| 4647 | public static function after(string $needle, string $hayStack, bool $returnOrigIfNeedleNotExists=false) : string |
||
| 4656 | |||
| 4657 | /** |
||
| 4658 | * @return int |
||
| 4659 | */ |
||
| 4660 | public function getUserId() |
||
| 4664 | |||
| 4665 | /** |
||
| 4666 | * @param string $entity |
||
| 4667 | * @param int $id |
||
| 4668 | * @return int |
||
| 4669 | */ |
||
| 4670 | public function getMaskByResourceAndId(string $entity, int $id) : int |
||
| 4674 | |||
| 4675 | /** |
||
| 4676 | * @param string|int|null $time |
||
| 4677 | * @return string |
||
| 4678 | */ |
||
| 4679 | public static function date($time=null) : string |
||
| 4683 | |||
| 4684 | /** |
||
| 4685 | * @param string|int|null $time |
||
| 4686 | * @return string |
||
| 4687 | */ |
||
| 4688 | public static function dateTime($time=null) : string |
||
| 4692 | |||
| 4693 | /** |
||
| 4694 | * @param string|int|null $time |
||
| 4695 | * @return string |
||
| 4696 | */ |
||
| 4697 | public static function atom($time=null) : string |
||
| 4701 | |||
| 4702 | /** |
||
| 4703 | * @param string|int|null $time |
||
| 4704 | * @return int |
||
| 4705 | */ |
||
| 4706 | public static function getTime($time=null) : int |
||
| 4719 | |||
| 4720 | /** |
||
| 4721 | * @param int $id |
||
| 4722 | * @param int $cacheTtl |
||
| 4723 | * @return string |
||
| 4724 | */ |
||
| 4725 | public function getCodeById(int $id, int $cacheTtl=self::ONE_DAY) : string |
||
| 4733 | |||
| 4734 | /** |
||
| 4735 | * @param array $authUserRoles |
||
| 4736 | * @param int $authUserId |
||
| 4737 | * @return FluentPdoModel |
||
| 4738 | */ |
||
| 4739 | public function applyRoleFilter(array $authUserRoles, int $authUserId) : FluentPdoModel |
||
| 4743 | |||
| 4744 | /** |
||
| 4745 | * @param int $id |
||
| 4746 | * @param string[] $authUserRoles |
||
| 4747 | * @param int $authUserId |
||
| 4748 | * @return bool |
||
| 4749 | */ |
||
| 4750 | public function canAccessIdWithRole(int $id, array $authUserRoles, int $authUserId) : bool |
||
| 4754 | } |
||
| 4755 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.