Beispiel #1
0
 public static function userInfo($message = NULL)
 {
     $currentTs = time();
     $ts = date(DateUtil::SQL_DT_FMT, $currentTs);
     $arrItems = json_decode($message, true);
     if (!isset($arrItems['ts'])) {
         $arrItems['ts'] = $ts;
     }
     $Log = new UserLogSystem();
     $Log->attributes = $arrItems;
     $Log->message = $message;
     $Log->save();
 }
 public function actionExportaccesslog()
 {
     $request = \Yii::$app->request;
     $logQuery = UserLogSystem::find();
     $filename = "";
     $datefrom = $request->post('datefrom', null);
     if (empty($datefrom)) {
         $datefrom = $request->get('datefrom', null);
     }
     $dateto = $request->post('dateto', null);
     if (empty($dateto)) {
         $dateto = $request->get('dateto', null);
     }
     if (!empty($datefrom) && !empty($dateto)) {
         $logQuery->andWhere(['between', 'ts', $datefrom, $dateto]);
         $filename .= $datefrom . "_" . $dateto;
     }
     $userId = $request->post('userId', '');
     if (empty($userId)) {
         $userId = $request->get('userId', '');
     }
     if (!empty($userId)) {
         $logQuery->andWhere('userId=:userId', [':userId' => $userId]);
         $user = User::find()->where("id={$userId}")->one();
         $filename .= "_" . $user->firstName . "_" . $user->lastName;
     }
     $models = $logQuery->orderBy('ts DESC')->all();
     //find all users' full name
     $arrUserFullName = [];
     $arrUserId = [];
     if ($models) {
         foreach ($models as $Object) {
             $arrUserId[$Object->userId] = $Object->userId;
         }
         if ($arrUserId) {
             $query = User::find();
             $query->andWhere(['in', 'id', $arrUserId]);
             $lst = $query->all();
             foreach ($lst as $Object) {
                 $arrUserFullName[$Object->id] = $Object->firstName . ' - ' . $Object->lastName;
             }
         }
     }
     $dataProvider = new ActiveDataProvider(['query' => $logQuery, 'pagination' => ['pageSize' => 5000]]);
     $filename = trim($filename, "_");
     $filename = $filename ? $filename : "all_access_log";
     $extension = 'xls';
     $response = \Yii::$app->response;
     $response->headers->set("Cache-Control", "no-cache");
     $response->headers->set("Expires", "0");
     $response->headers->set("Pragma", "no-cache");
     $response->headers->set("Content-Type", "application/{$extension}");
     $response->headers->set("Content-Disposition", "attachment; filename={$filename}.{$extension}");
     return $this->renderPartial('accessexcel', ['dataProvider' => $dataProvider, 'arrUserFullName' => $arrUserFullName]);
 }