@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | if (!is_null($probe_res = $this->get($probe_name))) { |
| 44 | 44 | $extract_model->set($column_name, $probe_res); |
| 45 | - } elseif (!$column->is_nullable() && $ignore_nullable===false) { |
|
| 45 | + } elseif (!$column->is_nullable() && $ignore_nullable === false) { |
|
| 46 | 46 | return null; |
| 47 | 47 | } |
| 48 | 48 | } |
@@ -95,15 +95,15 @@ discard block |
||
| 95 | 95 | public function save($operator_id, $tracer = null) : ?array |
| 96 | 96 | { |
| 97 | 97 | try { |
| 98 | - if (!empty($errors=$this->search_and_execute_trait_methods('before_save'))) { |
|
| 98 | + if (!empty($errors = $this->search_and_execute_trait_methods('before_save'))) { |
|
| 99 | 99 | return $errors; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - if (!empty($errors=$this->before_save())) { |
|
| 102 | + if (!empty($errors = $this->before_save())) { |
|
| 103 | 103 | return $errors; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - if (!empty($errors=$this->validate())) { // Model level validation |
|
| 106 | + if (!empty($errors = $this->validate())) { // Model level validation |
|
| 107 | 107 | return $errors; |
| 108 | 108 | } |
| 109 | 109 | |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | |
| 113 | 113 | |
| 114 | 114 | if ($table_row->is_altered()) { // someting to save ? |
| 115 | - if (!empty($persistence_errors=$table_row->persist())) { // validate and persist |
|
| 115 | + if (!empty($persistence_errors = $table_row->persist())) { // validate and persist |
|
| 116 | 116 | $errors = []; |
| 117 | 117 | foreach ($persistence_errors as $column_name => $err) { |
| 118 | 118 | $errors[sprintf('MODEL_%s_FIELD_%s', static::model_type(), $column_name)] = $err; |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | */ |
| 212 | 212 | public static function one($arg1, $arg2 = null) |
| 213 | 213 | { |
| 214 | - $mixed_info = is_null($arg2)? $arg1 : [$arg1=>$arg2]; |
|
| 214 | + $mixed_info = is_null($arg2) ? $arg1 : [$arg1=>$arg2]; |
|
| 215 | 215 | |
| 216 | 216 | $unique_identifiers = get_called_class()::table()->match_uniqueness($mixed_info); |
| 217 | 217 | |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | $ret = []; |
| 253 | 253 | $pk_name = implode('_', array_keys($Query->table()->primary_keys())); |
| 254 | 254 | |
| 255 | - if (count($pks = $Query->table()->primary_keys())>1) { |
|
| 255 | + if (count($pks = $Query->table()->primary_keys()) > 1) { |
|
| 256 | 256 | $concat_pk = sprintf('CONCAT(%s) as %s', implode(',', $pks), $pk_name); |
| 257 | 257 | $Query->select_also([$concat_pk]); |
| 258 | 258 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | // $foreign_table_alias = 'creator'; |
| 44 | 44 | // $select_also=['id','name']; |
| 45 | 45 | } else { |
| 46 | - $m=[]; |
|
| 46 | + $m = []; |
|
| 47 | 47 | if (preg_match('/(.+)_('.$fk_column->foreign_column_name().')$/', $fk_column->name(), $m)) { |
| 48 | 48 | $foreign_table_alias = $m[1]; |
| 49 | 49 | } else { |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | if (empty($select_also)) { |
| 58 | 58 | foreach ($foreign_table->columns() as $col) { |
| 59 | 59 | if (!$col->is_hidden()) { |
| 60 | - $select_also []= "$col"; |
|
| 60 | + $select_also [] = "$col"; |
|
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | } |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | |
| 71 | 71 | public function join($table_names, $joins, $join_type = '') |
| 72 | 72 | { |
| 73 | - list($join_table_name,$join_table_alias) = self::process_param_table_names($table_names); |
|
| 73 | + list($join_table_name, $join_table_alias) = self::process_param_table_names($table_names); |
|
| 74 | 74 | |
| 75 | 75 | if (preg_match('/^(INNER|LEFT|RIGHT|FULL)(\sOUTER)?/i', $join_type) !== 1) { |
| 76 | 76 | $join_type = ''; |
@@ -101,13 +101,13 @@ discard block |
||
| 101 | 101 | if (!is_null($bonding_column = $this->table()->single_foreign_key_to($other_table))) { |
| 102 | 102 | $relation_type = $relation_type ?? $bonding_column->is_nullable() ? 'LEFT OUTER' : 'INNER'; |
| 103 | 103 | // $joins []= [$bonding_column->table_name(), $bonding_column->name(), $other_table_alias ?? $bonding_column->foreign_table_alias(), $bonding_column->foreign_column_name()]; |
| 104 | - $joins []= [$this->table_alias(), $bonding_column->name(), $other_table_alias ?? $bonding_column->foreign_table_alias(), $bonding_column->foreign_column_name()]; |
|
| 104 | + $joins [] = [$this->table_alias(), $bonding_column->name(), $other_table_alias ?? $bonding_column->foreign_table_alias(), $bonding_column->foreign_column_name()]; |
|
| 105 | 105 | } |
| 106 | 106 | // elseif(count($bonding_column = $other_table->foreign_keys_by_table()[$this->table()->name()] ?? []) === 1) |
| 107 | 107 | elseif (!is_null($bonding_column = $other_table->single_foreign_key_to($this->table()))) { |
| 108 | 108 | // vd(__FUNCTION__.' : '.$other_table.' has fk to '.$this->table()); |
| 109 | 109 | $relation_type = $relation_type ?? 'LEFT OUTER'; |
| 110 | - $joins []= [$this->table_label(), $bonding_column->foreign_column_name(), $other_table_alias ?? $other_table->name(), $bonding_column->name()]; |
|
| 110 | + $joins [] = [$this->table_label(), $bonding_column->foreign_column_name(), $other_table_alias ?? $other_table->name(), $bonding_column->name()]; |
|
| 111 | 111 | } else { |
| 112 | 112 | $bondable_tables = $this->joinable_tables(); |
| 113 | 113 | if (isset($bondable_tables[$other_table_name])) { |
@@ -136,11 +136,11 @@ discard block |
||
| 136 | 136 | $joins = []; |
| 137 | 137 | |
| 138 | 138 | $bonding_column = current($bonding_column); |
| 139 | - $joins []= [$other_table_alias, $bonding_column->name(), $bonding_column->foreign_table_alias(), $bonding_column->foreign_column_name()]; |
|
| 139 | + $joins [] = [$other_table_alias, $bonding_column->name(), $bonding_column->foreign_table_alias(), $bonding_column->foreign_column_name()]; |
|
| 140 | 140 | |
| 141 | 141 | // vd($other_table_alias); |
| 142 | 142 | $bonding_column = current($bondable_tables[$table_name]); |
| 143 | - $joins []= [$bonding_column->table_name(), $bonding_column->name(), $bonding_column->foreign_table_alias(), $bonding_column->foreign_column_name()]; |
|
| 143 | + $joins [] = [$bonding_column->table_name(), $bonding_column->name(), $bonding_column->foreign_table_alias(), $bonding_column->foreign_column_name()]; |
|
| 144 | 144 | |
| 145 | 145 | // $relation_type = $relation_type ?? (($parent_column->is_nullable() || $bonding_column->is_nullable()) ? 'LEFT OUTER' : 'INNER'); |
| 146 | 146 | $relation_type = $relation_type ?? (($bonding_column->is_nullable()) ? 'LEFT OUTER' : 'INNER'); |
@@ -182,13 +182,13 @@ discard block |
||
| 182 | 182 | foreach ($join_fields as $join_cond) { |
| 183 | 183 | if (isset($join_cond[3])) { // 4 joins param -> t.f = t.f |
| 184 | 184 | list($table, $field, $join_table, $join_table_field) = $join_cond; |
| 185 | - $join_parts []= $this->field_label($field, $table) . ' = ' . $this->field_label($join_table_field, $join_table); |
|
| 185 | + $join_parts [] = $this->field_label($field, $table).' = '.$this->field_label($join_table_field, $join_table); |
|
| 186 | 186 | } elseif (isset($join_cond[2])) { // 3 joins param -> t.f = v |
| 187 | 187 | list($table, $field, $value) = $join_cond; |
| 188 | 188 | $bind_label = ':loj_'.$join_table_alias.'_'.$table.'_'.$field; |
| 189 | 189 | $this->add_binding($bind_label, $value); |
| 190 | 190 | |
| 191 | - $join_parts []= $this->field_label($field, $table) . ' = ' . $bind_label; |
|
| 191 | + $join_parts [] = $this->field_label($field, $table).' = '.$bind_label; |
|
| 192 | 192 | } |
| 193 | 193 | } |
| 194 | 194 | return sprintf('%s JOIN `%s` %s ON %s', $join_type, $join_table_name, $join_table_alias, implode(' AND ', $join_parts)); |
@@ -156,25 +156,25 @@ |
||
| 156 | 156 | |
| 157 | 157 | $query_fields = empty($this->selection) ? ['*'] : $this->selection; |
| 158 | 158 | |
| 159 | - $ret = PHP_EOL . 'SELECT '.implode(', '.PHP_EOL, $query_fields); |
|
| 160 | - $ret.= PHP_EOL . sprintf(' FROM `%s` %s ', $this->table_name(), $this->table_alias); |
|
| 159 | + $ret = PHP_EOL.'SELECT '.implode(', '.PHP_EOL, $query_fields); |
|
| 160 | + $ret .= PHP_EOL.sprintf(' FROM `%s` %s ', $this->table_name(), $this->table_alias); |
|
| 161 | 161 | |
| 162 | 162 | if (!empty($this->join)) { |
| 163 | - $ret.= PHP_EOL . ' '.implode(PHP_EOL.' ', $this->join); |
|
| 163 | + $ret .= PHP_EOL.' '.implode(PHP_EOL.' ', $this->join); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | $ret .= $this->generate_where(); |
| 167 | 167 | |
| 168 | 168 | foreach (['group' => 'GROUP BY', 'having' => 'HAVING', 'order' => 'ORDER BY'] as $part => $prefix) { |
| 169 | 169 | if (!empty($this->$part)) { |
| 170 | - $ret.= PHP_EOL . " $prefix " . implode(', ', $this->$part); |
|
| 170 | + $ret .= PHP_EOL." $prefix ".implode(', ', $this->$part); |
|
| 171 | 171 | } |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | if (!empty($this->limit_number)) { |
| 175 | 175 | $offset = $this->limit_offset ?? 0; |
| 176 | 176 | $number = $this->limit_number; |
| 177 | - $ret.= PHP_EOL . " LIMIT $offset, $number"; |
|
| 177 | + $ret .= PHP_EOL." LIMIT $offset, $number"; |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | return $ret; |
@@ -72,20 +72,20 @@ discard block |
||
| 72 | 72 | |
| 73 | 73 | public function aw_eq($field, $value, $table_name = null, $bindname = null) |
| 74 | 74 | { |
| 75 | - return $this->aw_bind_field($table_name, $field, self::$OP_EQ, $value, $bindname); |
|
| 75 | + return $this->aw_bind_field($table_name, $field, self::$OP_EQ, $value, $bindname); |
|
| 76 | 76 | } |
| 77 | 77 | public function aw_gt($field, $value, $table_name = null, $bindname = null) |
| 78 | 78 | { |
| 79 | - return $this->aw_bind_field($table_name, $field, self::$OP_GT, $value, $bindname); |
|
| 79 | + return $this->aw_bind_field($table_name, $field, self::$OP_GT, $value, $bindname); |
|
| 80 | 80 | } |
| 81 | 81 | public function aw_lt($field, $value, $table_name = null, $bindname = null) |
| 82 | 82 | { |
| 83 | - return $this->aw_bind_field($table_name, $field, self::$OP_LT, $value, $bindname); |
|
| 83 | + return $this->aw_bind_field($table_name, $field, self::$OP_LT, $value, $bindname); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | public function aw_gte($field, $value, $table_name = null, $bindname = null) |
| 87 | 87 | { |
| 88 | - return $this->aw_bind_field($table_name, $field, self::$OP_GTE, $value, $bindname); |
|
| 88 | + return $this->aw_bind_field($table_name, $field, self::$OP_GTE, $value, $bindname); |
|
| 89 | 89 | } |
| 90 | 90 | public function aw_lte($field, $value, $table_name = null, $bindname = null) |
| 91 | 91 | { |
@@ -184,10 +184,10 @@ discard block |
||
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
| 187 | - * @param array $filters_content with 2 indexes: 'term', the search string, 'fields', the search fields |
|
| 188 | - * @param $search_table String to filter |
|
| 189 | - * @param $filters_operator Object, inclusive or exclusive search |
|
| 190 | - */ |
|
| 187 | + * @param array $filters_content with 2 indexes: 'term', the search string, 'fields', the search fields |
|
| 188 | + * @param $search_table String to filter |
|
| 189 | + * @param $filters_operator Object, inclusive or exclusive search |
|
| 190 | + */ |
|
| 191 | 191 | public function aw_filter_content($filters_content, $search_table = null, $filters_operator = null) // sub array filters[$content] |
| 192 | 192 | { |
| 193 | 193 | if (!isset($filters_content['term']) || !isset($filters_content['fields'])) { |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | { |
| 53 | 53 | $this->where = $this->where ?? []; |
| 54 | 54 | |
| 55 | - $this->where[]= "($where_condition)"; |
|
| 55 | + $this->where[] = "($where_condition)"; |
|
| 56 | 56 | |
| 57 | 57 | foreach ($where_bindings as $k => $v) { |
| 58 | 58 | $this->add_binding($k, $v); |
@@ -212,11 +212,11 @@ discard block |
||
| 212 | 212 | $search_field = $this->field_label($search_field, $search_table); |
| 213 | 213 | |
| 214 | 214 | if ($search_mode === self::$OP_EQ) { |
| 215 | - $content_wc []= "$search_field = '$search_term' "; // TODO bindthis |
|
| 215 | + $content_wc [] = "$search_field = '$search_term' "; // TODO bindthis |
|
| 216 | 216 | } else // %% |
| 217 | 217 | { |
| 218 | 218 | $pattern = str_replace('TERM', $search_term, $search_mode); |
| 219 | - $content_wc []= " $search_field LIKE '$pattern' "; // TODO bindthis |
|
| 219 | + $content_wc [] = " $search_field LIKE '$pattern' "; // TODO bindthis |
|
| 220 | 220 | } |
| 221 | 221 | } |
| 222 | 222 | |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | protected function generate_where() |
| 248 | 248 | { |
| 249 | 249 | if (!empty($this->where)) { |
| 250 | - return PHP_EOL .' WHERE '. implode(PHP_EOL.' AND ', $this->where); |
|
| 250 | + return PHP_EOL.' WHERE '.implode(PHP_EOL.' AND ', $this->where); |
|
| 251 | 251 | } |
| 252 | 252 | } |
| 253 | 253 | } |
@@ -45,7 +45,7 @@ |
||
| 45 | 45 | |
| 46 | 46 | $binding_name = $this->bind_label($field_name); |
| 47 | 47 | $this->add_binding($binding_name, $value); |
| 48 | - $this->alterations []= $this->field_label($field_name)." = $binding_name"; |
|
| 48 | + $this->alterations [] = $this->field_label($field_name)." = $binding_name"; |
|
| 49 | 49 | } |
| 50 | 50 | return $this; |
| 51 | 51 | } |
@@ -23,7 +23,7 @@ |
||
| 23 | 23 | public function generate() : string |
| 24 | 24 | { |
| 25 | 25 | if (empty($this->where)) { |
| 26 | - throw new CruditesException('DELETE_USED_AS_TRUNCATE'); // prevents haphazardous generation of dangerous DELETE statement |
|
| 26 | + throw new CruditesException('DELETE_USED_AS_TRUNCATE'); // prevents haphazardous generation of dangerous DELETE statement |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | return sprintf('DELETE FROM `%s` %s ', $this->table_name(), $this->generate_where()); |
@@ -13,15 +13,15 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | const STATE_SUCCESS = '00000'; //PDO "error" code for "all is fine" |
| 15 | 15 | |
| 16 | - const CODE_CREATE = 'C'; |
|
| 16 | + const CODE_CREATE = 'C'; |
|
| 17 | 17 | const CODE_RETRIEVE = 'R'; |
| 18 | - const CODE_UPDATE = 'U'; |
|
| 19 | - const CODE_DELETE = 'D'; |
|
| 18 | + const CODE_UPDATE = 'U'; |
|
| 19 | + const CODE_DELETE = 'D'; |
|
| 20 | 20 | |
| 21 | - protected $database=null; |
|
| 22 | - protected $table=null; |
|
| 23 | - protected $statement=null; |
|
| 24 | - protected $bindings=[]; |
|
| 21 | + protected $database = null; |
|
| 22 | + protected $table = null; |
|
| 23 | + protected $statement = null; |
|
| 24 | + protected $bindings = []; |
|
| 25 | 25 | |
| 26 | 26 | protected $connection = null; |
| 27 | 27 | protected $executed = false; |
@@ -179,8 +179,7 @@ discard block |
||
| 179 | 179 | $this->prepared_statement = $this->connection()->prepare($this->statement()); |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | - if ($this->prepared_statement->execute($this->bindings()) !== false) { // execute returns TRUE on success or FALSE on failure. |
|
| 183 | - ++self::$executions; |
|
| 182 | + if ($this->prepared_statement->execute($this->bindings()) !== false) { // execute returns TRUE on success or FALSE on failure.++self::$executions; |
|
| 184 | 183 | |
| 185 | 184 | $this->is_executed(true); |
| 186 | 185 | |
@@ -98,7 +98,7 @@ |
||
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | // TODO SELECT field order can't change without adapting the result parsing code (foreach $res) |
| 101 | - $select_fields = ['SUBSTR(query_on, 1, 10) AS working_day', 'query_table', 'query_id', 'GROUP_CONCAT(DISTINCT query_type, "-", query_by) as action_by']; |
|
| 101 | + $select_fields = ['SUBSTR(query_on, 1, 10) AS working_day', 'query_table', 'query_id', 'GROUP_CONCAT(DISTINCT query_type, "-", query_by) as action_by']; |
|
| 102 | 102 | $q = $this->tracing_table()->select($select_fields); |
| 103 | 103 | $q->order_by(['', 'working_day', 'DESC']); |
| 104 | 104 | $q->order_by([$this->tracing_table()->name(), 'query_table', 'DESC']); |
@@ -74,17 +74,17 @@ discard block |
||
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
| 77 | - * loads row content from database, |
|
| 78 | - * |
|
| 79 | - * looks for primary key matching data in $dat_ass and sets the $load variable |
|
| 80 | - * $load stays null if |
|
| 81 | - * 1. not match is found in $dat_ass |
|
| 82 | - * 2. multiple records are returned |
|
| 83 | - * 3. no record is found |
|
| 84 | - * |
|
| 85 | - * @param Array $dat_ass an associative array containing primary key data matches |
|
| 86 | - * @return $this |
|
| 87 | - */ |
|
| 77 | + * loads row content from database, |
|
| 78 | + * |
|
| 79 | + * looks for primary key matching data in $dat_ass and sets the $load variable |
|
| 80 | + * $load stays null if |
|
| 81 | + * 1. not match is found in $dat_ass |
|
| 82 | + * 2. multiple records are returned |
|
| 83 | + * 3. no record is found |
|
| 84 | + * |
|
| 85 | + * @param Array $dat_ass an associative array containing primary key data matches |
|
| 86 | + * @return $this |
|
| 87 | + */ |
|
| 88 | 88 | public function load($dat_ass) |
| 89 | 89 | { |
| 90 | 90 | $pks = $this->table()->primary_keys_match($dat_ass); |
@@ -186,8 +186,8 @@ discard block |
||
| 186 | 186 | |
| 187 | 187 | //------------------------------------------------------------ type:data validation |
| 188 | 188 | /** |
| 189 | - * @return array containing all invalid data, indexed by field name, or empty if all valid |
|
| 190 | - */ |
|
| 189 | + * @return array containing all invalid data, indexed by field name, or empty if all valid |
|
| 190 | + */ |
|
| 191 | 191 | public function validate() : array |
| 192 | 192 | { |
| 193 | 193 | $errors = []; |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | public function __toString() |
| 28 | 28 | { |
| 29 | - return PHP_EOL .'load: '.json_encode($this->load) . PHP_EOL.'alterations: '.json_encode(array_keys($this->alterations)); |
|
| 29 | + return PHP_EOL.'load: '.json_encode($this->load).PHP_EOL.'alterations: '.json_encode(array_keys($this->alterations)); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | public function __debugInfo() : array |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | $this->last_alter_query = $this->table()->insert($this->export()); |
| 149 | 149 | $this->last_alter_query->run(); |
| 150 | 150 | if ($this->last_alter_query->is_success() && !is_null($aipk = $this->last_alter_query->table()->auto_incremented_primary_key())) { |
| 151 | - $this->alterations[$aipk->name()]=$this->last_alter_query->inserted_id(); |
|
| 151 | + $this->alterations[$aipk->name()] = $this->last_alter_query->inserted_id(); |
|
| 152 | 152 | } |
| 153 | 153 | } else { |
| 154 | 154 | $pk_match = $this->table()->primary_keys_match($this->load); |