Inheritance: extends Magic
Exemplo n.º 1
0
 function update()
 {
     $res = $this->mapper->update();
     if (is_array($res)) {
         $res = $this->mapper;
     }
     if (is_object($res)) {
         $res = $this->factory($res);
     }
     return is_int($res) ? $this : $res;
 }
Exemplo n.º 2
0
 /**
  * Resolve default filter and assign default value if field not changed
  */
 public function resolveDefaultFilter()
 {
     $app = Base::instance();
     foreach ($this->map ? $this->map->schema() : [] as $field => $schema) {
         if ($schema['pkey'] && PDO::PARAM_INT === $schema['pdo_type']) {
             continue;
         }
         $filters = [];
         $filters['required'] = [!$schema['nullable']];
         if (preg_match('/^(?<type>\\w+)(?:\\((?<length>.+)\\))?/', $schema['type'], $match)) {
             $length = isset($match['length']) ? $match['length'] : null;
             switch ($match['type']) {
                 case 'int':
                 case 'bigint':
                 case 'smallint':
                 case 'tinyint':
                 case 'integer':
                     $filters['maxInt'] = [null, $length];
                     break;
                 case 'decimal':
                 case 'double':
                 case 'float':
                 case 'real':
                     $x = $app->split($length);
                     $base = pow(10, $x[0] - $x[1]) - 1;
                     $precision = (pow(10, $x[1]) - 1) * 1 / pow(10, $x[1]);
                     $max = $base + $precision;
                     $filters['maxFloat'] = [$max, $length];
                     break;
                 case 'enum':
                 case 'set':
                     $filters['choices'] = [$app->split(str_replace(['"', "'"], '', $length)), $schema['nullable']];
                     break;
                 case 'date':
                     $filters['date'] = [$schema['nullable']];
                     break;
                 default:
                     $filters['maxLength'] = [$length, $schema['nullable']];
                     break;
             }
         }
         $this->filters[$field] = $filters;
         if (!$schema['changed'] && (is_null($schema['value']) || '' === $schema['value']) && !(is_null($schema['default']) || '' === $schema['default'])) {
             $this->map->set($field, $schema['default']);
         }
     }
     return $this;
 }
Exemplo n.º 3
0
 /**
 		Reset cursor
 		@return NULL
 	**/
 function reset()
 {
     $this->id = NULL;
     $this->document = array();
     parent::reset();
 }
Exemplo n.º 4
0
 /**
 		Reset cursor
 		@return NULL
 	**/
 function reset()
 {
     foreach ($this->fields as &$field) {
         $field['value'] = NULL;
         $field['changed'] = FALSE;
         if ($field['pkey']) {
             $field['previous'] = NULL;
         }
         unset($field);
     }
     foreach ($this->adhoc as &$field) {
         $field['value'] = NULL;
         unset($field);
     }
     parent::reset();
 }
Exemplo n.º 5
0
 function dbtype()
 {
     return $this->mapper->dbtype();
 }
Exemplo n.º 6
0
 /**
  *	Reset cursor
  *	@return NULL
  **/
 function reset()
 {
     $this->document = [];
     parent::reset();
 }
Exemplo n.º 7
0
 /**
  * Get mapper value
  *
  * @param  string
  * @return string
  */
 protected function value($name, $default = null)
 {
     return $this->mapper && $this->mapper->exists($name) ? $this->mapper->get($name) : $this->get($name, $default);
 }