Esempio n. 1
0
 public function run()
 {
     if (BackendAccessControl::checkPermissionAccess(AdminLogController::BACKEND_PERMISSION)) {
         $logs = AdminLog::find()->joinWith('user')->orderBy(['id' => SORT_DESC])->limit($this->limit)->all();
         $logsFull = [];
         if ($logs) {
             $prevIcon = '';
             foreach ($logs as $log) {
                 $logFull['additional_icon'] = RadiataHelper::getActionAdditionalIconClass($log['action']);
                 $logFull['action'] = RadiataHelper::getActionName($log['action']);
                 if ($log['user_id'] > 0) {
                     $logFull['user'] = $log['user']->getFullName();
                 }
                 if ($prevIcon != $log['icon']) {
                     $logFull['icon'] = $log['icon'];
                     $prevIcon = $log['icon'];
                 } else {
                     $logFull['icon'] = '';
                 }
                 $logFull['data'] = $log['data'];
                 $logFull['created_at'] = $log['created_at'];
                 $logFull['user_id'] = $log['user_id'];
                 $logsFull[] = $logFull;
             }
         }
         if (count($logsFull) > 0) {
             return $this->render('AdminLog', ['logs' => $logsFull]);
         }
     }
 }
Esempio n. 2
0
 public static function saveEvent($event, $action, $data = [])
 {
     if (Yii::$app->controller) {
         $adminLog = new AdminLog();
         $adminLog->module = Yii::$app->controller->module->id;
         if (get_parent_class($event->sender) == 'yii\\db\\ActiveRecord') {
             $adminLog->model = get_class($event->sender);
             if (isset($event->sender->attributes[$event->data['title']])) {
                 $adminLog->data = $event->sender->attributes[$event->data['title']];
             } elseif (isset($event->sender->{$event->data['title']})) {
                 $adminLog->data = $event->sender->{$event->data['title']};
             }
         } else {
             $adminLog->data = isset($data['data']) ? $data['data'] : '';
         }
         $adminLog->icon = $event->data['icon'] ? $event->data['icon'] : $data['icon'];
         $adminLog->action = $action;
         $adminLog->user_id = Yii::$app->user->getId();
         $adminLog->save();
     }
 }
Esempio n. 3
0
 public static function getActions()
 {
     $actionsData = AdminLog::find()->select('action')->distinct()->column();
     if (count($actionsData) > 0) {
         $actions = [];
         foreach ($actionsData as $action) {
             $actions[$action] = RadiataHelper::getActionName($action);
         }
         return $actions;
     } else {
         return [];
     }
 }