/** * Stores log messages to Log System Table. */ public static function info($message = NULL, $categories = NULL) { $currentTs = time(); $ts = date(DateUtil::SQL_DT_FMT, $currentTs); $arrItems = json_decode($message, true); $arrItems['categories'] = $categories; if (!isset($arrItems['ts'])) { $arrItems['ts'] = $ts; } $Log = new LogSystem(); $Log->attributes = $arrItems; $Log->message = $message; $Log->save(); }
public function run() { $attributes = array(); $arrUserId = array(); $arrUser = array(); $arrParams = array(); switch ($this->entity) { case Entity::TYPE_CONTENT: $arrParams = array('entityType' => Entity::TYPE_CONTENT, 'categories' => 'audit.content.update'); break; } $arrLog = []; if (!empty($this->_Content->id)) { $arrParams['refId'] = $this->_Content->id; $query = LogSystem::find(); $query->andWhere($arrParams); $query->orderBy(['ts' => SORT_DESC]); $arrLog = $query->all(); if ($arrLog) { foreach ($arrLog as $object) { $arrUserId[$object->userId] = $object->userId; } } } if ($arrUserId) { $query = User::find(); $query->andWhere(['in', 'id', $arrUserId]); $user = $query->all(); if ($user) { foreach ($user as $object) { $arrUser[$object->id] = $object->firstName . ' - ' . $object->lastName; } } } echo $this->render('content/newsLog', ['Content' => $this->_Content, 'arrLog' => $arrLog, 'arrUser' => $arrUser]); }
public function actionExportcontentlog() { $request = \Yii::$app->request; $arrUser = []; $filename = ""; $query = User::find()->andWhere(['status' => User::STATUS_ACTIVE])->all(); foreach ($query as $Object) { $arrUser[$Object->id] = $Object->firstName . ' - ' . $Object->lastName; } $logQuery = LogSystem::find(); $logQuery->andWhere(['entityType' => Entity::TYPE_CONTENT]); $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; } $status = $request->post('status', ''); if (empty($status)) { $status = $request->get('status', ''); } if (!empty($status)) { $logQuery->andWhere('status=:status', [':status' => $status]); $filename .= "_" . Workflow::$arrStatusTpbs[$status]; } $userId = $request->post('userId', ''); if (empty($userId)) { $userId = $request->get('userId', ''); } if (!empty($userId)) { $logQuery->andWhere('userId=:userId', [':userId' => $userId]); $filename .= "_user_" . $userId; } $logQuery->orderBy('ts DESC'); $logLst = $logQuery->all(); $arrUserName = []; $arrContent = []; $arrUserId = []; $arrContentId = []; if ($logLst) { foreach ($logLst as $Object) { $arrUserId[$Object->userId] = $Object->userId; $arrContentId[$Object->refId] = $Object->refId; } if (!empty($arrUserId)) { $query = User::find(); $query->andWhere(['in', 'id', $arrUserId]); $lst = $query->all(); foreach ($lst as $Object) { $arrUserName[$Object->id] = $Object->firstName . ' - ' . $Object->lastName; } } if (!empty($arrContentId)) { $query = Content::find(); $query->andWhere(['in', 'id', $arrContentId]); $lst = $query->all(); foreach ($lst as $Object) { $arrContent[$Object->id] = $Object->title; } } } $dataProvider = new ActiveDataProvider(['query' => $logQuery]); $filename = trim($filename, "_"); $filename = $filename ? $filename : "all_content_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('excel', ['dataProvider' => $dataProvider, 'arrUserName' => $arrUserName, 'arrContent' => $arrContent]); }