mirror of
https://github.com/humhub/humhub.git
synced 2025-01-17 22:28:51 +01:00
Notification Mails/Rendering
This commit is contained in:
parent
f4b50fe2cf
commit
161312ea0c
BIN
img/mail_ico_check.png
Normal file
BIN
img/mail_ico_check.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.5 KiB |
BIN
img/mail_ico_not.png
Normal file
BIN
img/mail_ico_not.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.0 KiB |
@ -10,10 +10,12 @@ namespace humhub\components;
|
||||
|
||||
use Yii;
|
||||
use yii\helpers\Html;
|
||||
use humhub\modules\user\models\User;
|
||||
use humhub\modules\content\components\ContentContainerActiveRecord;
|
||||
use humhub\modules\space\models\Space;
|
||||
use humhub\modules\content\interfaces\ContentOwner;
|
||||
use humhub\widgets\RichText;
|
||||
use humhub\libs\Helpers;
|
||||
|
||||
/**
|
||||
* This class represents a social Activity triggered within the network.
|
||||
@ -262,7 +264,7 @@ abstract class SocialActivity extends \yii\base\Object implements rendering\View
|
||||
/**
|
||||
* Returns an array representation of this notification.
|
||||
*/
|
||||
public function asArray()
|
||||
public function asArray(User $user)
|
||||
{
|
||||
$result = [
|
||||
'class' => $this->className(),
|
||||
@ -289,14 +291,60 @@ abstract class SocialActivity extends \yii\base\Object implements rendering\View
|
||||
* This is a combination a the type of the content with a short preview
|
||||
* of it.
|
||||
*
|
||||
* If no $content is provided the contentInfo of $source is returned.
|
||||
*
|
||||
* @param Content $content
|
||||
* @return string
|
||||
*/
|
||||
public function getContentInfo(ContentOwner $content)
|
||||
public function getContentInfo(ContentOwner $content = null)
|
||||
{
|
||||
if(!$this->hasContent() && !$content) {
|
||||
return;
|
||||
}else if(!$content) {
|
||||
$content = $this->source;
|
||||
}
|
||||
|
||||
return Html::encode($content->getContentName()) .
|
||||
' "' .
|
||||
RichText::widget(['text' => $content->getContentDescription(), 'minimal' => true, 'maxLength' => 60]) . '"';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the content name of $content or if not $content is provided of the
|
||||
* notification source.
|
||||
*
|
||||
* @param ContentOwner $content
|
||||
* @return type
|
||||
*/
|
||||
public function getContentName(ContentOwner $content = null)
|
||||
{
|
||||
if(!$this->hasContent() && !$content) {
|
||||
return;
|
||||
}else if(!$content) {
|
||||
$content = $this->source;
|
||||
}
|
||||
|
||||
return $content->getContentName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a short preview text of the content. The max length can be defined by setting
|
||||
* $maxLength (25 by default).
|
||||
*
|
||||
* If no $content is provided the contentPreview of $source is returned.
|
||||
*
|
||||
* @param Content $content
|
||||
* @return string
|
||||
*/
|
||||
public function getContentPreview(ContentOwner $content = null, $maxLength = 25)
|
||||
{
|
||||
if(!$this->hasContent() && !$content) {
|
||||
return;
|
||||
} else if(!$content) {
|
||||
$content = $this->source;
|
||||
}
|
||||
|
||||
return RichText::widget(['text' => $content->getContentDescription(), 'minimal' => true, 'maxLength' => $maxLength]);
|
||||
}
|
||||
|
||||
}
|
||||
|
45
protected/humhub/components/queue/driver/Instant.php
Normal file
45
protected/humhub/components/queue/driver/Instant.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @link https://www.humhub.org/
|
||||
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
|
||||
* @license https://www.humhub.com/licences
|
||||
*/
|
||||
|
||||
namespace humhub\components\queue\driver;
|
||||
|
||||
use zhuravljov\yii\queue\sync\Driver;
|
||||
|
||||
/**
|
||||
* Instant queue driver, mainly used for testing purposes
|
||||
*
|
||||
* @since 1.2
|
||||
* @author buddha
|
||||
*/
|
||||
class Instant extends Driver
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public $handle = true;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $_messages = [];
|
||||
|
||||
/**
|
||||
* Executes the jobs immediatly, serialization is done for testing purpose
|
||||
*/
|
||||
public function push($job)
|
||||
{
|
||||
$this->_messages[] = $this->serialize($job);
|
||||
|
||||
while (($message = array_shift($this->_messages)) !== null) {
|
||||
$job = $this->unserialize($message);
|
||||
$this->getQueue()->run($job);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace humhub\components\rendering;
|
||||
|
||||
use Yii;
|
||||
use humhub\components\rendering\Viewable;
|
||||
|
||||
/**
|
||||
* The DefaultViewPathRenderer is used to render Viewables.
|
||||
*
|
||||
* This Renderer can provide a $defaultView and $defaultViewPath which will be used
|
||||
* in case the view file could not be determined by means of the viewName property of the Viewable.
|
||||
*
|
||||
* The DefaultViewPathRenderer will search for a view file in the given order (without $parent and $subPath settings):
|
||||
*
|
||||
* - Search for the view relative to the Viewable class
|
||||
*
|
||||
* `[ViewableClassPath]/views/[viewName].php`
|
||||
*
|
||||
* - Search for the view within the $defaultViewPath (if given):
|
||||
*
|
||||
* defaultViewPath/[viewName].php
|
||||
*
|
||||
* - Use the $defaultView.
|
||||
*
|
||||
* @author buddha
|
||||
* @since 1.2
|
||||
*/
|
||||
class DefaultViewPathRenderer extends \humhub\components\rendering\ViewPathRenderer
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @var string fallback view
|
||||
*/
|
||||
public $defaultView;
|
||||
|
||||
/**
|
||||
* @var string fallback view path
|
||||
*/
|
||||
public $defaultViewPath;
|
||||
|
||||
/**
|
||||
* Returns the view file for the given Viewable.
|
||||
*
|
||||
* If there was no relative view file found, this function will search for the view file
|
||||
* within the $defaultPath or return the $defaultView at last resort.
|
||||
*
|
||||
* @param \humhub\modules\notification\components\Viewable $viewable
|
||||
* @return string view file of this notification
|
||||
*/
|
||||
public function getViewFile(Viewable $viewable)
|
||||
{
|
||||
$viewFile = parent::getViewFile($viewable);
|
||||
|
||||
if (!file_exists($viewFile) && $this->defaultViewPath) {
|
||||
$viewFile = Yii::getAlias($this->defaultViewPath) . '/' . $this->suffix($viewable->getViewName());
|
||||
}
|
||||
|
||||
if (!file_exists($viewFile) && $this->defaultView) {
|
||||
$viewFile = Yii::getAlias($this->defaultView);
|
||||
}
|
||||
|
||||
return $viewFile;
|
||||
}
|
||||
}
|
@ -20,6 +20,7 @@ use Yii;
|
||||
* '@myModule/views/layouts/myLayout.php'
|
||||
*
|
||||
* @author buddha
|
||||
* @since 1.2
|
||||
*/
|
||||
class LayoutRenderer extends ViewPathRenderer
|
||||
{
|
||||
@ -30,20 +31,25 @@ class LayoutRenderer extends ViewPathRenderer
|
||||
public $layout;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* If a $layout is given the result will embed the rendered viewFile into the
|
||||
* given $layout.
|
||||
*
|
||||
* @param \humhub\components\rendering\Viewable $viewable
|
||||
* @param type $params
|
||||
* @return string
|
||||
*/
|
||||
public function render(Viewable $viewable, $params = [])
|
||||
{
|
||||
// Render the view itself
|
||||
$viewParams = $viewable->getViewParams($params);
|
||||
|
||||
// Render the viewFile
|
||||
if(!isset($viewParams['content'])) {
|
||||
$viewParams['content'] = parent::renderView($viewable, $viewParams);
|
||||
}
|
||||
|
||||
// Embed content in layout if valid layout is given.
|
||||
$layout = $this->getLayout($viewable);
|
||||
|
||||
// Embed view into layout if provided
|
||||
if ($layout) {
|
||||
return Yii::$app->getView()->renderFile($layout, $viewParams, $viewable);
|
||||
} else {
|
||||
@ -51,6 +57,13 @@ class LayoutRenderer extends ViewPathRenderer
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the layout file path.
|
||||
* Subclasses may use the $viewable to determine the layout path.
|
||||
*
|
||||
* @param \humhub\components\rendering\Viewable $viewable
|
||||
* @return string
|
||||
*/
|
||||
protected function getLayout(Viewable $viewable)
|
||||
{
|
||||
return $this->layout;
|
||||
|
@ -2,19 +2,19 @@
|
||||
|
||||
namespace humhub\components\rendering;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* Description of MailLayoutRenderer
|
||||
* MailLayoutRenderer extends the LayoutRenderer with a renderText function.
|
||||
*
|
||||
* @author buddha
|
||||
* @since 1.2
|
||||
*/
|
||||
class MailLayoutRenderer extends LayoutRenderer
|
||||
{
|
||||
|
||||
public $subPath = 'mails';
|
||||
|
||||
/**
|
||||
* Layout for text rendering.
|
||||
* @var type
|
||||
* @var string Layout file path
|
||||
*/
|
||||
public $textLayout;
|
||||
|
||||
@ -28,14 +28,23 @@ class MailLayoutRenderer extends LayoutRenderer
|
||||
public function renderText(Viewable $viewable, $params = [])
|
||||
{
|
||||
$textRenderer = new LayoutRenderer([
|
||||
'subPath' => 'mails/plaintext',
|
||||
'parent' => $this->parent,
|
||||
'layout' => $this->getTextLayout($viewable)
|
||||
]);
|
||||
|
||||
// exclude the view only embed the viewable text to the textlayout.
|
||||
$params['content'] = $viewable->text();
|
||||
|
||||
return strip_tags($textRenderer->render($viewable, $params));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the $textLayout for the given $viewable.
|
||||
*
|
||||
* @param \humhub\components\rendering\Viewable $viewable
|
||||
* @return type
|
||||
*/
|
||||
public function getTextLayout(Viewable $viewable)
|
||||
{
|
||||
return $this->textLayout;
|
||||
|
50
protected/humhub/components/rendering/MailRenderer.php
Normal file
50
protected/humhub/components/rendering/MailRenderer.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace humhub\components\rendering;
|
||||
|
||||
/**
|
||||
* MailRenderer extends the DefaultViewPathRenderer with a renderText method.
|
||||
*
|
||||
* The $defaultTextView and/or $defaultTextViewPath can be set to define a fallback
|
||||
* view or search view path.
|
||||
*
|
||||
* @author buddha
|
||||
* @since 1.2
|
||||
*/
|
||||
class MailRenderer extends DefaultViewPathRenderer
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public $subPath = 'mails';
|
||||
|
||||
/**
|
||||
* @var string fallback text view.
|
||||
*/
|
||||
public $defaultTextView;
|
||||
|
||||
/**
|
||||
* @var string fallback text view path.
|
||||
*/
|
||||
public $defaultTextViewPath;
|
||||
|
||||
/**
|
||||
* Renders the text mail content for the given $viewable.
|
||||
*
|
||||
* @param \humhub\components\rendering\Viewable $viewable
|
||||
* @param array $params
|
||||
* @return type
|
||||
*/
|
||||
public function renderText(Viewable $viewable, $params = [])
|
||||
{
|
||||
$textRenderer = new static([
|
||||
'subPath' => 'mails/plaintext',
|
||||
'parent' => $this->parent,
|
||||
'defaultView' => $this->defaultTextView,
|
||||
'defaultViewPath' => $this->defaultTextViewPath,
|
||||
]);
|
||||
|
||||
return strip_tags($textRenderer->render($viewable, $params));
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ namespace humhub\components\rendering;
|
||||
* by converting it's data into a specific format.
|
||||
*
|
||||
* @author buddha
|
||||
* @since 1.2
|
||||
*/
|
||||
interface Renderer
|
||||
{
|
||||
@ -18,6 +19,10 @@ interface Renderer
|
||||
* forward the given $params to $viewable->getViewParams($params). By doing so, the
|
||||
* $params can be used to overwrite the default view parameter of $viewable.
|
||||
*
|
||||
* It is upon the renderer implementation to handle non existing views.
|
||||
* They could throw a yii\base\ViewNotFoundException, or provide a
|
||||
* default view.
|
||||
*
|
||||
* @param \humhub\components\rendering\Viewable $viewable
|
||||
* @param type $params
|
||||
*/
|
||||
|
@ -5,18 +5,45 @@ namespace humhub\components\rendering;
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* A ViewPathRenderer is a simple Renderer implementation for rendering Viewable
|
||||
* instances by searching for the Viewable viewName within the given $viewPath.
|
||||
* A ViewPathRenderer is a simple Renderer implementation for rendering Viewables by searching for a matching viewFile relative
|
||||
* to the Viewables class path or relative to a given $viewPath.
|
||||
*
|
||||
* If no $viewPath is given, we'll determine the view path of the viewable as following:
|
||||
* If a $viewPath is given the renderer will search for the view within this path directly.
|
||||
*
|
||||
* ViewableClassPath/../views
|
||||
* If no $viewPath is given, the ViewPathRenderer will determine the view path relative to the Viewable as following:
|
||||
*
|
||||
* - In case $parent = false the renderer will search directly in the class path subdirectory views:
|
||||
*
|
||||
* `viewableClassPath/views`
|
||||
*
|
||||
* - in case $parent = true the renderer will search in the parents views folder (e.g. in the modules main view folder):
|
||||
*
|
||||
* `viewableClassPath/../views`
|
||||
*
|
||||
* - in case $subPath is given the subPath will be appended to the view path e.g:
|
||||
*
|
||||
* For a subPath 'mail' and $parent = false the search path will be: `viewableClassPath/views/mail`
|
||||
*
|
||||
* @author buddha
|
||||
* @since 1.2
|
||||
*/
|
||||
class ViewPathRenderer extends \yii\base\Object implements Renderer
|
||||
{
|
||||
|
||||
/**
|
||||
* Can be used to search the parent's view folder (e.g. the modules base view folder) for the view file.
|
||||
* Otherwise this renderer searches for a direct views subdirectory.
|
||||
*
|
||||
* This field is ignored if $viewPath is given.
|
||||
* @var boolean if set to true the renderer will search in the parents view directory for the view.
|
||||
*/
|
||||
public $parent = false;
|
||||
|
||||
/**
|
||||
* @var string a subpath within the view folder used for searching the view e.g mails. This will only be used if $viewPath is not given.
|
||||
*/
|
||||
public $subPath;
|
||||
|
||||
/**
|
||||
* @var string view path
|
||||
*/
|
||||
@ -28,7 +55,8 @@ class ViewPathRenderer extends \yii\base\Object implements Renderer
|
||||
* If no viewPath is given this function uses '../views/viewName' as view file path.
|
||||
*
|
||||
* @param \humhub\components\rendering\Viewable $viewable
|
||||
* @return type
|
||||
* @return string
|
||||
* @throws ViewNotFoundException if the view file does not exist
|
||||
*/
|
||||
public function render(Viewable $viewable, $params = [])
|
||||
{
|
||||
@ -56,9 +84,27 @@ class ViewPathRenderer extends \yii\base\Object implements Renderer
|
||||
*/
|
||||
public function getViewFile(Viewable $viewable)
|
||||
{
|
||||
return $this->getViewPath($viewable) . '/' . $viewable->getViewName();
|
||||
return $this->getViewPath($viewable) . '/' . $this->suffix($viewable->getViewName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given $viewName has a file suffix or not.
|
||||
* If the viewName does not have a suffix we assume a php file and append '.php'.
|
||||
*
|
||||
* @param string $viewName
|
||||
* @return string vieName with suffix.
|
||||
*/
|
||||
protected function suffix($viewName)
|
||||
{
|
||||
// If no suffix is given, we assume a php file.
|
||||
if (!strpos($viewName, '.')) {
|
||||
return $viewName . '.php';
|
||||
} else {
|
||||
return $viewName;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the directory containing the view files for this event.
|
||||
* The default implementation returns the 'views' subdirectory under the directory containing the notification class file.
|
||||
@ -66,12 +112,20 @@ class ViewPathRenderer extends \yii\base\Object implements Renderer
|
||||
*/
|
||||
public function getViewPath(Viewable $viewable)
|
||||
{
|
||||
if ($this->viewPath !== null) {
|
||||
if ($this->viewPath) {
|
||||
return Yii::getAlias($this->viewPath);
|
||||
}
|
||||
|
||||
$class = new \ReflectionClass($viewable);
|
||||
return dirname($class->getFileName()) . DIRECTORY_SEPARATOR . 'views';
|
||||
|
||||
$dir = ($this->parent) ? dirname(dirname($class->getFileName())) . '/' . 'views'
|
||||
: dirname($class->getFileName()) . '/' . 'views';
|
||||
|
||||
if(!empty($this->subPath)) {
|
||||
$dir .= '/' . $this->subPath;
|
||||
}
|
||||
|
||||
return $dir;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,18 +1,15 @@
|
||||
Notifications
|
||||
=============
|
||||
|
||||
Notifications are used to inform one or a given set of users about a specific event, as the liking of a post or mentioning of a user, over multiple channels (e.g. web and mail).
|
||||
Notifications are used to inform one or a given set of users about a specific event in your network as the liking of a post or mentioning of a user over multiple channels (e.g. web and mail).
|
||||
|
||||
Custom notification types are derived from [[humhub\modules\notification\components\BaseNotification]] and can be assigned with an optional `$originator` user instance, which links
|
||||
the notification to the user who triggered the event. Furthermore the [[humhub\modules\notification\components\BaseNotification|BaseNotification]] can be assigned with a `$source` attribute of type [[yii\db\ActiveRecord]],
|
||||
which links the notification to a source instance like a Content or ContentAddon (e.g. a Post or Like).
|
||||
Custom notification classes are derived from [[humhub\modules\notification\components\BaseNotification]].
|
||||
A [[humhub\modules\notification\components\BaseNotification|BaseNotification]] usually is assigned with an
|
||||
`$originator` user instance and a `$source` instance, which connects the Notification with a Content or any other kind of [[yii\db\ActiveRecord]].
|
||||
|
||||
The BaseNotification is responsible for:
|
||||
A Notification can be sent to a user by calling the `send()` or `sendBulk()` function. This will persist an [[humhub\modules\notification\models\Notification]] instance for each user send out a notification to all allowed NotificationTargets.
|
||||
|
||||
- **instantiating** and **persisting** [[humhub\modules\notification\models\Notification]] model instances.
|
||||
- **rendering** the notification output for the differen output channels.
|
||||
|
||||
![Notification Class Diagram](images/notificationClassDiag.jpg)
|
||||
> Note: Unlike Activities which are targeted for multiple users e.g. all Users of a Space, a Notification Model instance is always related to a single user.
|
||||
|
||||
Examples for core notifications are:
|
||||
|
||||
@ -26,7 +23,8 @@ Examples for core notifications are:
|
||||
#### Notification Class
|
||||
|
||||
Custom Notifications are derived from [[humhub\modules\notification\components\BaseNotification|BaseNotification]] and should reside in the `notifications` subfolder of your module's root directory.
|
||||
The notification class at least has to overwrite the `$moduleId` variable with the id of your module and the `$viewName` with the name of the view which is used to render the notification.
|
||||
|
||||
The notification class at least has to overwrite the `$moduleId` variable with the id of your module and the.
|
||||
|
||||
```php
|
||||
<?php
|
||||
@ -46,13 +44,12 @@ class SomethingHappend extends BaseNotification
|
||||
// Viewname (required)
|
||||
public $viewName = "somethingHappend";
|
||||
}
|
||||
?>
|
||||
```
|
||||
|
||||
#### Notification View
|
||||
|
||||
By default, the view of a notification should be located inside the subfolder `notifications/views`.
|
||||
The view of our example is therefore located in `/modules/examples/notifications/views/somethingHappened.php`.
|
||||
The view of the example above should therefore be located in `/modules/examples/notifications/views/somethingHappened.php`.
|
||||
|
||||
```php
|
||||
<?php
|
||||
@ -62,7 +59,6 @@ use yii\helpers\Html;
|
||||
echo Yii::t('SomethingHappend.views_notifications_somethingHappened', "%someUser% did something cool.", [
|
||||
'%someUser%' => '<strong>' . Html::encode($originator->displayName) . '</strong>'
|
||||
]);
|
||||
?>
|
||||
```
|
||||
|
||||
> Info: If you require a different notification view for mails, you have to add an extra view file to a subfolder `notifications/views/mail`.
|
||||
@ -75,36 +71,15 @@ After an event was triggered, you'll have to instantiate your custom [[humhub\mo
|
||||
A notification can optionally be assigned with a `$source` model instance (e.g. a post or comment related to the notification) which has to be derived from [[yii\db\ActiveRecord]].
|
||||
|
||||
```php
|
||||
$notification = new \johndoe\example\notifications\SomethingHappend();
|
||||
// Sending to a single user
|
||||
\johndoe\example\notifications\SomethingHappend::instance()->from($user)->about($source)->send($targetUser);
|
||||
|
||||
// Link to the object which fired the notification e.g. a SomethingHappened content-addon (optional)
|
||||
$notification->source = $this;
|
||||
|
||||
// The user which triggered the notification (optional)
|
||||
$notification->originator = $this->user;
|
||||
|
||||
// Send it to a set of users
|
||||
$notification->sendBulk(User::find()->where([...]));
|
||||
|
||||
// or: a single user
|
||||
$notification->send($user);
|
||||
// Sending to multiple users
|
||||
\johndoe\example\notifications\SomethingHappend::instance()->from($user)->about($source)->sendBulk($users);
|
||||
```
|
||||
> Info: If the notification was created in the context of a space (e.g. `$source` is a Content, ContentAddon or ContentContainer) the `$space` variable is set with the corresponding space instance automatically.
|
||||
|
||||
> Info: The `send` and `sendBulk` will create and persist a [[humhub\modules\notification\models\Notification]] instance for each user.
|
||||
|
||||
> Tip: Notifications are often created and sent within the `afterSave` hook of the related `source` instance. This should be prefered over the instantiation within a controller.
|
||||
|
||||
> Note: Notifications are only sent by mail depending on the user's account settings.
|
||||
|
||||
## Delete Notifications
|
||||
|
||||
By default notifications will automatically be deleted after a given period of time or if the originator(user) object is removed.
|
||||
|
||||
Example for manual notification deletion:
|
||||
|
||||
```php
|
||||
$notification = new johndoe\example\notifications\SomethingHappend();
|
||||
$notification->source = $this;
|
||||
$notification->delete(User::findOne(['id' => $userId]));
|
||||
```
|
||||
> Note: Notifications are only sent to a specific NotificationTarget depending on the user's account settings.
|
@ -16,17 +16,17 @@ use humhub\components\rendering\MailLayoutRenderer;
|
||||
* @since 1.2
|
||||
* @author buddha
|
||||
*/
|
||||
class MailRenderer extends MailLayoutRenderer
|
||||
class ActivityMailRenderer extends MailLayoutRenderer
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public $layout = '@activity/views/mails/activityLayout.php';
|
||||
public $layout = '@activity/views/layouts/mail.php';
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public $textLayout = "@activity/views/mails/plaintext/activityLayout.php";
|
||||
public $textLayout = '@activity/views/layouts/mail_plaintext.php';
|
||||
|
||||
}
|
@ -12,20 +12,21 @@ use Yii;
|
||||
use humhub\components\rendering\Viewable;
|
||||
|
||||
/**
|
||||
* The WebTargetRenderer is used to render Notifications for the WebNotificationTarget.
|
||||
* The ActivityWebRenderer is used to render BaseActivity instances for the Activity Stream.
|
||||
*
|
||||
* A BaseNotification can overwrite the default view and layout by setting a specific $viewName and
|
||||
* A BaseActivity can overwrite the default view and layout by setting a specific $viewName and
|
||||
* defining the following files:
|
||||
*
|
||||
* Overwrite default view for this notification:
|
||||
* @module/views/notification/viewname.php
|
||||
* Overwrite default view for this Activity:
|
||||
* @module/activities/views/[viewname].php
|
||||
*
|
||||
* Overwrite default layout for this notification:
|
||||
* @module/views/layouts/notification/viewname.php
|
||||
* Overwrite default layout for this Activity:
|
||||
* @module/activities/views/layout/[viewname].php
|
||||
*
|
||||
* @author buddha
|
||||
* @since 1.2
|
||||
*/
|
||||
class WebRenderer extends \humhub\components\rendering\LayoutRenderer
|
||||
class ActivityWebRenderer extends \humhub\components\rendering\LayoutRenderer
|
||||
{
|
||||
|
||||
/**
|
||||
@ -36,7 +37,7 @@ class WebRenderer extends \humhub\components\rendering\LayoutRenderer
|
||||
/**
|
||||
* @var string default layout
|
||||
*/
|
||||
public $defaultLayout = '@humhub/modules/activity/views/layouts/web.php';
|
||||
public $defaultLayout = '@activity/views/layouts/web.php';
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
@ -65,10 +66,10 @@ class WebRenderer extends \humhub\components\rendering\LayoutRenderer
|
||||
*/
|
||||
public function getViewFile(Viewable $viewable)
|
||||
{
|
||||
$viewFile = $this->getViewPath($viewable) . DIRECTORY_SEPARATOR . $viewable->getViewName();
|
||||
$viewFile = parent::getViewFile($viewable);
|
||||
|
||||
if (!file_exists($viewFile)) {
|
||||
$viewFile = Yii::getAlias($this->defaultViewPath) . DIRECTORY_SEPARATOR . $viewable->getViewName();
|
||||
$viewFile = Yii::getAlias($this->defaultViewPath) . '/' . $this->suffix($viewable->getViewName());
|
||||
}
|
||||
|
||||
if (!file_exists($viewFile)) {
|
||||
@ -81,17 +82,17 @@ class WebRenderer extends \humhub\components\rendering\LayoutRenderer
|
||||
/**
|
||||
* Returns the layout for the given Notification Viewable.
|
||||
*
|
||||
* This function will search for a layout file under module/views/layouts/mail with the view name defined
|
||||
* by $viwable.
|
||||
* This function will search for a layout file under `@module/views/layouts/mail` with the view name defined
|
||||
* by $viewable.
|
||||
*
|
||||
* If this file does not exists the default notification mail layout will be returned.
|
||||
* If this file does not exists the default layout will be returned.
|
||||
*
|
||||
* @param \humhub\modules\notification\components\Viewable $viewable
|
||||
* @return type
|
||||
*/
|
||||
public function getLayout(Viewable $viewable)
|
||||
{
|
||||
$layout = $this->getViewPath($viewable) . '/layouts/' . $viewable->getViewName();
|
||||
$layout = $this->getViewPath($viewable) . '/layouts/' . $this->suffix($viewable->getViewName());
|
||||
|
||||
if (!file_exists($layout)) {
|
||||
$layout = Yii::getAlias($this->defaultLayout);
|
||||
@ -101,3 +102,4 @@ class WebRenderer extends \humhub\components\rendering\LayoutRenderer
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ class MailSummary extends Component
|
||||
$outputHtml = '';
|
||||
$outputPlaintext = '';
|
||||
|
||||
$mailRenderer = new MailRenderer();
|
||||
$mailRenderer = new ActivityMailRenderer();
|
||||
foreach ($this->getActivities() as $activity) {
|
||||
$outputHtml .= $mailRenderer->render($activity);
|
||||
$outputPlaintext .= $mailRenderer->renderText($activity);
|
||||
|
@ -11,7 +11,7 @@ namespace humhub\modules\activity\models;
|
||||
use Yii;
|
||||
use yii\base\Exception;
|
||||
use humhub\modules\content\components\ContentActiveRecord;
|
||||
use humhub\modules\activity\components\WebRenderer;
|
||||
use humhub\modules\activity\components\ActivityWebRenderer;
|
||||
|
||||
/**
|
||||
* This is the model class for table "activity".
|
||||
@ -105,13 +105,12 @@ class Activity extends ContentActiveRecord
|
||||
if ($output === false) {
|
||||
$activity = $this->getActivityBaseClass();
|
||||
if ($activity !== null) {
|
||||
$renderer = new WebRenderer();
|
||||
$renderer = new ActivityWebRenderer();
|
||||
$output = $renderer->render($activity);
|
||||
Yii::$app->cache->set($cacheKey, $output);
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
@ -125,5 +124,4 @@ class Activity extends ContentActiveRecord
|
||||
{
|
||||
return $this->getPolymorphicRelation();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?php //[STAMP] e93907d5924b39a3cd4134cc6a6ea3a3
|
||||
<?php //[STAMP] 0468b7e2480518455b63a22d3aa6f7c2
|
||||
namespace activity\_generated;
|
||||
|
||||
// This class was automatically generated by build task
|
||||
|
@ -0,0 +1,5 @@
|
||||
<?php $this->beginContent('@activity/views/layouts/web.php', $_params_); ?>
|
||||
<?= html ?>
|
||||
<?php $this->endContent(); ?>
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
<!-- Show user image -->
|
||||
<img class="media-object img-rounded pull-left" data-src="holder.js/32x32" alt="32x32"
|
||||
style="width: 32px; height: 32px;"
|
||||
src="<?php echo $originator->getProfileImage()->getUrl(); ?>">
|
||||
src="<?= $originator->getProfileImage()->getUrl(); ?>">
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- Show space image, if you are outside from a space -->
|
||||
@ -27,11 +27,11 @@
|
||||
<div class="media-body text-break">
|
||||
|
||||
<!-- Show content -->
|
||||
<?php echo $content; ?><br/>
|
||||
<?= $content; ?><br/>
|
||||
|
||||
<!-- show time -->
|
||||
<?php echo \humhub\widgets\TimeAgo::widget(['timestamp' => $record->content->created_at]); ?>
|
||||
<?= \humhub\widgets\TimeAgo::widget(['timestamp' => $record->content->created_at]); ?>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<?php if ($clickable): ?></a><?php endif; ?>
|
||||
<?php if ($clickable): ?></a><?php endif; ?>
|
@ -1,121 +0,0 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
?>
|
||||
<!-- START NOTIFICATION/ACTIVITY -->
|
||||
<tr>
|
||||
<td align="center" valign="top" class="fix-box">
|
||||
|
||||
<!-- start container width 600px -->
|
||||
<table width="600" align="center" border="0" cellspacing="0" cellpadding="0" class="container" bgcolor="#ffffff"
|
||||
style="background-color: #ffffff; border-bottom-left-radius: 4px; border-bottom-left-radius: 4px;">
|
||||
<tr>
|
||||
<td valign="top">
|
||||
|
||||
<!-- start container width 560px -->
|
||||
<table width="560" align="center" border="0" cellspacing="0" cellpadding="0" class="full-width"
|
||||
bgcolor="#ffffff" style="background-color:#ffffff;">
|
||||
|
||||
<!-- start image and content -->
|
||||
<tr>
|
||||
<td valign="top" width="100%">
|
||||
|
||||
<!-- start content left -->
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="left">
|
||||
|
||||
<!--start space height -->
|
||||
<tr>
|
||||
<td height="20"></td>
|
||||
</tr>
|
||||
<!--end space height -->
|
||||
|
||||
|
||||
<!-- start content top-->
|
||||
<tr>
|
||||
<td valign="top" align="left">
|
||||
|
||||
<table border="0" cellspacing="0" cellpadding="0" align="left">
|
||||
<tr>
|
||||
|
||||
<td valign="top" align="left" style="padding-right:20px;">
|
||||
<!-- START: USER IMAGE -->
|
||||
<a href="<?php echo $originator->createUrl('/user/profile', [], true); ?>">
|
||||
<img
|
||||
src="<?php echo $originator->getProfileImage()->getUrl("", true); ?>"
|
||||
width="50"
|
||||
alt=""
|
||||
style="max-width:50px; display:block !important; border-radius: 4px;"
|
||||
border="0" hspace="0" vspace="0"/>
|
||||
</a>
|
||||
<!-- END: USER IMAGE -->
|
||||
</td>
|
||||
|
||||
|
||||
<td valign="top">
|
||||
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="0"
|
||||
align="left">
|
||||
|
||||
<tr>
|
||||
<td style="font-size: 13px; line-height: 22px; font-family:Open Sans,Arial,Tahoma, Helvetica, sans-serif; color:#555555; font-weight:300; text-align:left; ">
|
||||
|
||||
<!-- content output-->
|
||||
<?php echo $content; ?>
|
||||
|
||||
<!-- check if activity object has a space -->
|
||||
<?php if ($record->content->space !== null): ?>
|
||||
(<?php echo Yii::t('ActivityModule.views_activityLayoutMail', 'via'); ?>
|
||||
<a href="<?php echo $record->content->space->createUrl('/space/space', [], true); ?>"
|
||||
style="text-decoration: none; color: #555555;">
|
||||
<?php echo Html::encode($record->content->space->name); ?></a>)
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($url != "") : ?>
|
||||
<!-- START: CONTENT LINK -->
|
||||
<span
|
||||
style="text-decoration: none; color: #7191a8;"> - <a
|
||||
href="<?php echo $url; ?>"
|
||||
style="text-decoration: none; color: #7191a8; "><?php echo Yii::t('ActivityModule.views_activityLayoutMail', 'see online'); ?></a></span>
|
||||
<!-- END: CONTENT LINK -->
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<!-- end content top-->
|
||||
|
||||
|
||||
<!--start space height -->
|
||||
<tr>
|
||||
<td height="15" class="col-underline"></td>
|
||||
</tr>
|
||||
<!--end space height -->
|
||||
|
||||
|
||||
</table>
|
||||
<!-- end content left -->
|
||||
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<!-- end image and content -->
|
||||
|
||||
</table>
|
||||
<!-- end container width 560px -->
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<!-- end container width 600px -->
|
||||
</td>
|
||||
</tr>
|
||||
<!-- END NOTIFICATION/ACTIVITY -->
|
@ -1,3 +1,4 @@
|
||||
<?php $this->beginContent('@activity/views/layouts/mail.php', $_params_); ?>
|
||||
<tr>
|
||||
<td align="center" valign="top" class="fix-box">
|
||||
|
||||
@ -56,3 +57,4 @@
|
||||
</tr>
|
||||
|
||||
<?= $activities; ?>
|
||||
<?php $this->endContent(); ?>
|
@ -1,3 +1,5 @@
|
||||
<?php echo strip_tags(Yii::t('base', '<strong>Latest</strong> updates')); ?>
|
||||
<?php $this->beginContent('@activity/views/layouts/mail.php', $_params_); ?>
|
||||
<?php echo strip_tags(Yii::t('base', '<strong>Latest</strong> updates')); ?>
|
||||
|
||||
<?= $activitiesPlaintext; ?>
|
||||
<?= $activitiesPlaintext; ?>
|
||||
<?php $this->endContent(); ?>
|
@ -20,7 +20,14 @@ use humhub\modules\activity\interfaces\ConfigurableActivityInterface;
|
||||
class NewComment extends BaseActivity implements ConfigurableActivityInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public $moduleId = 'comment';
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public $viewName = "newComment";
|
||||
|
||||
/**
|
||||
|
@ -90,10 +90,8 @@ class CommentController extends \humhub\modules\content\components\ContentAddonC
|
||||
return '';
|
||||
}
|
||||
|
||||
$comment = new Comment;
|
||||
$comment->message = $message;
|
||||
$comment->object_model = $this->parentContent->className();
|
||||
$comment->object_id = $this->parentContent->getPrimaryKey();
|
||||
$comment = new Comment(['message' => $message]);
|
||||
$comment->setPolyMorphicRelation($this->parentContent);
|
||||
$comment->save();
|
||||
$comment->fileManager->attach($files);
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
namespace humhub\modules\comment\models;
|
||||
|
||||
use humhub\modules\post\models\Post;
|
||||
use \humhub\modules\content\interfaces\ContentOwner;
|
||||
use humhub\modules\comment\activities\NewComment;
|
||||
use humhub\modules\content\components\ContentAddonActiveRecord;
|
||||
use Yii;
|
||||
@ -33,7 +34,7 @@ use Yii;
|
||||
* @package humhub.modules_core.comment.models
|
||||
* @since 0.5
|
||||
*/
|
||||
class Comment extends ContentAddonActiveRecord
|
||||
class Comment extends ContentAddonActiveRecord implements ContentOwner
|
||||
{
|
||||
|
||||
/**
|
||||
@ -54,6 +55,21 @@ class Comment extends ContentAddonActiveRecord
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'class' => \humhub\components\behaviors\PolymorphicRelation::className(),
|
||||
'mustBeInstanceOf' => [
|
||||
\yii\db\ActiveRecord::className(),
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
@ -105,7 +121,7 @@ class Comment extends ContentAddonActiveRecord
|
||||
\humhub\modules\comment\notifications\NewComment::instance()
|
||||
->from($this->user)
|
||||
->about($this)
|
||||
->sendBulk($this->content->getPolymorphicRelation()->getFollowers(null, true, true));
|
||||
->sendBulk($this->getCommentedRecord()->getFollowers(null, true, true));
|
||||
}
|
||||
|
||||
$this->updateContentSearch();
|
||||
@ -119,11 +135,21 @@ class Comment extends ContentAddonActiveRecord
|
||||
*/
|
||||
protected function updateContentSearch()
|
||||
{
|
||||
if ($this->content->getPolymorphicRelation() instanceof \humhub\modules\search\interfaces\Searchable) {
|
||||
Yii::$app->search->update($this->content->getPolymorphicRelation());
|
||||
if ($this->getCommentedRecord() instanceof \humhub\modules\search\interfaces\Searchable) {
|
||||
Yii::$app->search->update($this->getCommentedRecord());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the commented record e.g. a Post
|
||||
*
|
||||
* @return \humhub\modules\content\components\ContentActiveRecord
|
||||
*/
|
||||
public function getCommentedRecord()
|
||||
{
|
||||
return $this->content->getPolymorphicRelation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a limited amount of comments
|
||||
*
|
||||
|
@ -11,6 +11,7 @@ namespace humhub\modules\comment\notifications;
|
||||
use Yii;
|
||||
use yii\bootstrap\Html;
|
||||
use humhub\modules\user\models\User;
|
||||
use humhub\libs\Helpers;
|
||||
|
||||
/**
|
||||
* Notification for new comments
|
||||
@ -28,7 +29,13 @@ class NewComment extends \humhub\modules\notification\components\BaseNotificatio
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function category() {
|
||||
public $viewName = 'newComment';
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function category()
|
||||
{
|
||||
return new CommentNotificationCategory();
|
||||
}
|
||||
|
||||
@ -38,7 +45,11 @@ class NewComment extends \humhub\modules\notification\components\BaseNotificatio
|
||||
public function send(User $user)
|
||||
{
|
||||
// Check if there is also a mention notification, so skip this notification
|
||||
if (\humhub\modules\notification\models\Notification::find()->where(['class' => \humhub\modules\user\notifications\Mentioned::className(), 'user_id' => $user->id, 'source_class' => $this->source->className(), 'source_pk' => $this->source->getPrimaryKey()])->count() > 0) {
|
||||
if (\humhub\modules\notification\models\Notification::find()->where([
|
||||
'class' => \humhub\modules\user\notifications\Mentioned::className(),
|
||||
'user_id' => $user->id,
|
||||
'source_class' => $this->source->className(),
|
||||
'source_pk' => $this->source->getPrimaryKey()])->count() > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -54,6 +65,75 @@ class NewComment extends \humhub\modules\notification\components\BaseNotificatio
|
||||
return $model->className() . '-' . $model->getPrimaryKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getTitle(User $user)
|
||||
{
|
||||
if ($this->groupCount > 1) {
|
||||
return $this->getGroupTitle($user);
|
||||
}
|
||||
|
||||
$contentRecord = $this->getCommentedRecord();
|
||||
$space = $this->getSpace();
|
||||
|
||||
if ($user->is($contentRecord->owner)) {
|
||||
if ($space) {
|
||||
return Yii::t('CommentModule.notification', "{displayName} just commented your content \"{preview}\" in space {space}", [
|
||||
'displayName' => Html::encode($this->originator->displayName),
|
||||
'preview' => Helpers::truncateText($contentRecord->getContentDescription(), 25),
|
||||
'space' => Html::encode($space->displayName)
|
||||
]);
|
||||
}
|
||||
return Yii::t('CommentModule.notification', "{displayName} just commented your content \"{preview}\"", [
|
||||
'displayName' => Html::encode($this->originator->displayName),
|
||||
'preview' => Helpers::truncateText($contentRecord->getContentDescription(), 25),
|
||||
]);
|
||||
} else if ($space) {
|
||||
return Yii::t('CommentModule.notification', "{displayName} commented \"{preview}\" in space {space}", [
|
||||
'displayName' => Html::encode($this->originator->displayName),
|
||||
'preview' => Helpers::truncateText($contentRecord->getContentDescription(), 25),
|
||||
'space' => Html::encode($space->displayName)
|
||||
]);
|
||||
} else {
|
||||
return Yii::t('CommentModule.notification', "{displayName} commented \"{preview}\"", [
|
||||
'displayName' => Html::encode($this->originator->displayName),
|
||||
'preview' => Helpers::truncateText($contentRecord->getContentDescription(), 25),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
private function getGroupTitle(User $user)
|
||||
{
|
||||
$contentRecord = $this->getCommentedRecord();
|
||||
$space = $this->getSpace();
|
||||
|
||||
if ($user->is($contentRecord->owner)) {
|
||||
if ($space) {
|
||||
return Yii::t('CommentModule.notification', "{displayNames} just commented your content \"{preview}\" in space {space}", [
|
||||
'displayNames' => $this->getGroupUserDisplayNames(),
|
||||
'preview' => Helpers::truncateText($contentRecord->getContentDescription(), 25),
|
||||
'space' => Html::encode($space->displayName)
|
||||
]);
|
||||
}
|
||||
return Yii::t('CommentModule.notification', "{displayNames} just commented your content \"{preview}\"", [
|
||||
'displayNames' => $this->getGroupUserDisplayNames(),
|
||||
'preview' => Helpers::truncateText($contentRecord->getContentDescription(), 25),
|
||||
]);
|
||||
} else if ($space) {
|
||||
return Yii::t('CommentModule.notification', "{displayNames} commented \"{preview}\" in space {space}", [
|
||||
'displayNames' => $this->getGroupUserDisplayNames(),
|
||||
'preview' => Helpers::truncateText($contentRecord->getContentDescription(), 25),
|
||||
'space' => Html::encode($space->displayName)
|
||||
]);
|
||||
} else {
|
||||
return Yii::t('CommentModule.notification', "{displayNames} commented \"{preview}\"", [
|
||||
'displayNames' => $this->getGroupUserDisplayNames(),
|
||||
'preview' => Helpers::truncateText($contentRecord->getContentDescription(), 25),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
@ -62,28 +142,26 @@ class NewComment extends \humhub\modules\notification\components\BaseNotificatio
|
||||
$contentInfo = $this->getContentInfo($this->getCommentedRecord());
|
||||
|
||||
if ($this->groupCount > 1) {
|
||||
return Yii::t('CommentModule.notification', "{displayNames} commented {contentTitle}.", array(
|
||||
return Yii::t('CommentModule.notification', "{displayNames} commented {contentTitle}.", [
|
||||
'displayNames' => $this->getGroupUserDisplayNames(),
|
||||
'contentTitle' => $contentInfo
|
||||
));
|
||||
]);
|
||||
}
|
||||
return Yii::t('CommentModule.notification', "{displayName} commented {contentTitle}.", array(
|
||||
return Yii::t('CommentModule.notification', "{displayName} commented {contentTitle}.", [
|
||||
'displayName' => Html::tag('strong', Html::encode($this->originator->displayName)),
|
||||
'contentTitle' => $contentInfo
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* The commented record
|
||||
* The commented record e.g. a Post
|
||||
*
|
||||
* @return \humhub\components\ActiveRecord
|
||||
* @return \humhub\modules\content\components\ContentActiveRecord
|
||||
*/
|
||||
protected function getCommentedRecord()
|
||||
public function getCommentedRecord()
|
||||
{
|
||||
return $this->source->content->getPolymorphicRelation();
|
||||
;
|
||||
return $this->source->getCommentedRecord();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $viewable humhub\modules\comment\notifications\NewComment */
|
||||
/* @var $url string */
|
||||
/* @var $date string */
|
||||
/* @var $isNew boolean */
|
||||
/* @var $isNew boolean */
|
||||
/* @var $originator \humhub\modules\user\models\User */
|
||||
/* @var source yii\db\ActiveRecord */
|
||||
/* @var contentContainer \humhub\modules\content\components\ContentContainerActiveRecord */
|
||||
/* @var space humhub\modules\space\models\Space */
|
||||
/* @var record \humhub\modules\notification\models\Notification */
|
||||
/* @var html string */
|
||||
/* @var text string */
|
||||
?>
|
||||
<?php $this->beginContent('@notification/views/layouts/mail.php', $_params_); ?>
|
||||
|
||||
<?php $comment = $viewable->source; ?>
|
||||
<?php $contentRecord = $viewable->getCommentedRecord() ?>
|
||||
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="left">
|
||||
<tr>
|
||||
<td>
|
||||
<table width="100%" style="background-color:#F5F5F5;border-radius:4px" border="0" cellspacing="0" cellpadding="0" align="left">
|
||||
<tr>
|
||||
<td height="10"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding-left:10px;">
|
||||
<?=
|
||||
humhub\modules\notification\widgets\MailContentEntry::widget([
|
||||
'originator' => $originator,
|
||||
'content' => $comment,
|
||||
'date' => $date,
|
||||
'space' => $space,
|
||||
'isComment' => true
|
||||
]);
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="10"></td>
|
||||
</tr>
|
||||
</table
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="10"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="10" style="border-top: 1px solid #eee;"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td >
|
||||
<?=
|
||||
humhub\modules\notification\widgets\MailContentEntry::widget([
|
||||
'originator' => $contentRecord->owner,
|
||||
'content' => $contentRecord,
|
||||
'date' => $date,
|
||||
'space' => $space
|
||||
]);
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
<?php
|
||||
$this->endContent();
|
@ -1,4 +1,4 @@
|
||||
<?php //[STAMP] e93907d5924b39a3cd4134cc6a6ea3a3
|
||||
<?php //[STAMP] 0468b7e2480518455b63a22d3aa6f7c2
|
||||
namespace comment\_generated;
|
||||
|
||||
// This class was automatically generated by build task
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace tests\codeception\unit\modules\comment\components;
|
||||
|
||||
use Yii;
|
||||
use tests\codeception\_support\HumHubDbTestCase;
|
||||
use Codeception\Specify;
|
||||
use humhub\modules\post\models\Post;
|
||||
|
@ -203,6 +203,14 @@ class ContentActiveRecord extends ActiveRecord implements ContentOwner
|
||||
parent::afterSave($insert, $changedAttributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \humhub\modules\user\models\User the owner of this content record
|
||||
*/
|
||||
public function getOwner()
|
||||
{
|
||||
return $this->content->createdBy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Related Content model
|
||||
*
|
||||
@ -224,7 +232,6 @@ class ContentActiveRecord extends ActiveRecord implements ContentOwner
|
||||
{
|
||||
return Yii::createObject(ActiveQueryContent::className(), [get_called_class()]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -122,7 +122,7 @@ class ContentContainerController extends Controller
|
||||
if ($this->contentContainer instanceof Space && (Yii::$app->request->isPjax || !Yii::$app->request->isAjax)) {
|
||||
$options = [
|
||||
'guid' => $this->contentContainer->guid,
|
||||
'name' => $this->contentContainer->name,
|
||||
'name' => \yii\helpers\Html::encode($this->contentContainer->name),
|
||||
'archived' => $this->contentContainer->isArchived(),
|
||||
'image' => \humhub\modules\space\widgets\Image::widget([
|
||||
'space' => $this->contentContainer,
|
||||
|
@ -10,6 +10,8 @@ namespace humhub\modules\content\notifications;
|
||||
|
||||
use Yii;
|
||||
use yii\bootstrap\Html;
|
||||
use humhub\modules\user\models\User;
|
||||
use humhub\libs\Helpers;
|
||||
|
||||
/**
|
||||
* ContentCreatedNotification is fired to all users which are manually selected
|
||||
@ -18,6 +20,11 @@ use yii\bootstrap\Html;
|
||||
class ContentCreated extends \humhub\modules\notification\components\BaseNotification
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public $viewName = 'contentCreated';
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
@ -26,7 +33,8 @@ class ContentCreated extends \humhub\modules\notification\components\BaseNotific
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function category() {
|
||||
public function category()
|
||||
{
|
||||
return new \humhub\modules\content\notifications\ContentCreatedNotificationCategory();
|
||||
}
|
||||
|
||||
@ -35,28 +43,55 @@ class ContentCreated extends \humhub\modules\notification\components\BaseNotific
|
||||
*/
|
||||
public function html()
|
||||
{
|
||||
return Yii::t('ContentModule.notifications_views_ContentCreated', '{displayName} created {contentTitle}.', array(
|
||||
return Yii::t('ContentModule.notifications_views_ContentCreated', '{displayName} created {contentTitle}.', [
|
||||
'displayName' => Html::tag('strong', Html::encode($this->originator->displayName)),
|
||||
'contentTitle' => $this->getContentInfo($this->source)
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getTitle()
|
||||
public function getTitle(User $user)
|
||||
{
|
||||
return Yii::t('ContentModule.notifications_ContentCreated', 'There is new content your are following available at '.Html::encode(Yii::$app->name));
|
||||
$space = $this->getSpace();
|
||||
if ($space) {
|
||||
if ($this->isExplicitNotifyUser($user)) {
|
||||
return Yii::t('ContentModule.notifications_ContentCreated', '{originator} notifies you about {contentType} "{preview}" in {space}',
|
||||
['originator' => Html::encode($this->originator->displayName),
|
||||
'space' => Html::encode($space->displayName),
|
||||
'contentType' => $this->source->getContentName(),
|
||||
'preview' => Helpers::truncateText($this->source->getContentDescription(), 25)]);
|
||||
}
|
||||
return Yii::t('ContentModule.notifications_ContentCreated', '{originator} just wrote {contentType} "{preview}" in space {space}',
|
||||
['originator' => Html::encode($this->originator->displayName),
|
||||
'space' => Html::encode($space->displayName),
|
||||
'contentType' => $this->source->getContentName(),
|
||||
'preview' => Helpers::truncateText($this->source->getContentDescription(), 25)]);
|
||||
} else {
|
||||
if ($this->isExplicitNotifyUser($user)) {
|
||||
return Yii::t('ContentModule.notifications_ContentCreated', '{originator} notifies you about {contentType} "{preview}"',
|
||||
['originator' => Html::encode($this->originator->displayName),
|
||||
'contentType' => $this->source->getContentName(),
|
||||
'preview' => Helpers::truncateText($this->source->getContentDescription(), 25)]);
|
||||
}
|
||||
return Yii::t('ContentModule.notifications_ContentCreated', '{originator} just wrote {contentType} "{preview}"',
|
||||
['originator' => Html::encode($this->originator->displayName),
|
||||
'contentType' => $this->source->getContentName(),
|
||||
'preview' => Helpers::truncateText($this->source->getContentDescription(), 25)]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getHeadline()
|
||||
protected function isExplicitNotifyUser(User $user)
|
||||
{
|
||||
return Yii::t('ContentModule.notifications_ContentCreated', 'New content available');
|
||||
$content = $this->getContent();
|
||||
foreach ($content->notifyUsersOfNewContent as $notifyUser) {
|
||||
if ($notifyUser->id === $user->id) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $viewable humhub\modules\content\notifications\ContentCreated */
|
||||
/* @var $url string */
|
||||
/* @var $date string */
|
||||
/* @var $isNew boolean */
|
||||
/* @var $isNew boolean */
|
||||
/* @var $originator \humhub\modules\user\models\User */
|
||||
/* @var source yii\db\ActiveRecord */
|
||||
/* @var contentContainer \humhub\modules\content\components\ContentContainerActiveRecord */
|
||||
/* @var space humhub\modules\space\models\Space */
|
||||
/* @var record \humhub\modules\notification\models\Notification */
|
||||
/* @var html string */
|
||||
/* @var text string */
|
||||
?>
|
||||
<?php $this->beginContent('@notification/views/layouts/mail.php', $_params_); ?>
|
||||
<?= humhub\modules\notification\widgets\MailContentEntry::widget([
|
||||
'originator' => $originator,
|
||||
'content' => $viewable->source,
|
||||
'date' => $date,
|
||||
'space' => $space
|
||||
])
|
||||
?>
|
||||
<?php $this->endContent();
|
@ -1,4 +1,4 @@
|
||||
<?php //[STAMP] e93907d5924b39a3cd4134cc6a6ea3a3
|
||||
<?php //[STAMP] 0468b7e2480518455b63a22d3aa6f7c2
|
||||
namespace content\_generated;
|
||||
|
||||
// This class was automatically generated by build task
|
||||
|
@ -5,7 +5,6 @@ namespace tests\codeception\unit;
|
||||
use Yii;
|
||||
use tests\codeception\_support\HumHubDbTestCase;
|
||||
use Codeception\Specify;
|
||||
use humhub\modules\content\tests\codeception\unit\models\TestContent;
|
||||
use humhub\modules\space\models\Space;
|
||||
use humhub\modules\user\models\User;
|
||||
|
||||
@ -14,20 +13,6 @@ class ContentCreatedTest extends HumHubDbTestCase
|
||||
|
||||
use Specify;
|
||||
|
||||
/**
|
||||
* Create a Mock Content class and assign a notify user save it and check if an email was sent and test wallout.
|
||||
*/
|
||||
public function testWallOut()
|
||||
{
|
||||
$this->becomeUser('User2');
|
||||
|
||||
$testContent = new TestContent(['message' => 'MyTestContent']);
|
||||
$testContent->content->setContainer(Space::findOne(['id' => 2]));
|
||||
$testContent->save();
|
||||
|
||||
$this->assertEquals('<div>Wallentry:MyTestContent</div>', trim($testContent->getWallOut()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test CreateContent notification for a space follower with send_notification setting (see user_follow fixture)
|
||||
*/
|
||||
|
@ -1,50 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace humhub\modules\content\tests\codeception\unit\models;
|
||||
|
||||
/**
|
||||
* Description of TestContent
|
||||
*
|
||||
* @author buddha
|
||||
*/
|
||||
class TestContent extends \humhub\modules\content\components\ContentActiveRecord
|
||||
{
|
||||
|
||||
public $message;
|
||||
public $_content;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public $wallEntryClass = 'humhub\modules\content\tests\codeception\unit\widgets\WallEntryTest';
|
||||
|
||||
public function save($runValidation = true, $attributeNames = null)
|
||||
{
|
||||
// Just a mock...
|
||||
$this->afterSave(true, []);
|
||||
}
|
||||
|
||||
public function getPrimaryKey($asArray = false)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
/**
|
||||
* Ensure there is always a corresponding Content
|
||||
*/
|
||||
if ($name == 'content') {
|
||||
if (!$this->_content) {
|
||||
$this->_content = new \humhub\modules\content\models\Content();
|
||||
$this->_content->setPolymorphicRelation($this);
|
||||
}
|
||||
return $this->_content;
|
||||
}
|
||||
return parent::__get($name);
|
||||
}
|
||||
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
<?php echo strip_tags(Yii::t('base', '<strong>Latest</strong> updates')); ?>
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
if ($notifications_plaintext != '') {
|
||||
echo $notifications_plaintext;
|
||||
} else if ($activities_plaintext != '') {
|
||||
echo $activities_plaintext;
|
||||
}
|
||||
|
||||
?>
|
@ -12,6 +12,8 @@ use Yii;
|
||||
use yii\helpers\Url;
|
||||
use yii\bootstrap\Html;
|
||||
use humhub\modules\notification\models\Notification;
|
||||
use humhub\modules\notification\jobs\SendNotification;
|
||||
use humhub\modules\notification\jobs\SendBulkNotification;
|
||||
use humhub\modules\user\models\User;
|
||||
|
||||
/**
|
||||
@ -29,12 +31,6 @@ use humhub\modules\user\models\User;
|
||||
abstract class BaseNotification extends \humhub\components\SocialActivity
|
||||
{
|
||||
|
||||
/**
|
||||
* Can be used to delay the NotificationJob execution.
|
||||
* @var type
|
||||
*/
|
||||
public $delay = 0;
|
||||
|
||||
/**
|
||||
* @var boolean automatically mark notification as seen after click on it
|
||||
*/
|
||||
@ -93,9 +89,10 @@ abstract class BaseNotification extends \humhub\components\SocialActivity
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user the recipient
|
||||
* @return string title text for this notification
|
||||
*/
|
||||
public function getTitle()
|
||||
public function getTitle(User $user)
|
||||
{
|
||||
$category = $this->getCategory();
|
||||
if ($category) {
|
||||
@ -106,11 +103,12 @@ abstract class BaseNotification extends \humhub\components\SocialActivity
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string the headline for this notification used for example in mails.
|
||||
* @param User $user the recipient
|
||||
* @return string the headline for this notification, can be used for example in mails.
|
||||
*/
|
||||
public function getHeadline()
|
||||
public function getHeadline(User $user)
|
||||
{
|
||||
return Yii::t('base', '<strong>Latest</strong> updates');
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -118,8 +116,18 @@ abstract class BaseNotification extends \humhub\components\SocialActivity
|
||||
*/
|
||||
public function getViewParams($params = [])
|
||||
{
|
||||
if($this->hasContent() && $this->getContent()->updated_at instanceof \yii\db\Expression) {
|
||||
$this->getContent()->refresh();
|
||||
$date = $this->getContent()->updated_at;
|
||||
} else if($this->hasContent()) {
|
||||
$date = $this->getContent()->updated_at;
|
||||
} else {
|
||||
$date = null;
|
||||
}
|
||||
|
||||
$result = [
|
||||
'url' => Url::to(['/notification/entry', 'id' => $this->record->id], true),
|
||||
'date' => $date,
|
||||
'isNew' => !$this->record->seen,
|
||||
];
|
||||
|
||||
@ -145,25 +153,23 @@ abstract class BaseNotification extends \humhub\components\SocialActivity
|
||||
}
|
||||
|
||||
// Filter out duplicates and the originator and save records
|
||||
$filteredUsers = $this->saveAndFilterRecords($users);
|
||||
$filteredUsers = $this->filterRecepients($users);
|
||||
|
||||
Yii::$app->notification->sendBulk($this, $filteredUsers);
|
||||
Yii::$app->queue->push(new SendBulkNotification(['notification' => $this, 'recepients' => $filteredUsers]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves an Notification record for users and filters out duplicates and the originator of the notification.
|
||||
* This function will return the array with unique user instances.
|
||||
* Filters out duplicates and the originator of the notification itself.
|
||||
*
|
||||
* @param User[] $users
|
||||
* @return User[] array of unique user instances
|
||||
*/
|
||||
protected function saveAndFilterRecords($users)
|
||||
protected function filterRecepients($users)
|
||||
{
|
||||
$userIds = [];
|
||||
$filteredUsers = [];
|
||||
foreach ($users as $user) {
|
||||
// Filter our duplicates and the originator of this notification.
|
||||
if (!in_array($user->id, $userIds) && !$this->isOriginator($user)) {
|
||||
$this->saveRecord($user);
|
||||
$filteredUsers[] = $user;
|
||||
$userIds[] = $user->id;
|
||||
}
|
||||
@ -187,10 +193,7 @@ abstract class BaseNotification extends \humhub\components\SocialActivity
|
||||
return;
|
||||
}
|
||||
|
||||
//$this->queueJob($user);
|
||||
$this->saveRecord($user);
|
||||
|
||||
Yii::$app->notification->send($this, $user);
|
||||
Yii::$app->queue->push(new SendNotification(['notification' => $this, 'recepient' => $user]));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -204,29 +207,6 @@ abstract class BaseNotification extends \humhub\components\SocialActivity
|
||||
return $this->originator && $this->originator->id == $user->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Queues the notification job. The Job is responsible for creating and sending
|
||||
* the Notifications out to its NotificationTargets.
|
||||
*
|
||||
* @param User $user
|
||||
*/
|
||||
protected function queueJob(User $user)
|
||||
{
|
||||
Yii::$app->notificationQueue->push(new NotificationJob([
|
||||
'notification' => $this,
|
||||
'user_id' => $user->id
|
||||
]));
|
||||
}
|
||||
|
||||
public function save(User $user)
|
||||
{
|
||||
// We reuse our record instance to save multiple records.
|
||||
$this->record->id = null;
|
||||
$this->record->isNewRecord = true;
|
||||
$this->record->user_id = $user->id;
|
||||
return $this->record->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the an Notification instance of the current BaseNotification type for the
|
||||
* given $user.
|
||||
@ -417,11 +397,11 @@ abstract class BaseNotification extends \humhub\components\SocialActivity
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function asArray()
|
||||
public function asArray(User $user)
|
||||
{
|
||||
$result = parent::asArray();
|
||||
$result['title'] = $this->getTitle();
|
||||
$result['headline'] = $this->getHeadline();
|
||||
$result = parent::asArray($user);
|
||||
$result['title'] = $this->getTitle($user);
|
||||
$result['headline'] = $this->getHeadline($user);
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ namespace humhub\modules\notification\components;
|
||||
|
||||
use Yii;
|
||||
use humhub\modules\user\models\User;
|
||||
use yii\helpers\Html;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -23,9 +24,12 @@ class MailNotificationTarget extends NotificationTarget
|
||||
*/
|
||||
public $defaultSetting = true;
|
||||
|
||||
/**
|
||||
* @var array Notification mail layout.
|
||||
*/
|
||||
public $view = [
|
||||
'html' => '@humhub/modules/content/views/mails/Update',
|
||||
'text' => '@humhub/modules/content/views/mails/plaintext/Update'
|
||||
'html' => '@notification/views/mails/Update',
|
||||
'text' => '@notification/views/mails/plaintext/Update'
|
||||
];
|
||||
|
||||
/**
|
||||
@ -39,32 +43,28 @@ class MailNotificationTarget extends NotificationTarget
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function handle(BaseNotification $notification, User $user)
|
||||
public function handle(BaseNotification $notification, User $recipient)
|
||||
{
|
||||
// TODO: find cleaner solution...
|
||||
Yii::$app->view->params['showUnsubscribe'] = true;
|
||||
|
||||
$viewParams = [
|
||||
'headline' => $notification->getHeadline(),
|
||||
'notifications' => $notification->render($this),
|
||||
'notifications_plaintext' => $this->getText($notification)
|
||||
];
|
||||
// Note: the renderer is configured in common.php by default its an instance of MailNotificatoinTarget
|
||||
$renderer = $this->getRenderer();
|
||||
|
||||
$viewParams = \yii\helpers\ArrayHelper::merge([
|
||||
'headline' => $notification->getHeadline($recipient),
|
||||
'notification' => $notification,
|
||||
'space' => $notification->getSpace(),
|
||||
'content' => $renderer->render($notification),
|
||||
'content_plaintext' => $renderer->renderText($notification)
|
||||
], $notification->getViewParams());
|
||||
|
||||
$from = $notification->originator
|
||||
? Html::encode($notification->originator->displayName).' ('.Html::encode(Yii::$app->name).')'
|
||||
: Yii::$app->settings->get('mailer.systemEmailName');
|
||||
|
||||
return Yii::$app->mailer->compose($this->view, $viewParams)
|
||||
->setFrom([Yii::$app->settings->get('mailer.systemEmailAddress') => Yii::$app->settings->get('mailer.systemEmailName')])
|
||||
->setTo($user->email)
|
||||
->setSubject($notification->getTitle())->send();
|
||||
->setFrom([Yii::$app->settings->get('mailer.systemEmailAddress') => $from])
|
||||
->setTo($recipient->email)
|
||||
->setSubject($notification->getTitle($recipient))->send();
|
||||
}
|
||||
|
||||
public function getText(BaseNotification $notification)
|
||||
{
|
||||
$textRenderer = $this->getRenderer();
|
||||
|
||||
if (!method_exists($textRenderer, 'renderText')) {
|
||||
$textRenderer = Yii::createObject(MailTargetRenderer::class);
|
||||
}
|
||||
|
||||
return $textRenderer->renderText($notification);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,9 +2,6 @@
|
||||
|
||||
namespace humhub\modules\notification\components;
|
||||
|
||||
use Yii;
|
||||
use humhub\components\rendering\Viewable;
|
||||
|
||||
/**
|
||||
* The MailTargetRenderer is used to render Notifications for the MailNotificationTarget.
|
||||
*
|
||||
@ -22,104 +19,25 @@ use humhub\components\rendering\Viewable;
|
||||
*
|
||||
* @author buddha
|
||||
*/
|
||||
class MailTargetRenderer extends \humhub\components\rendering\MailLayoutRenderer
|
||||
class MailTargetRenderer extends \humhub\components\rendering\MailRenderer
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public $defaultView = '@notification/views/mails/default.php';
|
||||
|
||||
/**
|
||||
* @var string default notification mail view path
|
||||
* @inheritdoc
|
||||
*/
|
||||
public $defaultViewPath = '@notification/views/notification/mail';
|
||||
public $defaultViewPath = '@notification/views/mails';
|
||||
|
||||
/**
|
||||
* @var string default notification mail view
|
||||
* @inheritdoc
|
||||
*/
|
||||
public $defaultView = '@notification/views/notification/mail/default.php';
|
||||
public $defaultTextView = '@notification/views/mails/plaintext/default.php';
|
||||
|
||||
/**
|
||||
* @var string layout file path
|
||||
* @inheritdoc
|
||||
*/
|
||||
public $defaultLayout = '@notification/views/layouts/mail.php';
|
||||
|
||||
/**
|
||||
* @var string default notification mail text view path
|
||||
*/
|
||||
public $defaultTextViewPath = '@notification/views/notification/mail/plaintext';
|
||||
|
||||
/**
|
||||
* @var string text layout file
|
||||
*/
|
||||
public $defaultTextLayout = "@notification/views/layouts/mail_plaintext.php";
|
||||
|
||||
/**
|
||||
* Returns the view file for the given Viewable Notification.
|
||||
*
|
||||
* This function will search for the view file defined in the Viewable within the module/views/notification/mail directory of
|
||||
* the viewable module.
|
||||
*
|
||||
* If the module view does not exist we search for the viewName within the default notification viewPath.
|
||||
*
|
||||
* If this view also does not exist we return the base notification view file.
|
||||
*
|
||||
* @param \humhub\modules\notification\components\Viewable $viewable
|
||||
* @return string view file of this notification
|
||||
*/
|
||||
public function getViewFile(Viewable $viewable)
|
||||
{
|
||||
$viewFile = $this->getViewPath($viewable) . '/mail/' . $viewable->getViewName();
|
||||
|
||||
if (!file_exists($viewFile)) {
|
||||
$viewFile = Yii::getAlias($this->defaultViewPath) . DIRECTORY_SEPARATOR . $viewable->getViewName();
|
||||
}
|
||||
|
||||
if (!file_exists($viewFile)) {
|
||||
$viewFile = Yii::getAlias($this->defaultView);
|
||||
}
|
||||
|
||||
return $viewFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the layout for the given Notification Viewable.
|
||||
*
|
||||
* This function will search for a layout file under module/views/layouts/mail with the view name defined
|
||||
* by $viwable.
|
||||
*
|
||||
* If this file does not exists the default notification mail layout will be returned.
|
||||
*
|
||||
* @param \humhub\modules\notification\components\Viewable $viewable
|
||||
* @return type
|
||||
*/
|
||||
public function getLayout(Viewable $viewable)
|
||||
{
|
||||
$layout = $this->getViewPath($viewable) . '/layouts/mail/' . $viewable->getViewName();
|
||||
|
||||
if (!file_exists($layout)) {
|
||||
$layout = Yii::getAlias($this->defaultLayout);
|
||||
}
|
||||
|
||||
return $layout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the text layout for the given Notification Viewable.
|
||||
*
|
||||
* This function will search for a view file under module/views/layouts/mail/plaintext with the view name defined
|
||||
* by $viwable.
|
||||
*
|
||||
* If this file does not exists the default notification text mail layout is returned.
|
||||
*
|
||||
* @param \humhub\modules\notification\components\Viewable $viewable
|
||||
* @return type
|
||||
*/
|
||||
public function getTextLayout(Viewable $viewable)
|
||||
{
|
||||
$layout = $this->getViewPath($viewable) . '/layouts/mail/plaintext/' . $viewable->getViewName();
|
||||
|
||||
if (!file_exists($layout)) {
|
||||
$layout = Yii::getAlias($this->defaultTextLayout);
|
||||
}
|
||||
|
||||
return $layout;
|
||||
}
|
||||
|
||||
public $defaultTextViewPath = '@notification/views/mails/plaintext';
|
||||
}
|
||||
|
@ -146,9 +146,6 @@ abstract class NotificationTarget extends \yii\base\Object
|
||||
} catch (\Exception $e) {
|
||||
Yii::error($e);
|
||||
$this->acknowledge($notification, false);
|
||||
if(!YII_ENV_PROD) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -160,10 +157,6 @@ abstract class NotificationTarget extends \yii\base\Object
|
||||
*/
|
||||
public function sendBulk(BaseNotification $notification, $users)
|
||||
{
|
||||
if ($users instanceof \yii\db\ActiveQuery) {
|
||||
$users = $users->all();
|
||||
}
|
||||
|
||||
foreach ($users as $user) {
|
||||
$this->send($notification, $user);
|
||||
}
|
||||
|
@ -2,89 +2,20 @@
|
||||
|
||||
namespace humhub\modules\notification\components;
|
||||
|
||||
use Yii;
|
||||
use humhub\components\rendering\Viewable;
|
||||
|
||||
/**
|
||||
* The WebTargetRenderer is used to render Notifications for the WebNotificationTarget.
|
||||
*
|
||||
* A BaseNotification can overwrite the default view and layout by setting a specific $viewName and
|
||||
* defining the following files:
|
||||
*
|
||||
* Overwrite default view for this notification:
|
||||
* @module/views/notification/viewname.php
|
||||
*
|
||||
* Overwrite default layout for this notification:
|
||||
* @module/views/layouts/notification/viewname.php
|
||||
*
|
||||
* @author buddha
|
||||
*/
|
||||
class WebTargetRenderer extends \humhub\components\rendering\LayoutRenderer
|
||||
class WebTargetRenderer extends \humhub\components\rendering\DefaultViewPathRenderer
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public $defaultView = '@notification/views/default.php';
|
||||
|
||||
/**
|
||||
* @var string default view path
|
||||
* @inheritdoc
|
||||
*/
|
||||
public $defaultViewPath = '@notification/views/notification';
|
||||
|
||||
/*
|
||||
* @var string default view
|
||||
*/
|
||||
public $defaultView = '@notification/views/notification/default.php';
|
||||
|
||||
/**
|
||||
* @var string default layout
|
||||
*/
|
||||
public $defaultLayout = '@notification/views/layouts/web.php';
|
||||
|
||||
/**
|
||||
* Returns the view file for the given Viewable Notification.
|
||||
*
|
||||
* This function will search for the view file defined in the Viewable within the module/views/mail directory of
|
||||
* the viewable module.
|
||||
*
|
||||
* If the module view does not exist we search for the viewName within the default notification viewPath.
|
||||
*
|
||||
* If this view also does not exist we return the base notification view file.
|
||||
*
|
||||
* @param \humhub\modules\notification\components\Viewable $viewable
|
||||
* @return string view file of this notification
|
||||
*/
|
||||
public function getViewFile(Viewable $viewable)
|
||||
{
|
||||
$viewFile = $this->getViewPath($viewable) . '/' . $viewable->getViewName();
|
||||
|
||||
if (!file_exists($viewFile)) {
|
||||
$viewFile = Yii::getAlias($this->defaultViewPath) . DIRECTORY_SEPARATOR . $viewable->getViewName();
|
||||
}
|
||||
|
||||
if (!file_exists($viewFile)) {
|
||||
$viewFile = Yii::getAlias($this->defaultView);
|
||||
}
|
||||
|
||||
return $viewFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the layout for the given Notification Viewable.
|
||||
*
|
||||
* This function will search for a layout file under module/views/layouts/mail with the view name defined
|
||||
* by $viwable.
|
||||
*
|
||||
* If this file does not exists the default notification mail layout will be returned.
|
||||
*
|
||||
* @param \humhub\modules\notification\components\Viewable $viewable
|
||||
* @return type
|
||||
*/
|
||||
public function getLayout(Viewable $viewable)
|
||||
{
|
||||
$layout = $this->getViewPath($viewable) . '/layouts/' . $viewable->getViewName();
|
||||
|
||||
if (!file_exists($layout)) {
|
||||
$layout = Yii::getAlias($this->defaultLayout);
|
||||
}
|
||||
|
||||
return $layout;
|
||||
}
|
||||
|
||||
public $defaultViewPath = '@notification/views';
|
||||
}
|
||||
|
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @link https://www.humhub.org/
|
||||
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
|
||||
* @license https://www.humhub.com/licences
|
||||
*/
|
||||
namespace humhub\modules\notification\jobs;
|
||||
|
||||
use Yii;
|
||||
use humhub\components\queue\ActiveJob;
|
||||
|
||||
/**
|
||||
* Description of SendNotification
|
||||
*
|
||||
* @author buddha
|
||||
* @since 1.2
|
||||
*/
|
||||
class SendBulkNotification extends ActiveJob
|
||||
{
|
||||
/**
|
||||
* @var array Basenotification data as array.
|
||||
*/
|
||||
public $notification;
|
||||
|
||||
/**
|
||||
* @var integer[] Recepient userids.
|
||||
*/
|
||||
public $recepients;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
foreach($this->recepients as $recepient) {
|
||||
$this->notification->saveRecord($recepient);
|
||||
}
|
||||
|
||||
Yii::$app->notification->sendBulk($this->notification, $this->recepients);
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @link https://www.humhub.org/
|
||||
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
|
||||
* @license https://www.humhub.com/licences
|
||||
*/
|
||||
|
||||
namespace humhub\modules\notification\jobs;
|
||||
|
||||
use Yii;
|
||||
use humhub\components\queue\ActiveJob;
|
||||
|
||||
/**
|
||||
* Description of SendNotification
|
||||
*
|
||||
* @author buddha
|
||||
* @since 1.2
|
||||
*/
|
||||
class SendNotification extends ActiveJob
|
||||
{
|
||||
/**
|
||||
* @var humhub\modules\notification\components\BaseNotification notification instance
|
||||
*/
|
||||
public $notification;
|
||||
|
||||
/**
|
||||
* @var \humhub\modules\user\models\User Recepient user id.
|
||||
*/
|
||||
public $recepient;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$this->notification->saveRecord($this->recepient);
|
||||
Yii::$app->notification->send($this->notification, $this->recepient);
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
<?php //[STAMP] e93907d5924b39a3cd4134cc6a6ea3a3
|
||||
<?php //[STAMP] 0468b7e2480518455b63a22d3aa6f7c2
|
||||
namespace notification\_generated;
|
||||
|
||||
// This class was automatically generated by build task
|
||||
|
@ -9,7 +9,6 @@ use humhub\modules\notification\components\MailNotificationTarget;
|
||||
|
||||
class MailTargetRenderTest extends HumHubDbTestCase
|
||||
{
|
||||
|
||||
use Specify;
|
||||
|
||||
public function testDefaultView()
|
||||
@ -27,17 +26,9 @@ class MailTargetRenderTest extends HumHubDbTestCase
|
||||
$notification->viewName = 'special';
|
||||
$target = Yii::$app->notification->getTarget(MailNotificationTarget::class);
|
||||
$renderer = $target->getRenderer();
|
||||
$this->assertContains('<div>Special:<h1>TestedMailViewNotificationHTML</h1></div>', $renderer->render($notification));
|
||||
$result = $renderer->render($notification);
|
||||
$this->assertContains('<div>Special:<h1>TestedMailViewNotificationHTML</h1></div>', $result);
|
||||
$this->assertContains('<div>MyLayout:', $result);
|
||||
$this->assertContains('TestedMailViewNotificationText', $renderer->renderText($notification));
|
||||
}
|
||||
|
||||
public function testOverwriteLayoutFile()
|
||||
{
|
||||
$notification = notifications\TestedMailViewNotification::instance();
|
||||
$notification->viewName = 'specialLayout';
|
||||
$target = Yii::$app->notification->getTarget(MailNotificationTarget::class);
|
||||
$renderer = $target->getRenderer();
|
||||
$this->assertEquals('<div>MyLayout:<h1>TestedMailViewNotificationHTML</h1></div>', trim($renderer->render($notification)));
|
||||
$this->assertEquals('MyLayout:TestedMailViewNotificationText', trim($renderer->renderText($notification)));
|
||||
}
|
||||
}
|
||||
|
@ -32,15 +32,4 @@ class WebTargetRenderTest extends HumHubDbTestCase
|
||||
$this->assertContains('New', $result);
|
||||
$this->assertContains('<div>Special:<h1>TestedMailViewNotificationHTML</h1></div>', $result);
|
||||
}
|
||||
|
||||
public function testOverwriteLayoutFile()
|
||||
{
|
||||
$notification = notifications\TestedMailViewNotification::instance();
|
||||
$notification->viewName = 'specialLayout';
|
||||
$target = Yii::$app->notification->getTarget(WebNotificationTarget::class);
|
||||
$renderer = $target->getRenderer();
|
||||
$result = $renderer->render($notification);
|
||||
$this->assertNotContains('New', $result);
|
||||
$this->assertEquals('<div>MyLayout:<h1>TestedMailViewNotificationHTML</h1></div>', trim($result));
|
||||
}
|
||||
}
|
||||
|
@ -1,2 +0,0 @@
|
||||
<div>Special:<?= $html ?></div>
|
||||
|
@ -0,0 +1,4 @@
|
||||
<?php $this->beginContent('@notification/tests/codeception/unit/rendering/notifications/views/layouts/specialLayout.php', $_params_); ?>
|
||||
<div>Special:<?= $html ?></div>
|
||||
<?php $this->endContent(); ?>
|
||||
|
@ -1,2 +1,4 @@
|
||||
<?php $this->beginContent('@notification/views/layouts/web.php', $_params_); ?>
|
||||
<div>Special:<?= $html ?></div>
|
||||
<?php $this->endContent(); ?>
|
||||
|
||||
|
3
protected/humhub/modules/notification/views/default.php
Normal file
3
protected/humhub/modules/notification/views/default.php
Normal file
@ -0,0 +1,3 @@
|
||||
<?php $this->beginContent('@notification/views/layouts/web.php', $_params_); ?>
|
||||
<?= $html; ?>
|
||||
<?php $this->endContent(); ?>
|
@ -1,7 +1,3 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
?>
|
||||
<!-- START NOTIFICATION -->
|
||||
<tr>
|
||||
<td align="center" valign="top" class="fix-box">
|
||||
@ -23,74 +19,24 @@ use yii\helpers\Html;
|
||||
<!-- start content left -->
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="left">
|
||||
|
||||
<!--start space height -->
|
||||
<tr>
|
||||
<td height="20"></td>
|
||||
</tr>
|
||||
<!--end space height -->
|
||||
|
||||
|
||||
|
||||
<!-- start content top-->
|
||||
<tr>
|
||||
<td valign="top" align="left">
|
||||
|
||||
<table border="0" cellspacing="0" cellpadding="0" align="left">
|
||||
<tr>
|
||||
|
||||
<td valign="top" align="left" style="padding-right:20px;">
|
||||
|
||||
<?php if ($originator !== null): ?>
|
||||
<!-- START: USER IMAGE -->
|
||||
<a href="<?php echo $originator->createUrl('/user/profile', [], true); ?>">
|
||||
<img src="<?php echo $originator->getProfileImage()->getUrl("", true); ?>"
|
||||
width="50"
|
||||
alt=""
|
||||
style="max-width:50px; display:block !important; border-radius: 4px;"
|
||||
border="0" hspace="0" vspace="0"/>
|
||||
</a>
|
||||
<!-- END: USER IMAGE -->
|
||||
<?php endif; ?>
|
||||
|
||||
</td>
|
||||
|
||||
|
||||
<td valign="top">
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="left">
|
||||
|
||||
<tr>
|
||||
<td style="font-size: 13px; line-height: 22px; font-family:Open Sans,Arial,Tahoma, Helvetica, sans-serif; color:#555555; font-weight:300; text-align:left; ">
|
||||
|
||||
<?= $content; ?>
|
||||
|
||||
<!-- check if activity object has a space -->
|
||||
<?php if ($space !== null): ?>
|
||||
(<?php echo Yii::t('NotificationModule.views_notificationLayoutMail', 'via'); ?>
|
||||
<a href="<?php echo $space->createUrl('/space/space', [], true); ?>"
|
||||
style="text-decoration: none; color: #555555;">
|
||||
<?php echo Html::encode($space->name); ?>
|
||||
</a>)
|
||||
<?php endif; ?>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
<?= $content ?>
|
||||
</td>
|
||||
</tr>
|
||||
<!--start space height -->
|
||||
<tr>
|
||||
<td height="15" class="col-underline"></td>
|
||||
<td height="15"></td>
|
||||
</tr>
|
||||
<!--end space height -->
|
||||
<tr>
|
||||
<td valign="top" width="auto" align="center">
|
||||
<table border="0" align="center" cellpadding="0" cellspacing="0">
|
||||
<td width="auto" align="center" valign="middle" height="32" style=" background-color:#7191a8; border-radius:5px; background-clip: padding-box;font-size:14px; font-family:Open Sans, Arial,Tahoma, Helvetica, sans-serif; text-align:center; color:#ffffff; font-weight: 600; padding-left:30px; padding-right:30px; padding-top: 5px; padding-bottom: 5px;">
|
||||
|
||||
<span style="color: #ffffff; font-weight: 300;">
|
||||
<a href="<?php echo $url; ?>" style="text-decoration: none; color: #ffffff; font-weight: 300;">
|
||||
<?php echo Yii::t('NotificationModule.views_notificationLayoutMail', 'see online'); ?>
|
||||
|
@ -4,10 +4,10 @@ use yii\helpers\Html;
|
||||
|
||||
?>
|
||||
|
||||
<?php echo $content; ?>
|
||||
<?= $content; ?>
|
||||
|
||||
<?php if (isset($space) && $space !== null): ?>(<?php echo strip_tags(Yii::t('NotificationModule.views_notificationLayoutMail', 'via')); ?> <?php echo Html::encode($space->name); ?>)
|
||||
<?php if (isset($space) && $space !== null): ?>(<?= strip_tags(Yii::t('NotificationModule.views_notificationLayoutMail', 'via')); ?> <?= Html::encode($space->name); ?>)
|
||||
|
||||
<?php endif; ?><?php echo strip_tags(Yii::t('NotificationModule.views_notificationLayoutMail', 'see online')); ?>: <?php echo urldecode($url); ?>
|
||||
<?php endif; ?><?= strip_tags(Yii::t('NotificationModule.views_notificationLayoutMail', 'see online')); ?>: <?php echo urldecode($url); ?>
|
||||
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php if(!empty($headline)) :?>
|
||||
<tr>
|
||||
<td align="center" valign="top" class="fix-box">
|
||||
|
||||
<!-- start container width 600px -->
|
||||
<table width="600" align="center" border="0" cellspacing="0" cellpadding="0" class="container" bgcolor="#ffffff" style="background-color: #ffffff; border-top-left-radius: 4px; border-top-right-radius: 4px;">
|
||||
<tr>
|
||||
@ -37,11 +37,10 @@
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<!-- end text content -->
|
||||
</table>
|
||||
<!-- end content left -->
|
||||
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<!-- end image content -->
|
||||
@ -54,13 +53,7 @@
|
||||
<!-- end container width 600px -->
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<!-- START NOTIFICATION/ACTIVITY CONTENT-->
|
||||
<?php
|
||||
if ($notifications != '') {
|
||||
echo $notifications;
|
||||
} else if ($activities != '') {
|
||||
echo $activities;
|
||||
}
|
||||
?>
|
||||
<!-- END NOTIFICATION/ACTIVITY CONTENT-->
|
||||
<?php endif; ?>
|
||||
<!-- START NOTIFICATION CONTENT-->
|
||||
<?= $content ?>
|
||||
<!-- END NOTIFICATION CONTENT-->
|
@ -0,0 +1,3 @@
|
||||
<?php $this->beginContent('@notification/views/layouts/mail.php', $_params_); ?>
|
||||
<?= $html; ?>
|
||||
<?php $this->endContent(); ?>
|
@ -0,0 +1,4 @@
|
||||
<?= strip_tags(Yii::t('base', '<strong>Latest</strong> updates')); ?>
|
||||
|
||||
<?= $content_plaintext ?>
|
||||
|
@ -0,0 +1,3 @@
|
||||
<?php $this->beginContent('@notification/views/layouts/mail_plaintext.php', $_params_); ?>
|
||||
<?= $text; ?>
|
||||
<?php $this->endContent(); ?>
|
@ -1 +0,0 @@
|
||||
<?= $html; ?>
|
@ -1 +0,0 @@
|
||||
<?= $html; ?>
|
@ -1 +0,0 @@
|
||||
<?= $text; ?>
|
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @link https://www.humhub.org/
|
||||
* @copyright Copyright (c) 2016 HumHub GmbH & Co. KG
|
||||
* @license https://www.humhub.com/licences
|
||||
*/
|
||||
|
||||
namespace humhub\modules\notification\widgets;
|
||||
|
||||
use humhub\modules\space\models\Space;
|
||||
|
||||
/**
|
||||
* MailContentContainerImage renders the profile image of a ContentContainer.
|
||||
*
|
||||
* @author buddha
|
||||
* @since 1.2
|
||||
*/
|
||||
class MailContentContainerImage extends \yii\base\Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* @var \humhub\modules\content\components\ContentContainerActiveRecord
|
||||
*/
|
||||
public $container;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$url = ($this->container instanceof Space)
|
||||
? $this->container->createUrl('/space/space', [], true)
|
||||
: $this->container->createUrl('/user/profile', [], true);
|
||||
|
||||
return $this->render('mailContentContainerImage', [
|
||||
'container' => $this->container,
|
||||
'url' => $url,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @link https://www.humhub.org/
|
||||
* @copyright Copyright (c) 2016 HumHub GmbH & Co. KG
|
||||
* @license https://www.humhub.com/licences
|
||||
*/
|
||||
|
||||
namespace humhub\modules\notification\widgets;
|
||||
|
||||
use humhub\libs\Helpers;
|
||||
|
||||
/**
|
||||
* MailContentContainerInfoBox for rendering a simple info box with contentcotnainer image,name and description.
|
||||
*
|
||||
* @author buddha
|
||||
* @since 1.2
|
||||
*/
|
||||
class MailContentContainerInfoBox extends \yii\base\Widget
|
||||
{
|
||||
public $container;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
if ($this->container instanceof \humhub\modules\space\models\Space) {
|
||||
return $this->render('contentContainerInfoBox', [
|
||||
'container' => $this->container,
|
||||
'url' => $this->container->createUrl('/space/space', [], true),
|
||||
'description' => Helpers::trimText($this->container->description, 60)
|
||||
|
||||
]);
|
||||
} else if ($this->container instanceof \humhub\modules\user\models\User) {
|
||||
return $this->render('contentContainerInfoBox', [
|
||||
'container' => $this->container,
|
||||
'url' => $this->container->createUrl('/user/profile', [], true),
|
||||
'description' => Helpers::trimText($this->container->profile->title, 60)
|
||||
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @link https://www.humhub.org/
|
||||
* @copyright Copyright (c) 2016 HumHub GmbH & Co. KG
|
||||
* @license https://www.humhub.com/licences
|
||||
*/
|
||||
|
||||
namespace humhub\modules\notification\widgets;
|
||||
|
||||
use Yii;
|
||||
use humhub\widgets\RichText;
|
||||
use humhub\components\rendering\ViewPathRenderer;
|
||||
use humhub\components\rendering\Viewable;
|
||||
use humhub\modules\content\interfaces\ContentOwner;
|
||||
|
||||
/**
|
||||
* MailContentEntry renders a simple mail content with originator information and an
|
||||
* content block to simulate a wall entry as good as poosible.
|
||||
*
|
||||
* @author buddha
|
||||
* @since 1.2
|
||||
*/
|
||||
class MailContentEntry extends \yii\base\Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* @var \humhub\modules\user\models\User content originator
|
||||
*/
|
||||
public $originator;
|
||||
|
||||
/**
|
||||
* @var string|Viewable|ContentOwner content to render
|
||||
*/
|
||||
public $content;
|
||||
|
||||
/**
|
||||
* @var \humhub\modules\space\models\Space space of content (optional)
|
||||
*/
|
||||
public $space;
|
||||
|
||||
/**
|
||||
* @var string content date
|
||||
*/
|
||||
public $date;
|
||||
|
||||
/**
|
||||
* @var boolean will render the content as comment
|
||||
*/
|
||||
public $isComment;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
if (is_string($this->content)) {
|
||||
$content = $this->content;
|
||||
} else if ($this->content instanceof Viewable) {
|
||||
try {
|
||||
$renderer = new ViewPathRenderer(['parent' => true, 'subPath' => 'mail']);
|
||||
$content = $renderer->render($this->content);
|
||||
} catch (\yii\base\ViewNotFoundException $e) {
|
||||
Yii::error($e);
|
||||
}
|
||||
} else if ($this->content instanceof \humhub\modules\content\interfaces\ContentOwner) {
|
||||
$content = RichText::widget(['text' => $this->content->getContentDescription(), 'minimal' => true]);
|
||||
}
|
||||
|
||||
|
||||
return $this->render('mailContentEntry', [
|
||||
'originator' => $this->originator,
|
||||
'content' => $content,
|
||||
'space' => $this->space,
|
||||
'date' => $this->date,
|
||||
'isComment' => $this->isComment,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -11,10 +11,10 @@ namespace humhub\modules\notification\widgets;
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* NotificationListWidget shows an stream of notifications for an user at the top menu.
|
||||
* Notificaiton overview widget.
|
||||
*
|
||||
* @author andystrobel
|
||||
* @since 0.5
|
||||
* @author buddha
|
||||
* @since 1.1
|
||||
*/
|
||||
class Overview extends \yii\base\Widget
|
||||
{
|
||||
@ -24,8 +24,9 @@ class Overview extends \yii\base\Widget
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
if (Yii::$app->user->isGuest)
|
||||
if (Yii::$app->user->isGuest) {
|
||||
return;
|
||||
}
|
||||
|
||||
return $this->render('overview', array(
|
||||
'update' => \humhub\modules\notification\controllers\ListController::getUpdates(),
|
||||
|
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
/* @var $container \humhub\modules\content\components\ContentContainerActiveRecord */
|
||||
/* @var $url string */
|
||||
/* @var $description string */
|
||||
?>
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="left">
|
||||
<tr>
|
||||
<!-- START: Space IMAGE COLUMN -->
|
||||
<td width="40" valign="top" align="left" style="padding-right:20px;">
|
||||
<?= humhub\modules\notification\widgets\MailContentContainerImage::widget(['container' => $container]); ?>
|
||||
</td>
|
||||
<!-- END: Space IMAGE COLUMN-->
|
||||
|
||||
<!-- START: CONTENT AND ORIGINATOR DESCRIPTION -->
|
||||
<td valign="top">
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="left">
|
||||
<tr>
|
||||
<td>
|
||||
<a href="<?= $url ?>" style="font-size: 15px; line-height: 22px; font-family:Open Sans,Arial,Tahoma, Helvetica, sans-serif; color:#555555; font-weight:300; text-align:left; ">
|
||||
<?= Html::encode($container->displayName) ?>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="15" style="font-size: 15px; line-height: 22px; font-family:Open Sans,Arial,Tahoma, Helvetica, sans-serif; color:#aeaeae; font-weight:300; text-align:left; ">
|
||||
<?= $description ?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
<!-- END: CONTENT AND ORIGINATOR DESCRIPTION -->
|
||||
</tr>
|
||||
</table>
|
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* @link https://www.humhub.org/
|
||||
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
|
||||
* @license https://www.humhub.com/licences
|
||||
*/
|
||||
|
||||
/* @var $container \humhub\modules\content\components\ContentContainerActiveRecord */
|
||||
/* @var $url string */
|
||||
|
||||
?>
|
||||
|
||||
<a href="<?= $url ?>">
|
||||
<img src="<?= $container->getProfileImage()->getUrl("", true); ?>"
|
||||
width="50"
|
||||
height="50"
|
||||
alt=""
|
||||
style="border-radius: 4px;"
|
||||
border="0" hspace="0" vspace="0"/>
|
||||
</a>
|
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
/* @var $space \humhub\modules\space\models\Space */
|
||||
/* @var $originator humhub\modules\user\models\User */
|
||||
/* @var $content string */
|
||||
/* @var $isComment boolean */
|
||||
/* @var $date string */
|
||||
|
||||
|
||||
|
||||
?>
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="left">
|
||||
<tr>
|
||||
<!-- START: USER IMAGE COLUMN -->
|
||||
<td width="40" valign="top" align="left" style="padding-right:20px;">
|
||||
|
||||
<?php if ($originator) : ?>
|
||||
<?= humhub\modules\notification\widgets\MailContentContainerImage::widget(['container' => $originator]); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
</td>
|
||||
<!-- END: USER IMAGE COLUMN-->
|
||||
|
||||
<!-- START: CONTENT AND ORIGINATOR DESCRIPTION -->
|
||||
<td valign="top">
|
||||
<?php if ($originator) : ?>
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="left">
|
||||
<tr>
|
||||
<td>
|
||||
<a href="<?= $originator->createUrl('/user/profile', [], true) ?>" style="font-size: 15px; line-height: 22px; font-family:Open Sans,Arial,Tahoma, Helvetica, sans-serif; color:#555555; font-weight:300; text-align:left; ">
|
||||
<?= $originator->displayName ?>
|
||||
</a>
|
||||
<?php if ($space && !$isComment) : ?>
|
||||
<span style="font-size: 11px; line-height: 22px; font-family:Open Sans,Arial,Tahoma, Helvetica, sans-serif; color:#bebebe; font-weight:300; text-align:left; ">
|
||||
► <a style="font-size: 11px; line-height: 22px; font-family:Open Sans,Arial,Tahoma, Helvetica, sans-serif; color:#bebebe; font-weight:bold; text-align:left; " href="<?= $space->getUrl() ?>"><?= Html::encode($space->displayName) ?></a>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
<?php if ($date) : ?>
|
||||
<span style="font-size: 11px; line-height: 22px; font-family:Open Sans,Arial,Tahoma, Helvetica, sans-serif; color:#bebebe; font-weight:300; text-align:left; ">
|
||||
<?= \humhub\widgets\TimeAgo::widget(['timestamp' => $date]) ?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<?php if($isComment) : ?>
|
||||
<td height="15" style="font-size: 14px; line-height: 22px; font-family:Open Sans,Arial,Tahoma, Helvetica, sans-serif; color:#555555; font-weight:300; text-align:left;">
|
||||
<?= $content ?>
|
||||
</td>
|
||||
<?php else : ?>
|
||||
<td height="15" style="font-size: 15px; line-height: 22px; font-family:Open Sans,Arial,Tahoma, Helvetica, sans-serif; color:#aeaeae; font-weight:300; text-align:left; ">
|
||||
<?= Html::encode($originator->profile->title); ?>
|
||||
</td>
|
||||
<?php endif; ?>
|
||||
</tr>
|
||||
</table>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<!-- END: CONTENT AND ORIGINATOR DESCRIPTION -->
|
||||
</tr>
|
||||
<?php if(!$isComment) : ?>
|
||||
<tr>
|
||||
<td colspan="2" height="10"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" style="padding-top:5px; padding-bottom:5px; font-size: 14px; line-height: 22px; font-family:Open Sans,Arial,Tahoma, Helvetica, sans-serif; color:#555555; font-weight:300; text-align:left; border-top: 1px solid #eee;">
|
||||
|
||||
<?= $content ?>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</table>
|
@ -25,6 +25,11 @@ class Invite extends BaseNotification
|
||||
*/
|
||||
public $moduleId = "space";
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public $viewName = "invite";
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
@ -38,6 +43,25 @@ class Invite extends BaseNotification
|
||||
return new SpaceMemberNotificationCategory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getSpace()
|
||||
{
|
||||
return $this->source;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getTitle(\humhub\modules\user\models\User $user)
|
||||
{
|
||||
return Yii::t('SpaceModule.notification', '{displayName} just invited you to the space {spaceName}', array(
|
||||
'{displayName}' => Html::encode($this->originator->displayName),
|
||||
'{spaceName}' => Html::encode($this->getSpace()->name)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
@ -45,7 +69,7 @@ class Invite extends BaseNotification
|
||||
{
|
||||
return Yii::t('SpaceModule.notification', '{displayName} invited you to the space {spaceName}', array(
|
||||
'{displayName}' => Html::tag('strong', Html::encode($this->originator->displayName)),
|
||||
'{spaceName}' => Html::tag('strong', Html::encode($this->source->name))
|
||||
'{spaceName}' => Html::tag('strong', Html::encode($this->getSpace()->name))
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,11 @@ class InviteAccepted extends BaseNotification
|
||||
*/
|
||||
public $moduleId = "space";
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public $viewName = "inviteDeclined";
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
@ -35,15 +40,26 @@ class InviteAccepted extends BaseNotification
|
||||
return new SpaceMemberNotificationCategory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getTitle(\humhub\modules\user\models\User $user)
|
||||
{
|
||||
return Yii::t('SpaceModule.notification', '{displayName} accepted your invite for the space {spaceName}', [
|
||||
'{displayName}' => Html::encode($this->originator->displayName),
|
||||
'{spaceName}' => Html::encode($this->source->name)
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function html()
|
||||
{
|
||||
return Yii::t('SpaceModule.notification', '{displayName} accepted your invite for the space {spaceName}', array(
|
||||
return Yii::t('SpaceModule.notification', '{displayName} accepted your invite for the space {spaceName}', [
|
||||
'{displayName}' => Html::tag('strong', Html::encode($this->originator->displayName)),
|
||||
'{spaceName}' => Html::tag('strong', Html::encode($this->source->name))
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,6 +27,11 @@ class InviteDeclined extends BaseNotification
|
||||
*/
|
||||
public $moduleId = "space";
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public $viewName = "inviteDeclined";
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
@ -35,15 +40,31 @@ class InviteDeclined extends BaseNotification
|
||||
return new SpaceMemberNotificationCategory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getSpace()
|
||||
{
|
||||
return $this->source;
|
||||
}
|
||||
|
||||
public function getTitle(\humhub\modules\user\models\User $user)
|
||||
{
|
||||
return Yii::t('SpaceModule.notification', '{displayName} declined your invite for the space {spaceName}', [
|
||||
'{displayName}' => Html::encode($this->originator->displayName),
|
||||
'{spaceName}' => Html::encode($this->getSpace()->name)
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function html()
|
||||
{
|
||||
return Yii::t('SpaceModule.notification', '{displayName} declined your invite for the space {spaceName}', array(
|
||||
return Yii::t('SpaceModule.notification', '{displayName} declined your invite for the space {spaceName}', [
|
||||
'{displayName}' => Html::tag('strong', Html::encode($this->originator->displayName)),
|
||||
'{spaceName}' => Html::tag('strong', Html::encode($this->source->name))
|
||||
));
|
||||
'{spaceName}' => Html::tag('strong', Html::encode($this->getSpace()->name))
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @link https://www.humhub.org/
|
||||
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
|
||||
* @license https://www.humhub.com/licences
|
||||
*/
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $viewable humhub\modules\user\notifications\Followed */
|
||||
/* @var $url string */
|
||||
/* @var $date string */
|
||||
/* @var $isNew boolean */
|
||||
/* @var $isNew boolean */
|
||||
/* @var $originator \humhub\modules\user\models\User */
|
||||
/* @var source yii\db\ActiveRecord */
|
||||
/* @var contentContainer \humhub\modules\content\components\ContentContainerActiveRecord */
|
||||
/* @var space humhub\modules\space\models\Space */
|
||||
/* @var record \humhub\modules\notification\models\Notification */
|
||||
/* @var html string */
|
||||
/* @var text string */
|
||||
?>
|
||||
|
||||
<?php $this->beginContent('@notification/views/layouts/mail.php', $_params_); ?>
|
||||
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="left">
|
||||
<tr>
|
||||
<td style="font-size: 14px; line-height: 22px; font-family:Open Sans,Arial,Tahoma, Helvetica, sans-serif; color:#555555; font-weight:300; text-align:left;">
|
||||
<?= $viewable->html(); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="10"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="border-top: 1px solid #eee;padding-top:10px;">
|
||||
<?= \humhub\modules\notification\widgets\MailContentContainerInfoBox::widget(['container' => $space])?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php $this->endContent();
|
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @link https://www.humhub.org/
|
||||
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
|
||||
* @license https://www.humhub.com/licences
|
||||
*/
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $viewable humhub\modules\user\notifications\Followed */
|
||||
/* @var $url string */
|
||||
/* @var $date string */
|
||||
/* @var $isNew boolean */
|
||||
/* @var $isNew boolean */
|
||||
/* @var $originator \humhub\modules\user\models\User */
|
||||
/* @var source yii\db\ActiveRecord */
|
||||
/* @var contentContainer \humhub\modules\content\components\ContentContainerActiveRecord */
|
||||
/* @var space humhub\modules\space\models\Space */
|
||||
/* @var record \humhub\modules\notification\models\Notification */
|
||||
/* @var html string */
|
||||
/* @var text string */
|
||||
?>
|
||||
|
||||
<?php $this->beginContent('@notification/views/layouts/mail.php', $_params_); ?>
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="left">
|
||||
<tr>
|
||||
<td style="font-size: 14px; line-height: 22px; font-family:Open Sans,Arial,Tahoma, Helvetica, sans-serif; color:#555555; font-weight:300; text-align:left;">
|
||||
<?= $viewable->html(); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="10"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="border-top: 1px solid #eee;padding-top:10px;">
|
||||
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="left">
|
||||
<tr>
|
||||
<td width="109"></td>
|
||||
<td width="50"><?= \humhub\modules\notification\widgets\MailContentContainerImage::widget(['container' => $originator])?></td>
|
||||
<td width="109"></td>
|
||||
<td width="25"><img src="<?= \yii\helpers\Url::to('@web/img/mail_ico_not.png', true); ?>" /></td>
|
||||
<td width="109"></td>
|
||||
<td width="50"><?= \humhub\modules\notification\widgets\MailContentContainerImage::widget(['container' => $space])?></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php $this->endContent();
|
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @link https://www.humhub.org/
|
||||
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
|
||||
* @license https://www.humhub.com/licences
|
||||
*/
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $viewable humhub\modules\user\notifications\Followed */
|
||||
/* @var $url string */
|
||||
/* @var $date string */
|
||||
/* @var $isNew boolean */
|
||||
/* @var $isNew boolean */
|
||||
/* @var $originator \humhub\modules\user\models\User */
|
||||
/* @var source yii\db\ActiveRecord */
|
||||
/* @var contentContainer \humhub\modules\content\components\ContentContainerActiveRecord */
|
||||
/* @var space humhub\modules\space\models\Space */
|
||||
/* @var record \humhub\modules\notification\models\Notification */
|
||||
/* @var html string */
|
||||
/* @var text string */
|
||||
?>
|
||||
|
||||
<?php $this->beginContent('@notification/views/layouts/mail.php', $_params_); ?>
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="left">
|
||||
<tr>
|
||||
<td style="font-size: 14px; line-height: 22px; font-family:Open Sans,Arial,Tahoma, Helvetica, sans-serif; color:#555555; font-weight:300; text-align:left;">
|
||||
<?= $viewable->html(); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="10"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="border-top: 1px solid #eee;padding-top:10px;">
|
||||
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="left">
|
||||
<tr>
|
||||
<td width="109"></td>
|
||||
<td width="50"><?= \humhub\modules\notification\widgets\MailContentContainerImage::widget(['container' => $originator])?></td>
|
||||
<td width="109"></td>
|
||||
<td width="25"><img src="<?= \yii\helpers\Url::to('@web/img/mail_ico_check.png', true); ?>" /></td>
|
||||
<td width="109"></td>
|
||||
<td width="50"><?= \humhub\modules\notification\widgets\MailContentContainerImage::widget(['container' => $space])?></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php $this->endContent();
|
@ -1,4 +1,4 @@
|
||||
<?php //[STAMP] e93907d5924b39a3cd4134cc6a6ea3a3
|
||||
<?php //[STAMP] 0468b7e2480518455b63a22d3aa6f7c2
|
||||
namespace space\_generated;
|
||||
|
||||
// This class was automatically generated by build task
|
||||
|
@ -6,8 +6,9 @@ use Yii;
|
||||
use tests\codeception\_support\HumHubDbTestCase;
|
||||
use Codeception\Specify;
|
||||
use humhub\modules\space\models\Space;
|
||||
use humhub\modules\space\models\Membership;
|
||||
|
||||
class ApprovalTest extends HumHubDbTestCase
|
||||
class MembershipTest extends HumHubDbTestCase
|
||||
{
|
||||
|
||||
use Specify;
|
||||
@ -16,14 +17,17 @@ class ApprovalTest extends HumHubDbTestCase
|
||||
{
|
||||
$this->becomeUser('User1');
|
||||
|
||||
// Space 1 is approval space
|
||||
$user1 = Yii::$app->user->getIdentity();
|
||||
|
||||
// Request Membership for Space 1 (approval join policity)
|
||||
$space = Space::findOne(['id' => 1]);
|
||||
$space->requestMembership(Yii::$app->user->id, 'Let me in!');
|
||||
|
||||
// Check approval mails are send and notification
|
||||
$this->assertMailSent(1, 'Approval notification admin mail');
|
||||
$this->assertHasNotification(\humhub\modules\space\notifications\ApprovalRequest::class, $space, Yii::$app->user->id, 'Approval Request Notification');
|
||||
|
||||
$membership = \humhub\modules\space\models\Membership::findOne(['space_id' => 1, 'user_id' => Yii::$app->user->id]);
|
||||
$membership = Membership::findOne(['space_id' => 1, 'user_id' => Yii::$app->user->id]);
|
||||
$this->assertNotNull($membership);
|
||||
$this->assertEquals($membership->status, \humhub\modules\space\models\Membership::STATUS_APPLICANT);
|
||||
|
||||
@ -32,6 +36,18 @@ class ApprovalTest extends HumHubDbTestCase
|
||||
$space->addMember(2);
|
||||
$this->assertMailSent(2, 'Approval notification admin mail');
|
||||
$this->assertHasNotification(\humhub\modules\space\notifications\ApprovalRequestAccepted::class, $space, 1, 'Approval Accepted Notification');
|
||||
|
||||
$memberships = Membership::findByUser($user1)->all();
|
||||
$this->assertNotEmpty($memberships, 'get all memberships of user query.');
|
||||
$match = null;
|
||||
|
||||
foreach($memberships as $membership) {
|
||||
if($membership->user_id == $user1->id) {
|
||||
$match = $membership;
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertNotNull($match);
|
||||
}
|
||||
|
||||
public function testJoinPolicityApprovalDecline()
|
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace tests\codeception\unit\modules\space;
|
||||
|
||||
use Yii;
|
||||
use tests\codeception\_support\HumHubDbTestCase;
|
||||
use Codeception\Specify;
|
||||
use humhub\modules\space\models\Space;
|
||||
use humhub\modules\user\models\Follow;
|
||||
|
||||
class SpaceFollowTest extends HumHubDbTestCase
|
||||
{
|
||||
|
||||
use Specify;
|
||||
|
||||
public function testSpaceFollow()
|
||||
{
|
||||
$this->becomeUser('User1');
|
||||
|
||||
// Follow Space 2
|
||||
$space = Space::findOne(['id' => 2]);
|
||||
$space->follow(null, false);
|
||||
|
||||
// Check if follow record was saved
|
||||
$follow = Follow::findOne(['object_model' => Space::class, 'object_id' => 2, 'user_id' => 2]);
|
||||
$this->assertNotNull($follow);
|
||||
$this->assertFalse(boolval($follow->send_notifications));
|
||||
|
||||
// Get all spaces this user follows and check if the new space is included
|
||||
$spaces = Follow::getFollowedSpacesQuery(Yii::$app->user->getIdentity())->all();
|
||||
$this->assertEquals(count($spaces), 1);
|
||||
$this->assertEquals($spaces[0]->id, 2);
|
||||
|
||||
// Get all followers of Space 2 and check if the user is included
|
||||
$followers = Follow::getFollowersQuery($space)->all();
|
||||
$this->assertEquals(count($followers), 2);
|
||||
|
||||
if($followers[0]->id == 2) {
|
||||
$this->assertTrue(true);
|
||||
} else if($followers[1]->id == 2) {
|
||||
$this->assertTrue(true);
|
||||
} else {
|
||||
$this->assertTrue(false, 'User not in follower list.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -78,7 +78,7 @@ class HeaderControlsMenu extends \humhub\widgets\BaseMenu
|
||||
|
||||
if (!$membership->send_notifications) {
|
||||
$this->addItem(array(
|
||||
'label' => Yii::t('SpaceModule.widgets_SpaceAdminMenuWidget', 'Receive notifications'),
|
||||
'label' => Yii::t('SpaceModule.widgets_SpaceAdminMenuWidget', 'Receive Notifications for new content'),
|
||||
'group' => 'admin',
|
||||
'url' => $this->space->createUrl('/space/membership/receive-notifications'),
|
||||
'icon' => '<i class="fa fa-star"></i>',
|
||||
@ -88,7 +88,7 @@ class HeaderControlsMenu extends \humhub\widgets\BaseMenu
|
||||
));
|
||||
} else {
|
||||
$this->addItem(array(
|
||||
'label' => Yii::t('SpaceModule.widgets_SpaceAdminMenuWidget', 'Don\'t receive notifications' ),
|
||||
'label' => Yii::t('SpaceModule.widgets_SpaceAdminMenuWidget', 'Don\'t receive notifications for new content'),
|
||||
'group' => 'admin',
|
||||
'url' => $this->space->createUrl('/space/membership/revoke-notifications'),
|
||||
'icon' => '<i class="fa fa-star-o"></i>',
|
||||
|
@ -470,6 +470,18 @@ class User extends ContentContainerActiveRecord implements \yii\web\IdentityInte
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given $user instance shares the same identity with this
|
||||
* user instance.
|
||||
*
|
||||
* @param \humhub\modules\user\models\User $user
|
||||
* @return boolean
|
||||
*/
|
||||
public function is(User $user)
|
||||
{
|
||||
return $user->id === $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
|
@ -24,6 +24,11 @@ class Followed extends BaseNotification
|
||||
*/
|
||||
public $moduleId = 'user';
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public $viewName = 'followed';
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
@ -40,14 +45,24 @@ class Followed extends BaseNotification
|
||||
return $this->originator->getUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getTitle(\humhub\modules\user\models\User $user)
|
||||
{
|
||||
return Yii::t('UserModule.notification', '{displayName} is now following you', [
|
||||
'displayName' => Html::encode($this->originator->displayName),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function html()
|
||||
{
|
||||
return Yii::t('UserModule.notification', '{displayName} is now following you.', array(
|
||||
return Yii::t('UserModule.notification', '{displayName} is now following you.', [
|
||||
'displayName' => Html::tag('strong', Html::encode($this->originator->displayName)),
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,6 +19,11 @@ use humhub\modules\notification\components\BaseNotification;
|
||||
class Mentioned extends BaseNotification
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public $viewName = 'mentioned';
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
@ -32,6 +37,18 @@ class Mentioned extends BaseNotification
|
||||
return new MentionedNotificationCategory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getViewName()
|
||||
{
|
||||
if($this->source instanceof \humhub\modules\comment\models\Comment) {
|
||||
return 'mentionedComment';
|
||||
}
|
||||
|
||||
return 'mentioned';
|
||||
}
|
||||
|
||||
/**
|
||||
* inheritdoc
|
||||
*/
|
||||
@ -45,6 +62,18 @@ class Mentioned extends BaseNotification
|
||||
return parent::send($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* inheritdoc
|
||||
*/
|
||||
public function getTitle(\humhub\modules\user\models\User $user)
|
||||
{
|
||||
return Yii::t('UserModule.notification', "{displayName} just mentioned you in {contentTitle} \"{preview}\"", [
|
||||
'displayName' => Html::encode($this->originator->displayName),
|
||||
'contentTitle' => $this->getContentName(),
|
||||
'preview' => $this->getContentPreview()
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
|
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @link https://www.humhub.org/
|
||||
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
|
||||
* @license https://www.humhub.com/licences
|
||||
*/
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $viewable humhub\modules\user\notifications\Followed */
|
||||
/* @var $url string */
|
||||
/* @var $date string */
|
||||
/* @var $isNew boolean */
|
||||
/* @var $isNew boolean */
|
||||
/* @var $originator \humhub\modules\user\models\User */
|
||||
/* @var source yii\db\ActiveRecord */
|
||||
/* @var contentContainer \humhub\modules\content\components\ContentContainerActiveRecord */
|
||||
/* @var space humhub\modules\space\models\Space */
|
||||
/* @var record \humhub\modules\notification\models\Notification */
|
||||
/* @var html string */
|
||||
/* @var text string */
|
||||
?>
|
||||
|
||||
<?php $this->beginContent('@notification/views/layouts/mail.php', $_params_); ?>
|
||||
<?= humhub\modules\notification\widgets\MailContentEntry::widget([
|
||||
'originator' => $originator,
|
||||
'content' => $viewable->html(),
|
||||
'date' => $date,
|
||||
'space' => $space
|
||||
])
|
||||
?>
|
||||
<?php $this->endContent();
|
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $viewable humhub\modules\user\notifications\Mentioned */
|
||||
/* @var $url string */
|
||||
/* @var $date string */
|
||||
/* @var $isNew boolean */
|
||||
/* @var $isNew boolean */
|
||||
/* @var $originator \humhub\modules\user\models\User */
|
||||
/* @var source yii\db\ActiveRecord */
|
||||
/* @var contentContainer \humhub\modules\content\components\ContentContainerActiveRecord */
|
||||
/* @var space humhub\modules\space\models\Space */
|
||||
/* @var record \humhub\modules\notification\models\Notification */
|
||||
/* @var html string */
|
||||
/* @var text string */
|
||||
?>
|
||||
<?php $this->beginContent('@notification/views/layouts/mail.php', $_params_); ?>
|
||||
<?= humhub\modules\notification\widgets\MailContentEntry::widget([
|
||||
'originator' => $originator,
|
||||
'content' => $viewable->source,
|
||||
'date' => $date,
|
||||
'space' => $space
|
||||
])
|
||||
?>
|
||||
<?php $this->endContent();
|
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $viewable humhub\modules\user\notifications\Mentioned */
|
||||
?>
|
||||
<?php $this->beginContent('@notification/views/layouts/mail.php', $_params_); ?>
|
||||
|
||||
<?php $comment = $viewable->source; ?>
|
||||
<?php $contentRecord = $comment->getCommentedRecord() ?>
|
||||
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="left">
|
||||
<tr>
|
||||
<td>
|
||||
<table width="100%" style="background-color:#F5F5F5;border-radius:4px" border="0" cellspacing="0" cellpadding="0" align="left">
|
||||
<tr>
|
||||
<td height="10"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding-left:10px;">
|
||||
<?=
|
||||
humhub\modules\notification\widgets\MailContentEntry::widget([
|
||||
'originator' => $originator,
|
||||
'content' => $comment,
|
||||
'date' => $date,
|
||||
'space' => $space,
|
||||
'isComment' => true
|
||||
]);
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="10"></td>
|
||||
</tr>
|
||||
</table
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="10"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="10" style="border-top: 1px solid #eee;"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td >
|
||||
<?=
|
||||
humhub\modules\notification\widgets\MailContentEntry::widget([
|
||||
'originator' => $contentRecord->owner,
|
||||
'content' => $contentRecord,
|
||||
'date' => $date,
|
||||
'space' => $space
|
||||
]);
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
<?php
|
||||
$this->endContent();
|
@ -1,4 +1,4 @@
|
||||
<?php //[STAMP] e93907d5924b39a3cd4134cc6a6ea3a3
|
||||
<?php //[STAMP] 0468b7e2480518455b63a22d3aa6f7c2
|
||||
namespace user\_generated;
|
||||
|
||||
// This class was automatically generated by build task
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace tests\codeception\unit\modules\space;
|
||||
namespace tests\codeception\unit;
|
||||
|
||||
use Yii;
|
||||
use tests\codeception\_support\HumHubDbTestCase;
|
||||
|
@ -7,18 +7,20 @@ use Codeception\Specify;
|
||||
use humhub\modules\space\models\Space;
|
||||
use humhub\modules\user\models\Mentioning;
|
||||
use humhub\modules\user\notifications\Mentioned;
|
||||
use humhub\modules\comment\models\Comment;
|
||||
use humhub\modules\post\models\Post;
|
||||
|
||||
class MentionTest extends HumHubDbTestCase
|
||||
{
|
||||
|
||||
use Specify;
|
||||
|
||||
public function testMentionUser()
|
||||
public function testPostMention()
|
||||
{
|
||||
$this->becomeUser('User2');
|
||||
$space = Space::findOne(['id' => 1]);
|
||||
|
||||
$post = new \humhub\modules\post\models\Post(['message' => '@-u01e50e0d-82cd-41fc-8b0c-552392f5839c']);
|
||||
$post = new Post(['message' => '@-u01e50e0d-82cd-41fc-8b0c-552392f5839c']);
|
||||
$post->content->container = $space;
|
||||
$post->save();
|
||||
|
||||
@ -28,4 +30,20 @@ class MentionTest extends HumHubDbTestCase
|
||||
$this->assertMailSent(1, 'Mentioned Notification');
|
||||
}
|
||||
|
||||
public function testCreateComment()
|
||||
{
|
||||
$this->becomeUser('User2');
|
||||
|
||||
$comment = new Comment([
|
||||
'message' => 'Hi @-u01e50e0d-82cd-41fc-8b0c-552392f5839c',
|
||||
'object_model' => Post::className(),
|
||||
'object_id' => 7
|
||||
]);
|
||||
|
||||
$comment->save();
|
||||
|
||||
$this->assertHasNotification(Mentioned::class, $comment);
|
||||
// Commented and Mentioned mail
|
||||
$this->assertMailSent(2, 'Comment Notification Mail sent');
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?php //[STAMP] 58ce1236f98ef299248ede5a3d5a3e7c
|
||||
<?php //[STAMP] ea40a453a487fa3632a18d4dadac1a58
|
||||
namespace _generated;
|
||||
|
||||
// This class was automatically generated by build task
|
||||
|
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace humhub\tests\codeception\unit;
|
||||
|
||||
use tests\codeception\_support\HumHubDbTestCase;
|
||||
use Codeception\Specify;
|
||||
use humhub\tests\codeception\unit\components\rendering\lib\TestViewable;
|
||||
use humhub\components\rendering\DefaultViewPathRenderer;
|
||||
|
||||
class DefaultViewPathRendererTest extends HumHubDbTestCase
|
||||
{
|
||||
|
||||
use Specify;
|
||||
|
||||
public function testSimpleDefaultView()
|
||||
{
|
||||
$viewable = new TestViewable(['viewName' => 'nonExistent']);
|
||||
$renderer = new DefaultViewPathRenderer(['defaultView' => '@tests/codeception/unit/components/rendering/views/parent.php']);
|
||||
$this->assertEquals('<h1>ParentView:TestTitle</h1>', $renderer->render($viewable));
|
||||
}
|
||||
|
||||
public function testDefaultPathView()
|
||||
{
|
||||
$viewable = new TestViewable(['viewName' => 'parent2']);
|
||||
$renderer = new DefaultViewPathRenderer([
|
||||
'defaultViewPath' => '@tests/codeception/unit/components/rendering/views',
|
||||
'defaultView' => '@tests/codeception/unit/components/rendering/views/parent.php'
|
||||
]);
|
||||
$this->assertEquals('<h1>ParentView2:TestTitle</h1>', $renderer->render($viewable));
|
||||
}
|
||||
|
||||
public function testViewFoundView()
|
||||
{
|
||||
$viewable = new TestViewable(['viewName' => 'testView']);
|
||||
$renderer = new DefaultViewPathRenderer([
|
||||
'defaultViewPath' => '@tests/codeception/unit/components/rendering/views',
|
||||
'defaultView' => '@tests/codeception/unit/components/rendering/views/parent.php'
|
||||
]);
|
||||
$this->assertEquals('<div>TestTitle</div>', $renderer->render($viewable));
|
||||
}
|
||||
|
||||
public function testViewFoundSettingsView()
|
||||
{
|
||||
$viewable = new TestViewable(['viewName' => 'mail']);
|
||||
$renderer = new DefaultViewPathRenderer([
|
||||
'parent' => true,
|
||||
'subPath' => 'mails',
|
||||
'defaultViewPath' => '@tests/codeception/unit/components/rendering/views',
|
||||
'defaultView' => '@tests/codeception/unit/components/rendering/views/parent.php'
|
||||
]);
|
||||
$this->assertEquals('<h1>MailView:TestTitle</h1>', $renderer->render($viewable));
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace humhub\tests\codeception\unit;
|
||||
|
||||
use tests\codeception\_support\HumHubDbTestCase;
|
||||
use Codeception\Specify;
|
||||
use humhub\tests\codeception\unit\components\rendering\lib\TestViewable;
|
||||
use humhub\components\rendering\LayoutRenderer;
|
||||
|
||||
class LayoutRendererTest extends HumHubDbTestCase
|
||||
{
|
||||
|
||||
use Specify;
|
||||
|
||||
public function testSimpleViewPathRenderer()
|
||||
{
|
||||
$viewable = new TestViewable(['viewName' => 'parent']);
|
||||
$renderer = new LayoutRenderer(['parent' => true, 'layout' => '@tests/codeception/unit/components/rendering/views/layouts/testLayout.php']);
|
||||
$this->assertEquals('<div>TestLayout:<h1>ParentView:TestTitle</h1></div>', $renderer->render($viewable));
|
||||
}
|
||||
|
||||
public function testNoLayout()
|
||||
{
|
||||
$viewable = new TestViewable(['viewName' => 'parent']);
|
||||
$renderer = new LayoutRenderer(['parent' => true]);
|
||||
$this->assertEquals('<h1>ParentView:TestTitle</h1>', $renderer->render($viewable));
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace humhub\tests\codeception\unit;
|
||||
|
||||
use tests\codeception\_support\HumHubDbTestCase;
|
||||
use Codeception\Specify;
|
||||
use humhub\tests\codeception\unit\components\rendering\lib\TestViewable;
|
||||
use humhub\components\rendering\MailLayoutRenderer;
|
||||
|
||||
class MailLayoutRendererTest extends HumHubDbTestCase
|
||||
{
|
||||
|
||||
use Specify;
|
||||
|
||||
public function testExistingTextView()
|
||||
{
|
||||
$viewable = new TestViewable(['viewName' => 'parent']);
|
||||
$renderer = new MailLayoutRenderer(['parent' => true,
|
||||
'textLayout' => '@tests/codeception/unit/components/rendering/views/layouts/testLayout.php']);
|
||||
$this->assertEquals('TestLayout:TestViewText', $renderer->renderText($viewable));
|
||||
}
|
||||
|
||||
public function testNoLayoutRenderText()
|
||||
{
|
||||
$viewable = new TestViewable(['viewName' => 'parent']);
|
||||
$renderer = new MailLayoutRenderer(['parent' => true]);
|
||||
$this->assertEquals('TestViewText', $renderer->renderText($viewable));
|
||||
}
|
||||
|
||||
public function testNonExistingTextLayout()
|
||||
{
|
||||
try {
|
||||
$viewable = new TestViewable(['viewName' => 'nonExisting']);
|
||||
$renderer = new MailLayoutRenderer(['textLayout' => '@tests/codeception/unit/components/rendering/views/layouts/nonExsting.php']);
|
||||
$renderer->renderText($viewable);
|
||||
$this->assertTrue(false);
|
||||
} catch (\yii\base\ViewNotFoundException $ex) {
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace humhub\tests\codeception\unit;
|
||||
|
||||
use tests\codeception\_support\HumHubDbTestCase;
|
||||
use Codeception\Specify;
|
||||
use humhub\tests\codeception\unit\components\rendering\lib\TestViewable;
|
||||
use humhub\components\rendering\MailRenderer;
|
||||
|
||||
class MailRendererTest extends HumHubDbTestCase
|
||||
{
|
||||
|
||||
use Specify;
|
||||
|
||||
public function testExistingTextView()
|
||||
{
|
||||
$viewable = new TestViewable(['viewName' => 'testView']);
|
||||
$renderer = new MailRenderer(['parent' => true,
|
||||
'defaultTextView' => '@tests/codeception/unit/components/rendering/lib/views',
|
||||
'defaultTextViewPath' => '@tests/codeception/unit/components/rendering/lib/views/specialView.php']);
|
||||
$this->assertEquals('TextView:TestTitle', $renderer->renderText($viewable));
|
||||
}
|
||||
|
||||
public function testNonExistingTextView()
|
||||
{
|
||||
$viewable = new TestViewable(['viewName' => 'nonExisting']);
|
||||
$renderer = new MailRenderer(['parent' => true,
|
||||
'defaultTextView' => '@tests/codeception/unit/components/rendering/lib/views/testView.php',
|
||||
'defaultTextViewPath' => '@tests/codeception/unit/components/rendering/lib/views']);
|
||||
$this->assertEquals('TestTitle', $renderer->renderText($viewable));
|
||||
}
|
||||
|
||||
public function testExistingViewPathTextView()
|
||||
{
|
||||
$viewable = new TestViewable(['viewName' => 'specialView']);
|
||||
$renderer = new MailRenderer(['parent' => true,
|
||||
'defaultTextView' => '@tests/codeception/unit/components/rendering/lib/views/testView.php',
|
||||
'defaultTextViewPath' => '@tests/codeception/unit/components/rendering/lib/views']);
|
||||
$this->assertEquals('SpecialView', $renderer->renderText($viewable));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace humhub\tests\codeception\unit;
|
||||
|
||||
use tests\codeception\_support\HumHubDbTestCase;
|
||||
use Codeception\Specify;
|
||||
use humhub\tests\codeception\unit\components\rendering\lib\TestViewable;
|
||||
use humhub\components\rendering\ViewPathRenderer;
|
||||
|
||||
class ViewPathRendererTest extends HumHubDbTestCase
|
||||
{
|
||||
|
||||
use Specify;
|
||||
|
||||
public function testSimpleViewPathRenderer()
|
||||
{
|
||||
$viewable = new TestViewable(['viewName' => 'testView']);
|
||||
$renderer = new ViewPathRenderer();
|
||||
$this->assertEquals('<div>TestTitle</div>', $renderer->render($viewable));
|
||||
}
|
||||
|
||||
public function testViewPathRendererSuffix()
|
||||
{
|
||||
$viewable = new TestViewable(['viewName' => 'testView.php']);
|
||||
$renderer = new ViewPathRenderer();
|
||||
$this->assertEquals('<div>TestTitle</div>', $renderer->render($viewable));
|
||||
}
|
||||
|
||||
public function testSetViewPath()
|
||||
{
|
||||
$viewable = new TestViewable(['viewName' => 'view2']);
|
||||
$renderer = new ViewPathRenderer(['viewPath' => '@tests/codeception/unit/components/rendering/lib/views2']);
|
||||
$this->assertEquals('<h1>TestTitle</h1>', $renderer->render($viewable));
|
||||
}
|
||||
|
||||
public function testParentSettingViewPath()
|
||||
{
|
||||
$viewable = new TestViewable(['viewName' => 'parent']);
|
||||
$renderer = new ViewPathRenderer(['parent' => true]);
|
||||
$this->assertEquals('<h1>ParentView:TestTitle</h1>', $renderer->render($viewable));
|
||||
}
|
||||
|
||||
public function testSubPathSettingViewPath()
|
||||
{
|
||||
$viewable = new TestViewable(['viewName' => 'mail']);
|
||||
$renderer = new ViewPathRenderer(['parent' => true, 'subPath' => 'mails']);
|
||||
$this->assertEquals('<h1>MailView:TestTitle</h1>', $renderer->render($viewable));
|
||||
}
|
||||
|
||||
public function testNonExistingViewPath()
|
||||
{
|
||||
$viewable = new TestViewable(['viewName' => 'nonExisting']);
|
||||
$renderer = new ViewPathRenderer(['parent' => true, 'subPath' => 'mails']);
|
||||
|
||||
try {
|
||||
$renderer->render($viewable);
|
||||
$this->assertTrue(false);
|
||||
} catch (\yii\base\ViewNotFoundException $ex) {
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace humhub\tests\codeception\unit\components\rendering\lib;
|
||||
|
||||
/**
|
||||
* Description of TestViwable
|
||||
*
|
||||
* @author buddha
|
||||
*/
|
||||
class TestViewable extends \yii\base\Object implements \humhub\components\rendering\Viewable
|
||||
{
|
||||
public $viewName;
|
||||
|
||||
public function getViewName()
|
||||
{
|
||||
return $this->viewName;
|
||||
}
|
||||
|
||||
public function getViewParams($params = [])
|
||||
{
|
||||
return \yii\helpers\ArrayHelper::merge(['title' => 'TestTitle'], $params);
|
||||
}
|
||||
|
||||
public function html()
|
||||
{
|
||||
return '<h1>TestView</h1>';
|
||||
}
|
||||
|
||||
public function json()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function text()
|
||||
{
|
||||
return 'TestViewText';
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
|
||||
echo 'SpecialView';
|
||||
|
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
|
||||
echo '<div>'.$title.'</div>';
|
||||
|
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
|
||||
echo '<h1>'.$title.'</h1>';
|
||||
|
@ -0,0 +1,3 @@
|
||||
<?php
|
||||
echo '<div>TestLayout:'.$content.'</div>';
|
||||
|
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
|
||||
echo '<h1>MailView:'.$title.'</h1>';
|
||||
|
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
|
||||
echo 'TextView:'.$title;
|
||||
|
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
|
||||
echo '<h1>ParentView:'.$title.'</h1>';
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user