InvitationModel::delete PHP Method

delete() public method

public delete ( string | unknown_type $InvitationID ) : boolean
$InvitationID string | unknown_type
return boolean
    public function delete($InvitationID)
    {
        $Session = Gdn::session();
        $UserID = $Session->UserID;
        // Validate that this user can delete this invitation:
        $Invitation = $this->getID($InvitationID, DATASET_TYPE_ARRAY);
        // Does the invitation exist?
        if (!$Invitation) {
            throw notFoundException('Invitation');
        }
        // Does this user own the invitation?
        if ($UserID != $Invitation['InsertUserID'] && !$Session->checkPermission('Garden.Moderation.Manage')) {
            throw permissionException('@' . t('InviteErrorPermission', t('ErrorPermission')));
        }
        // Delete it.
        $this->SQL->delete($this->Name, array('InvitationID' => $InvitationID));
        // Add the invitation back onto the user's account if the invitation has not been accepted.
        if (!$Invitation->AcceptedUserID) {
            Gdn::userModel()->IncreaseInviteCount($UserID);
        }
        return true;
    }

Usage Example

 /**
  * Revoke an invitation.
  *
  * @since 2.0.0
  * @param int $InvitationID Unique identifier.
  * @throws Exception Throws an exception when the invitation isn't found or the user doesn't have permission to delete it.
  */
 public function uninvite($InvitationID)
 {
     $this->permission('Garden.SignIn.Allow');
     if (!$this->Form->authenticatedPostBack()) {
         throw forbiddenException('GET');
     }
     $InvitationModel = new InvitationModel();
     $Session = Gdn::session();
     try {
         $Valid = $InvitationModel->delete($InvitationID, $this->UserModel);
         if ($Valid) {
             $this->informMessage(t('The invitation was removed successfully.'));
             $this->jsonTarget(".js-invitation[data-id=\"{$InvitationID}\"]", '', 'SlideUp');
         }
     } catch (Exception $ex) {
         $this->Form->addError(strip_tags($ex->getMessage()));
     }
     if ($this->Form->errorCount() == 0) {
         $this->render('Blank', 'Utility');
     }
 }