From 0fc28976866e1df3c3ef81ffed089a3b65bc4678 Mon Sep 17 00:00:00 2001 From: Basil Suter Date: Mon, 25 Jun 2018 16:18:32 +0200 Subject: [PATCH] message log for console command, detail view, icons #4 --- src/Module.php | 6 ++--- src/commands/AutoMessageController.php | 10 +++++++ src/models/MessageLog.php | 36 +++++++++++++++++++++++++- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/Module.php b/src/Module.php index e2d8660..4b53d60 100755 --- a/src/Module.php +++ b/src/Module.php @@ -28,10 +28,10 @@ public function getMenu() ->itemRoute('Status', 'remoteadmin/status/index', 'update') ->itemApi('Pages', 'remoteadmin/site/index', 'cloud', 'api-remote-site') ->group('Message') - ->itemApi('Templates', 'remoteadmin/message-template/index', 'label', 'api-remote-messagetemplate') - ->itemApi('History', 'remoteadmin/message-log/index', 'label', 'api-remote-messagelog') + ->itemApi('Templates', 'remoteadmin/message-template/index', 'drafts', 'api-remote-messagetemplate') + ->itemApi('History', 'remoteadmin/message-log/index', 'history', 'api-remote-messagelog') ->group('Billing') - ->itemApi('Products', 'remoteadmin/billing-product/index', 'label', 'api-remote-billingproduct') + ->itemApi('Products', 'remoteadmin/billing-product/index', 'monetization_on', 'api-remote-billingproduct') ->itemApi('Site Billing Product', 'remoteadmin/site-billing-product/index', 'label', 'api-remote-sitebillingproduct', ['hiddenInMenu' => true]); diff --git a/src/commands/AutoMessageController.php b/src/commands/AutoMessageController.php index 20faa78..50e6638 100644 --- a/src/commands/AutoMessageController.php +++ b/src/commands/AutoMessageController.php @@ -7,6 +7,7 @@ use luya\remoteadmin\models\Site; use luya\remoteadmin\models\MessageTemplate; use luya\console\Command; +use luya\remoteadmin\models\MessageLog; class AutoMessageController extends Command { @@ -42,6 +43,15 @@ public function actionIndex() if (Yii::$app->mail->compose($subject, $text)->addresses($addresses)->send()) { $this->outputSuccess("Mail has been sent to: " . implode(",", $addresses)); + + // add log entry for message. + $log = new MessageLog(); + $log->timestamp = time(); + $log->recipients = implode("; ", $addresses); + $log->text = $text; + $log->site_id = $item->id; + $log->save(false); + $item->updateAttributes(['last_message_timestamp' => time()]); } else { $this->outputError("Error while sending email: " . Yii::$app->mail->getError()); diff --git a/src/models/MessageLog.php b/src/models/MessageLog.php index d832b84..fd7ef01 100644 --- a/src/models/MessageLog.php +++ b/src/models/MessageLog.php @@ -6,6 +6,7 @@ use luya\admin\ngrest\base\NgRestModel; use luya\admin\ngrest\plugins\Html; use luya\remoteadmin\Module; +use luya\admin\aws\DetailViewActiveWindow; /** * Message Log. @@ -83,6 +84,39 @@ public function ngRestAttributeTypes() 'text' => ['class' => Html::class, 'nl2br' => false], ]; } + + public function ngRestExtraAttributeTypes() + { + return [ + 'site.url' => 'text', + ]; + } + + /** + * @inheritdoc + */ + public function ngRestActiveWindows() + { + return [ + [ + 'class' => DetailViewActiveWindow::class, + 'attributes' => [ + 'site.url', + 'timestamp:datetime', + 'recipients', + 'text:raw', + ] + ], + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getSite() + { + return $this->hasOne(Site::class, ['id' => 'site_id']); + } /** * @inheritdoc @@ -90,7 +124,7 @@ public function ngRestAttributeTypes() public function ngRestScopes() { return [ - [['list'], ['site_id', 'timestamp', 'recipients', 'text']], + [['list'], ['site.url', 'timestamp', 'recipients']], ['delete', false], ]; }