/** * Сохранить действие * @param Event $event */ public function action($event) { $save = true; $data = []; if (!empty($this->actions[$event->name])) { if ($event->name == ActiveRecord::EVENT_BEFORE_DELETE) { $action = $this->actions[$event->name]; if (is_array($this->actions[$event->name])) { if (!isset($this->actions[$event->name]['action'])) { throw new InvalidParamException('Param "action" must be in configuration array'); } $action = $this->actions[$event->name]['action']; } $data = $this->deleteRecord($event); } else { if (is_array($this->actions[$event->name])) { throw new InvalidParamException('Any action except "' . ActiveRecord::EVENT_BEFORE_DELETE . '" should not be an array'); } $action = $this->actions[$event->name]; $diff = array_diff($event->sender->getAttributes(), $event->sender->getOldAttributes()); $diff = array_diff(array_keys($diff), $this->exclude); if ($diff) { $data = ['old-attributes' => $event->sender->getOldAttributes(), 'attributes' => $event->sender->getAttributes()]; } else { $save = false; } } if ($save) { $userId = null; if (!Yii::$app instanceof \yii\console\Application) { $userId = Yii::$app->user->id; } Action::saveRecord($userId, $this->module, $action, $data); } } }
/** * Записать действие пользователя в историю * @param $userId * @param $module * @param $action * @param array $data * @return bool */ public function action($userId, $module, $action, $data = []) { return Action::saveRecord($userId, $module, $action, $data); }