MyBB Community Forums

Full Version: [MyAlerts Integration] Incorrect from_user_id
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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. 

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());

		}
	}
Did you read MyAlerts wiki on how to create custom alerts yet ?

There is a guidance on how to do, i refer by this to make a bridge on all plugins i wanna do, right now it is a very easy way to do, so if you have your plugin and need some help we can help you to add this feature in your plugin.

See yah !!!
Hi,

You need to call [pre]setFromuserId()[/pre]. SOmething like the following should work:

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 ($mybb->get_input('sendtestalert', MyBB::INPUT_BOOL) == true) {
	$fromuid = $mybb->get_input('userid', MyBB::INPUT_INT);

	$alertType = MybbStuff_MyAlerts_AlertTypeManager::getInstance()->getByCode('follower_alert_newthread');

	if (!is_null($alertType) && $alertType->getEnabled()) {
		$alert = new MybbStuff_MyAlerts_Entity_Alert($mybb->user['uid'], $alertType, $fromuid);
		$alert->setFromUserId($fromuid);

		$manager = MybbStuff_MyAlerts_AlertManager::getInstance();

		if (!is_null($manager) && $manager !== false) {
			$manager->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());
	}
}