Skip to content

Commit

Permalink
message log for console command, detail view, icons #4
Browse files Browse the repository at this point in the history
  • Loading branch information
nadar committed Jun 25, 2018
1 parent 7e9d10e commit 0fc2897
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);


Expand Down
10 changes: 10 additions & 0 deletions src/commands/AutoMessageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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());
Expand Down
36 changes: 35 additions & 1 deletion src/models/MessageLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -83,14 +84,47 @@ 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
*/
public function ngRestScopes()
{
return [
[['list'], ['site_id', 'timestamp', 'recipients', 'text']],
[['list'], ['site.url', 'timestamp', 'recipients']],
['delete', false],
];
}
Expand Down

0 comments on commit 0fc2897

Please sign in to comment.