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 ONE_DAY = 86400; |
||
41 | const ONE_WEEK = 60480060; |
||
42 | const ONE_HOUR = 3600; |
||
43 | const TEN_MINS = 600; |
||
44 | const OPERATOR_AND = ' AND '; |
||
45 | const OPERATOR_OR = ' OR '; |
||
46 | const ORDERBY_ASC = 'ASC'; |
||
47 | const ORDERBY_DESC = 'DESC'; |
||
48 | const SAVE_INSERT = 'INSERT'; |
||
49 | const SAVE_UPDATE = 'UPDATE'; |
||
50 | const LEFT_JOIN = 'LEFT'; |
||
51 | const INNER_JOIN = 'INNER'; |
||
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 $globalRemoveUnauthorisedFields = [ |
||
218 | '/global_table_meta#view' => [ |
||
219 | 'created_by_id', |
||
220 | 'created_by', |
||
221 | 'created_ts', |
||
222 | 'modified_by_id', |
||
223 | 'modified_by', |
||
224 | 'modified_ts', |
||
225 | 'status', |
||
226 | ], |
||
227 | ]; |
||
228 | |||
229 | |||
230 | /** |
||
231 | * @param AbstractPdo|null $connection |
||
232 | */ |
||
233 | public function __construct(AbstractPdo $connection=null) |
||
240 | |||
241 | public function init() |
||
243 | |||
244 | /** |
||
245 | * @return AbstractPdo |
||
246 | * @throws Exception |
||
247 | */ |
||
248 | public function getPdo() : AbstractPdo |
||
252 | |||
253 | /** |
||
254 | * @return LoggerInterface |
||
255 | */ |
||
256 | public function getLogger() : LoggerInterface |
||
260 | |||
261 | /** |
||
262 | * @return CacheInterface |
||
263 | */ |
||
264 | public function getCache() : CacheInterface |
||
268 | |||
269 | /** |
||
270 | * Define the working table and create a new instance |
||
271 | * |
||
272 | * @param string $tableName - Table name |
||
273 | * @param string $alias - The table alias name |
||
274 | * @param string $displayColumn |
||
275 | * @param string $primaryKeyName |
||
276 | * |
||
277 | * @return FluentPdoModel |
||
278 | */ |
||
279 | public function table(string $tableName, string $alias='', string $displayColumn='', string $primaryKeyName='id') : FluentPdoModel |
||
287 | |||
288 | /** |
||
289 | * @param string $primaryKeyName |
||
290 | * @return FluentPdoModel |
||
291 | */ |
||
292 | public function primaryKeyName(string $primaryKeyName) : FluentPdoModel |
||
298 | |||
299 | /** |
||
300 | * @param string $tableName |
||
301 | * |
||
302 | * @return FluentPdoModel |
||
303 | */ |
||
304 | public function tableName(string $tableName) : FluentPdoModel |
||
310 | |||
311 | /** |
||
312 | * @param $explicitSelect |
||
313 | * |
||
314 | * @return FluentPdoModel |
||
315 | */ |
||
316 | public function explicitSelectMode(bool $explicitSelect=true) : FluentPdoModel |
||
322 | |||
323 | /** |
||
324 | * @param bool $filterOnFetch |
||
325 | * |
||
326 | * @return FluentPdoModel |
||
327 | */ |
||
328 | public function filterOnFetch(bool $filterOnFetch=true) : FluentPdoModel |
||
334 | |||
335 | /** |
||
336 | * @param bool $logFilterChanges |
||
337 | * |
||
338 | * @return FluentPdoModel |
||
339 | */ |
||
340 | public function logFilterChanges(bool $logFilterChanges=true) : FluentPdoModel |
||
346 | |||
347 | /** |
||
348 | * Return the name of the table |
||
349 | * |
||
350 | * @return string |
||
351 | */ |
||
352 | public function getTableName() : string |
||
356 | |||
357 | /** |
||
358 | * @return string |
||
359 | */ |
||
360 | public function getDisplayColumn() : string |
||
364 | |||
365 | /** |
||
366 | * Set the display column |
||
367 | * |
||
368 | * @param string $column |
||
369 | * |
||
370 | * @return FluentPdoModel |
||
371 | */ |
||
372 | public function displayColumn(string $column) : FluentPdoModel |
||
378 | /** |
||
379 | * Set the table alias |
||
380 | * |
||
381 | * @param string $alias |
||
382 | * |
||
383 | * @return FluentPdoModel |
||
384 | */ |
||
385 | public function tableAlias(string $alias) : FluentPdoModel |
||
391 | |||
392 | /** |
||
393 | * @param int $cacheTtl |
||
394 | * @return FluentPdoModel |
||
395 | * @throws Exception |
||
396 | */ |
||
397 | protected function _cacheTtl(int $cacheTtl) : FluentPdoModel |
||
408 | |||
409 | /** |
||
410 | * @return string |
||
411 | */ |
||
412 | public function getTableAlias() : string |
||
416 | |||
417 | /** |
||
418 | * @param array $associations |
||
419 | * |
||
420 | * @return FluentPdoModel |
||
421 | */ |
||
422 | public function associations(array $associations) : FluentPdoModel |
||
428 | |||
429 | /** |
||
430 | * @param string $alias |
||
431 | * @param array $definition |
||
432 | * @return FluentPdoModel |
||
433 | */ |
||
434 | public function setBelongsTo(string $alias, array $definition) : FluentPdoModel |
||
443 | |||
444 | /** |
||
445 | * @param $alias |
||
446 | * @param $displayField |
||
447 | * @return FluentPdoModel |
||
448 | * @throws \Terah\Assert\AssertionFailedException |
||
449 | */ |
||
450 | public function setBelongsToDisplayField(string $alias, string $displayField) : FluentPdoModel |
||
460 | |||
461 | /** |
||
462 | * @param PDOStatement $stmt |
||
463 | * |
||
464 | * @param PDOStatement $stmt |
||
465 | * @param Closure $fnCallback |
||
466 | * @return bool|stdClass |
||
467 | */ |
||
468 | public function fetchRow(PDOStatement $stmt, Closure $fnCallback=null) |
||
488 | |||
489 | /** |
||
490 | * @param array $schema |
||
491 | * |
||
492 | * @return FluentPdoModel |
||
493 | */ |
||
494 | public function schema(array $schema) : FluentPdoModel |
||
500 | |||
501 | /** |
||
502 | * @param string|array $field |
||
503 | * @param $type |
||
504 | * @return FluentPdoModel |
||
505 | */ |
||
506 | public function addSchema($field, string $type) : FluentPdoModel |
||
522 | |||
523 | /** |
||
524 | * @param $keysOnly |
||
525 | * @return array |
||
526 | */ |
||
527 | public function getColumns(bool $keysOnly=true) : array |
||
531 | |||
532 | /** |
||
533 | * Get the primary key name |
||
534 | * |
||
535 | * @return string |
||
536 | */ |
||
537 | public function getPrimaryKeyName() : string |
||
541 | |||
542 | /** |
||
543 | * @param string $query |
||
544 | * @param array $parameters |
||
545 | * |
||
546 | * @return bool |
||
547 | * @throws Exception |
||
548 | */ |
||
549 | public function execute(string $query, array $parameters=[]) : bool |
||
574 | |||
575 | /** |
||
576 | * @param string $query |
||
577 | * @param array $params |
||
578 | * @return FluentPdoModel |
||
579 | */ |
||
580 | public function query(string $query, array $params=[]) : FluentPdoModel |
||
587 | |||
588 | /** |
||
589 | * @param string $sql |
||
590 | * @param array $params |
||
591 | * |
||
592 | * @return string |
||
593 | */ |
||
594 | public function buildQuery(string $sql, array $params=[]) : string |
||
622 | |||
623 | /** |
||
624 | * @param stdClass $record |
||
625 | * |
||
626 | * @return stdClass |
||
627 | */ |
||
628 | protected function _trimAndLowerCaseKeys(stdClass $record) : stdClass |
||
638 | |||
639 | /** |
||
640 | * Return the number of affected row by the last statement |
||
641 | * |
||
642 | * @return int |
||
643 | */ |
||
644 | public function rowCount() : int |
||
650 | |||
651 | /** |
||
652 | * @return PDOStatement|null |
||
653 | * @throws PDOException |
||
654 | */ |
||
655 | public function fetchStmt() |
||
664 | |||
665 | /** |
||
666 | * @return array |
||
667 | */ |
||
668 | public function fetchSqlQuery() : array |
||
678 | |||
679 | /** |
||
680 | * @param string $tableName |
||
681 | * @param bool $dropIfExists |
||
682 | * @param array $indexes |
||
683 | * @return boolean |
||
684 | * @throws Exception |
||
685 | */ |
||
686 | public function fetchIntoMemoryTable(string $tableName, bool $dropIfExists=true, array $indexes=[]) : bool |
||
708 | |||
709 | /** |
||
710 | * @param string $keyedOn |
||
711 | * @param int $cacheTtl |
||
712 | * @return stdClass[] |
||
713 | */ |
||
714 | public function fetch(string $keyedOn='', int $cacheTtl=self::CACHE_NO) : array |
||
752 | |||
753 | /** |
||
754 | * @return string |
||
755 | */ |
||
756 | protected function _parseWhereForPrimaryLookup() : string |
||
772 | |||
773 | /** |
||
774 | * @param string $cacheKey |
||
775 | * @param Closure $func |
||
776 | * @param int $cacheTtl - 0 for default ttl, -1 for no cache or int for custom ttl |
||
777 | * @return mixed |
||
778 | */ |
||
779 | protected function _cacheData(string $cacheKey, Closure $func, int $cacheTtl=self::CACHE_DEFAULT) |
||
817 | |||
818 | /** |
||
819 | * @param string $cacheKey |
||
820 | * @return bool |
||
821 | */ |
||
822 | public function clearCache(string $cacheKey) : bool |
||
826 | |||
827 | /** |
||
828 | * @param string $table |
||
829 | * @return bool |
||
830 | */ |
||
831 | public function clearCacheByTable(string $table='') : bool |
||
841 | |||
842 | /** |
||
843 | * @param Closure $fnCallback |
||
844 | * @return int |
||
845 | */ |
||
846 | public function fetchCallback(Closure $fnCallback) : int |
||
855 | |||
856 | /** |
||
857 | * @param Closure $fnCallback |
||
858 | * @param string $keyedOn |
||
859 | * @return array |
||
860 | */ |
||
861 | public function fetchObjectsByCallback(Closure $fnCallback, string $keyedOn='') : array |
||
878 | |||
879 | /** |
||
880 | * @param $numFailures |
||
881 | * @return FluentPdoModel |
||
882 | */ |
||
883 | public function maxCallbackFailures(int $numFailures) : FluentPdoModel |
||
890 | |||
891 | /** |
||
892 | * @param PDOStatement $stmt |
||
893 | * @param Closure $fnCallback |
||
894 | * @param int $successCnt |
||
895 | * @return bool|null|stdClass |
||
896 | */ |
||
897 | protected function _tallySuccessCount(PDOStatement $stmt, Closure $fnCallback, int &$successCnt) |
||
928 | |||
929 | /** |
||
930 | * @return bool |
||
931 | */ |
||
932 | public function canGenericUpdate() : bool |
||
936 | |||
937 | /** |
||
938 | * @return bool |
||
939 | */ |
||
940 | public function canGenericAdd() : bool |
||
944 | |||
945 | /** |
||
946 | * @return bool |
||
947 | */ |
||
948 | public function canGenericDelete() : bool |
||
952 | |||
953 | /** |
||
954 | * @param string $keyedOn |
||
955 | * @param string $valueField |
||
956 | * @param int $cacheTtl |
||
957 | * @return mixed |
||
958 | */ |
||
959 | public function fetchList(string $keyedOn='', string $valueField='', int $cacheTtl=self::CACHE_NO) : array |
||
1011 | |||
1012 | /** |
||
1013 | * @param string $column |
||
1014 | * @param int $cacheTtl |
||
1015 | * @param bool|true $unique |
||
1016 | * @return array |
||
1017 | */ |
||
1018 | public function fetchColumn(string $column, int $cacheTtl=self::CACHE_NO, bool $unique=true) : array |
||
1027 | |||
1028 | /** |
||
1029 | * @param null|string $field |
||
1030 | * @param null|int $itemId |
||
1031 | * @param int $cacheTtl |
||
1032 | * @return mixed|null |
||
1033 | */ |
||
1034 | public function fetchField(string $field='', int $itemId=0, int $cacheTtl=self::CACHE_NO) |
||
1057 | |||
1058 | /** |
||
1059 | * @param string $field |
||
1060 | * @param int $itemId |
||
1061 | * @param int $cacheTtl |
||
1062 | * @return string |
||
1063 | */ |
||
1064 | public function fetchStr(string $field='', $itemId=0, int $cacheTtl=self::CACHE_NO) : string |
||
1068 | |||
1069 | /** |
||
1070 | * @param int $cacheTtl |
||
1071 | * @return int |
||
1072 | */ |
||
1073 | public function fetchId(int $cacheTtl=self::CACHE_NO) : int |
||
1077 | |||
1078 | /** |
||
1079 | * @param string $field |
||
1080 | * @param int $itemId |
||
1081 | * @param int $cacheTtl |
||
1082 | * @return int |
||
1083 | */ |
||
1084 | public function fetchInt(string $field='', $itemId=0, int $cacheTtl=self::CACHE_NO) : int |
||
1088 | |||
1089 | /** |
||
1090 | * @param string $field |
||
1091 | * @param int $itemId |
||
1092 | * @param int $cacheTtl |
||
1093 | * @return float |
||
1094 | */ |
||
1095 | public function fetchFloat(string $field='', $itemId=0, int $cacheTtl=self::CACHE_NO) : float |
||
1099 | |||
1100 | /** |
||
1101 | * @param string $field |
||
1102 | * @param int $itemId |
||
1103 | * @param int $cacheTtl |
||
1104 | * @return bool |
||
1105 | */ |
||
1106 | public function fetchBool(string $field='', $itemId=0, int $cacheTtl=self::CACHE_NO) : bool |
||
1110 | |||
1111 | /** |
||
1112 | * @param int|null $id |
||
1113 | * @param int $cacheTtl |
||
1114 | * @return stdClass|bool |
||
1115 | */ |
||
1116 | public function fetchOne(int $id=0, int $cacheTtl=self::CACHE_NO) |
||
1127 | |||
1128 | /** |
||
1129 | * @param int|null $id |
||
1130 | * @param int $cacheTtl |
||
1131 | * @return boolean |
||
1132 | */ |
||
1133 | public function fetchExists(int $id=0, int $cacheTtl=self::CACHE_NO) : bool |
||
1142 | |||
1143 | /*------------------------------------------------------------------------------ |
||
1144 | Fluent Query Builder |
||
1145 | *-----------------------------------------------------------------------------*/ |
||
1146 | |||
1147 | /** |
||
1148 | * Create the select clause |
||
1149 | * |
||
1150 | * @param mixed $columns - the column to select. Can be string or array of fields |
||
1151 | * @param string $alias - an alias to the column |
||
1152 | * @param boolean $explicitSelect |
||
1153 | * @return FluentPdoModel |
||
1154 | */ |
||
1155 | public function select($columns='*', string $alias='', bool $explicitSelect=true) : FluentPdoModel |
||
1197 | |||
1198 | /** |
||
1199 | * @param string $select |
||
1200 | * @return FluentPdoModel |
||
1201 | */ |
||
1202 | public function selectRaw(string $select) : FluentPdoModel |
||
1208 | |||
1209 | /** |
||
1210 | * @param bool $logQueries |
||
1211 | * |
||
1212 | * @return FluentPdoModel |
||
1213 | */ |
||
1214 | public function logQueries(bool $logQueries=true) : FluentPdoModel |
||
1220 | |||
1221 | /** |
||
1222 | * @param bool $includeCnt |
||
1223 | * |
||
1224 | * @return FluentPdoModel |
||
1225 | */ |
||
1226 | public function includeCount(bool $includeCnt=true) : FluentPdoModel |
||
1232 | |||
1233 | /** |
||
1234 | * @param bool $distinct |
||
1235 | * |
||
1236 | * @return FluentPdoModel |
||
1237 | */ |
||
1238 | public function distinct(bool $distinct=true) : FluentPdoModel |
||
1244 | |||
1245 | /** |
||
1246 | * @param array $fields |
||
1247 | * @return FluentPdoModel |
||
1248 | */ |
||
1249 | public function withBelongsTo(array $fields=[]) : FluentPdoModel |
||
1262 | |||
1263 | /** |
||
1264 | * @param string $alias |
||
1265 | * @param string $type |
||
1266 | * @param bool $addSelectField |
||
1267 | * @return FluentPdoModel |
||
1268 | */ |
||
1269 | public function autoJoin(string $alias, string $type=self::LEFT_JOIN, bool $addSelectField=true) : FluentPdoModel |
||
1286 | |||
1287 | /** |
||
1288 | * Add where condition, more calls appends with AND |
||
1289 | * |
||
1290 | * @param string $condition possibly containing ? or :name |
||
1291 | * @param mixed $parameters accepted by PDOStatement::execute or a scalar value |
||
1292 | * @param mixed ... |
||
1293 | * @return FluentPdoModel |
||
1294 | */ |
||
1295 | public function where($condition, $parameters=[]) : FluentPdoModel |
||
1344 | |||
1345 | /** |
||
1346 | * Create an AND operator in the where clause |
||
1347 | * |
||
1348 | * @return FluentPdoModel |
||
1349 | */ |
||
1350 | public function _and() : FluentPdoModel |
||
1364 | |||
1365 | |||
1366 | /** |
||
1367 | * Create an OR operator in the where clause |
||
1368 | * |
||
1369 | * @return FluentPdoModel |
||
1370 | */ |
||
1371 | public function _or() : FluentPdoModel |
||
1385 | |||
1386 | /** |
||
1387 | * To group multiple where clauses together. |
||
1388 | * |
||
1389 | * @return FluentPdoModel |
||
1390 | */ |
||
1391 | public function wrap() : FluentPdoModel |
||
1401 | |||
1402 | /** |
||
1403 | * Where Primary key |
||
1404 | * |
||
1405 | * @param int $id |
||
1406 | * @param bool $addAlias |
||
1407 | * |
||
1408 | * @return FluentPdoModel |
||
1409 | */ |
||
1410 | public function wherePk(int $id, bool $addAlias=true) : FluentPdoModel |
||
1416 | |||
1417 | /** |
||
1418 | * WHERE $columnName != $value |
||
1419 | * |
||
1420 | * @param string $columnName |
||
1421 | * @param mixed $value |
||
1422 | * @return FluentPdoModel |
||
1423 | */ |
||
1424 | public function whereNot(string $columnName, $value) : FluentPdoModel |
||
1428 | /** |
||
1429 | * WHERE $columnName != $value |
||
1430 | * |
||
1431 | * @param string $columnName |
||
1432 | * @param mixed $value |
||
1433 | * @return FluentPdoModel |
||
1434 | */ |
||
1435 | public function whereCoercedNot(string $columnName, $value) : FluentPdoModel |
||
1439 | |||
1440 | /** |
||
1441 | * WHERE $columnName LIKE $value |
||
1442 | * |
||
1443 | * @param string $columnName |
||
1444 | * @param mixed $value |
||
1445 | * @return FluentPdoModel |
||
1446 | */ |
||
1447 | public function whereLike(string $columnName, $value) : FluentPdoModel |
||
1451 | |||
1452 | /** |
||
1453 | * @param string $columnName |
||
1454 | * @param mixed $value1 |
||
1455 | * @param mixed $value2 |
||
1456 | * @return FluentPdoModel |
||
1457 | */ |
||
1458 | public function whereBetween(string $columnName, $value1, $value2) : FluentPdoModel |
||
1462 | |||
1463 | /** |
||
1464 | * @param string $columnName |
||
1465 | * @param mixed $value1 |
||
1466 | * @param mixed $value2 |
||
1467 | * @return FluentPdoModel |
||
1468 | */ |
||
1469 | public function whereNotBetween(string $columnName, $value1, $value2) : FluentPdoModel |
||
1473 | |||
1474 | /** |
||
1475 | * @param string $columnName |
||
1476 | * @param string $regex |
||
1477 | * @return FluentPdoModel |
||
1478 | */ |
||
1479 | public function whereRegex(string $columnName, string $regex) : FluentPdoModel |
||
1483 | |||
1484 | /** |
||
1485 | * @param string $columnName |
||
1486 | * @param string $regex |
||
1487 | * @return FluentPdoModel |
||
1488 | */ |
||
1489 | public function whereNotRegex(string $columnName, string $regex) : FluentPdoModel |
||
1493 | |||
1494 | /** |
||
1495 | * WHERE $columnName NOT LIKE $value |
||
1496 | * |
||
1497 | * @param string $columnName |
||
1498 | * @param string $value |
||
1499 | * @return FluentPdoModel |
||
1500 | */ |
||
1501 | public function whereNotLike(string $columnName, string $value) : FluentPdoModel |
||
1505 | |||
1506 | /** |
||
1507 | * WHERE $columnName > $value |
||
1508 | * |
||
1509 | * @param string $columnName |
||
1510 | * @param mixed $value |
||
1511 | * @return FluentPdoModel |
||
1512 | */ |
||
1513 | public function whereGt(string $columnName, $value) : FluentPdoModel |
||
1517 | |||
1518 | /** |
||
1519 | * WHERE $columnName >= $value |
||
1520 | * |
||
1521 | * @param string $columnName |
||
1522 | * @param mixed $value |
||
1523 | * @return FluentPdoModel |
||
1524 | */ |
||
1525 | public function whereGte(string $columnName, $value) : FluentPdoModel |
||
1529 | |||
1530 | /** |
||
1531 | * WHERE $columnName < $value |
||
1532 | * |
||
1533 | * @param string $columnName |
||
1534 | * @param mixed $value |
||
1535 | * @return FluentPdoModel |
||
1536 | */ |
||
1537 | public function whereLt(string $columnName, $value) : FluentPdoModel |
||
1541 | |||
1542 | /** |
||
1543 | * WHERE $columnName <= $value |
||
1544 | * |
||
1545 | * @param string $columnName |
||
1546 | * @param mixed $value |
||
1547 | * @return FluentPdoModel |
||
1548 | */ |
||
1549 | public function whereLte(string $columnName, $value) : FluentPdoModel |
||
1553 | |||
1554 | /** |
||
1555 | * WHERE $columnName IN (?,?,?,...) |
||
1556 | * |
||
1557 | * @param string $columnName |
||
1558 | * @param array $values |
||
1559 | * @return FluentPdoModel |
||
1560 | */ |
||
1561 | public function whereIn(string $columnName, array $values) : FluentPdoModel |
||
1565 | |||
1566 | /** |
||
1567 | * WHERE $columnName NOT IN (?,?,?,...) |
||
1568 | * |
||
1569 | * @param string $columnName |
||
1570 | * @param array $values |
||
1571 | * @return FluentPdoModel |
||
1572 | */ |
||
1573 | public function whereNotIn(string $columnName, array $values) : FluentPdoModel |
||
1579 | |||
1580 | /** |
||
1581 | * WHERE $columnName IS NULL |
||
1582 | * |
||
1583 | * @param string $columnName |
||
1584 | * @return FluentPdoModel |
||
1585 | */ |
||
1586 | public function whereNull(string $columnName) : FluentPdoModel |
||
1590 | |||
1591 | /** |
||
1592 | * WHERE $columnName IS NOT NULL |
||
1593 | * |
||
1594 | * @param string $columnName |
||
1595 | * @return FluentPdoModel |
||
1596 | */ |
||
1597 | public function whereNotNull(string $columnName) : FluentPdoModel |
||
1601 | |||
1602 | /** |
||
1603 | * @param string $statement |
||
1604 | * @param string $operator |
||
1605 | * @return FluentPdoModel |
||
1606 | */ |
||
1607 | public function having(string $statement, string $operator=self::OPERATOR_AND) : FluentPdoModel |
||
1616 | |||
1617 | /** |
||
1618 | * ORDER BY $columnName (ASC | DESC) |
||
1619 | * |
||
1620 | * @param string $columnName - The name of the column or an expression |
||
1621 | * @param string $ordering (DESC | ASC) |
||
1622 | * @return FluentPdoModel |
||
1623 | */ |
||
1624 | public function orderBy(string $columnName='', string $ordering='DESC') : FluentPdoModel |
||
1638 | |||
1639 | /** |
||
1640 | * GROUP BY $columnName |
||
1641 | * |
||
1642 | * @param string $columnName |
||
1643 | * @return FluentPdoModel |
||
1644 | */ |
||
1645 | public function groupBy(string $columnName) : FluentPdoModel |
||
1655 | |||
1656 | |||
1657 | /** |
||
1658 | * LIMIT $limit |
||
1659 | * |
||
1660 | * @param int $limit |
||
1661 | * @param int|null $offset |
||
1662 | * @return FluentPdoModel |
||
1663 | */ |
||
1664 | public function limit(int $limit, int $offset=0) : FluentPdoModel |
||
1673 | |||
1674 | /** |
||
1675 | * Return the limit |
||
1676 | * |
||
1677 | * @return integer |
||
1678 | */ |
||
1679 | public function getLimit() : int |
||
1683 | |||
1684 | /** |
||
1685 | * OFFSET $offset |
||
1686 | * |
||
1687 | * @param int $offset |
||
1688 | * @return FluentPdoModel |
||
1689 | */ |
||
1690 | public function offset(int $offset) : FluentPdoModel |
||
1696 | |||
1697 | /** |
||
1698 | * Return the offset |
||
1699 | * |
||
1700 | * @return integer |
||
1701 | */ |
||
1702 | public function getOffset() : int |
||
1706 | |||
1707 | /** |
||
1708 | * Build a join |
||
1709 | * |
||
1710 | * @param string $table - The table name |
||
1711 | * @param string $constraint -> id = profile.user_id |
||
1712 | * @param string $tableAlias - The alias of the table name |
||
1713 | * @param string $joinOperator - LEFT | INNER | etc... |
||
1714 | * @return FluentPdoModel |
||
1715 | */ |
||
1716 | public function join(string $table, string $constraint='', string $tableAlias='', string $joinOperator='') : FluentPdoModel |
||
1735 | |||
1736 | /** |
||
1737 | * Create a left join |
||
1738 | * |
||
1739 | * @param string $table |
||
1740 | * @param string $constraint |
||
1741 | * @param string $tableAlias |
||
1742 | * @return FluentPdoModel |
||
1743 | */ |
||
1744 | public function leftJoin(string $table, string $constraint, string $tableAlias='') : FluentPdoModel |
||
1748 | |||
1749 | |||
1750 | /** |
||
1751 | * Return the build select query |
||
1752 | * |
||
1753 | * @return string |
||
1754 | */ |
||
1755 | public function getSelectQuery() : string |
||
1798 | |||
1799 | /** |
||
1800 | * Prepare columns to include the table alias name |
||
1801 | * @param array $columns |
||
1802 | * @return array |
||
1803 | */ |
||
1804 | protected function _prepareColumns(array $columns) : array |
||
1834 | |||
1835 | /** |
||
1836 | * Build the WHERE clause(s) |
||
1837 | * |
||
1838 | * @param bool $purgeAliases |
||
1839 | * @return string |
||
1840 | */ |
||
1841 | protected function _getWhereString(bool $purgeAliases=false) : string |
||
1874 | |||
1875 | /** |
||
1876 | * Return the HAVING clause |
||
1877 | * |
||
1878 | * @return string |
||
1879 | */ |
||
1880 | protected function _getHavingString() : string |
||
1899 | |||
1900 | /** |
||
1901 | * Return the values to be bound for where |
||
1902 | * |
||
1903 | * @param bool $purgeAliases |
||
1904 | * @return array |
||
1905 | */ |
||
1906 | protected function _getWhereParameters(bool $purgeAliases=false) : array |
||
1912 | |||
1913 | /** |
||
1914 | * @param array $record |
||
1915 | * @return stdClass |
||
1916 | */ |
||
1917 | public function insertArr(array $record) : stdClass |
||
1921 | |||
1922 | /** |
||
1923 | * Insert new rows |
||
1924 | * $records can be a stdClass or an array of stdClass to add a bulk insert |
||
1925 | * If a single row is inserted, it will return it's row instance |
||
1926 | * |
||
1927 | * @param stdClass $record |
||
1928 | * @return stdClass |
||
1929 | * @throws Exception |
||
1930 | */ |
||
1931 | public function insert(stdClass $record) : stdClass |
||
1954 | |||
1955 | /** |
||
1956 | * @param string $name |
||
1957 | * @return int |
||
1958 | */ |
||
1959 | public function getLastInsertId(string $name='') : int |
||
1963 | |||
1964 | /** |
||
1965 | * @param stdClass[] $records |
||
1966 | * @return stdClass[] |
||
1967 | */ |
||
1968 | public function insertSqlQuery(array $records) : array |
||
1988 | |||
1989 | /** |
||
1990 | * @param $data |
||
1991 | * @param array $matchOn |
||
1992 | * @param bool $returnObj |
||
1993 | * @return bool|int|stdClass |
||
1994 | */ |
||
1995 | public function upsert($data, array $matchOn=[], $returnObj=false) |
||
2017 | |||
2018 | /** |
||
2019 | * @param stdClass $object |
||
2020 | * @param array $matchOn |
||
2021 | * @param bool $returnObj |
||
2022 | * @return bool|int|stdClass |
||
2023 | */ |
||
2024 | public function upsertOne(stdClass $object, array $matchOn=[], $returnObj=false) |
||
2064 | |||
2065 | /** |
||
2066 | * @param array $data |
||
2067 | * @param array $matchOn |
||
2068 | * @param bool|false $returnObj |
||
2069 | * @return bool|int|stdClass |
||
2070 | */ |
||
2071 | public function upsertArr(array $data, array $matchOn=[], bool $returnObj=false) |
||
2075 | |||
2076 | /** |
||
2077 | * Update entries |
||
2078 | * Use the query builder to create the where clause |
||
2079 | * |
||
2080 | * @param stdClass $record |
||
2081 | * @param bool $updateAll |
||
2082 | * @return int |
||
2083 | * @throws Exception |
||
2084 | */ |
||
2085 | public function update(stdClass $record, $updateAll=false) : int |
||
2108 | |||
2109 | /** |
||
2110 | * @param array $record |
||
2111 | * @param bool|false $updateAll |
||
2112 | * @return int |
||
2113 | * @throws Exception |
||
2114 | */ |
||
2115 | public function updateArr(array $record, $updateAll=false) : int |
||
2119 | |||
2120 | |||
2121 | /** |
||
2122 | * @param string $field |
||
2123 | * @param mixed $value |
||
2124 | * @param int $id |
||
2125 | * @param bool|false $updateAll |
||
2126 | * @return int |
||
2127 | * @throws Exception |
||
2128 | */ |
||
2129 | public function updateField(string $field, $value, int $id=0, bool $updateAll=false) : int |
||
2138 | |||
2139 | /** |
||
2140 | * @param stdClass $record |
||
2141 | * @return bool|int |
||
2142 | * @throws Exception |
||
2143 | */ |
||
2144 | public function updateChanged(stdClass $record) : int |
||
2158 | |||
2159 | /** |
||
2160 | * @param string $expression |
||
2161 | * @param array $params |
||
2162 | * @return FluentPdoModel |
||
2163 | */ |
||
2164 | public function updateByExpression(string $expression, array $params) : FluentPdoModel |
||
2170 | |||
2171 | /** |
||
2172 | * @param array $data |
||
2173 | * @return int |
||
2174 | * @throws Exception |
||
2175 | */ |
||
2176 | public function rawUpdate(array $data=[]) : int |
||
2185 | |||
2186 | /** |
||
2187 | * @param stdClass $record |
||
2188 | * @return array |
||
2189 | */ |
||
2190 | public function updateSqlQuery(stdClass $record) : array |
||
2200 | |||
2201 | /** |
||
2202 | * @param $record |
||
2203 | * @return array |
||
2204 | */ |
||
2205 | protected function updateSql(array $record) : array |
||
2236 | |||
2237 | /** |
||
2238 | * @param bool $deleteAll |
||
2239 | * @param bool $force |
||
2240 | * @return int |
||
2241 | * @throws Exception |
||
2242 | */ |
||
2243 | public function delete(bool $deleteAll=false, bool $force=false) : int |
||
2259 | |||
2260 | /** |
||
2261 | * @param bool|false $force |
||
2262 | * @return FluentPdoModel |
||
2263 | * @throws Exception |
||
2264 | */ |
||
2265 | public function truncate(bool $force=false) : FluentPdoModel |
||
2279 | |||
2280 | /** |
||
2281 | * @return array |
||
2282 | */ |
||
2283 | public function deleteSqlQuery() : array |
||
2295 | |||
2296 | |||
2297 | /** |
||
2298 | * Return the aggregate count of column |
||
2299 | * |
||
2300 | * @param string $column |
||
2301 | * @param int $cacheTtl |
||
2302 | * @return float |
||
2303 | */ |
||
2304 | public function count(string $column='*', int $cacheTtl=self::CACHE_NO) : float |
||
2310 | |||
2311 | |||
2312 | /** |
||
2313 | * Return the aggregate max count of column |
||
2314 | * |
||
2315 | * @param string $column |
||
2316 | * @param int $cacheTtl |
||
2317 | * @return int|float|string|null |
||
2318 | */ |
||
2319 | public function max(string $column, int $cacheTtl=self::CACHE_NO) |
||
2325 | |||
2326 | |||
2327 | /** |
||
2328 | * Return the aggregate min count of column |
||
2329 | * |
||
2330 | * @param string $column |
||
2331 | * @param int $cacheTtl |
||
2332 | * @return int|float|string|null |
||
2333 | */ |
||
2334 | public function min(string $column, int $cacheTtl=self::CACHE_NO) |
||
2340 | |||
2341 | /** |
||
2342 | * Return the aggregate sum count of column |
||
2343 | * |
||
2344 | * @param string $column |
||
2345 | * @param int $cacheTtl |
||
2346 | * @return int|float|string|null |
||
2347 | */ |
||
2348 | public function sum(string $column, int $cacheTtl=self::CACHE_NO) |
||
2354 | |||
2355 | /** |
||
2356 | * Return the aggregate average count of column |
||
2357 | * |
||
2358 | * @param string $column |
||
2359 | * @param int $cacheTtl |
||
2360 | * @return int|float|string|null |
||
2361 | */ |
||
2362 | public function avg(string $column, int $cacheTtl=self::CACHE_NO) |
||
2368 | |||
2369 | /*******************************************************************************/ |
||
2370 | // Utilities methods |
||
2371 | |||
2372 | /** |
||
2373 | * Reset fields |
||
2374 | * |
||
2375 | * @return FluentPdoModel |
||
2376 | */ |
||
2377 | public function reset() : FluentPdoModel |
||
2405 | |||
2406 | |||
2407 | /** |
||
2408 | * @return FluentPdoModel |
||
2409 | */ |
||
2410 | public function removeUnauthorisedFields() : FluentPdoModel |
||
2414 | |||
2415 | /** |
||
2416 | * @return Closure[] |
||
2417 | */ |
||
2418 | protected function _getFieldHandlers() : array |
||
2485 | |||
2486 | /** |
||
2487 | * @return bool |
||
2488 | */ |
||
2489 | public function begin() : bool |
||
2503 | |||
2504 | /** |
||
2505 | * @return bool |
||
2506 | */ |
||
2507 | public function commit() : bool |
||
2525 | |||
2526 | /** |
||
2527 | * @return bool |
||
2528 | */ |
||
2529 | public function rollback() : bool |
||
2543 | |||
2544 | /** |
||
2545 | * @param stdClass $record |
||
2546 | * @param string $type |
||
2547 | * @return stdClass |
||
2548 | */ |
||
2549 | public function applyGlobalModifiers(stdClass $record, string $type) : stdClass |
||
2562 | |||
2563 | /** |
||
2564 | * @param stdClass $record |
||
2565 | * @param string $type |
||
2566 | * @return stdClass |
||
2567 | */ |
||
2568 | public function removeUnneededFields(stdClass $record, string $type) : stdClass |
||
2594 | |||
2595 | |||
2596 | /** |
||
2597 | * @param array $ids |
||
2598 | * @param array $values |
||
2599 | * @param int $batch |
||
2600 | * @return bool |
||
2601 | */ |
||
2602 | public function setById(array $ids, array $values, int $batch=1000) : bool |
||
2618 | |||
2619 | |||
2620 | /** |
||
2621 | * @param string $displayColumnValue |
||
2622 | * @return int |
||
2623 | */ |
||
2624 | public function resolveId(string $displayColumnValue) : int |
||
2635 | |||
2636 | /** |
||
2637 | * @param int $resourceId |
||
2638 | * @param array $query |
||
2639 | * @param array $extraFields |
||
2640 | * @param int $cacheTtl |
||
2641 | * @return array |
||
2642 | */ |
||
2643 | public function fetchApiResource(int $resourceId, array $query=[], array $extraFields=[], int $cacheTtl=self::CACHE_NO) : array |
||
2656 | |||
2657 | /** |
||
2658 | * @param array $query |
||
2659 | * @param array $extraFields |
||
2660 | * @param int $cacheTtl |
||
2661 | * @param string $permEntity |
||
2662 | * @return array |
||
2663 | */ |
||
2664 | public function fetchApiResources(array $query=[], array $extraFields=[], int $cacheTtl=self::CACHE_NO, string $permEntity='') : array |
||
2686 | |||
2687 | |||
2688 | /** |
||
2689 | * @return array |
||
2690 | */ |
||
2691 | public function getSearchableAssociations() : array |
||
2698 | |||
2699 | /** |
||
2700 | * @param array $fields |
||
2701 | */ |
||
2702 | public function removeUnrequestedFields(array $fields) |
||
2713 | |||
2714 | /** |
||
2715 | * @param array $removeFields |
||
2716 | */ |
||
2717 | public function removeFields(array $removeFields=[]) |
||
2742 | |||
2743 | /** |
||
2744 | * @return FluentPdoModel |
||
2745 | */ |
||
2746 | public function defaultFilters() : FluentPdoModel |
||
2750 | |||
2751 | /** |
||
2752 | * @param bool $allow |
||
2753 | * |
||
2754 | * @return FluentPdoModel |
||
2755 | */ |
||
2756 | public function allowMetaColumnOverride(bool $allow=false) : FluentPdoModel |
||
2762 | |||
2763 | /** |
||
2764 | * @param stdClass $record |
||
2765 | * @return stdClass |
||
2766 | */ |
||
2767 | public function onFetch(stdClass $record) : stdClass |
||
2779 | |||
2780 | /** |
||
2781 | * @param $value |
||
2782 | * @return string |
||
2783 | */ |
||
2784 | public function gzEncodeData(string $value) : string |
||
2793 | |||
2794 | /** |
||
2795 | * @param $value |
||
2796 | * @return mixed|string |
||
2797 | */ |
||
2798 | public function gzDecodeData(string $value) : string |
||
2808 | |||
2809 | /** |
||
2810 | * @param $value |
||
2811 | * @return bool |
||
2812 | */ |
||
2813 | protected function _hasGzipPrefix(string $value) : bool |
||
2817 | |||
2818 | /** |
||
2819 | * @param stdClass $record |
||
2820 | * @return stdClass |
||
2821 | */ |
||
2822 | public function fixTimestamps(stdClass $record) : stdClass |
||
2834 | |||
2835 | /** |
||
2836 | * @param int $max |
||
2837 | * @return FluentPdoModel |
||
2838 | */ |
||
2839 | public function setMaxRecords(int $max) : FluentPdoModel |
||
2846 | |||
2847 | |||
2848 | /** |
||
2849 | * @param stdClass $record |
||
2850 | * @param string $type |
||
2851 | * @return stdClass |
||
2852 | */ |
||
2853 | public function afterSave(stdClass $record, string $type) : stdClass |
||
2874 | |||
2875 | |||
2876 | /** |
||
2877 | * @param stdClass $record |
||
2878 | * @param string $type |
||
2879 | * @return stdClass |
||
2880 | */ |
||
2881 | public function addDefaultFields(stdClass $record, string $type) : stdClass |
||
2910 | |||
2911 | |||
2912 | /** |
||
2913 | * @return bool |
||
2914 | */ |
||
2915 | public function createTable() : bool |
||
2919 | |||
2920 | /** |
||
2921 | * @return bool |
||
2922 | */ |
||
2923 | public function dropTable() : bool |
||
2927 | |||
2928 | protected function _compileHandlers() |
||
2937 | |||
2938 | /** |
||
2939 | * @param string $viewName |
||
2940 | * @param int $cacheTtl |
||
2941 | * @return array |
||
2942 | */ |
||
2943 | public function getViewColumns($viewName, $cacheTtl=self::CACHE_NO) |
||
2947 | |||
2948 | /** |
||
2949 | * @param int $id |
||
2950 | * @return string |
||
2951 | */ |
||
2952 | public function getDisplayNameById(int $id) : string |
||
2962 | |||
2963 | /** |
||
2964 | * @param int $id |
||
2965 | * @param string $displayColumnValue |
||
2966 | * @return bool |
||
2967 | */ |
||
2968 | public function validIdDisplayNameCombo(int $id, $displayColumnValue) : bool |
||
2972 | |||
2973 | /** |
||
2974 | * @param array $toPopulate |
||
2975 | * @return stdClass |
||
2976 | */ |
||
2977 | protected function getEmptyObject(array $toPopulate=[]) : stdClass |
||
2983 | |||
2984 | /** |
||
2985 | * @param int $id |
||
2986 | * @return bool |
||
2987 | */ |
||
2988 | public static function isId(int $id) : bool |
||
2992 | |||
2993 | /** |
||
2994 | * @param int $cacheTtl |
||
2995 | * @return int |
||
2996 | */ |
||
2997 | public function activeCount(int $cacheTtl=self::CACHE_NO) : int |
||
3001 | |||
3002 | /** |
||
3003 | * @param string $tableAlias |
||
3004 | * @param string $columnName |
||
3005 | * @return FluentPdoModel |
||
3006 | */ |
||
3007 | public function whereActive(string $tableAlias='', string $columnName='status') : FluentPdoModel |
||
3011 | |||
3012 | /** |
||
3013 | * @param string $tableAlias |
||
3014 | * @param string $columnName |
||
3015 | * @return FluentPdoModel |
||
3016 | */ |
||
3017 | public function whereInactive(string $tableAlias='', string $columnName='status') : FluentPdoModel |
||
3021 | |||
3022 | /** |
||
3023 | * @param string $tableAlias |
||
3024 | * @param string $columnName |
||
3025 | * @return FluentPdoModel |
||
3026 | */ |
||
3027 | public function whereArchived(string $tableAlias='', string $columnName='status') : FluentPdoModel |
||
3031 | |||
3032 | /** |
||
3033 | * @param int $status |
||
3034 | * @param string $tableAlias |
||
3035 | * @param string $columnName |
||
3036 | * @return FluentPdoModel |
||
3037 | */ |
||
3038 | public function whereStatus(int $status, string $tableAlias='', string $columnName='status') : FluentPdoModel |
||
3047 | |||
3048 | /** |
||
3049 | * @param int $id |
||
3050 | * @return int |
||
3051 | */ |
||
3052 | public function updateActive(int $id=0) : int |
||
3062 | |||
3063 | /** |
||
3064 | * @param int $id |
||
3065 | * @return int |
||
3066 | */ |
||
3067 | public function updateInactive(int $id=0) : int |
||
3076 | |||
3077 | /** |
||
3078 | * @param string $field |
||
3079 | * @param int $id |
||
3080 | * @return int |
||
3081 | */ |
||
3082 | public function updateNow(string $field, int $id=0) : int |
||
3088 | /** |
||
3089 | * @param string $field |
||
3090 | * @param int $id |
||
3091 | * @return int |
||
3092 | */ |
||
3093 | public function updateToday($field, int $id=0) : int |
||
3099 | |||
3100 | /** |
||
3101 | * @param int $id |
||
3102 | * @return int |
||
3103 | */ |
||
3104 | public function updateArchived(int $id=0) : int |
||
3114 | |||
3115 | /** |
||
3116 | * @param int $status |
||
3117 | * @return int |
||
3118 | * @throws \Exception |
||
3119 | */ |
||
3120 | public function updateStatus(int $status) |
||
3126 | |||
3127 | /** |
||
3128 | * Return a YYYY-MM-DD HH:II:SS date format |
||
3129 | * |
||
3130 | * @param string $datetime - An english textual datetime description |
||
3131 | * now, yesterday, 3 days ago, +1 week |
||
3132 | * http://php.net/manual/en/function.strtotime.php |
||
3133 | * @return string YYYY-MM-DD HH:II:SS |
||
3134 | */ |
||
3135 | public static function NOW(string $datetime='now') : string |
||
3139 | |||
3140 | /** |
||
3141 | * Return a string containing the given number of question marks, |
||
3142 | * separated by commas. Eg '?, ?, ?' |
||
3143 | * |
||
3144 | * @param int - total of placeholder to insert |
||
3145 | * @return string |
||
3146 | */ |
||
3147 | protected function _makePlaceholders(int $numberOfPlaceholders=1) : string |
||
3151 | |||
3152 | /** |
||
3153 | * Format the table{Primary|Foreign}KeyName |
||
3154 | * |
||
3155 | * @param string $pattern |
||
3156 | * @param string $tableName |
||
3157 | * @return string |
||
3158 | */ |
||
3159 | protected function _formatKeyName(string $pattern, string $tableName) : string |
||
3163 | |||
3164 | |||
3165 | /** |
||
3166 | * @param array $query |
||
3167 | * @param array $extraFields |
||
3168 | * @return array |
||
3169 | * @throws \Exception |
||
3170 | */ |
||
3171 | protected function _prepareApiResource(array $query=[], array $extraFields=[]) : array |
||
3192 | |||
3193 | /** |
||
3194 | * @param string $query |
||
3195 | * @param array $parameters |
||
3196 | * |
||
3197 | * @return array |
||
3198 | */ |
||
3199 | protected function _logQuery(string $query, array $parameters) : array |
||
3212 | |||
3213 | /** |
||
3214 | * @param string $ident |
||
3215 | * @param string $builtQuery |
||
3216 | */ |
||
3217 | protected function _logSlowQueries(string $ident, string $builtQuery) |
||
3230 | |||
3231 | /** |
||
3232 | * @return float |
||
3233 | */ |
||
3234 | public function getTimeTaken() : float |
||
3240 | |||
3241 | /** |
||
3242 | * @param $secs |
||
3243 | * @return FluentPdoModel |
||
3244 | */ |
||
3245 | public function slowQuerySeconds(int $secs) : FluentPdoModel |
||
3252 | |||
3253 | |||
3254 | /** |
||
3255 | * @param $field |
||
3256 | * @param array $values |
||
3257 | * @param string $placeholderPrefix |
||
3258 | * |
||
3259 | * @return array |
||
3260 | */ |
||
3261 | public function getNamedWhereIn(string $field, array $values, string $placeholderPrefix='') : array |
||
3285 | |||
3286 | /** |
||
3287 | * @param string $field |
||
3288 | * @param string $delimiter |
||
3289 | * |
||
3290 | * @return array |
||
3291 | */ |
||
3292 | protected function _getColumnAliasParts(string $field, string $delimiter=':') : array |
||
3302 | |||
3303 | /** |
||
3304 | * @param string $column |
||
3305 | * @param string $term |
||
3306 | * @return FluentPdoModel |
||
3307 | */ |
||
3308 | protected function _addWhereClause(string $column, string $term) : FluentPdoModel |
||
3365 | |||
3366 | public function destroy() |
||
3375 | |||
3376 | public function __destruct() |
||
3380 | |||
3381 | /** |
||
3382 | * Load a model |
||
3383 | * |
||
3384 | * @param string $modelName |
||
3385 | * @param AbstractPdo $connection |
||
3386 | * @return FluentPdoModel |
||
3387 | * @throws ModelNotFoundException |
||
3388 | */ |
||
3389 | public static function loadModel(string $modelName, AbstractPdo $connection=null) : FluentPdoModel |
||
3399 | |||
3400 | /** |
||
3401 | * Load a model |
||
3402 | * |
||
3403 | * @param string $tableName |
||
3404 | * @param AbstractPdo $connection |
||
3405 | * @return FluentPdoModel |
||
3406 | */ |
||
3407 | public static function loadTable(string $tableName, AbstractPdo $connection=null) : FluentPdoModel |
||
3414 | |||
3415 | /** |
||
3416 | * @param string $columnName |
||
3417 | * @param int $cacheTtl |
||
3418 | * @param bool $flushCache |
||
3419 | * @return bool |
||
3420 | */ |
||
3421 | public function columnExists(string $columnName, int $cacheTtl=self::CACHE_NO, bool $flushCache=false) |
||
3426 | |||
3427 | /** |
||
3428 | * @param int $cacheTtl |
||
3429 | * @param bool $flushCache |
||
3430 | * @return FluentPdoModel |
||
3431 | */ |
||
3432 | public function loadSchemaFromDb(int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : FluentPdoModel |
||
3439 | |||
3440 | /** |
||
3441 | * @param int $cacheTtl |
||
3442 | * @param bool $flushCache |
||
3443 | * @return array |
||
3444 | */ |
||
3445 | public function getSchemaFromDb(int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : array |
||
3457 | |||
3458 | /** |
||
3459 | * @param string $table |
||
3460 | * @param int $cacheTtl |
||
3461 | * @param bool $flushCache |
||
3462 | * @return array |
||
3463 | */ |
||
3464 | protected function _getColumnsByTableFromDb(string $table, int $cacheTtl=self::CACHE_NO, bool $flushCache=false) : array |
||
3480 | |||
3481 | /** |
||
3482 | * @param string $table |
||
3483 | * @return bool |
||
3484 | */ |
||
3485 | public function clearSchemaCache(string $table) : bool |
||
3489 | |||
3490 | /** |
||
3491 | * @param stdClass $record |
||
3492 | * @return stdClass |
||
3493 | */ |
||
3494 | public function cleanseRecord(stdClass $record) : stdClass |
||
3511 | |||
3512 | /** |
||
3513 | * @param stdClass $record |
||
3514 | * @param string $type |
||
3515 | * @return stdClass |
||
3516 | */ |
||
3517 | public function beforeSave(stdClass $record, string $type) : stdClass |
||
3526 | |||
3527 | /** |
||
3528 | * @param array $data |
||
3529 | * @param string $saveType |
||
3530 | * @return array |
||
3531 | */ |
||
3532 | public function cleanseWebData(array $data, string $saveType) : array |
||
3547 | |||
3548 | /** |
||
3549 | * @return array |
||
3550 | */ |
||
3551 | public function skeleton() : array |
||
3562 | |||
3563 | /** |
||
3564 | * @param bool $toString |
||
3565 | * @return array |
||
3566 | */ |
||
3567 | public function getErrors(bool $toString=false) : array |
||
3582 | |||
3583 | /** |
||
3584 | * @param bool $throw |
||
3585 | * @return FluentPdoModel |
||
3586 | */ |
||
3587 | public function validationExceptions(bool $throw=true) : FluentPdoModel |
||
3593 | |||
3594 | /** |
||
3595 | * @param array $query array('_limit' => int, '_offset' => int, '_order' => string, '_fields' => string, _search) |
||
3596 | * |
||
3597 | * @return FluentPdoModel |
||
3598 | * @throws Exception |
||
3599 | */ |
||
3600 | public function paginate(array $query=[]) : FluentPdoModel |
||
3614 | |||
3615 | /** |
||
3616 | * @param int $limit |
||
3617 | * @param int $offset |
||
3618 | * @return FluentPdoModel |
||
3619 | */ |
||
3620 | protected function _setLimit(int $limit=0, int $offset=0) : FluentPdoModel |
||
3635 | |||
3636 | /** |
||
3637 | * @param array $fields |
||
3638 | * @return FluentPdoModel |
||
3639 | * @throws Exception |
||
3640 | */ |
||
3641 | protected function _setFields(array $fields=[]) : FluentPdoModel |
||
3689 | |||
3690 | /** |
||
3691 | * @param string $orderBy |
||
3692 | * @return FluentPdoModel|FluentPdoModel |
||
3693 | */ |
||
3694 | protected function _setOrderBy(string $orderBy='') : FluentPdoModel |
||
3731 | |||
3732 | /** |
||
3733 | * @return array |
||
3734 | */ |
||
3735 | public function getPagingMeta() |
||
3744 | |||
3745 | /** |
||
3746 | * @return FluentPdoModel |
||
3747 | */ |
||
3748 | public function setPagingMeta() : FluentPdoModel |
||
3770 | |||
3771 | /** |
||
3772 | * Take a web request and format a query |
||
3773 | * |
||
3774 | * @param array $query |
||
3775 | * |
||
3776 | * @return FluentPdoModel |
||
3777 | * @throws Exception |
||
3778 | */ |
||
3779 | public function filter(array $query=[]) : FluentPdoModel |
||
3845 | |||
3846 | /** |
||
3847 | * @param string $column |
||
3848 | * @param string $displayCol |
||
3849 | * @return string|null |
||
3850 | */ |
||
3851 | protected function _findFieldByQuery(string $column, string $displayCol) |
||
3898 | |||
3899 | /** |
||
3900 | * @param $keysOnly |
||
3901 | * @return array |
||
3902 | */ |
||
3903 | |||
3904 | public function columns(bool $keysOnly=true) : array |
||
3908 | |||
3909 | /** |
||
3910 | * @param string $field |
||
3911 | * @param mixed $value |
||
3912 | * @param bool|false $permissive |
||
3913 | * @return float|int|null|string |
||
3914 | */ |
||
3915 | protected function _fixType(string $field, $value, bool $permissive=false) |
||
3955 | |||
3956 | /** |
||
3957 | * @param stdClass $record |
||
3958 | * @param string $type |
||
3959 | * @return stdClass |
||
3960 | */ |
||
3961 | public function fixTypes(stdClass $record, string $type='') : stdClass |
||
3975 | |||
3976 | /** |
||
3977 | * @param stdClass $record |
||
3978 | * @param string $type |
||
3979 | * @return stdClass |
||
3980 | * @throws Exception |
||
3981 | */ |
||
3982 | public function applyHandlers(stdClass $record, string $type='INSERT') : stdClass |
||
4010 | |||
4011 | /** |
||
4012 | * @param string $field |
||
4013 | * @param mixed $value |
||
4014 | * @param string $type |
||
4015 | * @param stdClass $record |
||
4016 | * @return null |
||
4017 | * @throws Exception |
||
4018 | */ |
||
4019 | protected function applyHandler(string $field, $value, string $type='', stdClass $record=null) |
||
4043 | |||
4044 | /** |
||
4045 | * @param string $start |
||
4046 | * @param string $end |
||
4047 | * @param string $hayStack |
||
4048 | * @return mixed |
||
4049 | */ |
||
4050 | public static function between(string $start, string $end, string $hayStack) : string |
||
4054 | |||
4055 | /** |
||
4056 | * @param string $needle |
||
4057 | * @param string $hayStack |
||
4058 | * @param bool $returnOrigIfNeedleNotExists |
||
4059 | * @return mixed |
||
4060 | */ |
||
4061 | public static function before(string $needle, string $hayStack, bool $returnOrigIfNeedleNotExists=false) : string |
||
4071 | |||
4072 | /** |
||
4073 | * @param string $needle |
||
4074 | * @param string $hayStack |
||
4075 | * @param bool $returnOrigIfNeedleNotExists |
||
4076 | * @return string |
||
4077 | */ |
||
4078 | public static function after(string $needle, string $hayStack, bool $returnOrigIfNeedleNotExists=false) : string |
||
4087 | |||
4088 | /** |
||
4089 | * @return int |
||
4090 | */ |
||
4091 | public function getUserId() |
||
4095 | |||
4096 | /** |
||
4097 | * @param string $entity |
||
4098 | * @param int $id |
||
4099 | * @return int |
||
4100 | */ |
||
4101 | public function getMaskByResourceAndId(string $entity, int $id) : int |
||
4105 | |||
4106 | /** |
||
4107 | * @param string|int|null $time |
||
4108 | * @return string |
||
4109 | */ |
||
4110 | public static function date($time=null) : string |
||
4114 | |||
4115 | /** |
||
4116 | * @param string|int|null $time |
||
4117 | * @return string |
||
4118 | */ |
||
4119 | public static function dateTime($time=null) : string |
||
4123 | |||
4124 | /** |
||
4125 | * @param string|int|null $time |
||
4126 | * @return string |
||
4127 | */ |
||
4128 | public static function atom($time=null) : string |
||
4132 | |||
4133 | /** |
||
4134 | * @param string|int|null $time |
||
4135 | * @return int |
||
4136 | */ |
||
4137 | public static function getTime($time=null) : int |
||
4150 | |||
4151 | |||
4152 | /** |
||
4153 | * @param int $id |
||
4154 | * @param int $cacheTtl |
||
4155 | * @return string |
||
4156 | */ |
||
4157 | public function getCodeById(int $id, int $cacheTtl=self::ONE_DAY) : string |
||
4165 | } |
||
4166 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: