コード例 #1
0
 /**
  * Сохранить действие
  * @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);
         }
     }
 }
コード例 #2
0
 /**
  * Вроверить дополнительные условия для авторизации
  * @param null $userId
  * @return bool
  */
 public function verifyAuthCondition($userId)
 {
     $actions = Action::getRecords($userId, 'auth-error', $this->module->intervalAuthBan, true);
     if ($actions >= $this->module->amountAttemptsAuth) {
         return false;
     }
     return true;
 }
コード例 #3
0
 /**
  * @inheritdoc
  */
 public function attributeLabels()
 {
     $labels = parent::attributeLabels();
     return array_merge($labels, ['username' => Yii::t('users', 'USER'), 'date_from' => Yii::t('users', 'DATE_FROM'), 'date_to' => Yii::t('users', 'DATE_TO')]);
 }
コード例 #4
0
 /**
  * Действия пользователя
  * @return \yii\db\ActiveQuery
  */
 public function getActions()
 {
     return $this->hasMany(Action::className(), ['user_id' => 'id']);
 }