Example #1
0
 /**
  * Remove label
  * @method removeLabel
  * @param {string} $label
  * @param {string|null} [$userId=null]
  * @return {boolean}
  */
 static function removeLabel($label, $userId = null)
 {
     if (!isset($userId)) {
         $user = Users::loggedInUser(true);
         $userId = $user->id;
     }
     Users_Contact::delete()->where(array('label' => $label, 'userId' => $userId))->execute();
     $l = new Users_Label();
     $l->label = $label;
     $l->userId = $userId;
     return $l->remove();
 }
Example #2
0
/**
 * Removes a label from the system.
 * @param {array} $_REQUEST
 * @param {string} [$_REQUEST.title] Find it by title
 * @param {string} [$_REQUEST.label] Find it by label
 * @param {string} [$_REQUEST.userId=Users::loggedInUser(true)->id] You can override the user id, if another plugin adds a hook that allows you to do this
 */
function Users_label_delete($params = array())
{
    $req = array_merge($_REQUEST, $params);
    $loggedInUserId = Users::loggedInUser(true)->id;
    $userId = Q::ifset($req, 'userId', $loggedInUserId);
    $l = Q::ifset($req, 'label', null);
    if (!$l) {
        if ($title = Q::ifset($req, 'title', null)) {
            $l = 'Users/' . Q_Utils::normalize($title);
        } else {
            throw new Q_Exception_RequiredField(array('field' => 'label'));
        }
    }
    Users::canManageLabels($loggedInUserId, $userId, $l, true);
    $label = new Users_Label();
    $label->userId = Users::loggedInUser(true)->id;
    $label->label = $l;
    $label->remove();
}
Example #3
0
 /**
  * Remove label
  * @method removeLabel
  * @param {string} $label
  * @param {string|null} [$userId=null]
  *  The user whose label is to be removed
  * @param {string} [$asUserId=null] The user to do this operation as.
  *   Defaults to the logged-in user. Pass false to skip access checks.
  * @return {Db_Query_MySql}
  */
 static function removeLabel($label, $userId = null, $asUserId = null)
 {
     if (!isset($userId)) {
         $user = Users::loggedInUser(true);
         $userId = $user->id;
     }
     Users::canManageLabels($asUserId, $userId, $label, true);
     $label = new Users_Label();
     $label->userId = $userId;
     $label->label = $label;
     $label->remove();
 }