ActivityModel::queue PHP Метод

queue() публичный Метод

Queue an activity for saving later.
public queue ( array $Data, string | boolean $Preference = false, array $Options = [] )
$Data array The data in the activity.
$Preference string | boolean The name of the preference governing the activity.
$Options array Additional options for saving.
    public function queue($Data, $Preference = false, $Options = [])
    {
        $this->_touch($Data);
        if (!isset($Data['NotifyUserID']) || !isset($Data['ActivityType'])) {
            throw new Exception('Data missing NotifyUserID and/or ActivityType', 400);
        }
        if ($Data['ActivityUserID'] == $Data['NotifyUserID'] && !val('Force', $Options)) {
            return;
            // don't notify users of something they did.
        }
        $Notified = $Data['Notified'];
        $Emailed = $Data['Emailed'];
        if (isset(self::$Queue[$Data['NotifyUserID']][$Data['ActivityType']])) {
            list($CurrentData, $CurrentOptions) = self::$Queue[$Data['NotifyUserID']][$Data['ActivityType']];
            $Notified = $Notified ? $Notified : $CurrentData['Notified'];
            $Emailed = $Emailed ? $Emailed : $CurrentData['Emailed'];
            $Reason = null;
            if (isset($CurrentData['Data']['Reason']) && isset($Data['Data']['Reason'])) {
                $Reason = array_merge((array) $CurrentData['Data']['Reason'], (array) $Data['Data']['Reason']);
                $Reason = array_unique($Reason);
            }
            $Data = array_merge($CurrentData, $Data);
            $Options = array_merge($CurrentOptions, $Options);
            if ($Reason) {
                $Data['Data']['Reason'] = $Reason;
            }
        }
        $this->EventArguments['Preference'] = $Preference;
        $this->EventArguments['Options'] = $Options;
        $this->EventArguments['Data'] = $Data;
        $this->fireEvent('BeforeCheckPreference');
        if (!empty($Preference)) {
            list($Popup, $Email) = self::notificationPreference($Preference, $Data['NotifyUserID'], 'both');
            if (!$Popup && !$Email) {
                return;
                // don't queue if user doesn't want to be notified at all.
            }
            if ($Popup) {
                $Notified = self::SENT_PENDING;
            }
            if ($Email) {
                $Emailed = self::SENT_PENDING;
            }
        }
        $Data['Notified'] = $Notified;
        $Data['Emailed'] = $Emailed;
        self::$Queue[$Data['NotifyUserID']][$Data['ActivityType']] = [$Data, $Options];
    }

Usage Example

Пример #1
0
 /**
  * Unban a user.
  *
  * @param int $UserID The user to unban.
  * @param array $Options Options for the unban.
  * @since 2.1
  */
 public function unBan($UserID, $Options = [])
 {
     $User = $this->getID($UserID, DATASET_TYPE_ARRAY);
     if (!$User) {
         throw notFoundException();
     }
     $Banned = $User['Banned'];
     if (!BanModel::isBanned($Banned, BanModel::BAN_AUTOMATIC | BanModel::BAN_MANUAL)) {
         throw new Gdn_UserException(t("The user isn't banned.", "The user isn't banned or is banned by some other function."));
     }
     // Unban the user.
     $NewBanned = BanModel::setBanned($Banned, false, BanModel::BAN_AUTOMATIC | BanModel::BAN_MANUAL);
     $this->setField($UserID, 'Banned', $NewBanned);
     // Restore the user's content.
     if (val('RestoreContent', $Options)) {
         $BanLogID = $this->getAttribute($UserID, 'BanLogID');
         if ($BanLogID) {
             $LogModel = new LogModel();
             try {
                 $LogModel->restore($BanLogID);
             } catch (Exception $Ex) {
                 if ($Ex->getCode() != 404) {
                     throw $Ex;
                 }
             }
             $this->saveAttribute($UserID, 'BanLogID', null);
         }
     }
     // Add an activity for the unbanning.
     if (val('AddActivity', $Options, true)) {
         $ActivityModel = new ActivityModel();
         $Story = val('Story', $Options, null);
         // Notify the moderators of the unban.
         $Activity = ['ActivityType' => 'Ban', 'NotifyUserID' => ActivityModel::NOTIFY_MODS, 'ActivityUserID' => $UserID, 'RegardingUserID' => Gdn::session()->UserID, 'HeadlineFormat' => t('HeadlineFormat.Unban', '{RegardingUserID,You} unbanned {ActivityUserID,you}.'), 'Story' => $Story, 'Data' => ['Unban' => true]];
         $ActivityModel->queue($Activity);
         // Notify the user of the unban.
         $Activity['NotifyUserID'] = $UserID;
         $Activity['Emailed'] = ActivityModel::SENT_PENDING;
         $Activity['HeadlineFormat'] = t('HeadlineFormat.Unban.Notification', "You've been unbanned.");
         $ActivityModel->queue($Activity, false, ['Force' => true]);
         $ActivityModel->saveQueue();
     }
 }
All Usage Examples Of ActivityModel::queue