forked from humhub-contrib/linklist
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enh humhub-contrib#51: add "Posted links" section
- Loading branch information
1 parent
f266d8c
commit 24cbcf6
Showing
12 changed files
with
603 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
<?php | ||
/** | ||
* @link https://www.humhub.org/ | ||
* @copyright Copyright (c) 2021 HumHub GmbH & Co. KG | ||
* @license https://www.humhub.com/licences | ||
*/ | ||
|
||
namespace humhub\modules\linklist; | ||
|
||
use humhub\modules\comment\models\Comment; | ||
use humhub\modules\linklist\models\StreamLink; | ||
use humhub\modules\post\models\Post; | ||
use Yii; | ||
use yii\db\AfterSaveEvent; | ||
|
||
class Events | ||
{ | ||
/** | ||
* Defines what to do if a spaces sidebar is initialzed. | ||
* | ||
* @param $event | ||
*/ | ||
public static function onSpaceSidebarInit($event) | ||
{ | ||
|
||
$space = $event->sender->space; | ||
if ($space->isModuleEnabled('linklist')) { | ||
$event->sender->addWidget(widgets\Sidebar::className(), array('contentContainer' => $space), array( | ||
'sortOrder' => 200, | ||
)); | ||
} | ||
} | ||
|
||
/** | ||
* On build of a Space Navigation, check if this module is enabled. | ||
* When enabled add a menu item | ||
* | ||
* @param $event | ||
*/ | ||
public static function onSpaceMenuInit($event) | ||
{ | ||
|
||
$space = $event->sender->space; | ||
if ($space->isModuleEnabled('linklist') && $space->isMember()) { | ||
$event->sender->addItem(array( | ||
'label' => Yii::t('LinklistModule.base', 'Linklist'), | ||
'group' => 'modules', | ||
'url' => $space->createUrl('/linklist/linklist'), | ||
'icon' => '<i class="fa fa-link"></i>', | ||
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'linklist') | ||
)); | ||
} | ||
} | ||
|
||
/** | ||
* On build of a Profile Navigation, check if this module is enabled. | ||
* When enabled add a menu item | ||
* | ||
* @param $event | ||
*/ | ||
public static function onProfileMenuInit($event) | ||
{ | ||
$user = $event->sender->user; | ||
|
||
// Is Module enabled on this workspace? | ||
if ($user->isModuleEnabled('linklist') && !Yii::$app->user->isGuest && $user->id == Yii::$app->user->id) { | ||
$event->sender->addItem(array( | ||
'label' => Yii::t('LinklistModule.base', 'Linklist'), | ||
'url' => $user->createUrl('/linklist/linklist'), | ||
'icon' => '<i class="fa fa-link"></i>', | ||
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'linklist'), | ||
)); | ||
} | ||
} | ||
|
||
/** | ||
* Defines what to do if a spaces sidebar is initialzed. | ||
* | ||
* @param $event | ||
*/ | ||
public static function onProfileSidebarInit($event) | ||
{ | ||
$user = $event->sender->user; | ||
|
||
if ($user->isModuleEnabled('linklist')) { | ||
$event->sender->addWidget(widgets\Sidebar::className(), array('contentContainer' => $user), array( | ||
'sortOrder' => 200, | ||
)); | ||
} | ||
} | ||
|
||
/** | ||
* @param AfterSaveEvent $event | ||
*/ | ||
public static function onPostAfterInsert($event) | ||
{ | ||
if (!isset($event->sender)) { | ||
return; | ||
} | ||
|
||
/** @var Post $post */ | ||
$post = $event->sender; | ||
|
||
if (!empty($post->content->id) && !empty($post->message)) { | ||
StreamLink::updateLinks($post->message, $post->content->id, Post::class, $post->id); | ||
} | ||
} | ||
|
||
/** | ||
* @param AfterSaveEvent $event | ||
*/ | ||
public static function onCommentAfterInsert($event) | ||
{ | ||
if (!isset($event->sender)) { | ||
return; | ||
} | ||
|
||
/** @var Comment $comment */ | ||
$comment = $event->sender; | ||
|
||
if ($comment->object_model === Post::class && !empty($comment->content->id) && !empty($comment->message)) { | ||
StreamLink::updateLinks($comment->message, $comment->content->id, Comment::class, $comment->id); | ||
} | ||
} | ||
|
||
/** | ||
* @param AfterSaveEvent $event | ||
*/ | ||
public static function onPostAfterUpdate($event) | ||
{ | ||
if (!isset($event->sender, $event->changedAttributes)) { | ||
return; | ||
} | ||
|
||
/** @var Post $post */ | ||
$post = $event->sender; | ||
|
||
if (!empty($post->content->id) && !empty($post->message)) { | ||
StreamLink::updateLinks($post->message, $post->content->id, Post::class, $post->id); | ||
} | ||
} | ||
|
||
/** | ||
* @param AfterSaveEvent $event | ||
*/ | ||
public static function onCommentAfterUpdate($event) | ||
{ | ||
if (!isset($event->sender, $event->changedAttributes)) { | ||
return; | ||
} | ||
|
||
/** @var Comment $comment */ | ||
$comment = $event->sender; | ||
|
||
if ($comment->object_model === Post::class && !empty($comment->content->id) && !empty($comment->message)) { | ||
StreamLink::updateLinks($comment->message, $comment->content->id, Comment::class, $comment->id); | ||
} | ||
} | ||
|
||
/** | ||
* @param AfterSaveEvent $event | ||
*/ | ||
public static function onPostAfterDelete($event) | ||
{ | ||
if (!isset($event->sender)) { | ||
return; | ||
} | ||
|
||
/** @var Post $post */ | ||
$post = $event->sender; | ||
|
||
if ($post) { | ||
StreamLink::deleteAll(['object_model' => Post::class, 'object_id' => $post->id]); | ||
} | ||
} | ||
|
||
/** | ||
* @param AfterSaveEvent $event | ||
*/ | ||
public static function onCommentAfterDelete($event) | ||
{ | ||
if (!isset($event->sender)) { | ||
return; | ||
} | ||
|
||
/** @var Comment $comment */ | ||
$comment = $event->sender; | ||
|
||
if ($comment) { | ||
StreamLink::deleteAll(['object_model' => Comment::class, 'object_id' => $comment->id]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,28 @@ | ||
<?php | ||
|
||
use humhub\modules\comment\models\Comment; | ||
use humhub\modules\linklist\Events; | ||
use humhub\modules\post\models\Post; | ||
use humhub\modules\space\widgets\Menu; | ||
use humhub\modules\space\widgets\Sidebar; | ||
use humhub\modules\user\widgets\ProfileMenu; | ||
use humhub\modules\user\widgets\ProfileSidebar; | ||
use humhub\modules\space\widgets\Sidebar; | ||
|
||
return [ | ||
'id' => 'linklist', | ||
'class' => 'humhub\modules\linklist\Module', | ||
'namespace' => 'humhub\modules\linklist', | ||
'events' => [ | ||
array('class' => Menu::className(), 'event' => Menu::EVENT_INIT, 'callback' => array('humhub\modules\linklist\Module', 'onSpaceMenuInit')), | ||
array('class' => ProfileMenu::className(), 'event' => ProfileMenu::EVENT_INIT, 'callback' => array('humhub\modules\linklist\Module', 'onProfileMenuInit')), | ||
array('class' => Sidebar::className(), 'event' => Sidebar::EVENT_INIT, 'callback' => array('humhub\modules\linklist\Module', 'onSpaceSidebarInit')), | ||
array('class' => ProfileSidebar::className(), 'event' => ProfileSidebar::EVENT_INIT, 'callback' => array('humhub\modules\linklist\Module', 'onProfileSidebarInit')), | ||
['class' => Menu::className(), 'event' => Menu::EVENT_INIT, 'callback' => [Events::class, 'onSpaceMenuInit']], | ||
['class' => ProfileMenu::className(), 'event' => ProfileMenu::EVENT_INIT, 'callback' => [Events::class, 'onProfileMenuInit']], | ||
['class' => Sidebar::className(), 'event' => Sidebar::EVENT_INIT, 'callback' => [Events::class, 'onSpaceSidebarInit']], | ||
['class' => ProfileSidebar::className(), 'event' => ProfileSidebar::EVENT_INIT, 'callback' => [Events::class, 'onProfileSidebarInit']], | ||
['class' => Post::class, 'event' => Post::EVENT_AFTER_INSERT, 'callback' => [Events::class, 'onPostAfterInsert']], | ||
['class' => Comment::class, 'event' => Comment::EVENT_AFTER_INSERT, 'callback' => [Events::class, 'onCommentAfterInsert']], | ||
['class' => Post::class, 'event' => Post::EVENT_AFTER_UPDATE, 'callback' => [Events::class, 'onPostAfterUpdate']], | ||
['class' => Comment::class, 'event' => Comment::EVENT_AFTER_UPDATE, 'callback' => [Events::class, 'onCommentAfterUpdate']], | ||
['class' => Post::class, 'event' => Post::EVENT_AFTER_DELETE, 'callback' => [Events::class, 'onPostAfterDelete']], | ||
['class' => Comment::class, 'event' => Comment::EVENT_AFTER_DELETE, 'callback' => [Events::class, 'onCommentAfterDelete']], | ||
], | ||
]; | ||
?> |
Oops, something went wrong.