Skip to content

Commit

Permalink
Merge pull request #68 from humhub/enh/67-activity-wording
Browse files Browse the repository at this point in the history
Update text for activity and notification of shared contents
  • Loading branch information
luke- authored Dec 12, 2024
2 parents 85e29dd + d83e22d commit 8f21f1a
Show file tree
Hide file tree
Showing 18 changed files with 140 additions and 8 deletions.
23 changes: 23 additions & 0 deletions Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

namespace humhub\modules\sharebetween;

use humhub\modules\activity\models\Activity;
use humhub\modules\content\components\ContentActiveRecord;
use humhub\modules\content\events\ContentEvent;
use humhub\modules\notification\models\Notification;
use humhub\modules\sharebetween\models\Share;
use yii\base\BaseObject;

Expand Down Expand Up @@ -53,4 +55,25 @@ public static function onWallEntryLinksInit($event)
$stackWidget->addWidget(widgets\ShareLink::class, ['record' => $record]);
}

public static function onActivityAfterFind($event)
{
/* @var Activity $activity */
$activity = $event->sender;

if ($activity->object_model === Share::class) {
// Switch to render specific text for the shared content activity
$activity->class = activities\SharedContentCreated::class;
}
}

public static function onNotificationAfterFind($event)
{
/* @var Notification $activity */
$notification = $event->sender;

if ($notification->source_class === Share::class) {
// Switch to render specific text for the shared content notification
$notification->class = notifications\SharedContentCreated::class;
}
}
}
19 changes: 19 additions & 0 deletions activities/SharedContentCreated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/**
* @link https://www.humhub.org/
* @copyright Copyright (c) HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/

namespace humhub\modules\sharebetween\activities;

use humhub\modules\content\activities\ContentCreated;

class SharedContentCreated extends ContentCreated
{
/**
* @inheritdoc
*/
public $viewName = 'shared';
}
19 changes: 19 additions & 0 deletions activities/views/shared.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/**
* @link https://www.humhub.org/
* @copyright Copyright (c) HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/

use humhub\modules\sharebetween\models\Share;
use humhub\modules\user\models\User;
use yii\helpers\Html;

/* @var User $originator */
/* @var Share $source */

echo Yii::t('SharebetweenModule.base', '{user} shared something interesting from Space {space}.', [
'{user}' => '<strong>' . Html::encode($originator->displayName) . '</strong>',
'{space}' => '<strong>' . Html::encode($source->sharedContent->container->displayName) . '</strong>',
]);
1 change: 1 addition & 0 deletions assets/Assets.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2023 HumHub GmbH & Co. KG
Expand Down
11 changes: 8 additions & 3 deletions config.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
<?php

use humhub\modules\activity\models\Activity;
use humhub\modules\content\components\ContentActiveRecord;
use humhub\modules\content\models\Content;
use humhub\modules\content\widgets\WallEntryLinks;
use humhub\modules\notification\models\Notification;
use humhub\modules\sharebetween\Events;

return [
'id' => 'sharebetween',
'class' => 'humhub\modules\sharebetween\Module',
'namespace' => 'humhub\modules\sharebetween',
'events' => [
[Content::class, Content::EVENT_AFTER_SOFT_DELETE, ['humhub\modules\sharebetween\Events', 'onContentAfterSoftDelete']],
[ContentActiveRecord::class, ContentActiveRecord::EVENT_BEFORE_DELETE, ['humhub\modules\sharebetween\Events', 'onContentDelete']],
[WallEntryLinks::class, WallEntryLinks::EVENT_INIT, ['humhub\modules\sharebetween\Events', 'onWallEntryLinksInit']],
[Content::class, Content::EVENT_AFTER_SOFT_DELETE, [Events::class, 'onContentAfterSoftDelete']],
[ContentActiveRecord::class, ContentActiveRecord::EVENT_BEFORE_DELETE, [Events::class, 'onContentDelete']],
[WallEntryLinks::class, WallEntryLinks::EVENT_INIT, [Events::class, 'onWallEntryLinksInit']],
[Activity::class, Activity::EVENT_AFTER_FIND, [Events::class, 'onActivityAfterFind']],
[Notification::class, Notification::EVENT_AFTER_FIND, [Events::class, 'onNotificationAfterFind']],
],
];
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
=========

1.0.8 (Unreleased)
-------------------------
- Enh #67: Update text for activity and notification of shared contents

1.0.7 (November 14, 2024)
-------------------------
- Enh #65: Use PHP CS Fixer
Expand Down
26 changes: 22 additions & 4 deletions models/Share.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
use humhub\modules\sharebetween\services\ShareService;
use humhub\modules\sharebetween\widgets\WallEntry;
use Yii;
use yii\db\ActiveQuery;
use yii\web\IdentityInterface;

/**
* Class for shared content record between spaces or users
*
* @property $content_id int
* @property int $content_id
* @property-read Content $sharedContent
*/
class Share extends ContentActiveRecord
{
Expand All @@ -20,19 +23,25 @@ class Share extends ContentActiveRecord
*/
public $wallEntryClass = WallEntry::class;

/**
* @inheritdoc
*/
public static function tableName()
{
return 'sharebetween_share';
}

/**
* @inheritdoc
*/
public function rules()
{
return [
[['content_id'], 'required'],
];
}

public function getSharedContent()
public function getSharedContent(): ActiveQuery
{
return $this->hasOne(Content::class, ['id' => 'content_id']);
}
Expand All @@ -42,8 +51,7 @@ public function getContentRecord(): ContentActiveRecord
return $this->sharedContent->getModel();
}


public function getShareService(?IdentityInterface $user)
public function getShareService(?IdentityInterface $user): ShareService
{
if ($user === null) {
/** @var IdentityInterface $user */
Expand All @@ -53,6 +61,9 @@ public function getShareService(?IdentityInterface $user)
return new ShareService($this->getContentRecord(), $user);
}

/**
* @inheritdoc
*/
public function getIcon()
{
return 'fa-share-alt';
Expand All @@ -66,4 +77,11 @@ public function getContentName()
return Yii::t('SharebetweenModule.base', 'Shared content');
}

/**
* @inheritdoc
*/
public function getContentDescription()
{
return $this->sharedContent->getContentDescription();
}
}
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Share content",
"description": "Share content between Spaces in the simplest way possible.",
"keywords": ["share", "between", "content"],
"version": "1.0.7",
"version": "1.0.8",
"humhub": {
"minVersion": "1.14"
},
Expand Down
34 changes: 34 additions & 0 deletions notifications/SharedContentCreated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/**
* @link https://www.humhub.org/
* @copyright Copyright (c) HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/

namespace humhub\modules\sharebetween\notifications;

use humhub\modules\content\notifications\ContentCreated;
use humhub\modules\sharebetween\models\Share;
use Yii;
use yii\bootstrap\Html;

class SharedContentCreated extends ContentCreated
{
/**
* @inheritdoc
* @var Share
*/
public $source;

/**
* @inheritdoc
*/
public function html()
{
return Yii::t('SharebetweenModule.base', '{user} shared something interesting from Space {space}.', [
'user' => Html::tag('strong', Html::encode($this->originator->displayName)),
'space' => Html::tag('strong', Html::encode($this->source->sharedContent->container->displayName)),
]);
}
}
1 change: 1 addition & 0 deletions tests/codeception/_bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2015 HumHub GmbH & Co. KG
Expand Down
1 change: 1 addition & 0 deletions tests/codeception/acceptance/_bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Initialize the HumHub Application for functional testing. The default application configuration for this suite can be overwritten
* in @tests/config/functional.php
Expand Down
1 change: 1 addition & 0 deletions tests/codeception/fixtures/ShareFixture.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2023 HumHub GmbH & Co. KG
Expand Down
1 change: 1 addition & 0 deletions tests/codeception/fixtures/data/share.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2023 HumHub GmbH & Co. KG
Expand Down
1 change: 1 addition & 0 deletions tests/codeception/functional/_bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Initialize the HumHub Application for functional testing. The default application configuration for this suite can be overwritten
* in @tests/config/functional.php
Expand Down
1 change: 1 addition & 0 deletions tests/codeception/unit/_bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Initialize the HumHub Application for functional testing. The default application configuration for this suite can be overwritten
* in @tests/config/functional.php
Expand Down
1 change: 1 addition & 0 deletions tests/config/common.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This config is shared by all suites (unit/functional/acceptance) and can be overwritten by a suite config (e.g. functional.php)
*/
Expand Down
1 change: 1 addition & 0 deletions tests/config/functional.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Here you can overwrite the default config for the functional suite. The default config resides in @humhubTests/codeception/config/config.php
*/
Expand Down
1 change: 1 addition & 0 deletions tests/config/unit.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Here you can overwrite your functional humhub config. The default config resiedes in @humhubTests/codeception/config/config.php
*/
Expand Down

0 comments on commit 8f21f1a

Please sign in to comment.