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 | /** @var AbstractPdo $_connection */ |
||
56 | protected $_connection = null; |
||
57 | |||
58 | /** @var string */ |
||
59 | protected $_primary_key = 'id'; |
||
60 | |||
61 | /** @var array */ |
||
62 | protected $_where_parameters = []; |
||
63 | |||
64 | /** @var array */ |
||
65 | protected $_select_fields = []; |
||
66 | |||
67 | /** @var array */ |
||
68 | protected $_join_sources = []; |
||
69 | |||
70 | /** @var array */ |
||
71 | protected $_join_aliases = []; |
||
72 | |||
73 | /** @var array $_associations */ |
||
74 | protected $_associations = [ |
||
75 | 'belongsTo' => [], |
||
76 | ]; |
||
77 | |||
78 | /** @var array */ |
||
79 | protected $_where_conditions = []; |
||
80 | |||
81 | protected $_raw_sql = ''; |
||
82 | |||
83 | /** @var int */ |
||
84 | protected $_limit = 0; |
||
85 | |||
86 | /** @var int */ |
||
87 | protected $_offset = 0; |
||
88 | |||
89 | /** @var array */ |
||
90 | protected $_order_by = []; |
||
91 | |||
92 | /** @var array */ |
||
93 | protected $_group_by = []; |
||
94 | |||
95 | /** @var string */ |
||
96 | protected $_and_or_operator = self::OPERATOR_AND; |
||
97 | |||
98 | /** @var array */ |
||
99 | protected $_having = []; |
||
100 | |||
101 | /** @var bool */ |
||
102 | protected $_wrap_open = false; |
||
103 | |||
104 | /** @var int */ |
||
105 | protected $_last_wrap_position = 0; |
||
106 | |||
107 | /** @var PDOStatement $_pdo_stmt */ |
||
108 | protected $_pdo_stmt = null; |
||
109 | |||
110 | /** @var bool */ |
||
111 | protected $_distinct = false; |
||
112 | |||
113 | /** @var null */ |
||
114 | protected $_requested_fields = []; |
||
115 | |||
116 | /** @var null */ |
||
117 | protected $_filter_meta = []; |
||
118 | |||
119 | /** @var bool */ |
||
120 | protected $_log_queries = false; |
||
121 | |||
122 | /** @var array */ |
||
123 | protected $_timer = []; |
||
124 | |||
125 | /** @var int */ |
||
126 | protected $_slow_query_secs = 5; |
||
127 | |||
128 | /** @var array */ |
||
129 | protected $_pagination_attribs = [ |
||
130 | '_limit', |
||
131 | '_offset', |
||
132 | '_order', |
||
133 | '_fields', |
||
134 | '_search' |
||
135 | ]; |
||
136 | |||
137 | /** @var string $_table_name */ |
||
138 | protected $_table_name = ''; |
||
139 | |||
140 | /** @var string $_table_alias */ |
||
141 | protected $_table_alias = ''; |
||
142 | |||
143 | /** @var string $_display_column */ |
||
144 | protected $_display_column = ''; |
||
145 | |||
146 | /** @var string $_connection_name */ |
||
147 | protected $_connection_name = ''; |
||
148 | |||
149 | /** @var array $_schema */ |
||
150 | protected $_schema = []; |
||
151 | |||
152 | /** @var array $_virtual_fields */ |
||
153 | protected $_virtual_fields = []; |
||
154 | |||
155 | /** @var array $_errors */ |
||
156 | protected $_errors = []; |
||
157 | |||
158 | /** |
||
159 | * @var int - true = connection default x days |
||
160 | * - false = no cache |
||
161 | * - int = a specific amount |
||
162 | */ |
||
163 | protected $_cache_ttl = self::CACHE_NO; |
||
164 | |||
165 | /** @var string */ |
||
166 | protected $_tmp_table_prefix = 'tmp_'; |
||
167 | |||
168 | /** @var null|string */ |
||
169 | protected $_built_query = ''; |
||
170 | |||
171 | /** @var array */ |
||
172 | protected $_handlers = []; |
||
173 | |||
174 | /** @var bool User want to directly specify the fields */ |
||
175 | protected $_explicit_select_mode = false; |
||
176 | |||
177 | /** @var string[] */ |
||
178 | protected $_update_raw = []; |
||
179 | |||
180 | protected $_max_callback_failures = -1; |
||
181 | |||
182 | protected $_num_callback_failures = 0; |
||
183 | |||
184 | protected $_filter_on_fetch = false; |
||
185 | |||
186 | protected $_log_filter_changes = true; |
||
187 | |||
188 | protected $_include_count = false; |
||
189 | |||
190 | /** @var string */ |
||
191 | static protected $_model_namespace = ''; |
||
192 | |||
193 | /** @var bool */ |
||
194 | protected $_validation_exceptions = true; |
||
195 | |||
196 | /** @var array */ |
||
197 | protected $_paging_meta = []; |
||
198 | |||
199 | /** @var bool */ |
||
200 | protected $_soft_deletes = true; |
||
201 | |||
202 | |||
203 | /** @var bool */ |
||
204 | protected $_allow_meta_override = false; |
||
205 | |||
206 | /** @var int */ |
||
207 | protected $_default_max = 250; |
||
208 | |||
209 | /** @var array */ |
||
210 | protected $removeUnauthorisedFields = []; |
||
211 | |||
212 | protected $_can_generic_update = true; |
||
213 | protected $_can_generic_add = true; |
||
214 | protected $_can_generic_delete = true; |
||
215 | |||
216 | /** @var array */ |
||
217 | protected $row_meta_data = []; |
||
218 | |||
219 | /** @var array */ |
||
220 | protected $globalRemoveUnauthorisedFields = [ |
||
221 | '/global_table_meta#view' => [ |
||
222 | 'created_by_id', |
||
223 | 'created_by', |
||
224 | 'created_ts', |
||
225 | 'modified_by_id', |
||
226 | 'modified_by', |
||
227 | 'modified_ts', |
||
228 | 'status', |
||
229 | ], |
||
230 | ]; |
||
231 | |||
232 | |||
233 | /** |
||
234 | * @param AbstractPdo|null $connection |
||
235 | */ |
||
236 | public function __construct(AbstractPdo $connection=null) |
||
243 | |||
244 | public function init() |
||
246 | |||
247 | /** |
||
248 | * @return AbstractPdo |
||
249 | * @throws Exception |
||
250 | */ |
||
251 | public function getPdo() : AbstractPdo |
||
255 | |||
256 | /** |
||
257 | * @return LoggerInterface |
||
258 | */ |
||
259 | public function getLogger() : LoggerInterface |
||
263 | |||
264 | /** |
||
265 | * @return CacheInterface |
||
266 | */ |
||
267 | public function getCache() : CacheInterface |
||
271 | |||
272 | /** |
||
273 | * Define the working table and create a new instance |
||
274 | * |
||
275 | * @param string $tableName - Table name |
||
276 | * @param string $alias - The table alias name |
||
277 | * @param string $displayColumn |
||
278 | * @param string $primaryKeyName |
||
279 | * |
||
280 | * @return FluentPdoModel|$this |
||
281 | */ |
||
282 | public function table(string $tableName, string $alias='', string $displayColumn='', string $primaryKeyName='id') : FluentPdoModel |
||
290 | |||
291 | /** |
||
292 | * @param string $primaryKeyName |
||
293 | * @return FluentPdoModel|$this |
||
294 | */ |
||
295 | public function primaryKeyName(string $primaryKeyName) : FluentPdoModel |
||
301 | |||
302 | /** |
||
303 | * @param string $tableName |
||
304 | * |
||
305 | * @return FluentPdoModel|$this |
||
306 | */ |
||
307 | public function tableName(string $tableName) : FluentPdoModel |
||
313 | |||
314 | /** |
||
315 | * @param $explicitSelect |
||
316 | * |
||
317 | * @return FluentPdoModel|$this |
||
318 | */ |
||
319 | public function explicitSelectMode(bool $explicitSelect=true) : FluentPdoModel |
||
325 | |||
326 | /** |
||
327 | * @param bool $filterOnFetch |
||
328 | * |
||
329 | * @return FluentPdoModel|$this |
||
330 | */ |
||
331 | public function filterOnFetch(bool $filterOnFetch=true) : FluentPdoModel |
||
337 | |||
338 | /** |
||
339 | * @param bool $logFilterChanges |
||
340 | * |
||
341 | * @return FluentPdoModel|$this |
||
342 | */ |
||
343 | public function logFilterChanges(bool $logFilterChanges=true) : FluentPdoModel |
||
349 | |||
350 | /** |
||
351 | * Return the name of the table |
||
352 | * |
||
353 | * @return string |
||
354 | */ |
||
355 | public function getTableName() : string |
||
359 | |||
360 | /** |
||
361 | * @return string |
||
362 | */ |
||
363 | public function getDisplayColumn() : string |
||
367 | |||
368 | /** |
||
369 | * Set the display column |
||
370 | * |
||
371 | * @param string $column |
||
372 | * |
||
373 | * @return FluentPdoModel|$this |
||
374 | */ |
||
375 | public function displayColumn(string $column) : FluentPdoModel |
||
381 | /** |
||
382 | * Set the table alias |
||
383 | * |
||
384 | * @param string $alias |
||
385 | * |
||
386 | * @return FluentPdoModel|$this |
||
387 | */ |
||
388 | public function tableAlias(string $alias) : FluentPdoModel |
||
394 | |||
395 | /** |
||
396 | * @param int $cacheTtl |
||
397 | * @return FluentPdoModel|$this |
||
398 | * @throws Exception |
||
399 | */ |
||
400 | protected function _cacheTtl(int $cacheTtl) : FluentPdoModel |
||
411 | |||
412 | /** |
||
413 | * @return string |
||
414 | */ |
||
415 | public function getTableAlias() : string |
||
419 | |||
420 | /** |
||
421 | * @param array $associations |
||
422 | * |
||
423 | * @return FluentPdoModel|$this |
||
424 | */ |
||
425 | public function associations(array $associations) : FluentPdoModel |
||
431 | |||
432 | /** |
||
433 | * @param string $alias |
||
434 | * @param array $definition |
||
435 | * @return FluentPdoModel|$this |
||
436 | */ |
||
437 | public function setBelongsTo(string $alias, array $definition) : FluentPdoModel |
||
446 | |||
447 | /** |
||
448 | * @param $alias |
||
449 | * @param $displayField |
||
450 | * @return FluentPdoModel|$this |
||
451 | * @throws \Terah\Assert\AssertionFailedException |
||
452 | */ |
||
453 | public function setBelongsToDisplayField(string $alias, string $displayField) : FluentPdoModel |
||
463 | |||
464 | /** |
||
465 | * @param PDOStatement $stmt |
||
466 | * |
||
467 | * @param PDOStatement $stmt |
||
468 | * @param Closure $fnCallback |
||
469 | * @return bool|stdClass |
||
470 | */ |
||
471 | public function fetchRow(PDOStatement $stmt, Closure $fnCallback=null) |
||
494 | |||
495 | /** |
||
496 | * @param PDOStatement $stmt |
||
497 | * @param $record |
||
498 | * @return array |
||
499 | */ |
||
500 | protected function getColumnMeta(PDOStatement $stmt, $record) : array |
||
515 | |||
516 | /** |
||
517 | * @param array $schema |
||
518 | * |
||
519 | * @return FluentPdoModel|$this |
||
520 | */ |
||
521 | public function schema(array $schema) : FluentPdoModel |
||
527 | |||
528 | /** |
||
529 | * @param string|array $field |
||
530 | * @param $type |
||
531 | * @return FluentPdoModel|$this |
||
532 | */ |
||
533 | public function addSchema($field, string $type) : FluentPdoModel |
||
549 | |||
550 | /** |
||
551 | * @param $keysOnly |
||
552 | * @return array |
||
553 | */ |
||
554 | public function getColumns(bool $keysOnly=true) : array |
||
558 | |||
559 | /** |
||
560 | * Get the primary key name |
||
561 | * |
||
562 | * @return string |
||
563 | */ |
||
564 | public function getPrimaryKeyName() : string |
||
568 | |||
569 | /** |
||
570 | * @param string $query |
||
571 | * @param array $parameters |
||
572 | * |
||
573 | * @return bool |
||
574 | * @throws Exception |
||
575 | */ |
||
576 | public function execute(string $query, array $parameters=[]) : bool |
||
601 | |||
602 | /** |
||
603 | * @param string $query |
||
604 | * @param array $params |
||
605 | * @return FluentPdoModel|$this |
||
606 | */ |
||
607 | public function query(string $query, array $params=[]) : FluentPdoModel |
||
614 | |||
615 | /** |
||
616 | * @param string $sql |
||
617 | * @param array $params |
||
618 | * |
||
619 | * @return string |
||
620 | */ |
||
621 | public function buildQuery(string $sql, array $params=[]) : string |
||
649 | |||
650 | /** |
||
651 | * @param stdClass $record |
||
652 | * |
||
653 | * @return stdClass |
||
654 | */ |
||
655 | protected function _trimAndLowerCaseKeys(stdClass $record) : stdClass |
||
665 | |||
666 | /** |
||
667 | * Return the number of affected row by the last statement |
||
668 | * |
||
669 | * @return int |
||
670 | */ |
||
671 | public function rowCount() : int |
||
677 | |||
678 | /** |
||
679 | * @return PDOStatement |
||
680 | * @throws PDOException |
||
681 | */ |
||
682 | public function fetchStmt() |
||
691 | |||
692 | /** |
||
693 | * @return array |
||
694 | */ |
||
695 | public function fetchSqlQuery() : array |
||
705 | |||
706 | /** |
||
707 | * @param string $tableName |
||
708 | * @param bool $dropIfExists |
||
709 | * @param array $indexes |
||
710 | * @return boolean |
||
711 | * @throws Exception |
||
712 | */ |
||
713 | public function fetchIntoMemoryTable(string $tableName, bool $dropIfExists=true, array $indexes=[]) : bool |
||
735 | |||
736 | /** |
||
737 | * @param string $keyedOn |
||
738 | * @param int $cacheTtl |
||
739 | * @return stdClass[] |
||
740 | */ |
||
741 | public function fetch(string $keyedOn='', int $cacheTtl=self::CACHE_NO) : array |
||
779 | |||
780 | /** |
||
781 | * @return string |
||
782 | */ |
||
783 | protected function _parseWhereForPrimaryLookup() : string |
||
799 | |||
800 | /** |
||
801 | * @param string $cacheKey |
||
802 | * @param Closure $func |
||
803 | * @param int $cacheTtl - 0 for default ttl, -1 for no cache or int for custom ttl |
||
804 | * @return mixed |
||
805 | */ |
||
806 | protected function _cacheData(string $cacheKey, Closure $func, int $cacheTtl=self::CACHE_DEFAULT) |
||
844 | |||
845 | /** |
||
846 | * @param string $cacheKey |
||
847 | * @return bool |
||
848 | */ |
||
849 | public function clearCache(string $cacheKey) : bool |
||
853 | |||
854 | /** |
||
855 | * @param string $table |
||
856 | * @return bool |
||
857 | */ |
||
858 | public function clearCacheByTable(string $table='') : bool |
||
868 | |||
869 | /** |
||
870 | * @param Closure $fnCallback |
||
871 | * @return int |
||
872 | */ |
||
873 | public function fetchCallback(Closure $fnCallback) : int |
||
882 | |||
883 | /** |
||
884 | * @param Closure $fnCallback |
||
885 | * @param string $keyedOn |
||
886 | * @return array |
||
887 | */ |
||
888 | public function fetchObjectsByCallback(Closure $fnCallback, string $keyedOn='') : array |
||
905 | |||
906 | /** |
||
907 | * @param $numFailures |
||
908 | * @return FluentPdoModel|$this |
||
909 | */ |
||
910 | public function maxCallbackFailures(int $numFailures) : FluentPdoModel |
||
917 | |||
918 | /** |
||
919 | * @param PDOStatement $stmt |
||
920 | * @param Closure $fnCallback |
||
921 | * @param int $successCnt |
||
922 | * @return bool|null|stdClass |
||
923 | */ |
||
924 | protected function _tallySuccessCount(PDOStatement $stmt, Closure $fnCallback, int &$successCnt) |
||
955 | |||
956 | /** |
||
957 | * @return bool |
||
958 | */ |
||
959 | public function canGenericUpdate() : bool |
||
963 | |||
964 | /** |
||
965 | * @return bool |
||
966 | */ |
||
967 | public function canGenericAdd() : bool |
||
971 | |||
972 | /** |
||
973 | * @return bool |
||
974 | */ |
||
975 | public function canGenericDelete() : bool |
||
979 | |||
980 | /** |
||
981 | * @param string $keyedOn |
||
982 | * @param string $valueField |
||
983 | * @param int $cacheTtl |
||
984 | * @return mixed |
||
985 | */ |
||
986 | public function fetchList(string $keyedOn='', string $valueField='', int $cacheTtl=self::CACHE_NO) : array |
||
1038 | |||
1039 | /** |
||
1040 | * @param string $column |
||
1041 | * @param int $cacheTtl |
||
1042 | * @param bool|true $unique |
||
1043 | * @return array |
||
1044 | */ |
||
1045 | public function fetchColumn(string $column, int $cacheTtl=self::CACHE_NO, bool $unique=true) : array |
||
1054 | |||
1055 | /** |
||
1056 | * @param string $field |
||
1057 | * @param int $itemId |
||
1058 | * @param int $cacheTtl |
||
1059 | * @return mixed|null |
||
1060 | */ |
||
1061 | public function fetchField(string $field='', int $itemId=0, int $cacheTtl=self::CACHE_NO) |
||
1084 | |||
1085 | /** |
||
1086 | * @param string $field |
||
1087 | * @param int $itemId |
||
1088 | * @param int $cacheTtl |
||
1089 | * @return string |
||
1090 | */ |
||
1091 | public function fetchStr(string $field='', $itemId=0, int $cacheTtl=self::CACHE_NO) : string |
||
1095 | |||
1096 | /** |
||
1097 | * @param int $cacheTtl |
||
1098 | * @return int |
||
1099 | */ |
||
1100 | public function fetchId(int $cacheTtl=self::CACHE_NO) : int |
||
1104 | |||
1105 | /** |
||
1106 | * @param string $field |
||
1107 | * @param int $itemId |
||
1108 | * @param int $cacheTtl |
||
1109 | * @return int |
||
1110 | */ |
||
1111 | public function fetchInt(string $field='', int $itemId=0, int $cacheTtl=self::CACHE_NO) : int |
||
1115 | |||
1116 | /** |
||
1117 | * @param string $field |
||
1118 | * @param int $itemId |
||
1119 | * @param int $cacheTtl |
||
1120 | * @return float |
||
1121 | */ |
||
1122 | public function fetchFloat(string $field='', int $itemId=0, int $cacheTtl=self::CACHE_NO) : float |
||
1126 | |||
1127 | /** |
||
1128 | * @param string $field |
||
1129 | * @param int $itemId |
||
1130 | * @param int $cacheTtl |
||
1131 | * @return bool |
||
1132 | */ |
||
1133 | public function fetchBool(string $field='', int $itemId=0, int $cacheTtl=self::CACHE_NO) : bool |
||
1137 | |||
1138 | /** |
||
1139 | * @param int|null $id |
||
1140 | * @param int $cacheTtl |
||
1141 | * @return stdClass|bool |
||
1142 | */ |
||
1143 | public function fetchOne(int $id=0, int $cacheTtl=self::CACHE_NO) |
||
1154 | |||
1155 | /** |
||
1156 | * @param int|null $id |
||
1157 | * @param int $cacheTtl |
||
1158 | * @return boolean |
||
1159 | */ |
||
1160 | public function fetchExists(int $id=0, int $cacheTtl=self::CACHE_NO) : bool |
||
1169 | |||
1170 | /*------------------------------------------------------------------------------ |
||
1171 | Fluent Query Builder |
||
1172 | *-----------------------------------------------------------------------------*/ |
||
1173 | |||
1174 | /** |
||
1175 | * Create the select clause |
||
1176 | * |
||
1177 | * @param mixed $columns - the column to select. Can be string or array of fields |
||
1178 | * @param string $alias - an alias to the column |
||
1179 | * @param boolean $explicitSelect |
||
1180 | * @return FluentPdoModel|$this |
||
1181 | */ |
||
1182 | public function select($columns='*', string $alias='', bool $explicitSelect=true) : FluentPdoModel |
||
1224 | |||
1225 | /** |
||
1226 | * @param string $select |
||
1227 | * @return FluentPdoModel|$this |
||
1228 | */ |
||
1229 | public function selectRaw(string $select) : FluentPdoModel |
||
1235 | |||
1236 | /** |
||
1237 | * @param bool $logQueries |
||
1238 | * |
||
1239 | * @return FluentPdoModel|$this |
||
1240 | */ |
||
1241 | public function logQueries(bool $logQueries=true) : FluentPdoModel |
||
1247 | |||
1248 | /** |
||
1249 | * @param bool $includeCnt |
||
1250 | * |
||
1251 | * @return FluentPdoModel|$this |
||
1252 | */ |
||
1253 | public function includeCount(bool $includeCnt=true) : FluentPdoModel |
||
1259 | |||
1260 | /** |
||
1261 | * @param bool $distinct |
||
1262 | * |
||
1263 | * @return FluentPdoModel|$this |
||
1264 | */ |
||
1265 | public function distinct(bool $distinct=true) : FluentPdoModel |
||
1271 | |||
1272 | /** |
||
1273 | * @param array $fields |
||
1274 | * @return FluentPdoModel|$this |
||
1275 | */ |
||
1276 | public function withBelongsTo(array $fields=[]) : FluentPdoModel |
||
1289 | |||
1290 | /** |
||
1291 | * @param string $alias |
||
1292 | * @param string $type |
||
1293 | * @param bool $addSelectField |
||
1294 | * @return FluentPdoModel|$this |
||
1295 | */ |
||
1296 | public function autoJoin(string $alias, string $type=self::LEFT_JOIN, bool $addSelectField=true) : FluentPdoModel |
||
1313 | |||
1314 | /** |
||
1315 | * Add where condition, more calls appends with AND |
||
1316 | * |
||
1317 | * @param string $condition possibly containing ? or :name |
||
1318 | * @param mixed $parameters accepted by PDOStatement::execute or a scalar value |
||
1319 | * @param mixed ... |
||
1320 | * @return FluentPdoModel|$this |
||
1321 | */ |
||
1322 | public function where($condition, $parameters=[]) : FluentPdoModel |
||
1371 | |||
1372 | /** |
||
1373 | * Create an AND operator in the where clause |
||
1374 | * |
||
1375 | * @return FluentPdoModel|$this |
||
1376 | */ |
||
1377 | public function _and() : FluentPdoModel |
||
1391 | |||
1392 | |||
1393 | /** |
||
1394 | * Create an OR operator in the where clause |
||
1395 | * |
||
1396 | * @return FluentPdoModel|$this |
||
1397 | */ |
||
1398 | public function _or() : FluentPdoModel |
||
1412 | |||
1413 | /** |
||
1414 | * To group multiple where clauses together. |
||
1415 | * |
||
1416 | * @return FluentPdoModel|$this |
||
1417 | */ |
||
1418 | public function wrap() : FluentPdoModel |
||
1428 | |||
1429 | /** |
||
1430 | * Where Primary key |
||
1431 | * |
||
1432 | * @param int $id |
||
1433 | * @param bool $addAlias |
||
1434 | * |
||
1435 | * @return FluentPdoModel|$this |
||
1436 | */ |
||
1437 | public function wherePk(int $id, bool $addAlias=true) : FluentPdoModel |
||
1443 | |||
1444 | /** |
||
1445 | * WHERE $columnName != $value |
||
1446 | * |
||
1447 | * @param string $columnName |
||
1448 | * @param mixed $value |
||
1449 | * @return FluentPdoModel|$this |
||
1450 | */ |
||
1451 | public function whereNot(string $columnName, $value) : FluentPdoModel |
||
1455 | /** |
||
1456 | * WHERE $columnName != $value |
||
1457 | * |
||
1458 | * @param string $columnName |
||
1459 | * @param mixed $value |
||
1460 | * @return FluentPdoModel|$this |
||
1461 | */ |
||
1462 | public function whereCoercedNot(string $columnName, $value) : FluentPdoModel |
||
1466 | |||
1467 | /** |
||
1468 | * WHERE $columnName LIKE $value |
||
1469 | * |
||
1470 | * @param string $columnName |
||
1471 | * @param mixed $value |
||
1472 | * @return FluentPdoModel|$this |
||
1473 | */ |
||
1474 | public function whereLike(string $columnName, $value) : FluentPdoModel |
||
1478 | |||
1479 | /** |
||
1480 | * @param string $columnName |
||
1481 | * @param mixed $value1 |
||
1482 | * @param mixed $value2 |
||
1483 | * @return FluentPdoModel|$this |
||
1484 | */ |
||
1485 | public function whereBetween(string $columnName, $value1, $value2) : FluentPdoModel |
||
1492 | |||
1493 | /** |
||
1494 | * @param string $columnName |
||
1495 | * @param mixed $value1 |
||
1496 | * @param mixed $value2 |
||
1497 | * @return FluentPdoModel|$this |
||
1498 | */ |
||
1499 | public function whereNotBetween(string $columnName, $value1, $value2) : FluentPdoModel |
||
1506 | |||
1507 | /** |
||
1508 | * @param string $columnName |
||
1509 | * @param string $regex |
||
1510 | * @return FluentPdoModel|$this |
||
1511 | */ |
||
1512 | public function whereRegex(string $columnName, string $regex) : FluentPdoModel |
||
1516 | |||
1517 | /** |
||
1518 | * @param string $columnName |
||
1519 | * @param string $regex |
||
1520 | * @return FluentPdoModel|$this |
||
1521 | */ |
||
1522 | public function whereNotRegex(string $columnName, string $regex) : FluentPdoModel |
||
1526 | |||
1527 | /** |
||
1528 | * WHERE $columnName NOT LIKE $value |
||
1529 | * |
||
1530 | * @param string $columnName |
||
1531 | * @param string $value |
||
1532 | * @return FluentPdoModel|$this |
||
1533 | */ |
||
1534 | public function whereNotLike(string $columnName, string $value) : FluentPdoModel |
||
1538 | |||
1539 | /** |
||
1540 | * WHERE $columnName > $value |
||
1541 | * |
||
1542 | * @param string $columnName |
||
1543 | * @param mixed $value |
||
1544 | * @return FluentPdoModel|$this |
||
1545 | */ |
||
1546 | public function whereGt(string $columnName, $value) : FluentPdoModel |
||
1550 | |||
1551 | /** |
||
1552 | * WHERE $columnName >= $value |
||
1553 | * |
||
1554 | * @param string $columnName |
||
1555 | * @param mixed $value |
||
1556 | * @return FluentPdoModel|$this |
||
1557 | */ |
||
1558 | public function whereGte(string $columnName, $value) : FluentPdoModel |
||
1562 | |||
1563 | /** |
||
1564 | * WHERE $columnName < $value |
||
1565 | * |
||
1566 | * @param string $columnName |
||
1567 | * @param mixed $value |
||
1568 | * @return FluentPdoModel|$this |
||
1569 | */ |
||
1570 | public function whereLt(string $columnName, $value) : FluentPdoModel |
||
1574 | |||
1575 | /** |
||
1576 | * WHERE $columnName <= $value |
||
1577 | * |
||
1578 | * @param string $columnName |
||
1579 | * @param mixed $value |
||
1580 | * @return FluentPdoModel|$this |
||
1581 | */ |
||
1582 | public function whereLte(string $columnName, $value) : FluentPdoModel |
||
1586 | |||
1587 | /** |
||
1588 | * WHERE $columnName IN (?,?,?,...) |
||
1589 | * |
||
1590 | * @param string $columnName |
||
1591 | * @param array $values |
||
1592 | * @return FluentPdoModel|$this |
||
1593 | */ |
||
1594 | public function whereIn(string $columnName, array $values) : FluentPdoModel |
||
1598 | |||
1599 | /** |
||
1600 | * WHERE $columnName NOT IN (?,?,?,...) |
||
1601 | * |
||
1602 | * @param string $columnName |
||
1603 | * @param array $values |
||
1604 | * @return FluentPdoModel|$this |
||
1605 | */ |
||
1606 | public function whereNotIn(string $columnName, array $values) : FluentPdoModel |
||
1612 | |||
1613 | /** |
||
1614 | * WHERE $columnName IS NULL |
||
1615 | * |
||
1616 | * @param string $columnName |
||
1617 | * @return FluentPdoModel|$this |
||
1618 | */ |
||
1619 | public function whereNull(string $columnName) : FluentPdoModel |
||
1623 | |||
1624 | /** |
||
1625 | * WHERE $columnName IS NOT NULL |
||
1626 | * |
||
1627 | * @param string $columnName |
||
1628 | * @return FluentPdoModel|$this |
||
1629 | */ |
||
1630 | public function whereNotNull(string $columnName) : FluentPdoModel |
||
1634 | |||
1635 | /** |
||
1636 | * @param string $statement |
||
1637 | * @param string $operator |
||
1638 | * @return FluentPdoModel|$this |
||
1639 | */ |
||
1640 | public function having(string $statement, string $operator=self::OPERATOR_AND) : FluentPdoModel |
||
1649 | |||
1650 | /** |
||
1651 | * ORDER BY $columnName (ASC | DESC) |
||
1652 | * |
||
1653 | * @param string $columnName - The name of the column or an expression |
||
1654 | * @param string $ordering (DESC | ASC) |
||
1655 | * @return FluentPdoModel|$this |
||
1656 | */ |
||
1657 | public function orderBy(string $columnName='', string $ordering='DESC') : FluentPdoModel |
||
1671 | |||
1672 | /** |
||
1673 | * GROUP BY $columnName |
||
1674 | * |
||
1675 | * @param string $columnName |
||
1676 | * @return FluentPdoModel|$this |
||
1677 | */ |
||
1678 | public function groupBy(string $columnName) : FluentPdoModel |
||
1688 | |||
1689 | |||
1690 | /** |
||
1691 | * LIMIT $limit |
||
1692 | * |
||
1693 | * @param int $limit |
||
1694 | * @param int|null $offset |
||
1695 | * @return FluentPdoModel|$this |
||
1696 | */ |
||
1697 | public function limit(int $limit, int $offset=0) : FluentPdoModel |
||
1706 | |||
1707 | /** |
||
1708 | * Return the limit |
||
1709 | * |
||
1710 | * @return integer |
||
1711 | */ |
||
1712 | public function getLimit() : int |
||
1716 | |||
1717 | /** |
||
1718 | * OFFSET $offset |
||
1719 | * |
||
1720 | * @param int $offset |
||
1721 | * @return FluentPdoModel|$this |
||
1722 | */ |
||
1723 | public function offset(int $offset) : FluentPdoModel |
||
1729 | |||
1730 | /** |
||
1731 | * Return the offset |
||
1732 | * |
||
1733 | * @return integer |
||
1734 | */ |
||
1735 | public function getOffset() : int |
||
1739 | |||
1740 | /** |
||
1741 | * Build a join |
||
1742 | * |
||
1743 | * @param string $table - The table name |
||
1744 | * @param string $constraint -> id = profile.user_id |
||
1745 | * @param string $tableAlias - The alias of the table name |
||
1746 | * @param string $joinOperator - LEFT | INNER | etc... |
||
1747 | * @return FluentPdoModel|$this |
||
1748 | */ |
||
1749 | public function join(string $table, string $constraint='', string $tableAlias='', string $joinOperator='') : FluentPdoModel |
||
1768 | |||
1769 | /** |
||
1770 | * Create a left join |
||
1771 | * |
||
1772 | * @param string $table |
||
1773 | * @param string $constraint |
||
1774 | * @param string $tableAlias |
||
1775 | * @return FluentPdoModel|$this |
||
1776 | */ |
||
1777 | public function leftJoin(string $table, string $constraint, string $tableAlias='') : FluentPdoModel |
||
1781 | |||
1782 | |||
1783 | /** |
||
1784 | * Return the build select query |
||
1785 | * |
||
1786 | * @return string |
||
1787 | */ |
||
1788 | public function getSelectQuery() : string |
||
1831 | |||
1832 | /** |
||
1833 | * Prepare columns to include the table alias name |
||
1834 | * @param array $columns |
||
1835 | * @return array |
||
1836 | */ |
||
1837 | protected function _prepareColumns(array $columns) : array |
||
1867 | |||
1868 | /** |
||
1869 | * Build the WHERE clause(s) |
||
1870 | * |
||
1871 | * @param bool $purgeAliases |
||
1872 | * @return string |
||
1873 | */ |
||
1874 | protected function _getWhereString(bool $purgeAliases=false) : string |
||
1907 | |||
1908 | /** |
||
1909 | * Return the HAVING clause |
||
1910 | * |
||
1911 | * @return string |
||
1912 | */ |
||
1913 | protected function _getHavingString() : string |
||
1932 | |||
1933 | /** |
||
1934 | * Return the values to be bound for where |
||
1935 | * |
||
1936 | * @param bool $purgeAliases |
||
1937 | * @return array |
||
1938 | */ |
||
1939 | protected function _getWhereParameters(bool $purgeAliases=false) : array |
||
1945 | |||
1946 | /** |
||
1947 | * @param array $record |
||
1948 | * @return stdClass |
||
1949 | */ |
||
1950 | public function insertArr(array $record) : stdClass |
||
1954 | |||
1955 | /** |
||
1956 | * Insert new rows |
||
1957 | * $records can be a stdClass or an array of stdClass to add a bulk insert |
||
1958 | * If a single row is inserted, it will return it's row instance |
||
1959 | * |
||
1960 | * @param stdClass $record |
||
1961 | * @return stdClass |
||
1962 | * @throws Exception |
||
1963 | */ |
||
1964 | public function insert(stdClass $record) : stdClass |
||
1987 | |||
1988 | /** |
||
1989 | * @param string $name |
||
1990 | * @return int |
||
1991 | */ |
||
1992 | public function getLastInsertId(string $name='') : int |
||
1996 | |||
1997 | /** |
||
1998 | * @param stdClass[] $records |
||
1999 | * @return stdClass[] |
||
2000 | */ |
||
2001 | public function insertSqlQuery(array $records) : array |
||
2021 | |||
2022 | /** |
||
2023 | * @param $data |
||
2024 | * @param array $matchOn |
||
2025 | * @param bool $returnObj |
||
2026 | * @return bool|int|stdClass |
||
2027 | */ |
||
2028 | public function upsert($data, array $matchOn=[], $returnObj=false) |
||
2050 | |||
2051 | /** |
||
2052 | * @param stdClass $object |
||
2053 | * @param array $matchOn |
||
2054 | * @param bool $returnObj |
||
2055 | * @return bool|int|stdClass |
||
2056 | */ |
||
2057 | public function upsertOne(stdClass $object, array $matchOn=[], $returnObj=false) |
||
2097 | |||
2098 | /** |
||
2099 | * @param array $data |
||
2100 | * @param array $matchOn |
||
2101 | * @param bool|false $returnObj |
||
2102 | * @return bool|int|stdClass |
||
2103 | */ |
||
2104 | public function upsertArr(array $data, array $matchOn=[], bool $returnObj=false) |
||
2108 | |||
2109 | /** |
||
2110 | * Update entries |
||
2111 | * Use the query builder to create the where clause |
||
2112 | * |
||
2113 | * @param stdClass $record |
||
2114 | * @param bool $updateAll |
||
2115 | * @return int |
||
2116 | * @throws Exception |
||
2117 | */ |
||
2118 | public function update(stdClass $record, $updateAll=false) : int |
||
2141 | |||
2142 | /** |
||
2143 | * @param array $record |
||
2144 | * @param bool|false $updateAll |
||
2145 | * @return int |
||
2146 | * @throws Exception |
||
2147 | */ |
||
2148 | public function updateArr(array $record, $updateAll=false) : int |
||
2152 | |||
2153 | |||
2154 | /** |
||
2155 | * @param string $field |
||
2156 | * @param mixed $value |
||
2157 | * @param int $id |
||
2158 | * @param bool|false $updateAll |
||
2159 | * @return int |
||
2160 | * @throws Exception |
||
2161 | */ |
||
2162 | public function updateField(string $field, $value, int $id=0, bool $updateAll=false) : int |
||
2171 | |||
2172 | /** |
||
2173 | * @param stdClass $record |
||
2174 | * @return bool|int |
||
2175 | * @throws Exception |
||
2176 | */ |
||
2177 | public function updateChanged(stdClass $record) : int |
||
2191 | |||
2192 | /** |
||
2193 | * @param string $expression |
||
2194 | * @param array $params |
||
2195 | * @return FluentPdoModel|$this |
||
2196 | */ |
||
2197 | public function updateByExpression(string $expression, array $params) : FluentPdoModel |
||
2203 | |||
2204 | /** |
||
2205 | * @param array $data |
||
2206 | * @return int |
||
2207 | * @throws Exception |
||
2208 | */ |
||
2209 | public function rawUpdate(array $data=[]) : int |
||
2218 | |||
2219 | /** |
||
2220 | * @param stdClass $record |
||
2221 | * @return array |
||
2222 | */ |
||
2223 | public function updateSqlQuery(stdClass $record) : array |
||
2233 | |||
2234 | /** |
||
2235 | * @param $record |
||
2236 | * @return array |
||
2237 | */ |
||
2238 | protected function updateSql(array $record) : array |
||
2269 | |||
2270 | /** |
||
2271 | * @param bool $deleteAll |
||
2272 | * @param bool $force |
||
2273 | * @return int |
||
2274 | * @throws Exception |
||
2275 | */ |
||
2276 | public function delete(bool $deleteAll=false, bool $force=false) : int |
||
2292 | |||
2293 | /** |
||
2294 | * @param bool|false $force |
||
2295 | * @return FluentPdoModel|$this |
||
2296 | * @throws Exception |
||
2297 | */ |
||
2298 | public function truncate(bool $force=false) : FluentPdoModel |
||
2312 | |||
2313 | /** |
||
2314 | * @return array |
||
2315 | */ |
||
2316 | public function deleteSqlQuery() : array |
||
2328 | |||
2329 | |||
2330 | /** |
||
2331 | * Return the aggregate count of column |
||
2332 | * |
||
2333 | * @param string $column |
||
2334 | * @param int $cacheTtl |
||
2335 | * @return float |
||
2336 | */ |
||
2337 | public function count(string $column='*', int $cacheTtl=self::CACHE_NO) : float |
||
2343 | |||
2344 | |||
2345 | /** |
||
2346 | * Return the aggregate max count of column |
||
2347 | * |
||
2348 | * @param string $column |
||
2349 | * @param int $cacheTtl |
||
2350 | * @return int|float|string|null |
||
2351 | */ |
||
2352 | public function max(string $column, int $cacheTtl=self::CACHE_NO) |
||
2358 | |||
2359 | |||
2360 | /** |
||
2361 | * Return the aggregate min count of column |
||
2362 | * |
||
2363 | * @param string $column |
||
2364 | * @param int $cacheTtl |
||
2365 | * @return int|float|string|null |
||
2366 | */ |
||
2367 | public function min(string $column, int $cacheTtl=self::CACHE_NO) |
||
2373 | |||
2374 | /** |
||
2375 | * Return the aggregate sum count of column |
||
2376 | * |
||
2377 | * @param string $column |
||
2378 | * @param int $cacheTtl |
||
2379 | * @return int|float|string|null |
||
2380 | */ |
||
2381 | public function sum(string $column, int $cacheTtl=self::CACHE_NO) |
||
2387 | |||
2388 | /** |
||
2389 | * Return the aggregate average count of column |
||
2390 | * |
||
2391 | * @param string $column |
||
2392 | * @param int $cacheTtl |
||
2393 | * @return int|float|string|null |
||
2394 | */ |
||
2395 | public function avg(string $column, int $cacheTtl=self::CACHE_NO) |
||
2401 | |||
2402 | /*******************************************************************************/ |
||
2403 | // Utilities methods |
||
2404 | |||
2405 | /** |
||
2406 | * Reset fields |
||
2407 | * |
||
2408 | * @return FluentPdoModel|$this |
||
2409 | */ |
||
2410 | public function reset() : FluentPdoModel |
||
2438 | |||
2439 | |||
2440 | /** |
||
2441 | * @return FluentPdoModel|$this |
||
2442 | */ |
||
2443 | public function removeUnauthorisedFields() : FluentPdoModel |
||
2447 | |||
2448 | /** |
||
2449 | * @return Closure[] |
||
2450 | */ |
||
2451 | protected function _getFieldHandlers() : array |
||
2518 | |||
2519 | /** |
||
2520 | * @return bool |
||
2521 | */ |
||
2522 | public function begin() : bool |
||
2536 | |||
2537 | /** |
||
2538 | * @return bool |
||
2539 | */ |
||
2540 | public function commit() : bool |
||
2558 | |||
2559 | /** |
||
2560 | * @return bool |
||
2561 | */ |
||
2562 | public function rollback() : bool |
||
2576 | |||
2577 | /** |
||
2578 | * @param stdClass $record |
||
2579 | * @param string $type |
||
2580 | * @return stdClass |
||
2581 | */ |
||
2582 | public function applyGlobalModifiers(stdClass $record, string $type) : stdClass |
||
2595 | |||
2596 | /** |
||
2597 | * @param stdClass $record |
||
2598 | * @param string $type |
||
2599 | * @return stdClass |
||
2600 | */ |
||
2601 | public function removeUnneededFields(stdClass $record, string $type) : stdClass |
||
2627 | |||
2628 | |||
2629 | /** |
||
2630 | * @param array $ids |
||
2631 | * @param array $values |
||
2632 | * @param int $batch |
||
2633 | * @return bool |
||
2634 | */ |
||
2635 | public function setById(array $ids, array $values, int $batch=1000) : bool |
||
2651 | |||
2652 | |||
2653 | /** |
||
2654 | * @param string $displayColumnValue |
||
2655 | * @return int |
||
2656 | */ |
||
2657 | public function resolveId(string $displayColumnValue) : int |
||
2668 | |||
2669 | /** |
||
2670 | * @param int $resourceId |
||
2671 | * @param array $query |
||
2672 | * @param array $extraFields |
||
2673 | * @param int $cacheTtl |
||
2674 | * @return array |
||
2675 | */ |
||
2676 | public function fetchApiResource(int $resourceId, array $query=[], array $extraFields=[], int $cacheTtl=self::CACHE_NO) : array |
||
2689 | |||
2690 | /** |
||
2691 | * @param array $query |
||
2692 | * @param array $extraFields |
||
2693 | * @param int $cacheTtl |
||
2694 | * @param string $permEntity |
||
2695 | * @return array |
||
2696 | */ |
||
2697 | public function fetchApiResources(array $query=[], array $extraFields=[], int $cacheTtl=self::CACHE_NO, string $permEntity='') : array |
||
2719 | |||
2720 | |||
2721 | /** |
||
2722 | * @return array |
||
2723 | */ |
||
2724 | public function getSearchableAssociations() : array |
||
2731 | |||
2732 | /** |
||
2733 | * @param array $fields |
||
2734 | */ |
||
2735 | public function removeUnrequestedFields(array $fields) |
||
2746 | |||
2747 | /** |
||
2748 | * @param array $removeFields |
||
2749 | */ |
||
2750 | public function removeFields(array $removeFields=[]) |
||
2775 | |||
2776 | /** |
||
2777 | * @return FluentPdoModel|$this |
||
2778 | */ |
||
2779 | public function defaultFilters() : FluentPdoModel |
||
2783 | |||
2784 | /** |
||
2785 | * @param bool $allow |
||
2786 | * |
||
2787 | * @return FluentPdoModel|$this |
||
2788 | */ |
||
2789 | public function allowMetaColumnOverride(bool $allow=false) : FluentPdoModel |
||
2795 | |||
2796 | /** |
||
2797 | * @param stdClass $record |
||
2798 | * @return stdClass |
||
2799 | */ |
||
2800 | public function onFetch(stdClass $record) : stdClass |
||
2812 | |||
2813 | /** |
||
2814 | * @param $value |
||
2815 | * @return string |
||
2816 | */ |
||
2817 | public function gzEncodeData(string $value) : string |
||
2826 | |||
2827 | /** |
||
2828 | * @param $value |
||
2829 | * @return mixed|string |
||
2830 | */ |
||
2831 | public function gzDecodeData(string $value) : string |
||
2841 | |||
2842 | /** |
||
2843 | * @param $value |
||
2844 | * @return bool |
||
2845 | */ |
||
2846 | protected function _hasGzipPrefix(string $value) : bool |
||
2850 | |||
2851 | /** |
||
2852 | * @param stdClass $record |
||
2853 | * @return stdClass |
||
2854 | */ |
||
2855 | public function fixTimestamps(stdClass $record) : stdClass |
||
2867 | |||
2868 | /** |
||
2869 | * @param int $max |
||
2870 | * @return FluentPdoModel|$this |
||
2871 | */ |
||
2872 | public function setMaxRecords(int $max) : FluentPdoModel |
||
2879 | |||
2880 | |||
2881 | /** |
||
2882 | * @param stdClass $record |
||
2883 | * @param string $type |
||
2884 | * @return stdClass |
||
2885 | */ |
||
2886 | public function afterSave(stdClass $record, string $type) : stdClass |
||
2907 | |||
2908 | |||
2909 | /** |
||
2910 | * @param stdClass $record |
||
2911 | * @param string $type |
||
2912 | * @return stdClass |
||
2913 | */ |
||
2914 | public function addDefaultFields(stdClass $record, string $type) : stdClass |
||
2943 | |||
2944 | |||
2945 | /** |
||
2946 | * @return bool |
||
2947 | */ |
||
2948 | public function createTable() : bool |
||
2952 | |||
2953 | /** |
||
2954 | * @return bool |
||
2955 | */ |
||
2956 | public function dropTable() : bool |
||
2960 | |||
2961 | protected function _compileHandlers() |
||
2970 | |||
2971 | /** |
||
2972 | * @param string $viewName |
||
2973 | * @param int $cacheTtl |
||
2974 | * @return array |
||
2975 | */ |
||
2976 | public function getViewColumns($viewName, $cacheTtl=self::CACHE_NO) |
||
2980 | |||
2981 | /** |
||
2982 | * @param int $id |
||
2983 | * @return string |
||
2984 | */ |
||
2985 | public function getDisplayNameById(int $id) : string |
||
2995 | |||
2996 | /** |
||
2997 | * @param int $id |
||
2998 | * @param string $displayColumnValue |
||
2999 | * @return bool |
||
3000 | */ |
||
3001 | public function validIdDisplayNameCombo(int $id, $displayColumnValue) : bool |
||
3005 | |||
3006 | /** |
||
3007 | * @param array $toPopulate |
||
3008 | * @return stdClass |
||
3009 | */ |
||
3010 | protected function getEmptyObject(array $toPopulate=[]) : stdClass |
||
3016 | |||
3017 | /** |
||
3018 | * @param int $id |
||
3019 | * @return bool |
||
3020 | */ |
||
3021 | public static function isId(int $id) : bool |
||
3025 | |||
3026 | /** |
||
3027 | * @param int $cacheTtl |
||
3028 | * @return int |
||
3029 | */ |
||
3030 | public function activeCount(int $cacheTtl=self::CACHE_NO) : int |
||
3034 | |||
3035 | /** |
||
3036 | * @param string $tableAlias |
||
3037 | * @param string $columnName |
||
3038 | * @return FluentPdoModel|$this |
||
3039 | */ |
||
3040 | public function whereActive(string $tableAlias='', string $columnName='status') : FluentPdoModel |
||
3044 | |||
3045 | /** |
||
3046 | * @param string $tableAlias |
||
3047 | * @param string $columnName |
||
3048 | * @return FluentPdoModel|$this |
||
3049 | */ |
||
3050 | public function whereInactive(string $tableAlias='', string $columnName='status') : FluentPdoModel |
||
3054 | |||
3055 | /** |
||
3056 | * @param string $tableAlias |
||
3057 | * @param string $columnName |
||
3058 | * @return FluentPdoModel|$this |
||
3059 | */ |
||
3060 | public function whereArchived(string $tableAlias='', string $columnName='status') : FluentPdoModel |
||
3064 | |||
3065 | /** |
||
3066 | * @param int $status |
||
3067 | * @param string $tableAlias |
||
3068 | * @param string $columnName |
||
3069 | * @return FluentPdoModel|$this |
||
3070 | */ |
||
3071 | public function whereStatus(int $status, string $tableAlias='', string $columnName='status') : FluentPdoModel |
||
3080 | |||
3081 | /** |
||
3082 | * @param int $id |
||
3083 | * @return int |
||
3084 | */ |
||
3085 | public function updateActive(int $id=0) : int |
||
3095 | |||
3096 | /** |
||
3097 | * @param int $id |
||
3098 | * @return int |
||
3099 | */ |
||
3100 | public function updateInactive(int $id=0) : int |
||
3109 | |||
3110 | /** |
||
3111 | * @param string $field |
||
3112 | * @param int $id |
||
3113 | * @return int |
||
3114 | */ |
||
3115 | public function updateNow(string $field, int $id=0) : int |
||
3121 | /** |
||
3122 | * @param string $field |
||
3123 | * @param int $id |
||
3124 | * @return int |
||
3125 | */ |
||
3126 | public function updateToday($field, int $id=0) : int |
||
3132 | |||
3133 | /** |
||
3134 | * @param int $id |
||
3135 | * @return int |
||
3136 | */ |
||
3137 | public function updateArchived(int $id=0) : int |
||
3147 | |||
3148 | /** |
||
3149 | * @param int $status |
||
3150 | * @return int |
||
3151 | * @throws \Exception |
||
3152 | */ |
||
3153 | public function updateStatus(int $status) |
||
3159 | |||
3160 | /** |
||
3161 | * Return a YYYY-MM-DD HH:II:SS date format |
||
3162 | * |
||
3163 | * @param string $datetime - An english textual datetime description |
||
3164 | * now, yesterday, 3 days ago, +1 week |
||
3165 | * http://php.net/manual/en/function.strtotime.php |
||
3166 | * @return string YYYY-MM-DD HH:II:SS |
||
3167 | */ |
||
3168 | public static function NOW(string $datetime='now') : string |
||
3172 | |||
3173 | /** |
||
3174 | * Return a string containing the given number of question marks, |
||
3175 | * separated by commas. Eg '?, ?, ?' |
||
3176 | * |
||
3177 | * @param int - total of placeholder to insert |
||
3178 | * @return string |
||
3179 | */ |
||
3180 | protected function _makePlaceholders(int $numberOfPlaceholders=1) : string |
||
3184 | |||
3185 | /** |
||
3186 | * Format the table{Primary|Foreign}KeyName |
||
3187 | * |
||
3188 | * @param string $pattern |
||
3189 | * @param string $tableName |
||
3190 | * @return string |
||
3191 | */ |
||
3192 | protected function _formatKeyName(string $pattern, string $tableName) : string |
||
3196 | |||
3197 | |||
3198 | /** |
||
3199 | * @param array $query |
||
3200 | * @param array $extraFields |
||
3201 | * @return array |
||
3202 | * @throws \Exception |
||
3203 | */ |
||
3204 | protected function _prepareApiResource(array $query=[], array $extraFields=[]) : array |
||
3225 | |||
3226 | /** |
||
3227 | * @param string $query |
||
3228 | * @param array $parameters |
||
3229 | * |
||
3230 | * @return array |
||
3231 | */ |
||
3232 | protected function _logQuery(string $query, array $parameters) : array |
||
3245 | |||
3246 | /** |
||
3247 | * @param string $ident |
||
3248 | * @param string $builtQuery |
||
3249 | */ |
||
3250 | protected function _logSlowQueries(string $ident, string $builtQuery) |
||
3263 | |||
3264 | /** |
||
3265 | * @return float |
||
3266 | */ |
||
3267 | public function getTimeTaken() : float |
||
3273 | |||
3274 | /** |
||
3275 | * @param $secs |
||
3276 | * @return FluentPdoModel|$this |
||
3277 | */ |
||
3278 | public function slowQuerySeconds(int $secs) : FluentPdoModel |
||
3285 | |||
3286 | |||
3287 | /** |
||
3288 | * @param $field |
||
3289 | * @param array $values |
||
3290 | * @param string $placeholderPrefix |
||
3291 | * |
||
3292 | * @return array |
||
3293 | */ |
||
3294 | public function getNamedWhereIn(string $field, array $values, string $placeholderPrefix='') : array |
||
3318 | |||
3319 | /** |
||
3320 | * @param string $field |
||
3321 | * @param string $delimiter |
||
3322 | * |
||
3323 | * @return array |
||
3324 | */ |
||
3325 | protected function _getColumnAliasParts(string $field, string $delimiter=':') : array |
||
3335 | |||
3336 | /** |
||
3337 | * @param string $column |
||
3338 | * @param string $term |
||
3339 | * @return FluentPdoModel|$this |
||
3340 | */ |
||
3341 | protected function _addWhereClause(string $column, string $term) : FluentPdoModel |
||
3398 | |||
3399 | public function destroy() |
||
3408 | |||
3409 | public function __destruct() |
||
3413 | |||
3414 | /** |
||
3415 | * Load a model |
||
3416 | * |
||
3417 | * @param string $modelName |
||
3418 | * @param AbstractPdo $connection |
||
3419 | * @return FluentPdoModel|$this |
||
3420 | * @throws ModelNotFoundException |
||
3421 | */ |
||
3422 | public static function loadModel(string $modelName, AbstractPdo $connection=null) : FluentPdoModel |
||
3432 | |||
3433 | /** |
||
3434 | * Load a model |
||
3435 | * |
||
3436 | * @param string $tableName |
||
3437 | * @param AbstractPdo $connection |
||
3438 | * @return FluentPdoModel|$this |
||
3439 | */ |
||
3440 | public static function loadTable(string $tableName, AbstractPdo $connection=null) : FluentPdoModel |
||
3447 | |||
3448 | /** |
||
3449 | * @param string $columnName |
||
3450 | * @param int $cacheTtl |
||
3451 | * @param bool $flushCache |
||
3452 | * @return bool |
||
3453 | */ |
||
3454 | public function columnExists(string $columnName, int $cacheTtl=self::CACHE_NO, bool $flushCache=false) |
||
3459 | |||
3460 | /** |
||
3461 | * @param int $cacheTtl |
||
3462 | * @param bool $flushCache |
||
3463 | * @return FluentPdoModel|$this |
||
3464 | */ |
||
3465 | public function loadSchemaFromDb(int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : FluentPdoModel |
||
3472 | |||
3473 | /** |
||
3474 | * @param int $cacheTtl |
||
3475 | * @param bool $flushCache |
||
3476 | * @return array |
||
3477 | */ |
||
3478 | public function getSchemaFromDb(int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : array |
||
3490 | |||
3491 | /** |
||
3492 | * @param string $table |
||
3493 | * @param int $cacheTtl |
||
3494 | * @param bool $flushCache |
||
3495 | * @return array |
||
3496 | */ |
||
3497 | protected function _getColumnsByTableFromDb(string $table, int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : array |
||
3513 | |||
3514 | /** |
||
3515 | * @param string $table |
||
3516 | * @return bool |
||
3517 | */ |
||
3518 | public function clearSchemaCache(string $table) : bool |
||
3522 | |||
3523 | /** |
||
3524 | * @param stdClass $record |
||
3525 | * @return stdClass |
||
3526 | */ |
||
3527 | public function cleanseRecord(stdClass $record) : stdClass |
||
3544 | |||
3545 | /** |
||
3546 | * @param stdClass $record |
||
3547 | * @param string $type |
||
3548 | * @return stdClass |
||
3549 | */ |
||
3550 | public function beforeSave(stdClass $record, string $type) : stdClass |
||
3559 | |||
3560 | /** |
||
3561 | * @param array $data |
||
3562 | * @param string $saveType |
||
3563 | * @return array |
||
3564 | */ |
||
3565 | public function cleanseWebData(array $data, string $saveType) : array |
||
3580 | |||
3581 | /** |
||
3582 | * @return array |
||
3583 | */ |
||
3584 | public function skeleton() : array |
||
3595 | |||
3596 | /** |
||
3597 | * @param bool $toString |
||
3598 | * @return array |
||
3599 | */ |
||
3600 | public function getErrors(bool $toString=false) : array |
||
3615 | |||
3616 | /** |
||
3617 | * @param bool $throw |
||
3618 | * @return FluentPdoModel|$this |
||
3619 | */ |
||
3620 | public function validationExceptions(bool $throw=true) : FluentPdoModel |
||
3626 | |||
3627 | /** |
||
3628 | * @param array $query array('_limit' => int, '_offset' => int, '_order' => string, '_fields' => string, _search) |
||
3629 | * |
||
3630 | * @return FluentPdoModel|$this |
||
3631 | * @throws Exception |
||
3632 | */ |
||
3633 | public function paginate(array $query=[]) : FluentPdoModel |
||
3647 | |||
3648 | /** |
||
3649 | * @param int $limit |
||
3650 | * @param int $offset |
||
3651 | * @return FluentPdoModel|$this |
||
3652 | */ |
||
3653 | protected function _setLimit(int $limit=0, int $offset=0) : FluentPdoModel |
||
3668 | |||
3669 | /** |
||
3670 | * @param array $fields |
||
3671 | * @return FluentPdoModel|$this |
||
3672 | * @throws Exception |
||
3673 | */ |
||
3674 | protected function _setFields(array $fields=[]) : FluentPdoModel |
||
3722 | |||
3723 | /** |
||
3724 | * @param string $orderBy |
||
3725 | * @return FluentPdoModel|$this|FluentPdoModel |
||
3726 | */ |
||
3727 | protected function _setOrderBy(string $orderBy='') : FluentPdoModel |
||
3764 | |||
3765 | /** |
||
3766 | * @return array |
||
3767 | */ |
||
3768 | public function getPagingMeta() |
||
3777 | |||
3778 | /** |
||
3779 | * @return FluentPdoModel|$this |
||
3780 | */ |
||
3781 | public function setPagingMeta() : FluentPdoModel |
||
3803 | |||
3804 | /** |
||
3805 | * Take a web request and format a query |
||
3806 | * |
||
3807 | * @param array $query |
||
3808 | * |
||
3809 | * @return FluentPdoModel|$this |
||
3810 | * @throws Exception |
||
3811 | */ |
||
3812 | public function filter(array $query=[]) : FluentPdoModel |
||
3878 | |||
3879 | /** |
||
3880 | * @param string $column |
||
3881 | * @param string $displayCol |
||
3882 | * @return string|null |
||
3883 | */ |
||
3884 | protected function _findFieldByQuery(string $column, string $displayCol) |
||
3931 | |||
3932 | /** |
||
3933 | * @param $keysOnly |
||
3934 | * @return array |
||
3935 | */ |
||
3936 | |||
3937 | public function columns(bool $keysOnly=true) : array |
||
3941 | |||
3942 | /** |
||
3943 | * @param string $field |
||
3944 | * @param mixed $value |
||
3945 | * @param array $pdoMetaData |
||
3946 | * @return float|int |
||
3947 | * @throws Exception |
||
3948 | */ |
||
3949 | protected function _fixTypeToSentinel(string $field, $value, array $pdoMetaData=[]) |
||
4001 | |||
4002 | /** |
||
4003 | * @param string $field |
||
4004 | * @param mixed $value |
||
4005 | * @param bool|false $permissive |
||
4006 | * @return float|int|null|string |
||
4007 | */ |
||
4008 | protected function _fixType(string $field, $value, bool $permissive=false) |
||
4059 | |||
4060 | /** |
||
4061 | * @param stdClass $record |
||
4062 | * @param string $type |
||
4063 | * @return stdClass |
||
4064 | */ |
||
4065 | public function fixTypesToSentinel(stdClass $record, string $type='') : stdClass |
||
4092 | |||
4093 | /** |
||
4094 | * @param stdClass $record |
||
4095 | * @param string $type |
||
4096 | * @return stdClass |
||
4097 | * @throws Exception |
||
4098 | */ |
||
4099 | public function applyHandlers(stdClass $record, string $type='INSERT') : stdClass |
||
4127 | |||
4128 | /** |
||
4129 | * @param string $field |
||
4130 | * @param mixed $value |
||
4131 | * @param string $type |
||
4132 | * @param stdClass $record |
||
4133 | * @return null |
||
4134 | * @throws Exception |
||
4135 | */ |
||
4136 | protected function applyHandler(string $field, $value, string $type='', stdClass $record=null) |
||
4160 | |||
4161 | /** |
||
4162 | * @param string $start |
||
4163 | * @param string $end |
||
4164 | * @param string $hayStack |
||
4165 | * @return mixed |
||
4166 | */ |
||
4167 | public static function between(string $start, string $end, string $hayStack) : string |
||
4171 | |||
4172 | /** |
||
4173 | * @param string $needle |
||
4174 | * @param string $hayStack |
||
4175 | * @param bool $returnOrigIfNeedleNotExists |
||
4176 | * @return mixed |
||
4177 | */ |
||
4178 | public static function before(string $needle, string $hayStack, bool $returnOrigIfNeedleNotExists=false) : string |
||
4188 | |||
4189 | /** |
||
4190 | * @param string $needle |
||
4191 | * @param string $hayStack |
||
4192 | * @param bool $returnOrigIfNeedleNotExists |
||
4193 | * @return string |
||
4194 | */ |
||
4195 | public static function after(string $needle, string $hayStack, bool $returnOrigIfNeedleNotExists=false) : string |
||
4204 | |||
4205 | /** |
||
4206 | * @return int |
||
4207 | */ |
||
4208 | public function getUserId() |
||
4212 | |||
4213 | /** |
||
4214 | * @param string $entity |
||
4215 | * @param int $id |
||
4216 | * @return int |
||
4217 | */ |
||
4218 | public function getMaskByResourceAndId(string $entity, int $id) : int |
||
4222 | |||
4223 | /** |
||
4224 | * @param string|int|null $time |
||
4225 | * @return string |
||
4226 | */ |
||
4227 | public static function date($time=null) : string |
||
4231 | |||
4232 | /** |
||
4233 | * @param string|int|null $time |
||
4234 | * @return string |
||
4235 | */ |
||
4236 | public static function dateTime($time=null) : string |
||
4240 | |||
4241 | /** |
||
4242 | * @param string|int|null $time |
||
4243 | * @return string |
||
4244 | */ |
||
4245 | public static function atom($time=null) : string |
||
4249 | |||
4250 | /** |
||
4251 | * @param string|int|null $time |
||
4252 | * @return int |
||
4253 | */ |
||
4254 | public static function getTime($time=null) : int |
||
4267 | |||
4268 | |||
4269 | /** |
||
4270 | * @param int $id |
||
4271 | * @param int $cacheTtl |
||
4272 | * @return string |
||
4273 | */ |
||
4274 | public function getCodeById(int $id, int $cacheTtl=self::ONE_DAY) : string |
||
4282 | } |
||
4283 |