ActivityModel::add PHP Method

add() public method

Getting reworked for 2.1 so I'm cheating and skipping params for now. -mlr
public add ( integer $ActivityUserID, string $ActivityType, string $Story = null, integer | null $RegardingUserID = null, integer $CommentActivityID = null, string $Route = null, string | boolean $SendEmail = '' ) : integer
$ActivityUserID integer
$ActivityType string
$Story string
$RegardingUserID integer | null
$CommentActivityID integer
$Route string
$SendEmail string | boolean
return integer ActivityID of item created.
    public function add($ActivityUserID, $ActivityType, $Story = null, $RegardingUserID = null, $CommentActivityID = null, $Route = null, $SendEmail = '')
    {
        // Get the ActivityTypeID & see if this is a notification.
        $ActivityTypeRow = self::getActivityType($ActivityType);
        $Notify = val('Notify', $ActivityTypeRow, false);
        if ($ActivityTypeRow === false) {
            trigger_error(errorMessage(sprintf('Activity type could not be found: %s', $ActivityType), 'ActivityModel', 'Add'), E_USER_ERROR);
        }
        $Activity = ['ActivityUserID' => $ActivityUserID, 'ActivityType' => $ActivityType, 'Story' => $Story, 'RegardingUserID' => $RegardingUserID, 'Route' => $Route];
        // Massage $SendEmail to allow for only sending an email.
        if ($SendEmail === 'Only') {
            $SendEmail = '';
        } elseif ($SendEmail === 'QueueOnly') {
            $SendEmail = '';
            $Notify = true;
        }
        // If $SendEmail was FALSE or TRUE, let it override the $Notify setting.
        if ($SendEmail === false || $SendEmail === true) {
            $Notify = $SendEmail;
        }
        $Preference = false;
        if (($ActivityTypeRow['Notify'] || !$ActivityTypeRow['Public']) && !empty($RegardingUserID)) {
            $Activity['NotifyUserID'] = $Activity['RegardingUserID'];
            $Preference = $ActivityType;
        } else {
            $Activity['NotifyUserID'] = self::NOTIFY_PUBLIC;
        }
        // Otherwise let the decision to email lie with the $Notify setting.
        if ($SendEmail === 'Force' || $Notify) {
            $Activity['Emailed'] = self::SENT_PENDING;
        } elseif ($Notify) {
            $Activity['Emailed'] = self::SENT_PENDING;
        } elseif ($SendEmail === false) {
            $Activity['Emailed'] = self::SENT_ARCHIVE;
        }
        $Activity = $this->save($Activity, $Preference);
        return val('ActivityID', $Activity);
    }

Usage Example

 /**
  *
  *
  * @return bool
  * @throws Gdn_UserException
  */
 public function addActivity()
 {
     // Build the story for the activity.
     $Header = $this->getImportHeader();
     $PorterVersion = val('Vanilla Export', $Header, t('unknown'));
     $SourceData = val('Source', $Header, t('unknown'));
     $Story = sprintf(t('Vanilla Export: %s, Source: %s'), $PorterVersion, $SourceData);
     $ActivityModel = new ActivityModel();
     $ActivityModel->add(Gdn::session()->UserID, 'Import', $Story);
     return true;
 }
All Usage Examples Of ActivityModel::add