ActivityModel::deleteID PHP Method

deleteID() public method

Delete a particular activity item.
public deleteID ( integer $ActivityID, array $Options = [] ) : boolean
$ActivityID integer The unique ID of activity to be deleted.
$Options array Not used.
return boolean Returns **true** if the activity was deleted or **false** otherwise.
    public function deleteID($ActivityID, $Options = [])
    {
        // Get the activity first.
        $Activity = $this->getID($ActivityID);
        if ($Activity) {
            // Log the deletion.
            $Log = val('Log', $Options);
            if ($Log) {
                LogModel::insert($Log, 'Activity', $Activity);
            }
            // Delete comments on the activity item
            $this->SQL->delete('ActivityComment', ['ActivityID' => $ActivityID]);
            // Delete the activity item
            return parent::deleteID($ActivityID);
        } else {
            return false;
        }
    }

Usage Example

 /**
  * Delete an activity item.
  *
  * @since 2.0.0
  * @access public
  *
  * @param int $ActivityID Unique ID of item to delete.
  * @param string $TransientKey Verify intent.
  */
 public function delete($ActivityID = '', $TransientKey = '')
 {
     $session = Gdn::session();
     if (!$session->validateTransientKey($TransientKey)) {
         throw permissionException();
     }
     if (!is_numeric($ActivityID)) {
         throw Gdn_UserException('Invalid ID');
     }
     if (!$this->ActivityModel->canDelete($this->ActivityModel->getID($ActivityID))) {
         throw permissionException();
     }
     $this->ActivityModel->deleteID($ActivityID);
     if ($this->_DeliveryType === DELIVERY_TYPE_ALL) {
         $target = Gdn::request()->get('Target');
         if ($target) {
             // Bail with a redirect if we got one.
             redirect($target);
         } else {
             // We got this as a full page somehow, so send them back to /activity.
             $this->RedirectUrl = url('activity');
         }
     }
     $this->render();
 }