diff --git a/common/Alias/Model.php b/common/Alias/Model.php new file mode 100644 index 0000000..9f8f579 --- /dev/null +++ b/common/Alias/Model.php @@ -0,0 +1,87 @@ +id; + $orm = $this->orm; + $ref = new \ReflectionObject($orm); + if (!$ref->hasProperty('_dirty_fields')) { + return; + } + $dirty = $ref->getProperty('_dirty_fields'); + $dirty->setAccessible(true); + $new_values = $dirty->getValue($orm); + $changes = array_combine(array_keys($new_values), array_fill(0, count($new_values), ['old' => '', 'new' => ''])); + if ($this->isNew()) { + $old = (object) array_combine(array_keys($new_values), array_fill(0, count($new_values), '')); + } else { + $old = model(get_called_class())->findOne($this->{$this->getId()}); + } + foreach ($new_values as $column => $value) { + $changes[$column] = ['column' => $column, 'old' => $old->$column, 'new' => $value]; + } + $action = '[' . get_called_class() . ']'; + doLog($user, $action, $changes); + } + public function getId() + { + if (property_exists(get_called_class(), '_id_column')) { + return static::$_id_column; + } + return $this->id; + } + public function save() + { + $ref = new \ReflectionObject($this); + if ($ref->hasProperty('_timestamps')) { + $ref = $ref->getProperty('_timestamps'); + $ref->setAccessible(true); + if ($ref->getValue()) { + if ($this->is_new()) { + $this->setExpr('created_at', 'NOW()'); + } + $this->setExpr('updated_at', 'NOW()'); + } + } + if (!\ORM::getDb()->inTransaction()) { + \ORM::getDb()->beginTransaction(); + } + try { + parent::save(); + if (\ORM::getDb()->inTransaction()) { + \ORM::getDb()->commit(); + } + } catch (\Exception $e) { + if (\ORM::getDb()->inTransaction()) { + \ORM::getDb()->rollBack(); + } + throw $e; + } + $this->log(); + } + public function __call($method, $args) + { + if (!method_exists($this, $method)) { + $str = '' . Stringy::create($method)->underscored(); + if (method_exists($this, $str)) { + return call_user_func_array([$this, $str], $args); + } + throw new \BadMethodCallException($method . ' not found in ' . get_class($this)); + } + return call_user_func_array([$this, $str], $args); + } +} +?> diff --git a/common/Alias/NewEstado.php b/common/Alias/NewEstado.php new file mode 100644 index 0000000..4bf9089 --- /dev/null +++ b/common/Alias/NewEstado.php @@ -0,0 +1,20 @@ +fecha, config('app.timezone')); + } +} +?> \ No newline at end of file diff --git a/common/Alias/NewModel.php b/common/Alias/NewModel.php new file mode 100644 index 0000000..1c513b4 --- /dev/null +++ b/common/Alias/NewModel.php @@ -0,0 +1,9 @@ + \ No newline at end of file diff --git a/common/Alias/NewTipo.php b/common/Alias/NewTipo.php new file mode 100644 index 0000000..b5fa3fb --- /dev/null +++ b/common/Alias/NewTipo.php @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/common/Alias/OldModel.php b/common/Alias/OldModel.php new file mode 100644 index 0000000..f12a3cd --- /dev/null +++ b/common/Alias/OldModel.php @@ -0,0 +1,8 @@ +