public function actionLog()
 {
     \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     $data = \yii\helpers\Json::decode(\Yii::$app->request->post('data'));
     $entry = null;
     if (isset($data['auditEntry'])) {
         $entry = models\AuditEntry::findOne($data['auditEntry']);
     } else {
         return ['result' => 'error', 'message' => 'No audit entry to attach to'];
     }
     // Convert data into the loggable object
     $javascript = new models\AuditJavascript();
     $map = ['auditEntry' => 'audit_id', 'message' => 'message', 'type' => 'type', 'file' => 'origin', 'line' => function ($value) use($javascript) {
         $javascript->origin .= ':' . $value;
     }, 'col' => function ($value) use($javascript) {
         $javascript->origin .= ':' . $value;
     }, 'data' => function ($value) use($javascript) {
         if (count($value)) {
             $javascript->data = $value;
         }
     }];
     foreach ($map as $key => $target) {
         if (isset($data[$key])) {
             if (is_callable($target)) {
                 $target($data[$key]);
             } else {
                 $javascript->{$target} = $data[$key];
             }
         }
     }
     if ($javascript->save()) {
         return ['result' => 'ok'];
     }
     return ['result' => 'error', 'errors' => $javascript->getErrors()];
 }
 /**
  * Displays a single AuditEntry model.
  * @param integer $id
  * @return mixed
  * @throws \HttpInvalidParamException
  */
 public function actionView($id)
 {
     $model = AuditEntry::findOne($id);
     if (!$model) {
         throw new \HttpInvalidParamException('Invalid request number specified');
     }
     return $this->render('view', ['model' => $model]);
 }
 /**
  * Displays a single AuditEntry model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $entry = AuditEntry::findOne($id);
     if ($entry) {
         return $this->render('view', ['entry' => $entry]);
     } else {
         throw new \HttpInvalidParamException('Invalid request number specified');
     }
     $this->redirect(['index']);
 }
 /**
  * @param $id
  * @return [AuditEntry, Panel[]]
  * @throws NotFoundHttpException
  */
 public function loadData($id)
 {
     /** @var AuditEntry $model */
     $model = AuditEntry::findOne($id);
     if (!$model) {
         throw new NotFoundHttpException('The requested entry does not exist.');
     }
     // Why the separate panel list here?
     // Because we don't want to interfere with the modules' regular configuration.
     // We might as well be viewing an entry that has data for more panels than those who are currently active.
     // Updating the actual module panels would mean that for all audit viewing that panel would become active again
     $panels = $this->module->loadPanels($this->module->panelIdentifiers);
     $activePanels = [];
     $data = \yii\helpers\ArrayHelper::getColumn($model->data, 'data');
     foreach ($panels as $panelId => $panel) {
         if ($panel->hasEntryData($model)) {
             $panel->tag = $id;
             $panel->model = $model;
             $panel->load(isset($data[$panelId]) ? $data[$panelId] : null);
             $activePanels[$panelId] = $panel;
         }
     }
     return [$model, $activePanels];
 }