/** * function parseValues($data): * Parse the data and if some values met the type correct them. * * @param $data * * @return array */ private function parseValues($data) { $this->serializedFields = []; $record = []; $columns = array_keys($data); $values = array_values($data); foreach ($columns as $index => $column) { if (!in_array($column, $this->fields)) { unset($columns[$index], $values[$index]); } } foreach ($columns as $col) { $properties = (array) MatchaModel::__getFieldProperties($col, $this->model); // Check if the type property is set // but if the dataType is also defined // make use the dataType property (more database oriented) // if either type and dataType are defined auto set string if (isset($properties['type'])) { $type = $properties['type']; } elseif (isset($properties['dataType'])) { $type = $properties['dataType']; } else { $type = 'string'; } // Don't parse the value (skip it) if... // $properties['store'] is set and is not true OR // $properties['persist'] is set and is not true OR if ((!isset($properties['store']) || $properties['store']) && (!isset($properties['persist']) || $properties['persist'])) { if ($this->encryptedFields !== false && in_array($col, $this->encryptedFields)) { $data[$col] = $this->dataEncrypt($data[$col]); } else { if ($type == 'string' && is_string($data[$col])) { $data[$col] = html_entity_decode($data[$col]); } elseif ($type == 'date') { if ($data[$col] === '') { $data[$col] = '0000-00-00'; } //$data[$col] = ($data[$col] == '' || is_null($data[$col]) ? '0000-00-00' : $data[$col]); } elseif ($type == 'array') { if ($data[$col] == '') { $data[$col] = null; } else { $this->serializedFields[$col] = $data[$col]; $data[$col] = serialize($data[$col]); } } } /** * Do not trim bool, null, objects, or arrays values */ if ($this->autoTrim && ($type != 'bool' && $type != 'int' && $data[$col] != null && !is_object($data[$col]) && !is_array($data[$col]))) { $record[$col] = trim($data[$col]); } else { $record[$col] = $data[$col]; } } } return $record; }
/** * function parseValues($data): * Parse the data and if some values met the type correct them. * * @param $data * * @return array */ private function parseValues($data) { $this->serializedFields = []; $record = []; $columns = array_keys($data); $values = array_values($data); foreach ($columns as $index => $column) { if (!in_array($column, $this->fields)) { unset($columns[$index], $values[$index]); } } foreach ($columns as $col) { $properties = (array) MatchaModel::__getFieldProperties($col, $this->model); /** * Don't parse the value (skip it) if... * $properties['store'] is set and is not true OR * $properties['persist'] is set and is not true OR */ if ((!isset($properties['store']) || $properties['store']) && (!isset($properties['persist']) || $properties['persist'])) { $type = $properties['type']; if ($this->encryptedFields !== false && in_array($col, $this->encryptedFields)) { $data[$col] = $this->dataEncrypt($data[$col]); } else { if ($type == 'string' && is_string($data[$col])) { $data[$col] = html_entity_decode($data[$col]); } elseif ($type == 'date') { if ($data[$col] === '') { $data[$col] = '0000-00-00'; } // $data[$col] = ($data[$col] == '' || is_null($data[$col]) ? '0000-00-00' : $data[$col]); } elseif ($type == 'array') { if ($data[$col] == '') { $data[$col] = null; } else { $this->serializedFields[$col] = $data[$col]; $data[$col] = serialize($data[$col]); } } } /** * do not trim bool values */ if ($this->autoTrim && ($type != 'bool' && $type != 'int' && $data[$col] != null)) { $record[$col] = trim($data[$col]); } else { $record[$col] = $data[$col]; } } } return $record; }
/** * function parseValues($data): * Parse the data and if some values met the type correct them. * * @param $data * * @return array */ private function parseValues($data) { $record = array(); $columns = array_keys($data); $values = array_values($data); foreach ($columns as $index => $column) { if (!in_array($column, $this->fields)) { unset($columns[$index], $values[$index]); } } foreach ($columns as $col) { $properties = (array) MatchaModel::__getFieldProperties($col, $this->model); /** * Don't parse the value (skip it) if... * $properties['store'] is set and is not true OR * $properties['persist'] is set and is not true OR */ if ((!isset($properties['store']) || $properties['store']) && (!isset($properties['persist']) || $properties['persist'])) { $type = MatchaModel::__getFieldType($col, $this->model); if ($this->encryptedFields !== false && in_array($col, $this->encryptedFields)) { $data[$col] = $this->dataEncrypt($data[$col]); } else { if ($type == 'date') { $data[$col] = $data[$col] == '' ? null : $data[$col]; } elseif ($type == 'array') { $data[$col] = $data[$col] == '' ? null : serialize($data[$col]); } } /** * do not trim bool values */ if ($this->autoTrim && $type != 'bool') { $record[$col] = trim($data[$col]); } else { $record[$col] = $data[$col]; } } } return $record; }