2016-02-23, 08:22 AM
Hi folks! I am currently working on a large project to integrate myAlerts with one of my plugins that I may release here very soon.
I am experimenting with custom alert types, but the problem is, the from_user_id isn't the variable thats being defined. It always ends up as the UID. I am not sure what I am doing wrong. Perhaps you guys can take a look at it? Thanks!
What im trying to achieve is testing the alerts, so when I refresh the page, it will send an alert.
I am experimenting with custom alert types, but the problem is, the from_user_id isn't the variable thats being defined. It always ends up as the UID. I am not sure what I am doing wrong. Perhaps you guys can take a look at it? Thanks!
What im trying to achieve is testing the alerts, so when I refresh the page, it will send an alert.
function global_alert_formatter(){
if (class_exists('MybbStuff_MyAlerts_AlertFormatterManager')) {
$formatterManager = MybbStuff_MyAlerts_AlertFormatterManager::getInstance();
if (!$formatterManager) {
$formatterManager = MybbStuff_MyAlerts_AlertFormatterManager::createInstance($mybb, $lang);
}
$formatterManager->registerFormatter(
new FollowThreadAlertFormatter($mybb, $lang, 'follower_alert_newthread')
);
}
}
if ($_GET['sendtestalert'] == true) {
$fromuid = intval($_GET['userid']); // NEEDS TO BE from_user_id in the DATABASE
$alertType = MybbStuff_MyAlerts_AlertTypeManager::getInstance()->getByCode('follower_alert_newthread');
if(isset($alertType) && $alertType->getEnabled()){
$alert = new MybbStuff_MyAlerts_Entity_Alert($mybb->user['uid'], $alertType, $fromuid);
MybbStuff_MyAlerts_AlertManager::getInstance()->addAlert($alert);
}
die ("alert added");
}
class FollowThreadAlertFormatter extends MybbStuff_MyAlerts_Formatter_AbstractFormatter {
public function formatAlert(MybbStuff_MyAlerts_Entity_Alert $alert, array $outputAlert)
{
return $this->lang->sprintf(
$this->lang->follower_alert_thread,
$outputAlert['from_user']
);
}
public function init()
{
if (!$this->lang->follower) {
$this->lang->load('follower');
}
}
public function buildShowLink(MybbStuff_MyAlerts_Entity_Alert $alert)
{
return get_profile_link($alert->getFromUserId());
}
}