public function actionIndex() { $data = Log::find()->orderBy(['timestamp' => SORT_DESC])->limit(40)->all(); $groups = []; foreach ($data as $item) { $groups[strtotime('today', $item->timestamp)][] = $item; } return $this->renderPartial('index', ['groups' => $groups]); }
/** * Log the current event in a database to retrieve data in case of emergency. This method will be trigger * on: EVENT_BEFORE_DELETE, EVENT_AFTER_INSERT & EVENT_AFTER_UPDATE * * @param \yii\base\Event $event * @return boolean */ protected function eventLogger($event) { switch ($event->name) { case 'afterInsert': return Log::add(1, ['tableName' => 'cms_nav_item', 'action' => 'insert', 'row' => $this->id], 'cms_nav_item', $this->id, $this->toArray()); case 'afterUpdate': return Log::add(2, ['tableName' => 'cms_nav_item', 'action' => 'update', 'row' => $this->id], 'cms_nav_item', $this->id, $this->toArray()); case 'afterDelete': return Log::add(3, ['tableName' => 'cms_nav_item', 'action' => 'delete', 'row' => $this->id], 'cms_nav_item', $this->id, $this->toArray()); } }
public function eventAfterInsert() { $this->updateNavItemTimesamp(); $this->reindex($this->nav_item_page_id, $this->placeholder_var, $this->prev_id); Log::add(1, ['tableName' => 'cms_nav_item_page_block_item', 'action' => 'insert', 'row' => $this->id, 'pageTitle' => $this->droppedPageTitle, 'blockName' => $this->block->getNameForLog()], 'cms_nav_item_page_block_item', $this->id); }
public function reindex($e) { $i = 1; foreach (self::find()->where(['nav_container_id' => $this->nav_container_id, 'parent_nav_id' => $this->parent_nav_id])->orderBy('sort_index ASC')->asArray()->all() as $model) { Yii::$app->db->createCommand()->update(self::tableName(), ['sort_index' => $i], 'id=:id', ['id' => $model['id']])->execute(); ++$i; } switch ($e->name) { case 'afterInsert': Log::add(1, ['tableName' => 'cms_nav', 'action' => 'insert', 'row' => $this->id], 'cms_nav', $this->id, $this->toArray()); break; case 'afterUpdate': Log::add(2, ['tableName' => 'cms_nav', 'action' => 'update', 'row' => $this->id], 'cms_nav', $this->id, $this->toArray()); break; case 'afterDelete': Log::add(3, ['tableName' => 'cms_nav', 'action' => 'delete', 'row' => $this->id], 'cms_nav', $this->id, $this->toArray()); break; } }