Commit 8713b7c0 authored by Aster's avatar Aster Committed by waltermazza
Browse files

General Bug Fixes and Improvements

parent 820496c2
{
"name": "arter/amos-notify",
"description": "Modulo di gestione notifiche - plugin",
"keywords": [
"amos",
"notifiche",
"yii2"
],
"homepage": "http://www.arter.it/",
"type": "component",
"license": "BSD-3-Clause",
"support": {
"issues": "https://github.com/yiisoft/yii2/issues?state=open",
"forum": "http://www.yiiframework.com/forum/",
"wiki": "http://www.yiiframework.com/wiki/",
"irc": "irc://irc.freenode.net/yii",
"source": "https://github.com/yiisoft/yii2"
},
"require": {
"php": ">=5.4.0",
"arter/amos-admin": "^2.2.0",
"arter/amos-core": "^1.11.0",
"arter/amos-email-manager": "^1.1",
"arter/amos-workflow": "^1.0"
},
"config": {
"process-timeout": 1800,
"secure-http": false
},
"autoload": {
"psr-4": {
"arter\\amos\\notificationmanager\\": "src"
}
},
"scripts": {
"post-install-cmd": "php yii migrate --migrationPath=@vendor/arter/amos-notify/migrations --interactive=0"
"name": "arter/amos-notify",
"description": "Modulo di gestione notifiche - plugin",
"keywords": [
"amos",
"notifiche",
"yii2"
],
"homepage": "http://www.arter.it/",
"type": "component",
"license": "BSD-3-Clause",
"support": {
"issues": "https://github.com/yiisoft/yii2/issues?state=open",
"forum": "http://www.yiiframework.com/forum/",
"wiki": "http://www.yiiframework.com/wiki/",
"irc": "irc://irc.freenode.net/yii",
"source": "https://github.com/yiisoft/yii2"
},
"require": {
"php": ">=7.0",
"arter/amos-admin": "^2.2.0",
"arter/amos-core": "^1.19.0",
"arter/amos-email-manager": "^1.1.19",
"arter/amos-workflow": "^1.0"
},
"config": {
"process-timeout": 1800,
"secure-http": false
},
"autoload": {
"psr-4": {
"arter\\amos\\notificationmanager\\": "src"
}
}
\ No newline at end of file
},
"scripts": {
"post-install-cmd": "php yii migrate --migrationPath=@vendor/arter/amos-notify/migrations --interactive=0"
}
}
......@@ -4,11 +4,11 @@
* EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it
*
* @see https://repo.art-er.it Developers' community
* @see http://example.com Developers'community
* @license GPLv3
* @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3
*
* @package arter\amos\notificationmanager
* @package arter\amos\notify
* @category CategoryName
* @author Elite Division S.r.l.
*/
......@@ -16,7 +16,6 @@
namespace arter\amos\notificationmanager;
/**
*
* Plugin per la gestione delle notifiche.
*
* Si basa su una Behavior (NotifyBehavior) che aggiunge funzionalità al modello con gli Events:
......@@ -71,13 +70,42 @@ use yii\log\Logger;
*/
class AmosNotify extends AmosModule implements \yii\base\BootstrapInterface, NotifyWidget
{
public $batchFromDate; // format 'yyyy-mm-dd'
public $defaultSchedule = NotificationsConfOpt::EMAIL_DAY;
public $confirmEmailNotification = false;
/**
* disable notification for default behavior.
* enable notification only with post parameter: saveNotificationSendEmail = 1
*/
public $disableDefaultBehaviorClasses = [
];
public $orderEmailSummary = [
'arter\amos\events\models\Event',
'arter\amos\news\models\News',
'arter\amos\partnershipprofiles\models\PartnershipProfile',
'arter\amos\discussioni\models\DiscussioniTopic',
'arter\amos\sondaggi\models\Sondaggi',
];
/** @var bool */
public $enableNotificationContentLanguage = false;
private static $notifyworkflowlistener;
public $sleepingUserDayLimit = 30; // If the user is inactive for those days he is sleeping
public $contentsLimit = 2; // max items foreach content in email to userNotification
public $usersLimit = 5; // max users in email to userNotification (es max contatti, max visits)
public $enableNewsletter = false;
public $enableSuggestions = false;
/**
* @var array
* $personalizedValidatedEmail => [
* "arter\amos\admin\models\UserProfile" => [
'class' => 'backend\modules\poiadmin\utility\PoiAdminEmailUtility',
'method' => 'sendEmailUserValidated'
]
* ]
*/
public $personalizedValidatedEmail = [];
/**
* @var null |string
......@@ -98,6 +126,34 @@ class AmosNotify extends AmosModule implements \yii\base\BootstrapInterface, Not
*/
public $viewPathEmailNotifyValidated = [];
/**
*
* @var boolean $enableLegacyNotify
*/
public $enableLegacyNotify = false;
private static $notifyworkflowlistener;
private static $registerEvent = false;
/**
* @var array $customIconPlugins
*/
public $customIconPlugins = [];
public $contentToNotNotify = [];
/**
* @var string[] $mailThemeColor
*/
public $mailThemeColor = [
'bgPrimary' => '#297A38',
'bgPrimaryDark' => '#204D28',
'textContrastBgPrimary' => '#FFFFFF',
'textContrastBgPrimaryDark' => '#FFFFFF',
'textPrimary' => '#FFFFFF',
'textPrimaryDark' => '#FFFFFF'
];
/**
* @inheritdoc
*/
......@@ -126,9 +182,22 @@ class AmosNotify extends AmosModule implements \yii\base\BootstrapInterface, Not
public function init()
{
parent::init();
if (isset(Yii::$app->params['layoutMailConfigurations']['bgPrimary'])) {
$this->mailThemeColor['bgPrimary'] = Yii::$app->params['layoutMailConfigurations']['bgPrimary'];
}
if (isset(Yii::$app->params['layoutMailConfigurations']['bgPrimaryDark'])) {
$this->mailThemeColor['bgPrimaryDark'] = Yii::$app->params['layoutMailConfigurations']['bgPrimaryDark'];
}
if (isset(Yii::$app->params['layoutMailConfigurations']['textContrastBgPrimary'])) {
$this->mailThemeColor['textContrastBgPrimary'] = Yii::$app->params['layoutMailConfigurations']['textContrastBgPrimary'];
}
if (isset(Yii::$app->params['layoutMailConfigurations']['textContrastBgPrimaryDark'])) {
$this->mailThemeColor['textContrastBgPrimaryDark'] = Yii::$app->params['layoutMailConfigurations']['textContrastBgPrimaryDark'];
}
\Yii::setAlias('@arter/amos/notificationmanager/commands', __DIR__ . '/commands/');
// initialize the module with the configuration loaded from config.php
\Yii::configure($this, require(__DIR__ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php'));
$this->orderEmailSummary = array_unique($this->orderEmailSummary);
}
/**
......@@ -139,11 +208,13 @@ class AmosNotify extends AmosModule implements \yii\base\BootstrapInterface, Not
if ($app instanceof \yii\console\Application) {
$this->controllerNamespace = 'arter\amos\notificationmanager\commands';
} else {
Event::on(
Record::className(),
SimpleWorkflowBehavior::EVENT_AFTER_CHANGE_STATUS,
[self::$notifyworkflowlistener, 'afterChangeStatus']
);
if (self::$registerEvent == false) {
self::$registerEvent = true;
Event::on(
Record::className(), SimpleWorkflowBehavior::EVENT_AFTER_CHANGE_STATUS,
[self::$notifyworkflowlistener, 'afterChangeStatus']
);
}
}
}
......@@ -154,13 +225,21 @@ class AmosNotify extends AmosModule implements \yii\base\BootstrapInterface, Not
{
return [
'ChangeStatusEmail' => __NAMESPACE__ . '\\' . 'models\ChangeStatusEmail',
'Newsletter' => __NAMESPACE__ . '\\' . 'models\Newsletter',
'NewsletterContents' => __NAMESPACE__ . '\\' . 'models\NewsletterContents',
'NewsletterContentsConf' => __NAMESPACE__ . '\\' . 'models\NewsletterContentsConf',
'NewsletterSearch' => __NAMESPACE__ . '\\' . 'models\search\NewsletterSearch',
'Notification' => __NAMESPACE__ . '\\' . 'models\Notification',
'NotificationChannels' => __NAMESPACE__ . '\\' . 'models\NotificationChannels',
'NotificationConf' => __NAMESPACE__ . '\\' . 'models\NotificationConf',
'NotificationsConfOpt' => __NAMESPACE__ . '\\' . 'models\NotificationsConfOpt',
'NotificationconfNetwork' => __NAMESPACE__ . '\\' . 'models\NotificationconfNetwork',
'NotificationsRead' => __NAMESPACE__ . '\\' . 'models\NotificationsRead',
'NotificationContentLanguage' => __NAMESPACE__ . '\\' . 'models\NotificationContentLanguage',
'NotificationLanguagePreferences' => __NAMESPACE__ . '\\' . 'models\NotificationLanguagePreferences',
'NotificationsConfOpt' => __NAMESPACE__ . '\\' . 'models\NotificationsConfOpt',
'NotificationSendEmail' => __NAMESPACE__ . '\\' . 'models\NotificationSendEmail',
'NotificationsRead' => __NAMESPACE__ . '\\' . 'models\NotificationsRead',
'NotificationsSent' => __NAMESPACE__ . '\\' . 'models\NotificationsSent',
'NotificationConfContent' => __NAMESPACE__ . '\\' . 'models\NotificationConfContent',
];
}
......@@ -180,6 +259,24 @@ class AmosNotify extends AmosModule implements \yii\base\BootstrapInterface, Not
return [];
}
/**
* Same as calling AmosNotify::t('amosnotify', ...$args)
* @return string
*/
public static function txt($txt, ...$args)
{
return static::t('amosnotify', $txt, ...$args);
}
/**
* Same as calling AmosNotify::tHtml('amosnotify', ...$args)
* @return string
*/
public static function txtHtml($txt, ...$args)
{
return static::tHtml('amosnotify', $txt, ...$args);
}
/**
* @param int $uid
* @param string $class_name
......@@ -227,7 +324,7 @@ class AmosNotify extends AmosModule implements \yii\base\BootstrapInterface, Not
} catch (\Exception $ex) {
Yii::getLogger()->log($ex->getTraceAsString(), Logger::LEVEL_ERROR);
}
return $result;
}
......@@ -245,7 +342,7 @@ class AmosNotify extends AmosModule implements \yii\base\BootstrapInterface, Not
} catch (\Exception $ex) {
Yii::getLogger()->log($ex->getTraceAsString(), Logger::LEVEL_ERROR);
}
return $result;
}
......@@ -265,7 +362,7 @@ class AmosNotify extends AmosModule implements \yii\base\BootstrapInterface, Not
} catch (\Exception $ex) {
Yii::getLogger()->log($ex->getTraceAsString(), Logger::LEVEL_ERROR);
}
return $retval;
}
......@@ -284,7 +381,7 @@ class AmosNotify extends AmosModule implements \yii\base\BootstrapInterface, Not
} catch (\Exception $ex) {
Yii::getLogger()->log($ex->getTraceAsString(), Logger::LEVEL_ERROR);
}
return $ok;
}
......@@ -303,7 +400,7 @@ class AmosNotify extends AmosModule implements \yii\base\BootstrapInterface, Not
} catch (\Exception $ex) {
Yii::getLogger()->log($ex->getTraceAsString(), Logger::LEVEL_ERROR);
}
return $ok;
}
......@@ -316,8 +413,26 @@ class AmosNotify extends AmosModule implements \yii\base\BootstrapInterface, Not
{
$result = false;
try {
//$repository = new NotifierRepository();
//$result = $repository->isFavorite($model, $uid);
$repository = new NotifierRepository();
$result = $repository->isFavorite($model, $uid);
} catch (\Exception $ex) {
Yii::getLogger()->log($ex->getTraceAsString(), Logger::LEVEL_ERROR);
}
return $result;
}
/**
* @param $class_name
* @param int|null $uid
* @return bool
*/
public function getAllFavourites($class_name, $uid)
{
$result = false;
try {
$repository = new NotifierRepository();
$result = $repository->getAllFavourites($class_name, $uid);
} catch (\Exception $ex) {
Yii::getLogger()->log($ex->getTraceAsString(), Logger::LEVEL_ERROR);
}
......@@ -333,7 +448,7 @@ class AmosNotify extends AmosModule implements \yii\base\BootstrapInterface, Not
* @return bool
*/
public function saveNotificationConf($userId, $emailFrequency = 0, $smsFrequency = 0, $params = [])
{
{
$notifyUtility = new NotifyUtility();
return $notifyUtility->saveNotificationConf($userId, $emailFrequency, $smsFrequency, $params);
}
......@@ -348,4 +463,10 @@ class AmosNotify extends AmosModule implements \yii\base\BootstrapInterface, Not
$notifyUtility = new NotifyUtility();
return $notifyUtility->setDefaultNotificationsConfs($userId);
}
public function contactAccepted($user, $invitedUser)
{
$notifyUtility = new NotifyUtility();
$notifyUtility->contactAccepted($user, $invitedUser);
}
}
<?php
/**
* Copyright 2020 Art-ER S. Cons. P.A.
* EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it
*
* @see http://example.com Developers'community
* @license GPLv3
* @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3
*
* @package arter\amos\notificationmanager\base\builder
* @category CategoryName
* @author Elite Division S.r.l.
*/
namespace arter\amos\notificationmanager\assets;
use yii\web\AssetBundle;
/**
* Class NotifyAsset
* @package arter\amos\notificationmanager\assets
*/
class NotifyAsset extends AssetBundle
{
/**
* @inheritdoc
*/
public $sourcePath = '@vendor/arter/amos-notify/src/assets/web';
/**
* @inheritdoc
*/
public $css = [
'less/notify.less',
];
/**
* @inheritdoc
*/
public $js = [
'js/notify.js'
];
/**
* @inheritdoc
*/
public $depends = [
];
/**
* @inheritdoc
*/
public function init()
{
$moduleL = \Yii::$app->getModule('layout');
if (!is_null($moduleL)) {
$this->depends [] = 'arter\amos\layout\assets\BaseAsset';
} else {
$this->depends [] = 'arter\amos\core\views\assets\AmosCoreAsset';
}
parent::init();
}
}
/**
IMPORT AMOS-LAYOUT VARIABLES
*/
@import (optional) "../../vendor/arter/amos-layout/src/assets/resources/base/less/variables.less";
@import (optional) "../../vendor/arter/amos-layout/src/assets/resources/base/less/utility.less";
/**
IMPORT STYLE-CUSTOM
*/
@import (optional) "../../backend/web/less/style_custom.less";
/**
NOTIFY
*/
.modal-utility.modal-send-test-newsletter {
.modal-dialog .modal-content .modal-body {
.notify-textinput-class {
width: 100%;
white-space: normal;
}
}
}
.newsletter-can-be-sent {
font-weight: bold;
color: #29b043;
}
.newsletter-cannot-be-sent {
font-weight: bold;
color: #ff0000;
}
\ No newline at end of file
......@@ -4,7 +4,7 @@
* EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it
*
* @see https://repo.art-er.it Developers' community
* @see http://example.com Developers'community
* @license GPLv3
* @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3
*
......@@ -35,4 +35,11 @@ interface Builder
* @return string
*/
public function getSubject(array $resultset);
/**
* @param array $resultSetNormal
* @param array $resultSetNetwork
* @param User $user
* @return mixed
*/
}
......@@ -4,7 +4,7 @@
* EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it
*
* @see https://repo.art-er.it Developers' community
* @see http://example.com Developers'community
* @license GPLv3
* @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3
*
......@@ -15,32 +15,49 @@
namespace arter\amos\notificationmanager\base;
use arter\amos\notificationmanager\base\builder\ContactAcceptedMailBuilder;
use arter\amos\notificationmanager\base\builder\ContentImmediateMailBuilder;
use arter\amos\notificationmanager\base\builder\ContentMailBuilder;
use arter\amos\notificationmanager\base\builder\CustomMailBuilder;
use arter\amos\notificationmanager\base\builder\NewsletterBuilder;
use arter\amos\notificationmanager\base\builder\SleepingUserMailBuilder;
use arter\amos\notificationmanager\base\builder\SuccessfulContentMailBuilder;
use arter\amos\notificationmanager\base\builder\SuccessfulUserMailBuilder;
use arter\amos\notificationmanager\base\builder\SuggestedLinkMailBuilder;
use arter\amos\notificationmanager\base\builder\ValidatedMailBuilder;
use arter\amos\notificationmanager\base\builder\ValidatorsMailBuilder;
use arter\amos\notificationmanager\models\ChangeStatusEmail;
use yii\base\BaseObject;
class BuilderFactory extends BaseObject {
/**
* Class BuilderFactory
* @package arter\amos\notificationmanager\base
*/
class BuilderFactory extends BaseObject
{
const CONTENT_MAIL_BUILDER = 1;
const VALIDATORS_MAIL_BUILDER = 2;
const VALIDATED_MAIL_BUILDER = 3;
const CUSTOM_MAIL_BUILDER = 4;
const CONTENT_IMMEDIATE_MAIL_BUILDER = 5;
const CONTENT_SLEEPING_USER_BUILDER = 6;
const CONTENT_SUCCESSFUL_CONTENT_BUILDER = 7;
const CONTENT_SUCCESSFUL_USER_BUILDER = 8;
const CONTENT_SUGGESTED_LINK_BUILDER = 9;
const CONTENT_CONTACT_ACCEPTED_BUILDER = 10;
const NEWSLETTER_BUILDER = 11;
/**
* @param $type
* @param int $type
* @param ChangeStatusEmail|null $email
* @param string|null $endStatus
* @return ContentMailBuilder|CustomMailBuilder|ValidatedMailBuilder|ValidatorsMailBuilder|null
*/
public function create($type, $email = null, $endStatus = null){
public function create($type, $email = null, $endStatus = null)
{
$obj = null;
switch ($type){
switch ($type) {
case self::CONTENT_MAIL_BUILDER:
$obj = new ContentMailBuilder();
break;
......@@ -56,8 +73,26 @@ class BuilderFactory extends BaseObject {
case self::CUSTOM_MAIL_BUILDER:
$obj = new CustomMailBuilder(['emailConf' => $email, 'endStatus' => $endStatus]);
break;
case self::CONTENT_SLEEPING_USER_BUILDER:
$obj = new SleepingUserMailBuilder();
break;
case self::CONTENT_SUCCESSFUL_CONTENT_BUILDER:
$obj = new SuccessfulContentMailBuilder();
break;
case self::CONTENT_SUCCESSFUL_USER_BUILDER:
$obj = new SuccessfulUserMailBuilder();
break;
case self::CONTENT_SUGGESTED_LINK_BUILDER:
$obj = new SuggestedLinkMailBuilder();
break;
case self::CONTENT_CONTACT_ACCEPTED_BUILDER:
$obj = new ContactAcceptedMailBuilder();
break;
case self::NEWSLETTER_BUILDER:
$obj = new NewsletterBuilder();
break;
}
return $obj;
}
}
......@@ -4,11 +4,11 @@
* EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it
*
* @see https://repo.art-er.it Developers' community
* @see http://example.com Developers'community
* @license GPLv3
* @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3
*
* @package arter\amos\notificationmanager\base
* @package arter\amos\notify
* @category CategoryName
* @author Elite Division S.r.l.
*/
......@@ -27,6 +27,7 @@ use yii\db\ActiveQuery;
use yii\db\ActiveRecord;
use yii\db\Exception;
use yii\db\Query;
use yii\helpers\VarDumper;
use yii\log\Logger;
/**
......@@ -124,26 +125,28 @@ class NotifierRepository
{
$allOk = true;
try {
$classObj = new $class_name;
$classObj = new $class_name;
$subquery = new Query();
$subquery->distinct()
->select('id')
->from(['subquery' => $externalquery]);
$subquery = $subquery->all();
$query = new Query();
$query
->distinct()
->select('a.id as notification_id')
->from(Notification::tableName() . ' a')
->leftJoin(NotificationsRead::tableName() . ' b', 'a.id = b.notification_id and b.user_id = ' . $uid)
->leftJoin($classObj->tableName(), 'a.content_id = ' . $classObj->tableName() . '.id')
->from(Notification::tableName().' a')
->leftJoin(NotificationsRead::tableName().' b', 'a.id = b.notification_id and b.user_id = '.$uid)
->leftJoin($classObj->tableName(), 'a.content_id = '.$classObj->tableName().'.id')
->andWhere([
'b.user_id' => null,
'a.channels' => $channel,
'a.class_name' => $class_name,
$classObj->tableName() . '.id' => $subquery
]);
$classObj->tableName().'.id' => \yii\helpers\ArrayHelper::map($subquery, 'id', 'id')
]);
$result = $query->all();
foreach ($result as $model) {
/** @var NotificationsRead $read */
......@@ -284,4 +287,44 @@ class NotifierRepository
return ($result > 0);
}
/**