chore: bootstrap module from working instance and add install guide

This commit is contained in:
Kelin Rescue Hub
2026-04-09 14:18:10 -04:00
parent 97ad7da6f4
commit 6cda47760e
35 changed files with 6267 additions and 4 deletions

View File

@@ -0,0 +1,21 @@
<?php
namespace humhub\modules\donations\notifications;
use humhub\modules\notification\components\NotificationCategory;
use Yii;
class DonationNotificationCategory extends NotificationCategory
{
public $id = 'donations_activity';
public function getTitle()
{
return Yii::t('DonationsModule.base', 'Donations');
}
public function getDescription()
{
return Yii::t('DonationsModule.base', 'Receive notifications about successful or refunded donations.');
}
}

View File

@@ -0,0 +1,114 @@
<?php
namespace humhub\modules\donations\notifications;
use humhub\libs\Html;
use humhub\modules\notification\components\BaseNotification;
use humhub\modules\space\models\Space;
use Yii;
use yii\helpers\Json;
use yii\helpers\Url;
class DonationRefundedNotification extends BaseNotification
{
public $moduleId = 'donations';
public $requireSource = false;
public $requireOriginator = false;
public string $spaceGuid = '';
public string $goalTitle = '';
public string $amountLabel = '';
public function category()
{
return new DonationNotificationCategory();
}
public function getUrl()
{
$spaceGuid = $this->payloadString('spaceGuid', $this->spaceGuid);
$space = Space::findOne(['guid' => $spaceGuid]);
if ($space instanceof Space) {
return $space->createUrl('/donations/settings/history');
}
return Url::to(['/donations/settings/history', 'sguid' => $spaceGuid]);
}
public function html()
{
$goalTitle = $this->payloadString('goalTitle', $this->goalTitle);
$amountLabel = $this->payloadString('amountLabel', $this->amountLabel);
if ($this->originator) {
return Yii::t('DonationsModule.base', '{displayName} processed a refund of {amount} for {goal}.', [
'displayName' => Html::tag('strong', Html::encode($this->originator->displayName)),
'amount' => Html::tag('strong', Html::encode($amountLabel)),
'goal' => Html::tag('strong', Html::encode($goalTitle)),
]);
}
return Yii::t('DonationsModule.base', 'A refund of {amount} was processed for {goal}.', [
'amount' => Html::tag('strong', Html::encode($amountLabel)),
'goal' => Html::tag('strong', Html::encode($goalTitle)),
]);
}
public function getMailSubject()
{
$goalTitle = $this->payloadString('goalTitle', $this->goalTitle);
$amountLabel = $this->payloadString('amountLabel', $this->amountLabel);
return Yii::t('DonationsModule.base', 'Donation refunded: {amount} for {goal}', [
'amount' => $amountLabel,
'goal' => $goalTitle,
]);
}
public function __serialize(): array
{
$data = parent::__serialize();
$data['spaceGuid'] = $this->spaceGuid;
$data['goalTitle'] = $this->goalTitle;
$data['amountLabel'] = $this->amountLabel;
$data['payload'] = $this->payload;
return $data;
}
public function __unserialize($unserializedArr)
{
parent::__unserialize($unserializedArr);
$this->spaceGuid = (string)($unserializedArr['spaceGuid'] ?? '');
$this->goalTitle = (string)($unserializedArr['goalTitle'] ?? '');
$this->amountLabel = (string)($unserializedArr['amountLabel'] ?? '');
if (isset($unserializedArr['payload']) && is_array($unserializedArr['payload'])) {
$this->payload = $unserializedArr['payload'];
}
}
private function payloadString(string $key, string $fallback = ''): string
{
if (is_array($this->payload) && array_key_exists($key, $this->payload)) {
return trim((string)$this->payload[$key]);
}
if ($this->record !== null && !empty($this->record->payload)) {
try {
$decoded = Json::decode((string)$this->record->payload);
if (is_array($decoded)) {
$this->payload = $decoded;
if (array_key_exists($key, $decoded)) {
return trim((string)$decoded[$key]);
}
}
} catch (\Throwable $e) {
}
}
return trim($fallback);
}
}

View File

@@ -0,0 +1,114 @@
<?php
namespace humhub\modules\donations\notifications;
use humhub\libs\Html;
use humhub\modules\notification\components\BaseNotification;
use humhub\modules\space\models\Space;
use Yii;
use yii\helpers\Json;
use yii\helpers\Url;
class DonationSucceededNotification extends BaseNotification
{
public $moduleId = 'donations';
public $requireSource = false;
public $requireOriginator = false;
public string $spaceGuid = '';
public string $goalTitle = '';
public string $amountLabel = '';
public function category()
{
return new DonationNotificationCategory();
}
public function getUrl()
{
$spaceGuid = $this->payloadString('spaceGuid', $this->spaceGuid);
$space = Space::findOne(['guid' => $spaceGuid]);
if ($space instanceof Space) {
return $space->createUrl('/donations/donations/index');
}
return Url::to(['/donations/donations/index', 'sguid' => $spaceGuid]);
}
public function html()
{
$goalTitle = $this->payloadString('goalTitle', $this->goalTitle);
$amountLabel = $this->payloadString('amountLabel', $this->amountLabel);
if ($this->originator) {
return Yii::t('DonationsModule.base', '{displayName} completed a donation of {amount} for {goal}.', [
'displayName' => Html::tag('strong', Html::encode($this->originator->displayName)),
'amount' => Html::tag('strong', Html::encode($amountLabel)),
'goal' => Html::tag('strong', Html::encode($goalTitle)),
]);
}
return Yii::t('DonationsModule.base', 'A donation of {amount} was completed for {goal}.', [
'amount' => Html::tag('strong', Html::encode($amountLabel)),
'goal' => Html::tag('strong', Html::encode($goalTitle)),
]);
}
public function getMailSubject()
{
$goalTitle = $this->payloadString('goalTitle', $this->goalTitle);
$amountLabel = $this->payloadString('amountLabel', $this->amountLabel);
return Yii::t('DonationsModule.base', 'Donation confirmed: {amount} for {goal}', [
'amount' => $amountLabel,
'goal' => $goalTitle,
]);
}
public function __serialize(): array
{
$data = parent::__serialize();
$data['spaceGuid'] = $this->spaceGuid;
$data['goalTitle'] = $this->goalTitle;
$data['amountLabel'] = $this->amountLabel;
$data['payload'] = $this->payload;
return $data;
}
public function __unserialize($unserializedArr)
{
parent::__unserialize($unserializedArr);
$this->spaceGuid = (string)($unserializedArr['spaceGuid'] ?? '');
$this->goalTitle = (string)($unserializedArr['goalTitle'] ?? '');
$this->amountLabel = (string)($unserializedArr['amountLabel'] ?? '');
if (isset($unserializedArr['payload']) && is_array($unserializedArr['payload'])) {
$this->payload = $unserializedArr['payload'];
}
}
private function payloadString(string $key, string $fallback = ''): string
{
if (is_array($this->payload) && array_key_exists($key, $this->payload)) {
return trim((string)$this->payload[$key]);
}
if ($this->record !== null && !empty($this->record->payload)) {
try {
$decoded = Json::decode((string)$this->record->payload);
if (is_array($decoded)) {
$this->payload = $decoded;
if (array_key_exists($key, $decoded)) {
return trim((string)$decoded[$key]);
}
}
} catch (\Throwable $e) {
}
}
return trim($fallback);
}
}