function Users_user_response_users($params = array()) { $req = array_merge($_REQUEST, $params); Q_Valid::requireFields(array('userIds'), $req, true); $userIds = $req['userIds']; if (is_string($userIds)) { $userIds = explode(",", $userIds); } $fields = Q_Config::expect('Users', 'avatarFields'); $users = Users_User::select($fields)->where(array('id' => $userIds))->fetchDbRows(null, null, 'id'); return Q_Response::setSlot('users', Db::exportArray($users, array('asAvatar' => true))); }
function Q_response_dialogs() { // Here is where you would pre-generate various dialog elements // that you might show with Q.Dialogs.push if (!Users::roles(null, array('Websites/admins'))) { return ''; } $app = Q_Config::expect('Q', 'app'); $userIds = Users_Contact::select('contactUserId')->where(array('userId' => $app, 'label' => 'Websites/admins'))->fetchAll(PDO::FETCH_COLUMN, 'contactUserId'); $admins = Users_User::select('*')->where(array('id' => $userIds))->fetchDbRows(); return Q::view('Trump/dialogs/common.php', compact('admins')); }
function Broadcast_stream_response_content() { $publisherId = Streams::requestedPublisherId(true); $name = Streams::requestedName(true); $fields = Streams::requestedFields(); $user = Users::loggedInUser(); $userId = $user ? $user->id : 0; if (isset(Streams::$cache['stream'])) { $stream = Streams::$cache['stream']; } else { $streams = Streams::fetch($userId, $publisherId, $name, $fields, array('limit' => 30)); if (empty($streams)) { throw new Q_Exception("No such stream", 'name'); } $stream = reset($streams); } if ($publisherId != $userId and !$stream->testReadLevel('content')) { return "This belongs to someone else."; } if ($publisherId != $userId and !$stream->testReadLevel('content')) { throw new Users_Exception_NotAuthorized(); } $userIds = array(); $agreements = Broadcast_Agreement::select('userId')->where(array('publisherId' => $publisherId, 'streamName' => $name, 'platform' => 'facebook'))->fetchDbRows(); foreach ($agreements as $a) { $userIds[] = $a->userId; } if ($userIds) { $agreed_users = Users_User::select('*')->where(array('id' => $userIds))->fetchDbRows(); } else { $agreed_users = array(); } $src = 'Broadcast/widget?'; $q = array('publisherId' => $publisherId, 'streamName' => $name); foreach (array('css', 'button', 'checkmark', 'explanation') as $field) { if (isset($_REQUEST[$field])) { $q[$field] = $_REQUEST[$field]; } } $src .= http_build_query($q, null, '&'); $style = 'border: 0px;'; $code = Q_Html::tag('iframe', compact('src', 'style'), ''); Q_Response::addScript('plugins/Broadcast/js/Broadcast.js'); return Q::view('Broadcast/content/stream.php', compact('publisherId', 'name', 'fields', 'user', 'stream', 'agreed_users', 'code')); }
function Users_avatar_response($params) { $userIds = $batch = null; extract($_REQUEST, EXTR_IF_EXISTS); if ($batch) { $batch = json_decode($batch, true); if (!isset($batch)) { throw new Q_Exception_WrongValue(array('field' => 'batch', 'range' => '{userIds: [userId1, userId2, ...]}')); } if (!isset($batch['userIds'])) { throw new Q_Exception_RequiredField(array('field' => 'userIds')); } $userIds = $batch['userIds']; } else { if (!isset($userIds)) { throw new Q_Exception_RequiredField(array('field' => 'userIds'), 'userIds'); } } if (is_string($userIds)) { $userIds = explode(",", $userIds); } $fields = Q_Config::expect('Users', 'avatarFields'); $users = Users_User::select($fields)->where(array('id' => $userIds))->fetchDbRows(null, null, 'id'); $avatars = Db::exportArray($users); if (!isset($batch)) { Q_Response::setSlot('avatars', $avatars); return $avatars; } if ($batch) { $result = array(); foreach ($userIds as $userId) { $result[] = array('slots' => array('avatar' => isset($avatars[$userId]) ? $avatars[$userId] : null)); } Q_Response::setSlot('batch', $result); } return $avatars; }
/** * Verifies that users exist for these ids * @method verifyUserIds * @static * @param $userIds {string|array} * @param $throw=false {boolean} * @return {array} The array of found user ids */ static function verifyUserIds($userIds, $throw = false) { if (empty($userIds)) { return array(); } if (!is_array($userIds)) { $userIds = array_map('trim', explode(',', $userIds)); } $users = Users_User::select('id')->where(array('id' => $userIds))->fetchAll(PDO::FETCH_COLUMN); if ($throw && count($users) < count($userIds)) { $diff = array_diff($userIds, $users); if (count($diff)) { $ids = join(', ', $diff); throw new Q_Exception_MissingRow(array('table' => 'user', 'criteria' => "ids ({$ids})"), 'id'); } } return $users; }