/** * Finds the SystemMessage model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return SystemMessage the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = SystemMessage::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException(Yii::t('maddoger/admin', 'The requested system message does not exist.')); } }
/** * @return string */ public function actionError() { if (($exception = Yii::$app->getErrorHandler()->exception) === null) { return ''; } if ($exception instanceof HttpException) { $code = $exception->statusCode; } else { $code = $exception->getCode(); } if ($exception instanceof Exception) { $name = $exception->getName(); } else { $name = Yii::t('maddoger/admin', 'Error'); } if ($code) { $name .= " (#{$code})"; } if ($exception instanceof UserException) { $message = $exception->getMessage(); } else { $message = Yii::t('maddoger/admin', 'An internal server error occurred.'); if (Module::getInstance()->sendSystemMessageOnServerError) { SystemMessage::send($name . ' ' . Yii::$app->request->url, $exception->getMessage(), 'error', $exception->getTraceAsString()); } } if (Yii::$app->getRequest()->getIsAjax()) { return "{$name}: {$message}"; } else { return $this->render('error', ['name' => $name, 'message' => $message, 'exception' => $exception]); } }
/** * Send system message * @param string $title * @param string $message * @param string $type * @param mixed $data * @return bool */ public static function send($title, $message, $type = null, $data = null) { //Add only 1 hour if (SystemMessage::find()->where(['and', ['title' => $title], ['>', 'created_at', strtotime('-1 hour')]])->count() > 0) { return true; } $message = new SystemMessage(['title' => trim($title), 'message' => trim($message), 'data' => $data, 'type' => $type]); return $message->save(); }
?> <div class="panel panel-info"> <div class="panel-heading"> <h3 class="panel-title"><i class="fa fa-warning"></i> <?php echo Yii::t('maddoger/admin', 'System messages'); ?> <small><?php echo Html::a(Yii::t('maddoger/admin', 'more info'), ['system-messages/index']); ?> </small> </h3> </div> <!-- /.panel-header --> <div class="panel-body"> <?php $messages = SystemMessage::findLastMessages()->limit(10)->all(); if ($messages) { foreach ($messages as $message) { $options = ['class' => 'callout']; if ($message['type']) { Html::addCssClass($options, 'callout-' . $message['type']); } echo Html::tag('div', Html::tag('h4', $message->title) . Html::tag('span', Yii::$app->formatter->asDatetime($message->created_at), ['class' => 'small text-muted']) . Html::tag('p', $message->message), $options); } } else { echo '<p class="text-muted">' . Yii::t('maddoger/admin', 'No messages found.') . '</p>'; } ?> </div> <!-- /.panel-body --> </div>