예제 #1
0
파일: post.php 프로젝트: atirjavid/Platform
/**
 * Adds a label to the system. Fills the "label" (and possibly "icon") slot.
 * @param {array} $_REQUEST
 * @param {string} $_REQUEST.title The title of the label
 * @param {string} [$_REQUEST.label] You can override the label to use
 * @param {string} [$_REQUEST.icon] Optional path to an icon
 * @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_post($params = array())
{
    $req = array_merge($_REQUEST, $params);
    Q_Request::requireFields(array('title'), $req, true);
    $loggedInUserId = Users::loggedInUser(true)->id;
    $userId = Q::ifset($req, 'userId', $loggedInUserId);
    $icon = Q::ifset($req, 'icon', null);
    $title = $req['title'];
    $l = Q::ifset($req, 'label', 'Users/' . Q_Utils::normalize($title));
    Users::canManageLabels($loggedInUserId, $userId, $l, true);
    $label = new Users_Label();
    $label->userId = $userId;
    $label->label = $l;
    if ($label->retrieve()) {
        throw new Users_Exception_LabelExists();
    }
    $label->title = $title;
    if (is_array($icon)) {
        // Process any icon that was posted
        $icon['path'] = 'uploads/Users';
        $icon['subpath'] = "{$userId}/label/{$label}/icon";
        $data = Q::event("Q/image/post", $icon);
        Q_Response::setSlot('icon', $data);
        $label->icon = Q_Request::baseUrl() . '/' . $data[''];
    } else {
        $label->icon = 'default';
    }
    $label->save();
    Q_Response::setSlot('label', $label->exportArray());
}
예제 #2
0
파일: put.php 프로젝트: atirjavid/Platform
/**
 * Edits a label in the system. Fills the "label" (and possibly "icon") slot.
 * @param {array} $_REQUEST
 * @param {string} $_REQUEST.label The label
 * @param {string} [$_REQUEST.title] The title of the label
 * @param {string} [$_REQUEST.icon] Optional path to an icon
 * @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_put($params = array())
{
    $req = array_merge($_REQUEST, $params);
    Q_Request::requireFields(array('label'), $req, true);
    $loggedInUserId = Users::loggedInUser(true)->id;
    $userId = Q::ifset($req, 'userId', $loggedInUserId);
    $l = $req['label'];
    $icon = Q::ifset($req, 'icon', null);
    $title = Q::ifset($req, 'title', null);
    Users::canManageLabels($loggedInUserId, $userId, $l, true);
    $label = new Users_Label();
    $label->userId = $userId;
    $label->label = $l;
    if (!$label->retrieve()) {
        throw new Q_Exception_MissingRow(array('table' => 'Label', 'criteria' => json_encode($label->fields)));
    }
    if (isset($title)) {
        $label->title = $title;
    }
    if (is_array($icon)) {
        // Process any icon data
        $icon['path'] = 'uploads/Users';
        $icon['subpath'] = "{$userId}/label/{$label}/icon";
        $data = Q::event("Q/image/post", $icon);
        Q_Response::setSlot('icon', $data);
        $label->icon = Q_Request::baseUrl() . '/' . $data[''];
    }
    $label->save();
    Q_Response::setSlot('label', $label->exportArray());
}
예제 #3
0
파일: Label.php 프로젝트: dmitriz/Platform
 /**
  * Update labels
  * @method updateLabel
  * @static
  * @param {string} $userId
  * @param {string} $label
  * @param {array} $updates Can contain one or more of "title", "icon"
  * @param {string} [$asUserId=null] The user to do this operation as.
  *   Defaults to the logged-in user. Pass false to skip access checks.
  * @throws {Users_Exception_NotAuthorized}
  * @return {Db_Query_Mysql}
  */
 static function updateLabel($userId, $label, $updates, $asUserId = null)
 {
     foreach (array('userId', 'label', 'updates') as $field) {
         if (empty(${$field})) {
             throw new Q_Exception_RequiredField(compact($field));
         }
     }
     Users::canManageLabels($asUserId, $userId, $label, true);
     $l = new Users_Label();
     $l->userId = $userId;
     $l->label = $label;
     if (!$l->retrieve()) {
         throw new Q_Exception_MissingRow(array('table' => 'Label', 'criteria' => json_encode($l->fields)));
     }
     if (isset($updates['title'])) {
         $l->title = $title;
     }
     $icon = Q::ifset($updates, 'icon', null);
     self::_icon($l, $icon, $userId);
     $l->save();
     return $l;
 }
예제 #4
0
파일: post.php 프로젝트: atirjavid/Platform
/**
 * Adds contacts to the system. Fills the "contacts" slot.
 * @param {array} $_REQUEST
 * @param {string} $_REQUEST.label The label of the contact
 * @param {string} $_REQUEST.contactUserId The contactUserId of the contact
 * @param {string} [$_REQUEST.nickname] The nickname of the contact
 * @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_contact_post($params = array())
{
    $req = array_merge($_REQUEST, $params);
    Q_Request::requireFields(array('label', 'contactUserId'), $req, true);
    $loggedInUserId = Users::loggedInUser(true)->id;
    $userId = Q::ifset($req, 'userId', $loggedInUserId);
    $contactUserId = $req['contactUserId'];
    $nickname = Q::ifset($req, 'nickname', null);
    $l = $req['label'];
    if ($userId !== $loggedInUserId) {
        Users_User::fetch($userId, true);
    }
    Users_User::fetch($contactUserId, true);
    Users::canManageContacts($loggedInUserId, $userId, $l, true);
    $label = new Users_Label();
    $label->userId = $userId;
    $label->label = $l;
    if (!$label->retrieve()) {
        throw new Q_Exception_MissingRow(array('table' => 'Users_Label', 'criteria' => json_encode($label->fields)));
    }
    $contacts = Users_Contact::addContact($userId, $l, $contactUserId, $nickname);
    Q_Response::setSlot('contacts', Db::exportArray($contacts));
}