示例#1
0
 /**
  * Add a new alert.
  *
  * @param MybbStuff_MyAlerts_Entity_Alert $alert The alert to add.
  *
  * @return $this
  */
 public function addAlert(MybbStuff_MyAlerts_Entity_Alert $alert)
 {
     $fromUser = $alert->getFromUser();
     if (!isset($fromUser['uid'])) {
         $alert->setFromUser($this->mybb->user);
     }
     $alertType = $alert->getType();
     $usersWhoWantAlert = $this->doUsersWantAlert($alert->getType(), array($alert->getUserId()));
     if ($alertType->getEnabled() && (!empty($usersWhoWantAlert) || !$alertType->getCanBeUserDisabled())) {
         if ($alertType->getCode() === 'quoted') {
             // If there is already an alert queued to the user of the type
             // 'post_threadauthor', don't add the alert.
             $extraDetails = $alert->getExtraDetails();
             $tid = $extraDetails['tid'];
             if (isset(static::$alertQueue['post_threadauthor_' . $alert->getUserId() . '_' . $tid])) {
                 return $this;
             }
         }
         $passToHook = array('alertManager' => &$this, 'alert' => &$alert);
         $this->plugins->run_hooks('myalerts_alert_manager_add_alert', $passToHook);
         // Basic duplicate checking by overwrite - only one alert for each alert type/object id combination
         static::$alertQueue[$alert->getType()->getCode() . '_' . $alert->getUserId() . '_' . $alert->getObjectId()] = $alert;
     }
     return $this;
 }