custom-pages
custom-pages copied to clipboard
Simple custom notifications?
Is it possible to initiate a notification (web & email) to a user without resorting to creating a full fledged model for that?
I'd like to send a basic notification consisting of for example:
array(
"recipientUserId" => 123,
"message" => "Report for X finished generating!",
"link" => "https://link.to.report/for?user=x"
);
It's unclear to me if that's possible without a custom module?
Currently you need a separate class for each Notification type. This must be provided by a custom module. It would be conceivable, for example, to create the possibility of triggering generic notifications via the REST module.
Currently you need a separate class for each Notification type. This must be provided by a custom module. It would be conceivable, for example, to create the possibility of triggering generic notifications via the REST module.
So as it stands, there is no real way of triggering custom notifications without requiring a model?
I'm trying to externally piggyback of an existing model like admin notifications or something, but I'm not following the logic here at all. The farthest I got was to initiate a notification without an error but then the cronjob fails with
Could not execute queued job! Message: Class __PHP_Incomplete_Class has no unserializer
I understand this is not how Yii or Humhub works, but I just need a simple notification sent from my custom page ... Here's my "attempt" that spits out the above error.
namespace humhub\modules\admin\notifications;
require dirname(__FILE__).'/../protected/vendor/autoload.php';
require dirname(__FILE__).'/../protected/vendor/yiisoft/yii2/Yii.php';
$config = \yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../protected/humhub/config/common.php'),
require(__DIR__ . '/../protected/humhub/config/web.php'),
(is_readable(__DIR__ . '/../protected/config/dynamic.php')) ? require(__DIR__ . '/../protected/config/dynamic.php') : [],
);
new \humhub\components\Application($config);
use yii\helpers\Url;
use humhub\modules\user\models\User;
use humhub\modules\notification\components\BaseNotification;
class TestNotification extends BaseNotification {
public $moduleId = 'admin';
public $requireOriginator = false;
public $requireSource = false;
public function getUrl() {
return Url::to(['/some/test/url']);
}
public function html() {
return Yii::t('AdminModule.notification', 'Testing 123');
}
}
$getUser = User::findIdentity(123456789);
TestNotification::instance()->send($getUser);
I don't think, this will be possible without a custom module.
For a prototype, I would recommend that you simply create a Sekeleton module, activate the module and test the notification there. https://docs.humhub.org/docs/develop/modules#setup-a-module-skeleton