21 Commits

Author SHA1 Message Date
022ba575b7 Merge branch 'develop' into master 2021-06-04 21:15:26 -04:00
c913f65b91 Considera leer el dato y correccion en los nombres de los metodos 2021-03-16 00:22:13 -03:00
c8a7781c88 Merge branch 'develop' 2021-03-15 11:17:11 -03:00
1505539e61 Merge branch 'develop' into master 2021-03-09 00:19:55 -03:00
3087a48c43 Merge branch 'develop' into master 2021-03-09 00:15:12 -03:00
43f545516d Merge branch 'develop' 2020-08-04 01:33:09 -04:00
b757ed19b2 Merge branch 'develop' 2020-08-03 23:54:16 -04:00
9dc71e4d77 Merge branch 'develop' 2020-08-03 23:51:05 -04:00
c6806a1c62 Merge branch 'develop' 2020-08-03 23:42:11 -04:00
6fd19a11be Merge branch 'develop' 2020-08-03 23:38:41 -04:00
7c727d93e9 Merge branch 'develop' 2020-08-03 23:27:45 -04:00
e02b8c4063 Merge branch 'develop' 2020-08-03 23:17:38 -04:00
89d1db7a7e Merge branch 'develop' 2020-08-03 23:10:57 -04:00
8dc0a27fd9 Merge branch 'develop' 2020-08-03 22:07:24 -04:00
ae172b902c Merge branch 'develop' 2020-08-03 16:25:19 -04:00
7f81b987c9 Merge branch 'develop' 2020-07-24 12:06:16 -04:00
af801e769f Merge branch 'develop' 2020-07-24 11:58:16 -04:00
c40baaad3f Merge branch 'develop' 2020-07-24 11:47:39 -04:00
a82fdce64b Merge branch 'develop' 2020-07-22 23:08:52 -04:00
8126b1f67d Merge branch 'develop' 2020-07-22 22:57:48 -04:00
2177cb4652 Merge branch 'develop' 2020-07-22 14:08:09 -04:00
3 changed files with 25 additions and 25 deletions

View File

@ -124,33 +124,36 @@ abstract class Model extends BaseModel implements ModelInterface {
}
protected static function parseInput($input): array {
return array_intersect_key((array) $input, array_combine(static::$fields, static::$fields));
return array_intersect_key((array) $input, array_combine(self::$fields, self::$fields));
}
public static function add(ModelFactory $factory, $input): ?ModelInterface {
$data = static::parseInput($input);
public static function add(ModelFactory $factory, $input): bool {
$data = self::parseInput($input);
$class = get_called_class();
if (method_exists($class, 'find')) {
$obj = static::find($factory, $input);
$obj = self::find($factory, $input);
} else {
$where = $data;
array_walk($where, function(&$item, $key) {
$where = array_values(array_walk($where, function(&$item, $key) {
$item = [$key, $item];
});
$where = array_values($where);
}));
$obj = $factory->find($class)->where($where)->one();
}
if ($obj === null) {
if ($obj === false) {
$obj = $factory->create($class, $data);
return $obj->save();
}
return $obj;
return false;
}
public function edit($input): bool {
$data = static::parseInput($input);
foreach (static::$fields as $field) {
$data = self::parseInput($input);
foreach (self::$fields as $field) {
if ($this->{$field} != $data[$field]) {
$this->{$field} = $data[$field];
}
}
if ($this->isDirty()) {
return $this->save();
}
return false;
}
}

View File

@ -12,6 +12,6 @@ interface Model {
public function toArray(): array;
public static function add(ModelFactory $factory, $input): ?Model;
public static function add(ModelFactory $factory, $input): bool;
public function edit($input): bool;
}

View File

@ -79,9 +79,9 @@ class Model {
'table' => $j['table'] ?? $j[0],
'from' => $j['from'] ?? $j[1],
'to' => $j['to'] ?? $j[2],
'symb' => $j['symb'] ?? ($j[3] ?? '='),
'sym' => $j['sym'] ?? ($j[3] ?? '='),
'alias' => $j['alias'] ?? '',
'type' => strtolower($j['type'] ?? ''),
'type' => strtolower($j['type']) ?? '',
'params' => $j['params'] ?? ''
];
$this->joins []= $join;
@ -97,8 +97,8 @@ class Model {
$cond = (object) [
'column' => $c['column'] ?? $c[0],
'value' => $c['value'] ?? $c[1],
'symb' => strtolower($c['symb'] ?? ($c[2] ?? '=')),
'type' => strtolower($c['type'] ?? '')
'sym' => strtolower($c['sym'] ?? ($c[2] ?? '=')),
'type' => strtolower($c['type']) ?? ''
];
$this->conditions []= $cond;
}
@ -154,7 +154,7 @@ class Model {
return $orm;
}
foreach ($this->columns as $col) {
$orm = $orm->select(trim(implode('.', (array) $col), '.'));
$orm = $orm->select(trim(implode('.', $col), '.'));
}
return $orm;
}
@ -192,7 +192,7 @@ class Model {
}
if ($join->type == 'raw') {
$orm = $orm->{$method}($join->table, [$join->from, $join->symb, $join->to], $join->alias, $join->params);
} elseif ($join->alias !== '') {
} elseif ($join->alias === '') {
$orm = $orm->{$method}($join->table, [$join->from, $join->symb, $join->to], $join->alias);
} else {
$orm = $orm->{$method}($join->table, [$join->from, $join->symb, $join->to]);
@ -206,7 +206,7 @@ class Model {
}
foreach ($this->conditions as $cond) {
$method = 'where';
switch ($cond->symb) {
switch ($cond->sym) {
case '<':
$method = 'whereLt';
break;
@ -363,13 +363,10 @@ class Model {
return $results;
}
public function array(): ?array {
$results = $this->many();
if (!$results or $results === null) {
$results = $this->build()->findArray();
if (!$results) {
return null;
}
array_walk($results, function(&$item) {
$item = $item->toArray();
});
return $results;
}