Commit c4ff4ea4 authored by Aster's avatar Aster Committed by waltermazza
Browse files

General Bug Fixes and Improvements

parent c8454314
......@@ -11,13 +11,13 @@ Installation
Either run
```bash
composer require arter/amos-comments
composer require elitedivision/amos-comments
```
or add this row
```
"arter/amos-comments": "dev-master"
"elitedivision/amos-comments": "dev-master"
```
to the require section of your `composer.json` file.
......@@ -28,11 +28,11 @@ to the require section of your `composer.json` file.
<?php
'modules' => [
'comments' => [
'class' => 'arter\amos\comments\AmosComments',
'class' => 'elitedivision\amos\comments\AmosComments',
'modelsEnabled' => [
/**
* Add here the classnames of the models where you want the comments
* (i.e. 'arter\amos\events\models\Event')
* (i.e. 'elitedivision\amos\events\models\Event')
*/
],
// the following are mandatory fields
......@@ -57,7 +57,7 @@ Also, add these lines to your bootstrap:
<?php
'components' => [
'view' => [
'class' => 'arter\amos\core\components\AmosView',
'class' => 'elitedivision\amos\core\components\AmosView',
],
],
```
......@@ -65,7 +65,7 @@ Also, add these lines to your bootstrap:
4 Apply migrations
```bash
php yii migrate/up --migrationPath=@vendor/arter/amos-comments/src/migrations
php yii migrate/up --migrationPath=@vendor/elitedivision/amos-comments/src/migrations
```
or add this row to your migrations config in console:
......@@ -73,7 +73,7 @@ or add this row to your migrations config in console:
```php
<?php
return [
'@vendor/arter/amos-comments/src/migrations',
'@vendor/elitedivision/amos-comments/src/migrations',
];
```
......@@ -81,7 +81,7 @@ return [
```php
<?php
use arter\amos\comments\models\CommentInterface;
use elitedivision\amos\comments\models\CommentInterface;
/**
* Implement the CommentInterface
......@@ -103,7 +103,7 @@ public function isCommentable()
<?php
'modules' => [
'comments' => [
'class' => 'arter\amos\comments\AmosComments',
'class' => 'elitedivision\amos\comments\AmosComments',
'modelsEnabled' => [
'class_namespace\MyClass'
]
......@@ -118,7 +118,7 @@ public function isCommentable()
<?php
'modules' => [
'comments' => [
'class' => 'arter\amos\comments\AmosComments',
'class' => 'elitedivision\amos\comments\AmosComments',
'enableMailsNotification' => false,
'modelsEnabled' => [
'class_namespace\MyClass'
......@@ -127,15 +127,15 @@ public function isCommentable()
],
```
* **htmlMailContent** - string/array
***htmlMailContent** - string/array
change the content of the mail of notification when you insert a comment
you can insert an array
```php
'comments' => [
'htmlMailContent' => [
'arter\amos\news\models\News' => '@backend/mail/comment/content_news',
'arter\amos\discussioni\models\DiscussioniTopic' => '@backend/mail/comment/content_discussioni',
'arter\amos\documenti\models\Documenti' => '@backend/mail/comment/content_documenti'
'elitedivision\amos\news\models\News' => '@backend/mail/comment/content_news',
'elitedivision\amos\discussioni\models\DiscussioniTopic' => '@backend/mail/comment/content_discussioni',
'elitedivision\amos\documenti\models\Documenti' => '@backend/mail/comment/content_documenti'
],
```
or a string if the conente is valid for all contents(news/discussioni/docuemnts/ecc..)
......@@ -143,4 +143,13 @@ or a string if the conente is valid for all contents(news/discussioni/docuemnts/
'comments' => [
'htmlMailContent' => '@backend/mail/comment/content_news'
]
```
enableCommentOnlyWithScope
***enableCommentOnlyWithScope** - boolean default false
If true it enable the comments olny with the scope (in the community)
```php
'comments' => [
'enableCommentOnlyWithScope' => true,
]
```
\ No newline at end of file
{
"name": "arter/amos-comments",
"name": "elitedivision/amos-comments",
"description": "Comments for contents - plugin",
"keywords": ["amos", "yii2", "comments"],
"type": "plugin",
"license": "BSD-3-Clause",
"require": {
"php": ">=5.4.0",
"arter/amos-core": "^1.9.60",
"arter/amos-admin": ">=1.7",
"arter/amos-attachments": "^1.1.9"
"elitedivision/amos-admin": "^2.0",
"elitedivision/amos-attachments": "^1.1.9",
"elitedivision/amos-core": "^1.20.2"
},
"extra": {
"asset-installer-paths": {
......@@ -18,7 +18,7 @@
},
"autoload": {
"psr-4": {
"arter\\amos\\comments\\": "src"
"elitedivision\\amos\\comments\\": "src"
}
}
}
\ No newline at end of file
<?php
/**
* Copyright 2020 Art-ER S. Cons. P.A.
* EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it
* Lombardia Informatica S.p.A.
* OPEN 2.0
*
* @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\comments
* @package elitedivision\amos\comments
* @category CategoryName
* @author Elite Division S.r.l.
* @author Lombardia Informatica S.p.A.
*/
namespace arter\amos\comments;
namespace elitedivision\amos\comments;
use arter\amos\comments\components\CommentComponent;
use arter\amos\comments\models\Comment;
use arter\amos\comments\models\CommentReply;
use arter\amos\core\components\AmosView;
use arter\amos\core\module\AmosModule;
use arter\amos\core\module\ModuleInterface;
use elitedivision\amos\comments\components\CommentComponent;
use elitedivision\amos\comments\models\Comment;
use elitedivision\amos\comments\models\CommentReply;
use elitedivision\amos\core\components\AmosView;
use elitedivision\amos\core\module\AmosModule;
use elitedivision\amos\core\module\ModuleInterface;
use elitedivision\amos\core\record\Record;
use yii\base\BootstrapInterface;
use yii\base\Event;
use yii\db\ActiveRecord;
use yii\helpers\VarDumper;
/**
* Class AmosComments
* @package arter\amos\comments
* @package elitedivision\amos\comments
*/
class AmosComments extends AmosModule implements ModuleInterface, BootstrapInterface
{
......@@ -42,7 +44,7 @@ class AmosComments extends AmosModule implements ModuleInterface, BootstrapInter
/**
* @inheritdoc
*/
public $controllerNamespace = 'arter\amos\comments\controllers';
public $controllerNamespace = 'elitedivision\amos\comments\controllers';
public $newFileMode = 0666;
public $name = 'Comments';
public $layoutInverted = false;
......@@ -61,51 +63,51 @@ class AmosComments extends AmosModule implements ModuleInterface, BootstrapInter
/**
* This is the html used to render the subject of the e-mail. In the view is available the variable $profile
* that is an instance of 'arter\amos\admin\models\UserProfile'
* that is an instance of 'elitedivision\amos\admin\models\UserProfile'
* @var string
*/
public $htmlMailContentSubject = '@vendor/arter/amos-comments/src/views/comment/email/content_subject';
public $htmlMailContentSubject = '@vendor/elitedivision/amos-comments/src/views/comment/email/content_subject';
// public $htmlMailContentTitle = [
// 'arter\amos\news\models\News' => '@vendor/arter/amos-comments/src/views/comment/email/content_subject_news',
// 'arter\amos\discussioni\models\DiscussioniTopic' => '@vendor/arter/amos-comments/src/views/comment/email/content_subject_discussioni',
// 'arter\amos\documenti\models\Documenti' => '@vendor/arter/amos-comments/src/views/comment/email/content_subjcet_documenti'
// 'elitedivision\amos\news\models\News' => '@vendor/elitedivision/amos-comments/src/views/comment/email/content_subject_news',
// 'elitedivision\amos\discussioni\models\DiscussioniTopic' => '@vendor/elitedivision/amos-comments/src/views/comment/email/content_subject_discussioni',
// 'elitedivision\amos\documenti\models\Documenti' => '@vendor/elitedivision/amos-comments/src/views/comment/email/content_subjcet_documenti'
// ];
public $htmlMailContentSubjectDefault = '@vendor/arter/amos-comments/src/views/comment/email/content_subject';
public $htmlMailContentSubjectDefault = '@vendor/elitedivision/amos-comments/src/views/comment/email/content_subject';
/**
* This is the html used to render the subject of the e-mail. In the view is available the variable $profile
* that is an instance of 'arter\amos\admin\models\UserProfile'
* that is an instance of 'elitedivision\amos\admin\models\UserProfile'
* @var string
*/
public $htmlMailContentTitle = '@vendor/arter/amos-comments/src/views/comment/email/content_title';
public $htmlMailContentTitle = '@vendor/elitedivision/amos-comments/src/views/comment/email/content_title';
// public $htmlMailContentTitle = [
// 'arter\amos\news\models\News' => '@vendor/arter/amos-comments/src/views/comment/email/content_title_news',
// 'arter\amos\discussioni\models\DiscussioniTopic' => '@vendor/arter/amos-comments/src/views/comment/email/content_title_discussioni',
// 'arter\amos\documenti\models\Documenti' => '@vendor/arter/amos-comments/src/views/comment/email/content_title_documenti'
// 'elitedivision\amos\news\models\News' => '@vendor/elitedivision/amos-comments/src/views/comment/email/content_title_news',
// 'elitedivision\amos\discussioni\models\DiscussioniTopic' => '@vendor/elitedivision/amos-comments/src/views/comment/email/content_title_discussioni',
// 'elitedivision\amos\documenti\models\Documenti' => '@vendor/elitedivision/amos-comments/src/views/comment/email/content_title_documenti'
// ];
/*
*
*/
public $htmlMailContentTitleDefault = '@vendor/arter/amos-comments/src/views/comment/email/content_title';
public $htmlMailContentTitleDefault = '@vendor/elitedivision/amos-comments/src/views/comment/email/content_title';
/**
* This is the html used to render the message of the e-mail. In the view is available the variable $profile
* that is an instance of 'arter\amos\admin\models\UserProfile'
* that is an instance of 'elitedivision\amos\admin\models\UserProfile'
* @var string|array
*/
public $htmlMailContent = '@vendor/arter/amos-comments/src/views/comment/email/content';
public $htmlMailContent = '@vendor/elitedivision/amos-comments/src/views/comment/email/content';
// public $htmlMailContent = [
// 'arter\amos\news\models\News' => '@vendor/arter/amos-comments/src/views/comment/email/content_news',
// 'arter\amos\discussioni\models\DiscussioniTopic' => '@vendor/arter/amos-comments/src/views/comment/email/content_discussioni',
// 'arter\amos\documenti\models\Documenti' => '@vendor/arter/amos-comments/src/views/comment/email/content_documenti'
// 'elitedivision\amos\news\models\News' => '@vendor/elitedivision/amos-comments/src/views/comment/email/content_news',
// 'elitedivision\amos\discussioni\models\DiscussioniTopic' => '@vendor/elitedivision/amos-comments/src/views/comment/email/content_discussioni',
// 'elitedivision\amos\documenti\models\Documenti' => '@vendor/elitedivision/amos-comments/src/views/comment/email/content_documenti'
// ];
/*
*
*/
public $htmlMailContentDefault = '@vendor/arter/amos-comments/src/views/comment/email/content';
public $htmlMailContentDefault = '@vendor/elitedivision/amos-comments/src/views/comment/email/content';
/**
* Sets if the notify checkbox must be visible into the comments accordion
* @var bool
......@@ -143,6 +145,18 @@ class AmosComments extends AmosModule implements ModuleInterface, BootstrapInter
*/
public $disablePagination = false;
/**
* Example:
* [
* 'elitedivision\amos\documenti\models\Documenti',
* 'elitedivision\amos\news\models\News',
* 'elitedivision\amos\discussioni\models\Discussioni',
* ]
*
* @var boolean
*/
public $bellNotificationEnabledClasses = [];
/**
* @return string
*/
......@@ -157,7 +171,7 @@ class AmosComments extends AmosModule implements ModuleInterface, BootstrapInter
public function init()
{
parent::init();
\Yii::setAlias('@arter/amos/'.static::getModuleName().'/controllers', __DIR__.'/controllers/');
\Yii::setAlias('@elitedivision/amos/'.static::getModuleName().'/controllers', __DIR__.'/controllers/');
// custom initialization code goes here
\Yii::configure($this, require(__DIR__.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php'));
}
......@@ -192,6 +206,13 @@ class AmosComments extends AmosModule implements ModuleInterface, BootstrapInter
public function bootstrap($app)
{
Event::on(AmosView::className(), AmosView::AFTER_RENDER_CONTENT, [new CommentComponent(), 'showComments']);
if (!empty($this->bellNotificationEnabledClasses) && is_array($this->bellNotificationEnabledClasses)){
foreach ($this->bellNotificationEnabledClasses as $modelClassName){
Event::on($modelClassName, Record::EVENT_AFTER_INSERT, [new CommentComponent(), 'addCreatorEnableNotificationUser']);
}
}
}
/**
......@@ -204,7 +225,7 @@ class AmosComments extends AmosModule implements ModuleInterface, BootstrapInter
->andWhere(['context' => $model->className(), 'context_id' => $model->id])
->groupBy('comment.id');
/** @var \arter\amos\comments\models\Comment $lastComment */
/** @var \elitedivision\amos\comments\models\Comment $lastComment */
$countComment = $query->count();
$query = Comment::find()
->joinWith('commentReplies', true, 'LEFT JOIN')
......
<?php
/**
* Copyright 2020 Art-ER S. Cons. P.A.
* EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it
* Lombardia Informatica S.p.A.
* OPEN 2.0
*
* @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\comments\assets
* @package elitedivision\amos\comments\assets
* @category CategoryName
* @author Elite Division S.r.l.
* @author Lombardia Informatica S.p.A.
*/
namespace arter\amos\comments\assets;
namespace elitedivision\amos\comments\assets;
use yii\web\AssetBundle;
/**
* Class CommentsAsset
* @package arter\amos\comments\assets
* @package elitedivision\amos\comments\assets
*/
class CommentsAsset extends AssetBundle
{
/**
* @inheritdoc
*/
public $sourcePath = '@vendor/arter/amos-comments/src/assets/web';
public $sourcePath = '@vendor/elitedivision/amos-comments/src/assets/web';
/**
* @inheritdoc
......@@ -53,9 +53,9 @@ class CommentsAsset extends AssetBundle
{
$moduleL = \Yii::$app->getModule('layout');
if (!empty($moduleL)) {
$this->depends [] = 'arter\amos\layout\assets\BaseAsset';
$this->depends [] = 'elitedivision\amos\layout\assets\BaseAsset';
} else {
$this->depends [] = 'arter\amos\core\views\assets\AmosCoreAsset';
$this->depends [] = 'elitedivision\amos\core\views\assets\AmosCoreAsset';
}
parent::init(); // TODO: Change the autogenerated stub
}
......
<?php
/**
* Copyright 2020 Art-ER S. Cons. P.A.
* EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it
* Lombardia Informatica S.p.A.
* OPEN 2.0
*
* @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\comments\assets
* @package elitedivision\amos\comments\assets
* @category CategoryName
* @author Elite Division S.r.l.
* @author Lombardia Informatica S.p.A.
*/
namespace arter\amos\comments\assets;
namespace elitedivision\amos\comments\assets;
use yii\web\AssetBundle;
/**
* Class CommentsAsset
* @package arter\amos\comments\assets
* @package elitedivision\amos\comments\assets
*/
class CommentsBootstrapitaliaAsset extends AssetBundle
{
/**
* @inheritdoc
*/
public $sourcePath = '@vendor/arter/amos-comments/src/assets/web';
public $sourcePath = '@vendor/elitedivision/amos-comments/src/assets/web';
/**
* @inheritdoc
......
/**
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 (optional) "../../vendor/elitedivision/amos-layout/src/assets/resources/base/less/variables.less";
@import (optional) "../../vendor/elitedivision/amos-layout/src/assets/resources/base/less/utility.less";
/**
IMPORT STYLE-CUSTOM
*/
......
<?php
/**
* Copyright 2020 Art-ER S. Cons. P.A.
* EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it
* Lombardia Informatica S.p.A.
* OPEN 2.0
*
* @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\comments\base
* @package elitedivision\amos\comments\base
* @category CategoryName
* @author Elite Division S.r.l.
* @author Lombardia Informatica S.p.A.
*/
namespace arter\amos\comments\base;
use arter\amos\comments\AmosComments;
use arter\amos\comments\models\Comment;
use arter\amos\comments\models\CommentReply;
use arter\amos\core\controllers\CrudController;
use arter\amos\core\interfaces\ModelLabelsInterface;
use arter\amos\core\record\Record;
use arter\amos\core\user\User;
use arter\amos\core\utilities\Email;
namespace elitedivision\amos\comments\base;
use elitedivision\amos\comments\AmosComments;
use elitedivision\amos\comments\models\Comment;
use elitedivision\amos\comments\models\CommentNotification;
use elitedivision\amos\comments\models\CommentReply;
use elitedivision\amos\comments\utility\CommentsUtility;
use elitedivision\amos\core\controllers\CrudController;
use elitedivision\amos\core\interfaces\ModelLabelsInterface;
use elitedivision\amos\core\record\Record;
use elitedivision\amos\core\user\User;
use elitedivision\amos\core\utilities\Email;
use Yii;
use yii\base\BaseObject;
use yii\helpers\ArrayHelper;
use arter\amos\comments\models\CommentDisabledNotificationUsers;
use elitedivision\amos\comments\models\CommentNotificationUsers;
use elitedivision\amos\admin\models\UserProfile;
use yii\helpers\VarDumper;
/**
* Class PartecipantsNotification
* @package arter\amos\comments\base
* @package elitedivision\amos\comments\base
*/
class PartecipantsNotification extends BaseObject
{
......@@ -63,64 +66,71 @@ class PartecipantsNotification extends BaseObject
{
$model_reply = null;
if (!empty($this->commentsModule)) {
if (!$this->commentsModule->enableMailsNotification) {
return;
}
}
$model = $comment;
if ($comment instanceof CommentReply) {
$model = $comment->comment;
$model_reply = $comment;
}
/** @var \arter\amos\core\record\Record $contextModelClassName */
/** @var \elitedivision\amos\core\record\Record $contextModelClassName */
$contextModelClassName = $model->context;
/** @var \arter\amos\core\record\Record $contextModel */
/** @var \elitedivision\amos\core\record\Record $contextModel */
$contextModel = $contextModelClassName::findOne($model->context_id);
$users = $this->getRecipients($contextModel, $contextModelClassName);
// filter the user ID by excluding user_id from comment_disabled_notification_users
$users = $this->excludeCommentDisabledNotificationUsers($users);
foreach($users as $user) {
$notification = new CommentNotification();
$notification->user_id = $user;
$notification->model_class_name = get_class($model);
$notification->model_id = $model->id;
$notification->context_model_class_name = $contextModelClassName;
$notification->context_model_id = $model->context_id;
$notification->read = false;
$notification->save();
}
if (!empty($this->commentsModule)) {
if (!$this->commentsModule->enableMailsNotification) {
return;
}
}
$this->sendEmail($users, $contextModel, $model, $model_reply);
}
/**
* Method to exclude user with comment disabled notification from CommentDisabledNotificationUsers
* Method to exclude users when notification taggin user in content is disabled
* notify_tagging_user_in_content = 0
*
* @param array $users
* @return array $list_users_id
* @param array | custom type list | $users
* @param model | elitedivision\amos\comments\models\base\Comment | $comment
*
* @return array | custom type list | $users
*/
protected function excludeCommentDisabledNotificationUsers($users){
$comment_disabled_notification_users =
ArrayHelper::getColumn(
CommentDisabledNotificationUsers::find()->andWhere(['deleted_at' => null])->asArray()->all(),
function ($element) {
return $element['user_id'];
}
);
$list_users_id = null;
foreach ((array)$users as $key => $user_id) {
// check if user is not in array comment_disabled_notification_users
if( !in_array($user_id, $comment_disabled_notification_users) ){
$list_users_id[$key] = $user_id;
private function extractTagginNotificationUsers($users, $comment){
// get all taggin users from comment text
$users_taggin_id = Record::getMentionUserIdFromText($comment->comment_text);
// extract all user where notify_tagging_user_in_content is disabled and is mention in text
$users_id = ArrayHelper::getColumn(
UserProfile::find()
->select('user_id')
->andWhere(["notify_tagging_user_in_content" => 1])
->andWhere(["id" => $users_taggin_id])
->asArray()
->all(),
function ($element) {
return $element['user_id'];
}
}
);
return $list_users_id;
return $users_id;
}
/**
* This method returns an array that contains the ids of the users to be notified.
* @param Record $contextModel
......@@ -129,18 +139,26 @@ class PartecipantsNotification extends BaseObject
*/
protected function getRecipients($contextModel, $contextModelClassName)
{
$users = $this->getDiscussionsRecipients($contextModel);
if (in_array($contextModelClassName, AmosComments::instance()->bellNotificationEnabledClasses)) {
if (empty($users) && method_exists($contextModel, 'getRecipients')) {
$users = $contextModel->getRecipients();
}
if (empty($users)) {
$users = $this->getDefaultRecipients($contextModel, $contextModelClassName);
}
// if exist override of getRecipients on $contextModel use this method!
if (method_exists($contextModel, 'getRecipients')) {
$users = $contextModel->getRecipients();
} else {
$users = CommentsUtility::getAllCommentNotificationUserEnabled($contextModelClassName, $contextModel->id);
}
} else {
$users = $this->getDiscussionsRecipients($contextModel);
if (empty($users) && method_exists($contextModel, 'getRecipients')) {
$users = $contextModel->getRecipients();
}
if (empty($users)) {
$users = $this->getDefaultRecipients($contextModel, $contextModelClassName);
}
}
return $users;
}
......@@ -155,8 +173,8 @@ class PartecipantsNotification extends BaseObject
$users = [];
// If the context is discussion, the emails must be sent to the participants in the scope.
if (Yii::$app->hasModule('discussioni') && ($contextModel instanceof \arter\amos\discussioni\models\DiscussioniTopic)) {
/** @var \arter\amos\discussioni\AmosDiscussioni $moduleDiscussioni */
if (Yii::$app->hasModule('discussioni') && ($contextModel instanceof \elitedivision\amos\discussioni\models\DiscussioniTopic)) {
/** @var \elitedivision\amos\discussioni\AmosDiscussioni $moduleDiscussioni */
$moduleDiscussioni = Yii::$app->getModule('discussioni');
$session = \Yii::$app->session;
$moduleCwh = \Yii::$app->getModule