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 string */ |
||
| 177 | protected $_tmp_table_prefix = 'tmp_'; |
||
| 178 | |||
| 179 | /** @var null|string */ |
||
| 180 | protected $_built_query = ''; |
||
| 181 | |||
| 182 | /** @var array */ |
||
| 183 | protected $_handlers = []; |
||
| 184 | |||
| 185 | /** @var bool User want to directly specify the fields */ |
||
| 186 | protected $_explicit_select_mode = false; |
||
| 187 | |||
| 188 | /** @var string[] */ |
||
| 189 | protected $_update_raw = []; |
||
| 190 | |||
| 191 | protected $_max_callback_failures = -1; |
||
| 192 | |||
| 193 | protected $_num_callback_failures = 0; |
||
| 194 | |||
| 195 | protected $_filter_on_fetch = false; |
||
| 196 | |||
| 197 | protected $_log_filter_changes = true; |
||
| 198 | |||
| 199 | protected $_include_count = false; |
||
| 200 | |||
| 201 | /** @var string */ |
||
| 202 | static protected $_model_namespace = ''; |
||
| 203 | |||
| 204 | /** @var bool */ |
||
| 205 | protected $_validation_exceptions = true; |
||
| 206 | |||
| 207 | /** @var array */ |
||
| 208 | protected $_paging_meta = []; |
||
| 209 | |||
| 210 | /** @var bool */ |
||
| 211 | protected $_soft_deletes = true; |
||
| 212 | |||
| 213 | |||
| 214 | /** @var bool */ |
||
| 215 | protected $_allow_meta_override = false; |
||
| 216 | |||
| 217 | /** @var bool */ |
||
| 218 | protected $_skip_meta_updates = false; |
||
| 219 | |||
| 220 | /** @var bool */ |
||
| 221 | protected $_add_update_alias = false; |
||
| 222 | |||
| 223 | /** @var int */ |
||
| 224 | protected $_default_max = 250; |
||
| 225 | |||
| 226 | /** @var array */ |
||
| 227 | protected $removeUnauthorisedFields = []; |
||
| 228 | |||
| 229 | protected $_can_generic_update = true; |
||
| 230 | protected $_can_generic_add = true; |
||
| 231 | protected $_can_generic_delete = true; |
||
| 232 | |||
| 233 | /** @var array */ |
||
| 234 | protected $row_meta_data = []; |
||
| 235 | |||
| 236 | protected $excluded_search_cols = []; |
||
| 237 | |||
| 238 | |||
| 239 | /** @var array */ |
||
| 240 | protected $globalRemoveUnauthorisedFields = [ |
||
| 241 | '/global_table_meta#view' => [ |
||
| 242 | self::CREATOR_ID_FIELD, |
||
| 243 | self::CREATOR_FIELD, |
||
| 244 | self::CREATED_TS_FIELD, |
||
| 245 | self::MODIFIER_ID_FIELD, |
||
| 246 | self::MODIFIER_FIELD, |
||
| 247 | self::MODIFIED_TS_FIELD, |
||
| 248 | self::STATUS_FIELD, |
||
| 249 | ], |
||
| 250 | ]; |
||
| 251 | |||
| 252 | |||
| 253 | /** |
||
| 254 | * @param AbstractPdo|null $connection |
||
| 255 | */ |
||
| 256 | public function __construct(AbstractPdo $connection=null) |
||
| 263 | |||
| 264 | public function init() |
||
| 266 | |||
| 267 | /** |
||
| 268 | * @return AbstractPdo |
||
| 269 | * @throws Exception |
||
| 270 | */ |
||
| 271 | public function getPdo() : AbstractPdo |
||
| 275 | |||
| 276 | /** |
||
| 277 | * @return LoggerInterface |
||
| 278 | */ |
||
| 279 | public function getLogger() : LoggerInterface |
||
| 283 | |||
| 284 | /** |
||
| 285 | * @return CacheInterface |
||
| 286 | */ |
||
| 287 | public function getCache() : CacheInterface |
||
| 291 | |||
| 292 | /** |
||
| 293 | * Define the working table and create a new instance |
||
| 294 | * |
||
| 295 | * @param string $tableName - Table name |
||
| 296 | * @param string $alias - The table alias name |
||
| 297 | * @param string $displayColumn |
||
| 298 | * @param string $primaryKeyName |
||
| 299 | * |
||
| 300 | * @return FluentPdoModel|$this |
||
| 301 | */ |
||
| 302 | public function table(string $tableName, string $alias='', string $displayColumn='', string $primaryKeyName='id') : FluentPdoModel |
||
| 310 | |||
| 311 | /** |
||
| 312 | * @param string $primaryKeyName |
||
| 313 | * @return FluentPdoModel|$this |
||
| 314 | */ |
||
| 315 | public function primaryKeyName(string $primaryKeyName) : FluentPdoModel |
||
| 321 | |||
| 322 | /** |
||
| 323 | * @param string $tableName |
||
| 324 | * |
||
| 325 | * @return FluentPdoModel|$this |
||
| 326 | */ |
||
| 327 | public function tableName(string $tableName) : FluentPdoModel |
||
| 333 | |||
| 334 | /** |
||
| 335 | * @param $explicitSelect |
||
| 336 | * |
||
| 337 | * @return FluentPdoModel|$this |
||
| 338 | */ |
||
| 339 | public function explicitSelectMode(bool $explicitSelect=true) : FluentPdoModel |
||
| 345 | |||
| 346 | /** |
||
| 347 | * @param bool $filterOnFetch |
||
| 348 | * |
||
| 349 | * @return FluentPdoModel|$this |
||
| 350 | */ |
||
| 351 | public function filterOnFetch(bool $filterOnFetch=true) : FluentPdoModel |
||
| 357 | |||
| 358 | /** |
||
| 359 | * @param bool $logFilterChanges |
||
| 360 | * |
||
| 361 | * @return FluentPdoModel|$this |
||
| 362 | */ |
||
| 363 | public function logFilterChanges(bool $logFilterChanges=true) : FluentPdoModel |
||
| 369 | |||
| 370 | /** |
||
| 371 | * Return the name of the table |
||
| 372 | * |
||
| 373 | * @return string |
||
| 374 | */ |
||
| 375 | public function getTableName() : string |
||
| 379 | |||
| 380 | /** |
||
| 381 | * @return string |
||
| 382 | */ |
||
| 383 | public function getDisplayColumn() : string |
||
| 387 | |||
| 388 | /** |
||
| 389 | * Set the display column |
||
| 390 | * |
||
| 391 | * @param string $column |
||
| 392 | * |
||
| 393 | * @return FluentPdoModel|$this |
||
| 394 | */ |
||
| 395 | public function displayColumn(string $column) : FluentPdoModel |
||
| 401 | /** |
||
| 402 | * Set the table alias |
||
| 403 | * |
||
| 404 | * @param string $alias |
||
| 405 | * |
||
| 406 | * @return FluentPdoModel|$this |
||
| 407 | */ |
||
| 408 | public function tableAlias(string $alias) : FluentPdoModel |
||
| 414 | |||
| 415 | /** |
||
| 416 | * @param int $cacheTtl |
||
| 417 | * @return FluentPdoModel|$this |
||
| 418 | * @throws Exception |
||
| 419 | */ |
||
| 420 | protected function _cacheTtl(int $cacheTtl) : FluentPdoModel |
||
| 431 | |||
| 432 | /** |
||
| 433 | * @return string |
||
| 434 | */ |
||
| 435 | public function getTableAlias() : string |
||
| 439 | |||
| 440 | /** |
||
| 441 | * @param array $associations |
||
| 442 | * |
||
| 443 | * @return FluentPdoModel|$this |
||
| 444 | */ |
||
| 445 | public function associations(array $associations) : FluentPdoModel |
||
| 451 | |||
| 452 | /** |
||
| 453 | * @param string $alias |
||
| 454 | * @param array $definition |
||
| 455 | * @return FluentPdoModel|$this |
||
| 456 | */ |
||
| 457 | public function setBelongsTo(string $alias, array $definition) : FluentPdoModel |
||
| 466 | |||
| 467 | /** |
||
| 468 | * @param $alias |
||
| 469 | * @param $displayField |
||
| 470 | * @return FluentPdoModel|$this |
||
| 471 | * @throws \Terah\Assert\AssertionFailedException |
||
| 472 | */ |
||
| 473 | public function setBelongsToDisplayField(string $alias, string $displayField) : FluentPdoModel |
||
| 483 | |||
| 484 | /** |
||
| 485 | * @param PDOStatement $stmt |
||
| 486 | * |
||
| 487 | * @param PDOStatement $stmt |
||
| 488 | * @param Closure $fnCallback |
||
| 489 | * @return bool|stdClass |
||
| 490 | */ |
||
| 491 | public function fetchRow(PDOStatement $stmt, Closure $fnCallback=null) |
||
| 514 | |||
| 515 | /** |
||
| 516 | * @param PDOStatement $stmt |
||
| 517 | * @param $record |
||
| 518 | * @return array |
||
| 519 | */ |
||
| 520 | protected function getColumnMeta(PDOStatement $stmt, $record) : array |
||
| 539 | |||
| 540 | /** |
||
| 541 | * @param array $schema |
||
| 542 | * |
||
| 543 | * @return FluentPdoModel|$this |
||
| 544 | */ |
||
| 545 | public function schema(array $schema) : FluentPdoModel |
||
| 551 | |||
| 552 | /** |
||
| 553 | * @param string|array $field |
||
| 554 | * @param $type |
||
| 555 | * @return FluentPdoModel|$this |
||
| 556 | */ |
||
| 557 | public function addSchema($field, string $type) : FluentPdoModel |
||
| 573 | |||
| 574 | /** |
||
| 575 | * @param $keysOnly |
||
| 576 | * @return array |
||
| 577 | */ |
||
| 578 | public function getColumns(bool $keysOnly=true) : array |
||
| 582 | |||
| 583 | /** |
||
| 584 | * Get the primary key name |
||
| 585 | * |
||
| 586 | * @return string |
||
| 587 | */ |
||
| 588 | public function getPrimaryKeyName() : string |
||
| 592 | |||
| 593 | /** |
||
| 594 | * @param string $query |
||
| 595 | * @param array $parameters |
||
| 596 | * |
||
| 597 | * @return bool |
||
| 598 | * @throws Exception |
||
| 599 | */ |
||
| 600 | public function execute(string $query, array $parameters=[]) : bool |
||
| 625 | |||
| 626 | /** |
||
| 627 | * @param string $query |
||
| 628 | * @param array $params |
||
| 629 | * @return FluentPdoModel|$this |
||
| 630 | */ |
||
| 631 | public function query(string $query, array $params=[]) : FluentPdoModel |
||
| 638 | |||
| 639 | /** |
||
| 640 | * @param string $sql |
||
| 641 | * @param array $params |
||
| 642 | * |
||
| 643 | * @return string |
||
| 644 | */ |
||
| 645 | public function buildQuery(string $sql, array $params=[]) : string |
||
| 673 | |||
| 674 | /** |
||
| 675 | * @param stdClass $record |
||
| 676 | * |
||
| 677 | * @return stdClass |
||
| 678 | */ |
||
| 679 | protected function _trimAndLowerCaseKeys(stdClass $record) : stdClass |
||
| 689 | |||
| 690 | /** |
||
| 691 | * Return the number of affected row by the last statement |
||
| 692 | * |
||
| 693 | * @return int |
||
| 694 | */ |
||
| 695 | public function rowCount() : int |
||
| 701 | |||
| 702 | /** |
||
| 703 | * @return PDOStatement |
||
| 704 | * @throws PDOException |
||
| 705 | */ |
||
| 706 | public function fetchStmt() |
||
| 715 | |||
| 716 | /** |
||
| 717 | * @return array |
||
| 718 | */ |
||
| 719 | public function fetchSqlQuery() : array |
||
| 729 | |||
| 730 | /** |
||
| 731 | * @param string $tableName |
||
| 732 | * @param bool $dropIfExists |
||
| 733 | * @param array $indexes |
||
| 734 | * @return boolean |
||
| 735 | * @throws Exception |
||
| 736 | */ |
||
| 737 | public function fetchIntoMemoryTable(string $tableName, bool $dropIfExists=true, array $indexes=[]) : bool |
||
| 759 | |||
| 760 | /** |
||
| 761 | * @param string $keyedOn |
||
| 762 | * @param int $cacheTtl |
||
| 763 | * @return stdClass[] |
||
| 764 | */ |
||
| 765 | public function fetch(string $keyedOn='', int $cacheTtl=self::CACHE_NO) : array |
||
| 803 | |||
| 804 | /** |
||
| 805 | * @return string |
||
| 806 | */ |
||
| 807 | protected function _parseWhereForPrimaryLookup() : string |
||
| 823 | |||
| 824 | /** |
||
| 825 | * @param string $cacheKey |
||
| 826 | * @param Closure $func |
||
| 827 | * @param int $cacheTtl - 0 for default ttl, -1 for no cache or int for custom ttl |
||
| 828 | * @return mixed |
||
| 829 | */ |
||
| 830 | protected function _cacheData(string $cacheKey, Closure $func, int $cacheTtl=self::CACHE_DEFAULT) |
||
| 868 | |||
| 869 | /** |
||
| 870 | * @param string $cacheKey |
||
| 871 | * @return bool |
||
| 872 | */ |
||
| 873 | public function clearCache(string $cacheKey) : bool |
||
| 877 | |||
| 878 | /** |
||
| 879 | * @param string $table |
||
| 880 | * @return bool |
||
| 881 | */ |
||
| 882 | public function clearCacheByTable(string $table='') : bool |
||
| 892 | |||
| 893 | /** |
||
| 894 | * @param Closure $fnCallback |
||
| 895 | * @return int |
||
| 896 | */ |
||
| 897 | public function fetchCallback(Closure $fnCallback) : int |
||
| 906 | |||
| 907 | /** |
||
| 908 | * @param Closure $fnCallback |
||
| 909 | * @param string $keyedOn |
||
| 910 | * @return array |
||
| 911 | */ |
||
| 912 | public function fetchObjectsByCallback(Closure $fnCallback, string $keyedOn='') : array |
||
| 929 | |||
| 930 | /** |
||
| 931 | * @param $numFailures |
||
| 932 | * @return FluentPdoModel|$this |
||
| 933 | */ |
||
| 934 | public function maxCallbackFailures(int $numFailures) : FluentPdoModel |
||
| 941 | |||
| 942 | /** |
||
| 943 | * @param PDOStatement $stmt |
||
| 944 | * @param Closure $fnCallback |
||
| 945 | * @param int $successCnt |
||
| 946 | * @return bool|null|stdClass |
||
| 947 | */ |
||
| 948 | protected function _tallySuccessCount(PDOStatement $stmt, Closure $fnCallback, int &$successCnt) |
||
| 979 | |||
| 980 | /** |
||
| 981 | * @return bool |
||
| 982 | */ |
||
| 983 | public function canGenericUpdate() : bool |
||
| 987 | |||
| 988 | /** |
||
| 989 | * @return bool |
||
| 990 | */ |
||
| 991 | public function canGenericAdd() : bool |
||
| 995 | |||
| 996 | /** |
||
| 997 | * @return bool |
||
| 998 | */ |
||
| 999 | public function canGenericDelete() : bool |
||
| 1003 | |||
| 1004 | /** |
||
| 1005 | * @param string $keyedOn |
||
| 1006 | * @param string $valueField |
||
| 1007 | * @param int $cacheTtl |
||
| 1008 | * @return mixed |
||
| 1009 | */ |
||
| 1010 | public function fetchList(string $keyedOn='', string $valueField='', int $cacheTtl=self::CACHE_NO) : array |
||
| 1072 | |||
| 1073 | /** |
||
| 1074 | * @param string $column |
||
| 1075 | * @param int $cacheTtl |
||
| 1076 | * @param bool|true $unique |
||
| 1077 | * @return array |
||
| 1078 | */ |
||
| 1079 | public function fetchColumn(string $column, int $cacheTtl=self::CACHE_NO, bool $unique=true) : array |
||
| 1088 | |||
| 1089 | /** |
||
| 1090 | * @param string $field |
||
| 1091 | * @param int $itemId |
||
| 1092 | * @param int $cacheTtl |
||
| 1093 | * @return mixed|null |
||
| 1094 | */ |
||
| 1095 | public function fetchField(string $field='', int $itemId=0, int $cacheTtl=self::CACHE_NO) |
||
| 1118 | |||
| 1119 | /** |
||
| 1120 | * @param string $field |
||
| 1121 | * @param int $itemId |
||
| 1122 | * @param int $cacheTtl |
||
| 1123 | * @return string |
||
| 1124 | */ |
||
| 1125 | public function fetchStr(string $field='', $itemId=0, int $cacheTtl=self::CACHE_NO) : string |
||
| 1129 | |||
| 1130 | /** |
||
| 1131 | * @param int $cacheTtl |
||
| 1132 | * @return int |
||
| 1133 | */ |
||
| 1134 | public function fetchId(int $cacheTtl=self::CACHE_NO) : int |
||
| 1138 | |||
| 1139 | /** |
||
| 1140 | * @param string $field |
||
| 1141 | * @param int $itemId |
||
| 1142 | * @param int $cacheTtl |
||
| 1143 | * @return int |
||
| 1144 | */ |
||
| 1145 | public function fetchInt(string $field='', int $itemId=0, int $cacheTtl=self::CACHE_NO) : int |
||
| 1149 | |||
| 1150 | /** |
||
| 1151 | * @param string $field |
||
| 1152 | * @param int $itemId |
||
| 1153 | * @param int $cacheTtl |
||
| 1154 | * @return float |
||
| 1155 | */ |
||
| 1156 | public function fetchFloat(string $field='', int $itemId=0, int $cacheTtl=self::CACHE_NO) : float |
||
| 1160 | |||
| 1161 | /** |
||
| 1162 | * @param string $field |
||
| 1163 | * @param int $itemId |
||
| 1164 | * @param int $cacheTtl |
||
| 1165 | * @return bool |
||
| 1166 | */ |
||
| 1167 | public function fetchBool(string $field='', int $itemId=0, int $cacheTtl=self::CACHE_NO) : bool |
||
| 1171 | |||
| 1172 | /** |
||
| 1173 | * @param int|null $id |
||
| 1174 | * @param int $cacheTtl |
||
| 1175 | * @return stdClass|bool |
||
| 1176 | */ |
||
| 1177 | public function fetchOne(int $id=0, int $cacheTtl=self::CACHE_NO) |
||
| 1188 | |||
| 1189 | /** |
||
| 1190 | * @param int|null $id |
||
| 1191 | * @param int $cacheTtl |
||
| 1192 | * @return boolean |
||
| 1193 | */ |
||
| 1194 | public function fetchExists(int $id=0, int $cacheTtl=self::CACHE_NO) : bool |
||
| 1204 | |||
| 1205 | /*------------------------------------------------------------------------------ |
||
| 1206 | Fluent Query Builder |
||
| 1207 | *-----------------------------------------------------------------------------*/ |
||
| 1208 | |||
| 1209 | /** |
||
| 1210 | * Create the select clause |
||
| 1211 | * |
||
| 1212 | * @param mixed $columns - the column to select. Can be string or array of fields |
||
| 1213 | * @param string $alias - an alias to the column |
||
| 1214 | * @param boolean $explicitSelect |
||
| 1215 | * @return FluentPdoModel|$this |
||
| 1216 | */ |
||
| 1217 | public function select($columns='*', string $alias='', bool $explicitSelect=true) : FluentPdoModel |
||
| 1259 | |||
| 1260 | /** |
||
| 1261 | * @param string $select |
||
| 1262 | * @return FluentPdoModel|$this |
||
| 1263 | */ |
||
| 1264 | public function selectRaw(string $select) : FluentPdoModel |
||
| 1270 | |||
| 1271 | /** |
||
| 1272 | * @param bool $logQueries |
||
| 1273 | * |
||
| 1274 | * @return FluentPdoModel|$this |
||
| 1275 | */ |
||
| 1276 | public function logQueries(bool $logQueries=true) : FluentPdoModel |
||
| 1282 | |||
| 1283 | /** |
||
| 1284 | * @param bool $includeCnt |
||
| 1285 | * |
||
| 1286 | * @return FluentPdoModel|$this |
||
| 1287 | */ |
||
| 1288 | public function includeCount(bool $includeCnt=true) : FluentPdoModel |
||
| 1294 | |||
| 1295 | /** |
||
| 1296 | * @param bool $distinct |
||
| 1297 | * |
||
| 1298 | * @return FluentPdoModel|$this |
||
| 1299 | */ |
||
| 1300 | public function distinct(bool $distinct=true) : FluentPdoModel |
||
| 1306 | |||
| 1307 | /** |
||
| 1308 | * @param array $fields |
||
| 1309 | * @return FluentPdoModel|$this |
||
| 1310 | */ |
||
| 1311 | public function withBelongsTo(array $fields=[]) : FluentPdoModel |
||
| 1324 | |||
| 1325 | /** |
||
| 1326 | * @param string $alias |
||
| 1327 | * @param bool $addSelectField |
||
| 1328 | * @return FluentPdoModel |
||
| 1329 | */ |
||
| 1330 | public function autoInnerJoin(string $alias, bool $addSelectField=true) : FluentPdoModel |
||
| 1334 | |||
| 1335 | /** |
||
| 1336 | * @param string $alias |
||
| 1337 | * @param string $type |
||
| 1338 | * @param bool $addSelectField |
||
| 1339 | * @return FluentPdoModel|$this |
||
| 1340 | */ |
||
| 1341 | public function autoJoin(string $alias, string $type=self::LEFT_JOIN, bool $addSelectField=true) : FluentPdoModel |
||
| 1370 | |||
| 1371 | /** |
||
| 1372 | * @param array $conditions |
||
| 1373 | * @return FluentPdoModel |
||
| 1374 | */ |
||
| 1375 | public function whereArr(array $conditions) : FluentPdoModel |
||
| 1384 | /** |
||
| 1385 | * Add where condition, more calls appends with AND |
||
| 1386 | * |
||
| 1387 | * @param string $condition possibly containing ? or :name |
||
| 1388 | * @param mixed $parameters accepted by PDOStatement::execute or a scalar value |
||
| 1389 | * @param mixed ... |
||
| 1390 | * @return FluentPdoModel|$this |
||
| 1391 | */ |
||
| 1392 | public function where($condition, $parameters=[]) : FluentPdoModel |
||
| 1441 | |||
| 1442 | /** |
||
| 1443 | * Create an AND operator in the where clause |
||
| 1444 | * |
||
| 1445 | * @return FluentPdoModel|$this |
||
| 1446 | */ |
||
| 1447 | public function _and() : FluentPdoModel |
||
| 1461 | |||
| 1462 | |||
| 1463 | /** |
||
| 1464 | * Create an OR operator in the where clause |
||
| 1465 | * |
||
| 1466 | * @return FluentPdoModel|$this |
||
| 1467 | */ |
||
| 1468 | public function _or() : FluentPdoModel |
||
| 1482 | |||
| 1483 | /** |
||
| 1484 | * To group multiple where clauses together. |
||
| 1485 | * |
||
| 1486 | * @return FluentPdoModel|$this |
||
| 1487 | */ |
||
| 1488 | public function wrap() : FluentPdoModel |
||
| 1498 | |||
| 1499 | /** |
||
| 1500 | * Where Primary key |
||
| 1501 | * |
||
| 1502 | * @param int $id |
||
| 1503 | * @param bool $addAlias |
||
| 1504 | * |
||
| 1505 | * @return FluentPdoModel|$this |
||
| 1506 | */ |
||
| 1507 | public function wherePk(int $id, bool $addAlias=true) : FluentPdoModel |
||
| 1513 | |||
| 1514 | /** |
||
| 1515 | * @param string $name |
||
| 1516 | * @param bool $addAlias |
||
| 1517 | * @return FluentPdoModel |
||
| 1518 | */ |
||
| 1519 | public function whereDisplayName(string $name, bool $addAlias=true) : FluentPdoModel |
||
| 1525 | |||
| 1526 | /** |
||
| 1527 | * WHERE $columnName != $value |
||
| 1528 | * |
||
| 1529 | * @param string $columnName |
||
| 1530 | * @param mixed $value |
||
| 1531 | * @return FluentPdoModel|$this |
||
| 1532 | */ |
||
| 1533 | public function whereNot(string $columnName, $value) : FluentPdoModel |
||
| 1537 | /** |
||
| 1538 | * WHERE $columnName != $value |
||
| 1539 | * |
||
| 1540 | * @param string $columnName |
||
| 1541 | * @param mixed $value |
||
| 1542 | * @return FluentPdoModel|$this |
||
| 1543 | */ |
||
| 1544 | public function whereCoercedNot(string $columnName, $value) : FluentPdoModel |
||
| 1548 | |||
| 1549 | /** |
||
| 1550 | * WHERE $columnName LIKE $value |
||
| 1551 | * |
||
| 1552 | * @param string $columnName |
||
| 1553 | * @param mixed $value |
||
| 1554 | * @return FluentPdoModel|$this |
||
| 1555 | */ |
||
| 1556 | public function whereLike(string $columnName, $value) : FluentPdoModel |
||
| 1560 | |||
| 1561 | /** |
||
| 1562 | * @param string $columnName |
||
| 1563 | * @param mixed $value1 |
||
| 1564 | * @param mixed $value2 |
||
| 1565 | * @return FluentPdoModel|$this |
||
| 1566 | */ |
||
| 1567 | public function whereBetween(string $columnName, $value1, $value2) : FluentPdoModel |
||
| 1574 | |||
| 1575 | /** |
||
| 1576 | * @param string $columnName |
||
| 1577 | * @param mixed $value1 |
||
| 1578 | * @param mixed $value2 |
||
| 1579 | * @return FluentPdoModel|$this |
||
| 1580 | */ |
||
| 1581 | public function whereNotBetween(string $columnName, $value1, $value2) : FluentPdoModel |
||
| 1588 | |||
| 1589 | /** |
||
| 1590 | * @param string $columnName |
||
| 1591 | * @param string $regex |
||
| 1592 | * @return FluentPdoModel|$this |
||
| 1593 | */ |
||
| 1594 | public function whereRegex(string $columnName, string $regex) : FluentPdoModel |
||
| 1598 | |||
| 1599 | /** |
||
| 1600 | * @param string $columnName |
||
| 1601 | * @param string $regex |
||
| 1602 | * @return FluentPdoModel|$this |
||
| 1603 | */ |
||
| 1604 | public function whereNotRegex(string $columnName, string $regex) : FluentPdoModel |
||
| 1608 | |||
| 1609 | /** |
||
| 1610 | * WHERE $columnName NOT LIKE $value |
||
| 1611 | * |
||
| 1612 | * @param string $columnName |
||
| 1613 | * @param string $value |
||
| 1614 | * @return FluentPdoModel|$this |
||
| 1615 | */ |
||
| 1616 | public function whereNotLike(string $columnName, string $value) : FluentPdoModel |
||
| 1620 | |||
| 1621 | /** |
||
| 1622 | * WHERE $columnName > $value |
||
| 1623 | * |
||
| 1624 | * @param string $columnName |
||
| 1625 | * @param mixed $value |
||
| 1626 | * @return FluentPdoModel|$this |
||
| 1627 | */ |
||
| 1628 | public function whereGt(string $columnName, $value) : FluentPdoModel |
||
| 1632 | |||
| 1633 | /** |
||
| 1634 | * WHERE $columnName >= $value |
||
| 1635 | * |
||
| 1636 | * @param string $columnName |
||
| 1637 | * @param mixed $value |
||
| 1638 | * @return FluentPdoModel|$this |
||
| 1639 | */ |
||
| 1640 | public function whereGte(string $columnName, $value) : FluentPdoModel |
||
| 1644 | |||
| 1645 | /** |
||
| 1646 | * WHERE $columnName < $value |
||
| 1647 | * |
||
| 1648 | * @param string $columnName |
||
| 1649 | * @param mixed $value |
||
| 1650 | * @return FluentPdoModel|$this |
||
| 1651 | */ |
||
| 1652 | public function whereLt(string $columnName, $value) : FluentPdoModel |
||
| 1656 | |||
| 1657 | /** |
||
| 1658 | * WHERE $columnName <= $value |
||
| 1659 | * |
||
| 1660 | * @param string $columnName |
||
| 1661 | * @param mixed $value |
||
| 1662 | * @return FluentPdoModel|$this |
||
| 1663 | */ |
||
| 1664 | public function whereLte(string $columnName, $value) : FluentPdoModel |
||
| 1668 | |||
| 1669 | /** |
||
| 1670 | * WHERE $columnName IN (?,?,?,...) |
||
| 1671 | * |
||
| 1672 | * @param string $columnName |
||
| 1673 | * @param array $values |
||
| 1674 | * @return FluentPdoModel|$this |
||
| 1675 | */ |
||
| 1676 | public function whereIn(string $columnName, array $values) : FluentPdoModel |
||
| 1680 | |||
| 1681 | /** |
||
| 1682 | * WHERE $columnName NOT IN (?,?,?,...) |
||
| 1683 | * |
||
| 1684 | * @param string $columnName |
||
| 1685 | * @param array $values |
||
| 1686 | * @return FluentPdoModel|$this |
||
| 1687 | */ |
||
| 1688 | public function whereNotIn(string $columnName, array $values) : FluentPdoModel |
||
| 1694 | |||
| 1695 | /** |
||
| 1696 | * WHERE $columnName IS NULL |
||
| 1697 | * |
||
| 1698 | * @param string $columnName |
||
| 1699 | * @return FluentPdoModel|$this |
||
| 1700 | */ |
||
| 1701 | public function whereNull(string $columnName) : FluentPdoModel |
||
| 1705 | |||
| 1706 | /** |
||
| 1707 | * WHERE $columnName IS NOT NULL |
||
| 1708 | * |
||
| 1709 | * @param string $columnName |
||
| 1710 | * @return FluentPdoModel|$this |
||
| 1711 | */ |
||
| 1712 | public function whereNotNull(string $columnName) : FluentPdoModel |
||
| 1716 | |||
| 1717 | /** |
||
| 1718 | * @param string $statement |
||
| 1719 | * @param string $operator |
||
| 1720 | * @return FluentPdoModel|$this |
||
| 1721 | */ |
||
| 1722 | public function having(string $statement, string $operator=self::OPERATOR_AND) : FluentPdoModel |
||
| 1731 | |||
| 1732 | /** |
||
| 1733 | * ORDER BY $columnName (ASC | DESC) |
||
| 1734 | * |
||
| 1735 | * @param string $columnName - The name of the column or an expression |
||
| 1736 | * @param string $ordering (DESC | ASC) |
||
| 1737 | * @return FluentPdoModel|$this |
||
| 1738 | */ |
||
| 1739 | public function orderBy(string $columnName='', string $ordering='ASC') : FluentPdoModel |
||
| 1753 | |||
| 1754 | /** |
||
| 1755 | * GROUP BY $columnName |
||
| 1756 | * |
||
| 1757 | * @param string $columnName |
||
| 1758 | * @return FluentPdoModel|$this |
||
| 1759 | */ |
||
| 1760 | public function groupBy(string $columnName) : FluentPdoModel |
||
| 1770 | |||
| 1771 | |||
| 1772 | /** |
||
| 1773 | * LIMIT $limit |
||
| 1774 | * |
||
| 1775 | * @param int $limit |
||
| 1776 | * @param int|null $offset |
||
| 1777 | * @return FluentPdoModel|$this |
||
| 1778 | */ |
||
| 1779 | public function limit(int $limit, int $offset=0) : FluentPdoModel |
||
| 1788 | |||
| 1789 | /** |
||
| 1790 | * Return the limit |
||
| 1791 | * |
||
| 1792 | * @return integer |
||
| 1793 | */ |
||
| 1794 | public function getLimit() : int |
||
| 1798 | |||
| 1799 | /** |
||
| 1800 | * OFFSET $offset |
||
| 1801 | * |
||
| 1802 | * @param int $offset |
||
| 1803 | * @return FluentPdoModel|$this |
||
| 1804 | */ |
||
| 1805 | public function offset(int $offset) : FluentPdoModel |
||
| 1811 | |||
| 1812 | /** |
||
| 1813 | * Return the offset |
||
| 1814 | * |
||
| 1815 | * @return integer |
||
| 1816 | */ |
||
| 1817 | public function getOffset() : int |
||
| 1821 | |||
| 1822 | /** |
||
| 1823 | * Build a join |
||
| 1824 | * |
||
| 1825 | * @param string $table - The table name |
||
| 1826 | * @param string $constraint -> id = profile.user_id |
||
| 1827 | * @param string $tableAlias - The alias of the table name |
||
| 1828 | * @param string $joinOperator - LEFT | INNER | etc... |
||
| 1829 | * @return FluentPdoModel|$this |
||
| 1830 | */ |
||
| 1831 | public function join(string $table, string $constraint='', string $tableAlias='', string $joinOperator='') : FluentPdoModel |
||
| 1850 | |||
| 1851 | /** |
||
| 1852 | * Create a left join |
||
| 1853 | * |
||
| 1854 | * @param string $table |
||
| 1855 | * @param string $constraint |
||
| 1856 | * @param string $tableAlias |
||
| 1857 | * @return FluentPdoModel|$this |
||
| 1858 | */ |
||
| 1859 | public function leftJoin(string $table, string $constraint, string $tableAlias='') : FluentPdoModel |
||
| 1863 | |||
| 1864 | |||
| 1865 | /** |
||
| 1866 | * Return the build select query |
||
| 1867 | * |
||
| 1868 | * @return string |
||
| 1869 | */ |
||
| 1870 | public function getSelectQuery() : string |
||
| 1913 | |||
| 1914 | /** |
||
| 1915 | * @param string $field |
||
| 1916 | * @param string $column |
||
| 1917 | * @return string |
||
| 1918 | */ |
||
| 1919 | public function getFieldComment(string $field, string $column) : string |
||
| 1923 | |||
| 1924 | /** |
||
| 1925 | * Prepare columns to include the table alias name |
||
| 1926 | * @param array $columns |
||
| 1927 | * @return array |
||
| 1928 | */ |
||
| 1929 | protected function _prepareColumns(array $columns) : array |
||
| 1959 | |||
| 1960 | /** |
||
| 1961 | * Build the WHERE clause(s) |
||
| 1962 | * |
||
| 1963 | * @param bool $purgeAliases |
||
| 1964 | * @return string |
||
| 1965 | */ |
||
| 1966 | protected function _getWhereString(bool $purgeAliases=false) : string |
||
| 1999 | |||
| 2000 | /** |
||
| 2001 | * Return the HAVING clause |
||
| 2002 | * |
||
| 2003 | * @return string |
||
| 2004 | */ |
||
| 2005 | protected function _getHavingString() : string |
||
| 2024 | |||
| 2025 | /** |
||
| 2026 | * Return the values to be bound for where |
||
| 2027 | * |
||
| 2028 | * @param bool $purgeAliases |
||
| 2029 | * @return array |
||
| 2030 | */ |
||
| 2031 | protected function _getWhereParameters(bool $purgeAliases=false) : array |
||
| 2037 | |||
| 2038 | /** |
||
| 2039 | * @param array $record |
||
| 2040 | * @return stdClass |
||
| 2041 | */ |
||
| 2042 | public function insertArr(array $record) : stdClass |
||
| 2046 | |||
| 2047 | /** |
||
| 2048 | * Insert new rows |
||
| 2049 | * $records can be a stdClass or an array of stdClass to add a bulk insert |
||
| 2050 | * If a single row is inserted, it will return it's row instance |
||
| 2051 | * |
||
| 2052 | * @param stdClass $record |
||
| 2053 | * @return stdClass |
||
| 2054 | * @throws Exception |
||
| 2055 | */ |
||
| 2056 | public function insert(stdClass $record) : stdClass |
||
| 2079 | |||
| 2080 | /** |
||
| 2081 | * @param string $name |
||
| 2082 | * @return int |
||
| 2083 | */ |
||
| 2084 | public function getLastInsertId(string $name='') : int |
||
| 2088 | |||
| 2089 | /** |
||
| 2090 | * @param stdClass[] $records |
||
| 2091 | * @return stdClass[] |
||
| 2092 | */ |
||
| 2093 | public function insertSqlQuery(array $records) : array |
||
| 2113 | |||
| 2114 | /** |
||
| 2115 | * @param $data |
||
| 2116 | * @param array $matchOn |
||
| 2117 | * @param bool $returnObj |
||
| 2118 | * @return bool|int|stdClass |
||
| 2119 | */ |
||
| 2120 | public function upsert($data, array $matchOn=[], $returnObj=false) |
||
| 2142 | |||
| 2143 | /** |
||
| 2144 | * @param stdClass $object |
||
| 2145 | * @param array $matchOn |
||
| 2146 | * @param bool $returnObj |
||
| 2147 | * @return bool|int|stdClass |
||
| 2148 | */ |
||
| 2149 | public function upsertOne(stdClass $object, array $matchOn=[], $returnObj=false) |
||
| 2189 | |||
| 2190 | /** |
||
| 2191 | * @param array $data |
||
| 2192 | * @param array $matchOn |
||
| 2193 | * @param bool|false $returnObj |
||
| 2194 | * @return bool|int|stdClass |
||
| 2195 | */ |
||
| 2196 | public function upsertArr(array $data, array $matchOn=[], bool $returnObj=false) |
||
| 2200 | |||
| 2201 | /** |
||
| 2202 | * Update entries |
||
| 2203 | * Use the query builder to create the where clause |
||
| 2204 | * |
||
| 2205 | * @param stdClass $record |
||
| 2206 | * @param bool $updateAll |
||
| 2207 | * @return int |
||
| 2208 | * @throws Exception |
||
| 2209 | */ |
||
| 2210 | public function update(stdClass $record, $updateAll=false) : int |
||
| 2233 | |||
| 2234 | /** |
||
| 2235 | * @param array $record |
||
| 2236 | * @param bool|false $updateAll |
||
| 2237 | * @return int |
||
| 2238 | * @throws Exception |
||
| 2239 | */ |
||
| 2240 | public function updateArr(array $record, $updateAll=false) : int |
||
| 2244 | |||
| 2245 | |||
| 2246 | /** |
||
| 2247 | * @param string $field |
||
| 2248 | * @param mixed $value |
||
| 2249 | * @param int $id |
||
| 2250 | * @param bool|false $updateAll |
||
| 2251 | * @return int |
||
| 2252 | * @throws Exception |
||
| 2253 | */ |
||
| 2254 | public function updateField(string $field, $value, int $id=0, bool $updateAll=false) : int |
||
| 2263 | |||
| 2264 | /** |
||
| 2265 | * @param stdClass $record |
||
| 2266 | * @return bool|int |
||
| 2267 | * @throws Exception |
||
| 2268 | */ |
||
| 2269 | public function updateChanged(stdClass $record) : int |
||
| 2283 | |||
| 2284 | /** |
||
| 2285 | * @param string $expression |
||
| 2286 | * @param array $params |
||
| 2287 | * @return FluentPdoModel|$this |
||
| 2288 | */ |
||
| 2289 | public function updateByExpression(string $expression, array $params) : FluentPdoModel |
||
| 2295 | |||
| 2296 | /** |
||
| 2297 | * @param array $data |
||
| 2298 | * @return int |
||
| 2299 | * @throws Exception |
||
| 2300 | */ |
||
| 2301 | public function rawUpdate(array $data=[]) : int |
||
| 2310 | |||
| 2311 | /** |
||
| 2312 | * @param stdClass $record |
||
| 2313 | * @return array |
||
| 2314 | */ |
||
| 2315 | public function updateSqlQuery(stdClass $record) : array |
||
| 2325 | |||
| 2326 | /** |
||
| 2327 | * @param $record |
||
| 2328 | * @return array |
||
| 2329 | */ |
||
| 2330 | protected function updateSql(array $record) : array |
||
| 2363 | |||
| 2364 | /** |
||
| 2365 | * @param bool $deleteAll |
||
| 2366 | * @param bool $force |
||
| 2367 | * @return int |
||
| 2368 | * @throws Exception |
||
| 2369 | */ |
||
| 2370 | public function delete(bool $deleteAll=false, bool $force=false) : int |
||
| 2386 | |||
| 2387 | /** |
||
| 2388 | * @return bool |
||
| 2389 | */ |
||
| 2390 | public function isSoftDelete() : bool |
||
| 2394 | |||
| 2395 | /** |
||
| 2396 | * @param bool|false $force |
||
| 2397 | * @return FluentPdoModel|$this |
||
| 2398 | * @throws Exception |
||
| 2399 | */ |
||
| 2400 | public function truncate(bool $force=false) : FluentPdoModel |
||
| 2414 | |||
| 2415 | /** |
||
| 2416 | * @return array |
||
| 2417 | */ |
||
| 2418 | public function deleteSqlQuery() : array |
||
| 2430 | |||
| 2431 | |||
| 2432 | /** |
||
| 2433 | * Return the aggregate count of column |
||
| 2434 | * |
||
| 2435 | * @param string $column |
||
| 2436 | * @param int $cacheTtl |
||
| 2437 | * @return float |
||
| 2438 | */ |
||
| 2439 | public function count(string $column='*', int $cacheTtl=self::CACHE_NO) : float |
||
| 2459 | |||
| 2460 | |||
| 2461 | /** |
||
| 2462 | * Return the aggregate max count of column |
||
| 2463 | * |
||
| 2464 | * @param string $column |
||
| 2465 | * @param int $cacheTtl |
||
| 2466 | * @return int|float|string|null |
||
| 2467 | */ |
||
| 2468 | public function max(string $column, int $cacheTtl=self::CACHE_NO) |
||
| 2474 | |||
| 2475 | |||
| 2476 | /** |
||
| 2477 | * Return the aggregate min count of column |
||
| 2478 | * |
||
| 2479 | * @param string $column |
||
| 2480 | * @param int $cacheTtl |
||
| 2481 | * @return int|float|string|null |
||
| 2482 | */ |
||
| 2483 | public function min(string $column, int $cacheTtl=self::CACHE_NO) |
||
| 2489 | |||
| 2490 | /** |
||
| 2491 | * Return the aggregate sum count of column |
||
| 2492 | * |
||
| 2493 | * @param string $column |
||
| 2494 | * @param int $cacheTtl |
||
| 2495 | * @return int|float|string|null |
||
| 2496 | */ |
||
| 2497 | public function sum(string $column, int $cacheTtl=self::CACHE_NO) |
||
| 2503 | |||
| 2504 | /** |
||
| 2505 | * Return the aggregate average count of column |
||
| 2506 | * |
||
| 2507 | * @param string $column |
||
| 2508 | * @param int $cacheTtl |
||
| 2509 | * @return int|float|string|null |
||
| 2510 | */ |
||
| 2511 | public function avg(string $column, int $cacheTtl=self::CACHE_NO) |
||
| 2517 | |||
| 2518 | /*******************************************************************************/ |
||
| 2519 | // Utilities methods |
||
| 2520 | |||
| 2521 | /** |
||
| 2522 | * Reset fields |
||
| 2523 | * |
||
| 2524 | * @return FluentPdoModel|$this |
||
| 2525 | */ |
||
| 2526 | public function reset() : FluentPdoModel |
||
| 2554 | |||
| 2555 | |||
| 2556 | /** |
||
| 2557 | * @return FluentPdoModel|$this |
||
| 2558 | */ |
||
| 2559 | public function removeUnauthorisedFields() : FluentPdoModel |
||
| 2563 | |||
| 2564 | /** |
||
| 2565 | * @return Closure[] |
||
| 2566 | */ |
||
| 2567 | protected function _getFieldHandlers() : array |
||
| 2635 | |||
| 2636 | /** |
||
| 2637 | * @return bool |
||
| 2638 | */ |
||
| 2639 | public function begin() : bool |
||
| 2653 | |||
| 2654 | /** |
||
| 2655 | * @return bool |
||
| 2656 | */ |
||
| 2657 | public function commit() : bool |
||
| 2675 | |||
| 2676 | /** |
||
| 2677 | * @return bool |
||
| 2678 | */ |
||
| 2679 | public function rollback() : bool |
||
| 2693 | |||
| 2694 | /** |
||
| 2695 | * @param stdClass $record |
||
| 2696 | * @param string $type |
||
| 2697 | * @return stdClass |
||
| 2698 | */ |
||
| 2699 | public function applyGlobalModifiers(stdClass $record, string $type) : stdClass |
||
| 2712 | |||
| 2713 | /** |
||
| 2714 | * @param stdClass $record |
||
| 2715 | * @param string $type |
||
| 2716 | * @return stdClass |
||
| 2717 | */ |
||
| 2718 | public function removeUnneededFields(stdClass $record, string $type) : stdClass |
||
| 2747 | |||
| 2748 | |||
| 2749 | /** |
||
| 2750 | * @param array $ids |
||
| 2751 | * @param array $values |
||
| 2752 | * @param int $batch |
||
| 2753 | * @return bool |
||
| 2754 | */ |
||
| 2755 | public function setById(array $ids, array $values, int $batch=1000) : bool |
||
| 2771 | |||
| 2772 | |||
| 2773 | /** |
||
| 2774 | * @param string $displayColumnValue |
||
| 2775 | * @return int |
||
| 2776 | */ |
||
| 2777 | public function resolveId(string $displayColumnValue) : int |
||
| 2788 | |||
| 2789 | /** |
||
| 2790 | * @param int $resourceId |
||
| 2791 | * @param array $query |
||
| 2792 | * @param array $extraFields |
||
| 2793 | * @param int $cacheTtl |
||
| 2794 | * @return array |
||
| 2795 | */ |
||
| 2796 | public function fetchApiResource(int $resourceId, array $query=[], array $extraFields=[], int $cacheTtl=self::CACHE_NO) : array |
||
| 2809 | |||
| 2810 | /** |
||
| 2811 | * @param array $query |
||
| 2812 | * @param array $extraFields |
||
| 2813 | * @param int $cacheTtl |
||
| 2814 | * @param string $permEntity |
||
| 2815 | * @return array |
||
| 2816 | */ |
||
| 2817 | public function fetchApiResources(array $query=[], array $extraFields=[], int $cacheTtl=self::CACHE_NO, string $permEntity='') : array |
||
| 2839 | |||
| 2840 | |||
| 2841 | /** |
||
| 2842 | * @return array |
||
| 2843 | */ |
||
| 2844 | public function getSearchableAssociations() : array |
||
| 2851 | |||
| 2852 | /** |
||
| 2853 | * @param array $fields |
||
| 2854 | */ |
||
| 2855 | public function removeUnrequestedFields(array $fields) |
||
| 2866 | |||
| 2867 | /** |
||
| 2868 | * @param array $removeFields |
||
| 2869 | */ |
||
| 2870 | public function removeFields(array $removeFields=[]) |
||
| 2895 | |||
| 2896 | /** |
||
| 2897 | * @return FluentPdoModel|$this |
||
| 2898 | */ |
||
| 2899 | public function defaultFilters() : FluentPdoModel |
||
| 2903 | |||
| 2904 | /** |
||
| 2905 | * @param bool $allow |
||
| 2906 | * |
||
| 2907 | * @return FluentPdoModel|$this |
||
| 2908 | */ |
||
| 2909 | public function allowMetaColumnOverride(bool $allow=false) : FluentPdoModel |
||
| 2915 | |||
| 2916 | /** |
||
| 2917 | * @param bool $skip |
||
| 2918 | * |
||
| 2919 | * @return FluentPdoModel|$this |
||
| 2920 | */ |
||
| 2921 | public function skipMetaUpdates(bool $skip=true) : FluentPdoModel |
||
| 2927 | |||
| 2928 | /** |
||
| 2929 | * @param bool $add |
||
| 2930 | * |
||
| 2931 | * @return FluentPdoModel|$this |
||
| 2932 | */ |
||
| 2933 | public function addUpdateAlias(bool $add=true) : FluentPdoModel |
||
| 2939 | |||
| 2940 | /** |
||
| 2941 | * @param stdClass $record |
||
| 2942 | * @return stdClass |
||
| 2943 | */ |
||
| 2944 | public function onFetch(stdClass $record) : stdClass |
||
| 2956 | |||
| 2957 | /** |
||
| 2958 | * @param $value |
||
| 2959 | * @return string |
||
| 2960 | */ |
||
| 2961 | public function gzEncodeData(string $value) : string |
||
| 2970 | |||
| 2971 | /** |
||
| 2972 | * @param $value |
||
| 2973 | * @return mixed|string |
||
| 2974 | */ |
||
| 2975 | public function gzDecodeData(string $value) : string |
||
| 2985 | |||
| 2986 | /** |
||
| 2987 | * @param $value |
||
| 2988 | * @return bool |
||
| 2989 | */ |
||
| 2990 | protected function _hasGzipPrefix(string $value) : bool |
||
| 2994 | |||
| 2995 | /** |
||
| 2996 | * @param stdClass $record |
||
| 2997 | * @return stdClass |
||
| 2998 | */ |
||
| 2999 | public function fixTimestamps(stdClass $record) : stdClass |
||
| 3011 | |||
| 3012 | /** |
||
| 3013 | * @param int $max |
||
| 3014 | * @return FluentPdoModel|$this |
||
| 3015 | */ |
||
| 3016 | public function setMaxRecords(int $max) : FluentPdoModel |
||
| 3023 | |||
| 3024 | |||
| 3025 | /** |
||
| 3026 | * @param stdClass $record |
||
| 3027 | * @param string $type |
||
| 3028 | * @return stdClass |
||
| 3029 | */ |
||
| 3030 | public function afterSave(stdClass $record, string $type) : stdClass |
||
| 3051 | |||
| 3052 | /** |
||
| 3053 | * @param stdClass $record |
||
| 3054 | * @param string $type |
||
| 3055 | * @return stdClass |
||
| 3056 | */ |
||
| 3057 | public function addDefaultFields(stdClass $record, string $type) : stdClass |
||
| 3090 | |||
| 3091 | |||
| 3092 | /** |
||
| 3093 | * @return bool |
||
| 3094 | */ |
||
| 3095 | public function createTable() : bool |
||
| 3099 | |||
| 3100 | /** |
||
| 3101 | * @return bool |
||
| 3102 | */ |
||
| 3103 | public function dropTable() : bool |
||
| 3107 | |||
| 3108 | protected function _compileHandlers() |
||
| 3117 | |||
| 3118 | /** |
||
| 3119 | * @param string $viewName |
||
| 3120 | * @param int $cacheTtl |
||
| 3121 | * @return array |
||
| 3122 | */ |
||
| 3123 | public function getViewColumns($viewName, $cacheTtl=self::CACHE_NO) |
||
| 3127 | |||
| 3128 | /** |
||
| 3129 | * @param int $id |
||
| 3130 | * @return string |
||
| 3131 | */ |
||
| 3132 | public function getDisplayNameById(int $id) : string |
||
| 3142 | |||
| 3143 | /** |
||
| 3144 | * @param int $id |
||
| 3145 | * @param string $displayColumnValue |
||
| 3146 | * @return bool |
||
| 3147 | */ |
||
| 3148 | public function validIdDisplayNameCombo(int $id, $displayColumnValue) : bool |
||
| 3152 | |||
| 3153 | /** |
||
| 3154 | * @param array $toPopulate |
||
| 3155 | * @return stdClass |
||
| 3156 | */ |
||
| 3157 | protected function getEmptyObject(array $toPopulate=[]) : stdClass |
||
| 3163 | |||
| 3164 | /** |
||
| 3165 | * @param int $id |
||
| 3166 | * @return bool |
||
| 3167 | */ |
||
| 3168 | public static function isId(int $id) : bool |
||
| 3172 | |||
| 3173 | /** |
||
| 3174 | * @param int $cacheTtl |
||
| 3175 | * @return int |
||
| 3176 | */ |
||
| 3177 | public function activeCount(int $cacheTtl=self::CACHE_NO) : int |
||
| 3181 | |||
| 3182 | /** |
||
| 3183 | * @param string $tableAlias |
||
| 3184 | * @param string $columnName |
||
| 3185 | * @return FluentPdoModel|$this |
||
| 3186 | */ |
||
| 3187 | public function whereActive(string $tableAlias='', string $columnName=self::STATUS_FIELD) : FluentPdoModel |
||
| 3191 | |||
| 3192 | /** |
||
| 3193 | * @param string $tableAlias |
||
| 3194 | * @param string $columnName |
||
| 3195 | * @return FluentPdoModel|$this |
||
| 3196 | */ |
||
| 3197 | public function whereInactive(string $tableAlias='', string $columnName=self::STATUS_FIELD) : FluentPdoModel |
||
| 3201 | |||
| 3202 | /** |
||
| 3203 | * @param string $tableAlias |
||
| 3204 | * @param string $columnName |
||
| 3205 | * @return FluentPdoModel|$this |
||
| 3206 | */ |
||
| 3207 | public function whereArchived(string $tableAlias='', string $columnName='status') : FluentPdoModel |
||
| 3211 | |||
| 3212 | /** |
||
| 3213 | * @param int $status |
||
| 3214 | * @param string $tableAlias |
||
| 3215 | * @param string $columnName |
||
| 3216 | * @return FluentPdoModel|$this |
||
| 3217 | */ |
||
| 3218 | public function whereStatus(int $status, string $tableAlias='', string $columnName=self::STATUS_FIELD) : FluentPdoModel |
||
| 3227 | |||
| 3228 | /** |
||
| 3229 | * @param int $id |
||
| 3230 | * @return int |
||
| 3231 | */ |
||
| 3232 | public function updateActive(int $id=0) : int |
||
| 3242 | |||
| 3243 | /** |
||
| 3244 | * @param int $id |
||
| 3245 | * @return int |
||
| 3246 | */ |
||
| 3247 | public function updateInactive(int $id=0) : int |
||
| 3256 | |||
| 3257 | /** |
||
| 3258 | * @param string $field |
||
| 3259 | * @param int $id |
||
| 3260 | * @return int |
||
| 3261 | */ |
||
| 3262 | public function updateNow(string $field, int $id=0) : int |
||
| 3268 | /** |
||
| 3269 | * @param string $field |
||
| 3270 | * @param int $id |
||
| 3271 | * @return int |
||
| 3272 | */ |
||
| 3273 | public function updateToday($field, int $id=0) : int |
||
| 3279 | |||
| 3280 | /** |
||
| 3281 | * @param int $id |
||
| 3282 | * @return int |
||
| 3283 | */ |
||
| 3284 | public function updateDeleted(int $id=0) : int |
||
| 3297 | |||
| 3298 | /** |
||
| 3299 | * @param int $id |
||
| 3300 | * @return int |
||
| 3301 | */ |
||
| 3302 | public function updateArchived(int $id=0) : int |
||
| 3312 | |||
| 3313 | /** |
||
| 3314 | * @param int $status |
||
| 3315 | * @return int |
||
| 3316 | * @throws \Exception |
||
| 3317 | */ |
||
| 3318 | public function updateStatus(int $status) |
||
| 3324 | |||
| 3325 | /** |
||
| 3326 | * Return a YYYY-MM-DD HH:II:SS date format |
||
| 3327 | * |
||
| 3328 | * @param string $datetime - An english textual datetime description |
||
| 3329 | * now, yesterday, 3 days ago, +1 week |
||
| 3330 | * http://php.net/manual/en/function.strtotime.php |
||
| 3331 | * @return string YYYY-MM-DD HH:II:SS |
||
| 3332 | */ |
||
| 3333 | public static function NOW(string $datetime='now') : string |
||
| 3337 | |||
| 3338 | /** |
||
| 3339 | * Return a string containing the given number of question marks, |
||
| 3340 | * separated by commas. Eg '?, ?, ?' |
||
| 3341 | * |
||
| 3342 | * @param int - total of placeholder to insert |
||
| 3343 | * @return string |
||
| 3344 | */ |
||
| 3345 | protected function _makePlaceholders(int $numberOfPlaceholders=1) : string |
||
| 3349 | |||
| 3350 | /** |
||
| 3351 | * Format the table{Primary|Foreign}KeyName |
||
| 3352 | * |
||
| 3353 | * @param string $pattern |
||
| 3354 | * @param string $tableName |
||
| 3355 | * @return string |
||
| 3356 | */ |
||
| 3357 | protected function _formatKeyName(string $pattern, string $tableName) : string |
||
| 3361 | |||
| 3362 | |||
| 3363 | /** |
||
| 3364 | * @param array $query |
||
| 3365 | * @param array $extraFields |
||
| 3366 | * @return array |
||
| 3367 | * @throws \Exception |
||
| 3368 | */ |
||
| 3369 | protected function _prepareApiResource(array $query=[], array $extraFields=[]) : array |
||
| 3390 | |||
| 3391 | /** |
||
| 3392 | * @param string $query |
||
| 3393 | * @param array $parameters |
||
| 3394 | * |
||
| 3395 | * @return array |
||
| 3396 | */ |
||
| 3397 | protected function _logQuery(string $query, array $parameters) : array |
||
| 3410 | |||
| 3411 | /** |
||
| 3412 | * @param string $ident |
||
| 3413 | * @param string $builtQuery |
||
| 3414 | */ |
||
| 3415 | protected function _logSlowQueries(string $ident, string $builtQuery) |
||
| 3428 | |||
| 3429 | /** |
||
| 3430 | * @return float |
||
| 3431 | */ |
||
| 3432 | public function getTimeTaken() : float |
||
| 3438 | |||
| 3439 | /** |
||
| 3440 | * @param $secs |
||
| 3441 | * @return FluentPdoModel|$this |
||
| 3442 | */ |
||
| 3443 | public function slowQuerySeconds(int $secs) : FluentPdoModel |
||
| 3450 | |||
| 3451 | |||
| 3452 | /** |
||
| 3453 | * @param $field |
||
| 3454 | * @param array $values |
||
| 3455 | * @param string $placeholderPrefix |
||
| 3456 | * |
||
| 3457 | * @return array |
||
| 3458 | */ |
||
| 3459 | public function getNamedWhereIn(string $field, array $values, string $placeholderPrefix='') : array |
||
| 3483 | |||
| 3484 | /** |
||
| 3485 | * @param string $field |
||
| 3486 | * @param string $delimiter |
||
| 3487 | * |
||
| 3488 | * @return array |
||
| 3489 | */ |
||
| 3490 | protected function _getColumnAliasParts(string $field, string $delimiter=':') : array |
||
| 3505 | |||
| 3506 | /** |
||
| 3507 | * @param string $column |
||
| 3508 | * @param string $term |
||
| 3509 | * @return FluentPdoModel|$this |
||
| 3510 | */ |
||
| 3511 | protected function _addWhereClause(string $column, string $term) : FluentPdoModel |
||
| 3568 | |||
| 3569 | public function destroy() |
||
| 3578 | |||
| 3579 | public function __destruct() |
||
| 3583 | |||
| 3584 | /** |
||
| 3585 | * Load a model |
||
| 3586 | * |
||
| 3587 | * @param string $modelName |
||
| 3588 | * @param AbstractPdo $connection |
||
| 3589 | * @return FluentPdoModel|$this |
||
| 3590 | * @throws ModelNotFoundException |
||
| 3591 | */ |
||
| 3592 | public static function loadModel(string $modelName, AbstractPdo $connection=null) : FluentPdoModel |
||
| 3602 | |||
| 3603 | /** |
||
| 3604 | * Load a model |
||
| 3605 | * |
||
| 3606 | * @param string $tableName |
||
| 3607 | * @param AbstractPdo $connection |
||
| 3608 | * @return FluentPdoModel|$this |
||
| 3609 | */ |
||
| 3610 | public static function loadTable(string $tableName, AbstractPdo $connection=null) : FluentPdoModel |
||
| 3617 | |||
| 3618 | /** |
||
| 3619 | * @param string $columnName |
||
| 3620 | * @param int $cacheTtl |
||
| 3621 | * @param bool $flushCache |
||
| 3622 | * @return bool |
||
| 3623 | */ |
||
| 3624 | public function columnExists(string $columnName, int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : bool |
||
| 3630 | |||
| 3631 | /** |
||
| 3632 | * @param string $indexName |
||
| 3633 | * @param int $cacheTtl |
||
| 3634 | * @param bool $flushCache |
||
| 3635 | * @return bool |
||
| 3636 | */ |
||
| 3637 | public function indexExists(string $indexName, int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : bool |
||
| 3659 | |||
| 3660 | |||
| 3661 | |||
| 3662 | /** |
||
| 3663 | * @param int $cacheTtl |
||
| 3664 | * @param bool $flushCache |
||
| 3665 | * @return FluentPdoModel|$this |
||
| 3666 | */ |
||
| 3667 | public function loadSchemaFromDb(int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : FluentPdoModel |
||
| 3674 | |||
| 3675 | /** |
||
| 3676 | * @param int $cacheTtl |
||
| 3677 | * @param bool $flushCache |
||
| 3678 | * @return array |
||
| 3679 | */ |
||
| 3680 | public function getSchemaFromDb(int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : array |
||
| 3692 | |||
| 3693 | /** |
||
| 3694 | * @param string $table |
||
| 3695 | * @param int $cacheTtl |
||
| 3696 | * @param bool $flushCache |
||
| 3697 | * @return Column[][] |
||
| 3698 | */ |
||
| 3699 | protected function _getColumnsByTableFromDb(string $table, int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : array |
||
| 3715 | |||
| 3716 | /** |
||
| 3717 | * @param string $table |
||
| 3718 | * @return bool |
||
| 3719 | */ |
||
| 3720 | public function clearSchemaCache(string $table) : bool |
||
| 3724 | |||
| 3725 | /** |
||
| 3726 | * @param stdClass $record |
||
| 3727 | * @return stdClass |
||
| 3728 | */ |
||
| 3729 | public function cleanseRecord(stdClass $record) : stdClass |
||
| 3746 | |||
| 3747 | /** |
||
| 3748 | * @param stdClass $record |
||
| 3749 | * @param string $type |
||
| 3750 | * @return stdClass |
||
| 3751 | */ |
||
| 3752 | public function beforeSave(stdClass $record, string $type) : stdClass |
||
| 3761 | |||
| 3762 | /** |
||
| 3763 | * @param array $data |
||
| 3764 | * @param string $saveType |
||
| 3765 | * @return array |
||
| 3766 | */ |
||
| 3767 | public function cleanseWebData(array $data, string $saveType) : array |
||
| 3782 | |||
| 3783 | /** |
||
| 3784 | * @return array |
||
| 3785 | */ |
||
| 3786 | public function skeleton() : array |
||
| 3797 | |||
| 3798 | /** |
||
| 3799 | * @param bool $toString |
||
| 3800 | * @return array |
||
| 3801 | */ |
||
| 3802 | public function getErrors(bool $toString=false) : array |
||
| 3817 | |||
| 3818 | /** |
||
| 3819 | * @param bool $throw |
||
| 3820 | * @return FluentPdoModel|$this |
||
| 3821 | */ |
||
| 3822 | public function validationExceptions(bool $throw=true) : FluentPdoModel |
||
| 3828 | |||
| 3829 | /** |
||
| 3830 | * @param array $query array('_limit' => int, '_offset' => int, '_order' => string, '_fields' => string, _search) |
||
| 3831 | * |
||
| 3832 | * @return FluentPdoModel|$this |
||
| 3833 | * @throws Exception |
||
| 3834 | */ |
||
| 3835 | public function paginate(array $query=[]) : FluentPdoModel |
||
| 3849 | |||
| 3850 | /** |
||
| 3851 | * @param int $limit |
||
| 3852 | * @param int $offset |
||
| 3853 | * @return FluentPdoModel|$this |
||
| 3854 | */ |
||
| 3855 | protected function _setLimit(int $limit=0, int $offset=0) : FluentPdoModel |
||
| 3870 | |||
| 3871 | /** |
||
| 3872 | * @param array $fields |
||
| 3873 | * @return FluentPdoModel|$this |
||
| 3874 | * @throws Exception |
||
| 3875 | */ |
||
| 3876 | protected function _setFields(array $fields=[]) : FluentPdoModel |
||
| 3924 | |||
| 3925 | /** |
||
| 3926 | * @param string $orderBy |
||
| 3927 | * @return FluentPdoModel|$this|FluentPdoModel |
||
| 3928 | */ |
||
| 3929 | protected function _setOrderBy(string $orderBy='') : FluentPdoModel |
||
| 3966 | |||
| 3967 | /** |
||
| 3968 | * @return array |
||
| 3969 | */ |
||
| 3970 | public function getPagingMeta() |
||
| 3979 | |||
| 3980 | /** |
||
| 3981 | * @return FluentPdoModel|$this |
||
| 3982 | */ |
||
| 3983 | public function setPagingMeta() : FluentPdoModel |
||
| 4005 | |||
| 4006 | /** |
||
| 4007 | * Take a web request and format a query |
||
| 4008 | * |
||
| 4009 | * @param array $query |
||
| 4010 | * |
||
| 4011 | * @return FluentPdoModel|$this |
||
| 4012 | * @throws Exception |
||
| 4013 | */ |
||
| 4014 | public function filter(array $query=[]) : FluentPdoModel |
||
| 4084 | |||
| 4085 | /** |
||
| 4086 | * @param string $column |
||
| 4087 | * @param string $displayCol |
||
| 4088 | * @return string|null |
||
| 4089 | */ |
||
| 4090 | protected function _findFieldByQuery(string $column, string $displayCol) |
||
| 4137 | |||
| 4138 | /** |
||
| 4139 | * @param $keysOnly |
||
| 4140 | * @return array |
||
| 4141 | */ |
||
| 4142 | |||
| 4143 | public function columns(bool $keysOnly=true) : array |
||
| 4147 | |||
| 4148 | /** |
||
| 4149 | * @param string $field |
||
| 4150 | * @param mixed $value |
||
| 4151 | * @param array $pdoMetaData |
||
| 4152 | * @return float|int |
||
| 4153 | * @throws Exception |
||
| 4154 | */ |
||
| 4155 | protected function _fixTypeToSentinel(string $field, $value, array $pdoMetaData=[]) |
||
| 4207 | |||
| 4208 | /** |
||
| 4209 | * @param string $field |
||
| 4210 | * @param mixed $value |
||
| 4211 | * @param bool|false $permissive |
||
| 4212 | * @return float|int|null|string |
||
| 4213 | */ |
||
| 4214 | protected function _fixType(string $field, $value, bool $permissive=false) |
||
| 4265 | |||
| 4266 | /** |
||
| 4267 | * @param stdClass $record |
||
| 4268 | * @param string $type |
||
| 4269 | * @return stdClass |
||
| 4270 | */ |
||
| 4271 | public function fixTypesToSentinel(stdClass $record, string $type='') : stdClass |
||
| 4298 | |||
| 4299 | /** |
||
| 4300 | * @param stdClass $record |
||
| 4301 | * @param string $type |
||
| 4302 | * @return stdClass |
||
| 4303 | * @throws Exception |
||
| 4304 | */ |
||
| 4305 | public function applyHandlers(stdClass $record, string $type='INSERT') : stdClass |
||
| 4333 | |||
| 4334 | |||
| 4335 | /** |
||
| 4336 | * @param stdClass $record |
||
| 4337 | * @param array $fields |
||
| 4338 | * @param string $type |
||
| 4339 | * @return bool |
||
| 4340 | */ |
||
| 4341 | protected function uniqueCheck(stdClass $record, array $fields, string $type) : bool |
||
| 4354 | |||
| 4355 | /** |
||
| 4356 | * @param string $field |
||
| 4357 | * @param mixed $value |
||
| 4358 | * @param string $type |
||
| 4359 | * @param stdClass $record |
||
| 4360 | * @return null |
||
| 4361 | * @throws Exception |
||
| 4362 | */ |
||
| 4363 | protected function applyHandler(string $field, $value, string $type='', stdClass $record=null) |
||
| 4387 | |||
| 4388 | /** |
||
| 4389 | * @param string $start |
||
| 4390 | * @param string $end |
||
| 4391 | * @param string $hayStack |
||
| 4392 | * @return mixed |
||
| 4393 | */ |
||
| 4394 | public static function between(string $start, string $end, string $hayStack) : string |
||
| 4398 | |||
| 4399 | /** |
||
| 4400 | * @param string $needle |
||
| 4401 | * @param string $hayStack |
||
| 4402 | * @param bool $returnOrigIfNeedleNotExists |
||
| 4403 | * @return mixed |
||
| 4404 | */ |
||
| 4405 | public static function before(string $needle, string $hayStack, bool $returnOrigIfNeedleNotExists=false) : string |
||
| 4415 | |||
| 4416 | /** |
||
| 4417 | * @param string $needle |
||
| 4418 | * @param string $hayStack |
||
| 4419 | * @param bool $returnOrigIfNeedleNotExists |
||
| 4420 | * @return string |
||
| 4421 | */ |
||
| 4422 | public static function after(string $needle, string $hayStack, bool $returnOrigIfNeedleNotExists=false) : string |
||
| 4431 | |||
| 4432 | /** |
||
| 4433 | * @return int |
||
| 4434 | */ |
||
| 4435 | public function getUserId() |
||
| 4439 | |||
| 4440 | /** |
||
| 4441 | * @param string $entity |
||
| 4442 | * @param int $id |
||
| 4443 | * @return int |
||
| 4444 | */ |
||
| 4445 | public function getMaskByResourceAndId(string $entity, int $id) : int |
||
| 4449 | |||
| 4450 | /** |
||
| 4451 | * @param string|int|null $time |
||
| 4452 | * @return string |
||
| 4453 | */ |
||
| 4454 | public static function date($time=null) : string |
||
| 4458 | |||
| 4459 | /** |
||
| 4460 | * @param string|int|null $time |
||
| 4461 | * @return string |
||
| 4462 | */ |
||
| 4463 | public static function dateTime($time=null) : string |
||
| 4467 | |||
| 4468 | /** |
||
| 4469 | * @param string|int|null $time |
||
| 4470 | * @return string |
||
| 4471 | */ |
||
| 4472 | public static function atom($time=null) : string |
||
| 4476 | |||
| 4477 | /** |
||
| 4478 | * @param string|int|null $time |
||
| 4479 | * @return int |
||
| 4480 | */ |
||
| 4481 | public static function getTime($time=null) : int |
||
| 4494 | |||
| 4495 | /** |
||
| 4496 | * @param int $id |
||
| 4497 | * @param int $cacheTtl |
||
| 4498 | * @return string |
||
| 4499 | */ |
||
| 4500 | public function getCodeById(int $id, int $cacheTtl=self::ONE_DAY) : string |
||
| 4508 | |||
| 4509 | /** |
||
| 4510 | * @param array $authUserRoles |
||
| 4511 | * @param int $authUserId |
||
| 4512 | * @return FluentPdoModel |
||
| 4513 | */ |
||
| 4514 | public function applyRoleFilter(array $authUserRoles, int $authUserId) : FluentPdoModel |
||
| 4518 | |||
| 4519 | /** |
||
| 4520 | * @param int $id |
||
| 4521 | * @param string[] $authUserRoles |
||
| 4522 | * @param int $authUserId |
||
| 4523 | * @return bool |
||
| 4524 | */ |
||
| 4525 | public function canAccessIdWithRole(int $id, array $authUserRoles, int $authUserId) : bool |
||
| 4529 | } |
||
| 4530 |