本文整理汇总了PHP中Streams::fetch方法的典型用法代码示例。如果您正苦于以下问题:PHP Streams::fetch方法的具体用法?PHP Streams::fetch怎么用?PHP Streams::fetch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Streams
的用法示例。
在下文中一共展示了Streams::fetch方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Streams_participant_response_participant
function Streams_participant_response_participant()
{
if (isset(Streams::$cache['participant'])) {
return Streams::$cache['participant'];
}
$publisherId = Streams::requestedPublisherId(true);
$streamName = Streams::requestedName(true);
if (empty($_REQUEST['userId'])) {
throw new Q_Exception_RequiredField(array('field' => 'userId'));
}
$user = Users::loggedInUser();
$userId = $user ? $user->id : "";
$stream = Streams::fetch($userId, $publisherId, $streamName);
if (empty($stream)) {
throw new Q_Exception_MissingRow(array('table' => 'Stream', 'criteria' => "{publisherId: '{$publisherId}', name: '{$streamName}'}"));
}
$stream = reset($stream);
if (!$stream->testReadLevel('participants')) {
throw new Users_Exception_NotAuthorized();
}
$p = new Streams_Participant();
$p->publisherId = $publisherId;
$p->streamName = $streamName;
$p->userId = $_REQUEST['userId'];
if ($p->retrieve()) {
return $p->exportArray();
}
return null;
}
示例2: Streams_category_response_player
/**
* Provide player content to view the members of category listing
* Uses Streams/$type/category.php view (Streams/$streamType/category/get.php can be used for viewing the category
* stream itself if type of category is $streamType/category)
* and Streams::related to retrieve streams data
*
**/
function Streams_category_response_player()
{
$user = Users::loggedInUser();
$userId = $user ? $user->id : 0;
// These are PK of the category!
$publisherId = Streams::requestedPublisherId(true);
$name = Streams::requestedName(true);
// need to know publisher and type of the streams to list
$streamType = Streams::requestedType();
if ($streamType) {
$prefix = "{$streamType}/";
}
$stream_publisherId = Q::expect('Streams', $streamType, 'publisher');
if (substr($name, -1) === '/') {
throw new Q_Exception("Player cannot show listing for multiple categories", compact('publisherId', 'name'));
}
/*
* Get shall return only streams which user is authorized to see.
*/
$categories = Streams::fetch($userId, $publisherId, $name);
if (empty($categories)) {
throw new Q_Exception_MissingRow(array('table' => 'stream', 'criteria' => compact('publisherId', 'name')));
}
$category = reset($categories);
// Are you authorized to see category content?
if (!$category->testReadLevel('content')) {
throw new Users_Exception_NotAuthorized();
}
// get all the streams which are members of this category
// as Streams::get verifies access rights, it's safe to show all streams' content
list($relations, $streams) = Streams::related($userId, $publisherId, $name, true, array('prefix' => $prefix, 'skipAccess' => true));
Q::view("Stream/{$type}/category.php", compact('relations', 'streams', 'userId'));
}
示例3: Websites_seo_tool
/**
* Tool for admins to edit the url, title, keywords, description of the current page
* @class Websites seo
* @constructor
* @param {Object} [$options] Options for the tool
* @param {String} [$options.skipIfNotAuthorized=true] Whether to skip rendering the contents of the tool if the logged-in user is not authorized to edit the SEO information for this page.
*/
function Websites_seo_tool($options)
{
$skipIfNotAuthorized = Q::ifset($options, 'skipIfNotAuthorized', true);
if ($skipIfNotAuthorized) {
$websitesUserId = Users::communityId();
$sha1 = sha1(Q_Dispatcher::uri());
$seoStreamName = "Websites/seo/{$sha1}";
$stream = Streams::fetchOne(null, $websitesUserId, $seoStreamName);
$user = Users::loggedInUser();
if (!$user or $stream and !$stream->testWriteLevel('suggest')) {
$options['skip'] = true;
}
if (!$stream and !Streams::isAuthorizedToCreate($user->id, $websitesUserId, 'Websites/seo')) {
$options['skip'] = true;
}
}
unset($options['skipIfNotAuthorized']);
Q_Response::addStylesheet('plugins/Websites/css/Websites.css');
Q_Response::addScript("plugins/Websites/js/Websites.js");
Q_Response::setToolOptions($options);
$user = Users::loggedInUser(false, false);
$userId = $user ? $user->id : "";
$communityId = Users::communityId();
$sha1 = sha1(Q_Dispatcher::uri());
$seoStreamName = "Websites/seo/{$sha1}";
$streams = Streams::fetch($userId, $communityId, array("Websites/header", "Websites/title", "Websites/slogan", $seoStreamName));
foreach ($streams as $name => $s) {
if ($s) {
$s->addPreloaded($userId);
}
}
}
示例4: Streams_related_post
/**
* Used to create a new relation
*
* @param array $_REQUEST
* toPublisherId, toStreamName, type
* fromPublisherId, fromStreamName, weight
* @return {void}
*/
function Streams_related_post($params)
{
$user = Users::loggedInUser(true);
$asUserId = $user->id;
$toPublisherId = $_REQUEST['toPublisherId'];
$toStreamName = $_REQUEST['toStreamName'];
$type = $_REQUEST['type'];
$fromPublisherId = $_REQUEST['fromPublisherId'];
$fromStreamName = $_REQUEST['fromStreamName'];
// TODO: When we start supporting multiple hosts, this will have to be rewritten
// to make servers communicate with one another when establishing relations between streams
if (!($stream = Streams::fetch($asUserId, $toPublisherId, $toStreamName))) {
throw new Q_Exception_MissingRow(array('table' => 'stream', 'criteria' => 'with those fields'), array('publisherId', 'name'));
}
if (!($stream = Streams::fetch($asUserId, $fromPublisherId, $fromStreamName))) {
throw new Q_Exception_MissingRow(array('table' => 'stream', 'criteria' => 'with those fields'), array('fromPublisherId', 'from_name'));
}
$weight = "+1";
if (isset($_REQUEST['weight'])) {
if (!$stream->testWriteLevel('relations')) {
throw new Users_Exception_NotAuthorized();
}
$weight = $_REQUEST['weight'];
}
$result = Streams::relate($asUserId, $toPublisherId, $toStreamName, $type, $fromPublisherId, $fromStreamName, compact('weight'));
Q_Response::setSlot('result', $result);
}
示例5: Streams_message_post
/**
* Used to post messages to EXISTING stream
* $_REQUEST shall contain the content of the message. Also may include 'streamNames'
* field which is an array of additional names of the streams to post message to.
*
* @param string $params
* publisher id and stream name of existing stream shall be supplied
* @return {void}
*/
function Streams_message_post()
{
$user = Users::loggedInUser(true);
$publisherId = Streams::requestedPublisherId(true);
$streamName = Streams::requestedName(true);
// check if type is allowed
$streams = Streams::fetch($user->id, $publisherId, $streamName);
if (empty($streams)) {
throw new Streams_Exception_NoSuchStream();
}
$stream = reset($streams);
if (empty($_REQUEST['type'])) {
throw new Q_Exception_RequiredField(array('field' => 'type'), 'type');
}
$type = $_REQUEST['type'];
if (!Q_Config::get("Streams", "types", $stream->type, "messages", $type, 'post', false)) {
throw new Q_Exception("This app doesn't support directly posting messages of type '{$type}' for streams of type '{$stream->type}'");
}
$result = Streams_Message::post($user->id, $publisherId, $streamName, $_REQUEST);
if (is_array($result)) {
Streams::$cache['messages'] = $result;
} else {
Streams::$cache['message'] = $result;
}
}
示例6: Streams_stream_response_data
function Streams_stream_response_data()
{
// happens only during non-GET requests
if (isset(Streams::$cache['removed_count'])) {
return array('removed_count' => Streams::$cache['removed_count']);
}
if (isset(Streams::$cache['result'])) {
return Streams::$cache['result'];
}
if (isset(Streams::$cache['stream'])) {
$user = Users::loggedInUser();
$userId = $user ? $user->id : "";
return Streams::$cache['stream']->exportArray(array('asUserId' => $userId));
}
$publisherId = Streams::requestedPublisherId(true);
$name = Streams::requestedName(true);
$fields = Streams::requestedFields();
$user = Users::loggedInUser();
$userId = $user ? $user->id : 0;
$streams = array();
foreach (Streams::fetch($userId, $publisherId, $name, $fields) as $key => $stream) {
$streams[$key] = $stream->exportArray(array('asUserId' => $userId));
if ($userId && !empty($_REQUEST['join'])) {
$stream->join();
// NOTE: one of the rare times we may change state in a response handler
}
}
return Streams::$cache['result'] = array('stream' => empty($streams) ? null : reset($streams));
}
示例7: Users_avatar_tool
/**
* This tool renders a user avatar
*
* @param {array} $options An associative array of parameters, containing:
* @param {string} [$options.userId]
* The user's id. Defaults to id of the logged-in user, if any.
* Can be '' for a blank-looking avatar.
* @param {boolean} [options.short]
* Optional. Renders the short version of the display name.
* @param {boolean|integer} [options.icon=false]
* Optional. Pass the size in pixels of the (square) icon to render
* before the username. Or pass true to render the default size.
* @param {array} [options.iconAttributes]
* Optional. Array of attributes to render for the icon.
* @param {boolean|array} [options.editable=false]
* Optional. Whether to provide an interface for editing the user's info. Can be array containing one or more of "icon", "name".
* @param {boolean} [$options.show] The parts of the name to show. Can have the letters "f", "l", "u" in any order.
* @param {boolean} [options.cacheBust=null]
* Number of milliseconds to use for Q_Uri::cacheBust for combating unintended caching on some environments.
* @param {boolean} [options.renderOnClient]
* If true, only the html container is rendered, so the client will do the rest.
*/
function Users_avatar_tool($options)
{
$defaults = array('icon' => false, 'short' => false, 'cacheBust' => null, 'editable' => false);
$options = array_merge($defaults, $options);
Q_Response::addStylesheet('plugins/Users/css/Users.css');
$loggedInUser = Users::loggedInUser();
$loggedInUserId = $loggedInUser ? $loggedInUser->id : "";
if (empty($options['userId'])) {
$options['userId'] = $loggedInUserId;
}
unset($options['iconAttributes']);
if (empty($options['editable'])) {
$options['editable'] = array();
} else {
if (is_string($options['editable'])) {
$options['editable'] = array($options['editable']);
} else {
if ($options['editable'] === true) {
$options['editable'] = array('icon', 'name');
}
}
}
Q_Response::setToolOptions($options);
if (!empty($options['renderOnClient'])) {
return '';
}
$avatar = Streams_Avatar::fetch($loggedInUserId, $options['userId']);
if (!$avatar) {
return '';
}
$result = '';
if ($icon = $options['icon']) {
if ($icon === true) {
$icon = Q_Config::get('Users', 'icon', 'defaultSize', 40);
}
$attributes = isset($options['iconAttributes']) ? $options['iconAttributes'] : array();
$class = "Users_avatar_icon Users_avatar_icon_{$icon}";
$attributes['class'] = isset($attributes['class']) ? $attributes['class'] . ' ' . $class : $class;
if (isset($options['cacheBust'])) {
$attributes['cacheBust'] = $options['cacheBust'];
}
$result .= Q_Html::img(Users::iconUrl($avatar->icon, "{$icon}.png"), 'user icon', $attributes);
}
$o = $options['short'] ? array('short' => true) : array();
$o['html'] = true;
if (in_array('name', $options['editable'])) {
$o['show'] = 'fl';
$streams = Streams::fetch(null, $options['userId'], array('Streams/user/firstName', 'Streams/user/lastName', 'Streams/user/username'));
foreach ($streams as $s) {
$s->addPreloaded();
}
}
if (!empty($options['show'])) {
$o['show'] = $options['show'];
}
$displayName = $avatar->displayName($o, 'Someone');
$result .= "<span class='Users_avatar_name'>{$displayName}</span>";
return $result;
}
示例8: Streams_participating_response
function Streams_participating_response()
{
if (!Q_Request::isAjax()) {
return;
}
$max_limit = Q_Config::expect('Streams', 'db', 'limits', 'participating');
$user = Users::loggedInUser(true);
$type = Streams::requestedType();
$limit = Streams::requestedField('limit', false, $max_limit);
if ($limit > $max_limit) {
throw new Q_Exception("limit is too large, must be <= {$max_limit}");
}
$offset = Streams::requestedField('offset', false, 0);
$order = Streams::requestedField('order', false, true);
$participating = array();
$q = Streams_Participating::select('*')->where(array('userId' => $user->id));
if ($type) {
$q = $q->where(array('streamName' => new Db_Range($type . '/', true, false, true)));
}
if ($limit) {
$q = $q->limit($limit, $offset);
}
if ($order) {
$q = $q->orderBy('updatedTime', false);
}
$res_participating = $q->fetchDbRows();
foreach ($res_participating as $part) {
$part_safe = $part->exportArray();
if (isset($part_safe)) {
$participating[] = $part_safe;
}
}
Q_Response::setSlot('participating', $participating);
if (!Q_Request::slotName('streams')) {
return;
}
$res_streams = array();
$streamNames = array();
foreach ($res_participating as $p) {
$streamNames[$p->publisherId][] = $p->streamName;
}
foreach ($streamNames as $p_id => $names) {
$res_streams[$p_id] = Streams::fetch($user->id, $p_id, $names);
}
$streams = array();
$o = array('asUserId' => $user->id);
foreach ($res_streams as $publisherId => $streams_array) {
if (!empty($streams_array)) {
$streams[$publisherId] = array();
foreach ($streams_array as $streamName => $stream) {
$streams[$publisherId][$streamName] = $stream->exportArray($o);
}
}
}
Q_Response::setSlot('streams', $streams);
}
示例9: Streams_basic_post
/**
* Post one or more fields here to change the corresponding basic streams for the logged-in user. Fields can include:
* "firstName": specify the first name directly
* "lastName": specify the last name directly
* "fullName": the user's full name, which if provided will be split into first and last name and override them
* "gender": the user's gender
* "birthday_year": the year the user was born
* "birthday_month": the month the user was born
* "birthday_day": the day the user was born
*/
function Streams_basic_post()
{
Q_Valid::nonce(true);
$user = Users::loggedInUser(true);
$request = $_REQUEST;
$fields = array();
if (!empty($request['birthday_year']) && !empty($request['birthday_month']) && !empty($request['birthday_day'])) {
$request['birthday'] = sprintf("%04d-%02d-%02d", $_REQUEST['birthday_year'], $_REQUEST['birthday_month'], $_REQUEST['birthday_day']);
}
// $request['icon'] = $user->icon;
if (isset($request['fullName'])) {
$name = Streams::splitFullName($request['fullName']);
$request['firstName'] = $name['first'];
$request['lastName'] = $name['last'];
}
foreach (array('firstName', 'lastName', 'birthday', 'gender') as $field) {
if (isset($request[$field])) {
$fields[] = $field;
}
}
$p = new Q_Tree();
$p->load(STREAMS_PLUGIN_CONFIG_DIR . DS . 'streams.json');
$p->load(APP_CONFIG_DIR . DS . 'streams.json');
$names = array();
foreach ($fields as $field) {
$names[] = "Streams/user/{$field}";
}
$streams = Streams::fetch($user, $user->id, $names);
foreach ($fields as $field) {
$name = "Streams/user/{$field}";
$type = $p->get($name, "type", null);
if (!$type) {
throw new Q_Exception("Missing {$name} type", $field);
}
$title = $p->get($name, "title", null);
if (!$title) {
throw new Q_Exception("Missing {$name} title", $field);
}
$stream = $streams[$name];
if (isset($stream) and $stream->content === (string) $request[$field]) {
continue;
}
if (!isset($stream)) {
$stream = new Streams_Stream();
$stream->publisherId = $user->id;
$stream->name = $name;
}
$messageType = $stream->wasRetrieved() ? 'Streams/changed' : 'Streams/created';
$stream->content = (string) $request[$field];
$stream->type = $type;
$stream->title = $title;
$stream->changed($user->id, $messageType);
}
}
示例10: Streams_stream_response_streams
function Streams_stream_response_streams()
{
// happens only during non-GET requests
$publisherId = Streams::requestedPublisherId(true);
$name = Streams::requestedName(true);
$fields = Streams::requestedFields();
$limit = isset($_REQUEST['limit']) ? $_REQUEST['limit'] : null;
$user = Users::loggedInUser();
$userId = $user ? $user->id : "";
$streams = Streams::fetch($userId, $publisherId, $name, $fields ? $fields : '*', $limit ? compact('limit') : array());
return Streams::$cache['streams'] = Db::exportArray($streams);
}
示例11: Streams_message_tool
function Streams_message_tool($options)
{
extract($options);
$user = Users::loggedInUser();
if (!$user) {
throw new Users_Exception_NotLoggedIn();
}
if (empty($publisherId)) {
$publisherId = Streams::requestedPublisherId();
}
if (empty($publisherId)) {
$publisherId = $_REQUEST['publisherId'] = $user->id;
}
if (empty($name)) {
$name = Streams::requestedName(true);
}
$stream = Streams::fetch($user->id, $publisherId, $name);
$stream = !empty($stream) ? reset($stream) : null;
if (!$stream) {
throw new Q_Exception_MissingRow(array('table' => 'stream', 'criteria' => 'with that name'), 'streamName');
}
if (!$stream->testReadLevel('messages') || !$stream->testWriteLevel('post')) {
throw new Users_Exception_NotAuthorized();
}
$hidden = array('publisherId' => $publisherId, 'streamName' => $name);
$fields = array('stream' => array('label' => 'Stream', 'type' => 'static', 'value' => $stream->title));
$type = Streams::requestedType();
// check if stream has messages
$types = Q_Config::get('Streams', 'messages', $stream->type, array());
if (count($types) === 0) {
throw new Q_Exception("Stream of type '{$stream->type}' does not support messages");
}
if (!empty($type) && !in_array($type, $types)) {
throw new Q_Exception("Requested message type '{$type}' is not alowed for streams of type '{$stream->type}'");
}
if (!empty($type)) {
$hidden['type'] = $type;
$fields['type'] = array('label' => 'Message type', 'type' => 'static', 'value' => $type);
} else {
$fields['type'] = array('label' => 'Message type', 'type' => 'select', 'options' => array_merge(array('' => 'Select type'), array_combine($types, $types)), 'value' => '');
}
$fields['content'] = array('label' => 'Content', 'type' => 'textarea');
$fields['submit'] = array('label' => '', 'type' => 'submit_buttons', 'options' => array('submit' => 'Post'));
return Q_Html::tag('h3', array(), 'Post a message') . Q_Html::form(Q_Request::baseUrl() . '/action.php/Streams/message', 'post', array(), Q_Html::hidden($hidden) . Q::tool('Q/form', array('fields' => $fields, 'onSuccess' => 'function (data) {
if (data.errors) alert(data.errors);
else {
alert("Message posted");
var message = Q.getObject(["slots", "form", "fields"], data);
Q.handle(Q.info.baseUrl+"/plugins/Streams/message?publisherId="+message.publisherId+"&name="+message.streamName);
}
}')));
}
示例12: Streams_leave_post
function Streams_leave_post()
{
$user = Users::loggedInUser(true);
$publisherId = Streams::requestedPublisherId();
$streamName = Streams::requestedName(true);
$streams = Streams::fetch($user->id, $publisherId, $streamName);
if (empty($streams)) {
throw new Q_Exception_MissingRow(array('table' => 'stream', 'criteria' => "{publisherId: '{$publisherId}', name: '{$streamName}'}"));
}
$stream = reset($streams);
$stream->leave(array(), $participant);
Q_Response::setSlot('participant', $participant->exportArray());
}
示例13: Streams_stream_response_streams
function Streams_stream_response_streams()
{
// happens only during non-GET requests
$publisherId = Streams::requestedPublisherId(true);
$name = Streams::requestedName(true);
$fields = Streams::requestedFields();
$limit = isset($_REQUEST['limit']) ? $_REQUEST['limit'] : null;
$user = Users::loggedInUser();
$userId = $user ? $user->id : "";
$options = array('withParticipant' => true);
if (isset($limit)) {
$options['limit'] = $limit;
}
$streams = Streams::fetch($userId, $publisherId, $name, $fields ? $fields : '*', $options);
return Streams::$cache['streams'] = Db::exportArray($streams);
}
示例14: Streams_join_post
function Streams_join_post()
{
$user = Users::loggedInUser(true);
$publisherId = Streams::requestedPublisherId();
$streamName = Streams::requestedName(true);
$streams = Streams::fetch($user->id, $publisherId, $streamName);
if (empty($streams)) {
throw new Q_Exception_MissingRow(array('table' => 'stream', 'criteria' => "{publisherId: '{$publisherId}', name: '{$streamName}'}"));
}
$stream = reset($streams);
$options = array();
if (isset($_REQUEST['extra'])) {
$options['extra'] = json_decode($_REQUEST['extra'], true);
}
$stream->join($options, $participant);
Q_Response::setSlot('participant', $participant->exportArray());
}
示例15: Broadcast_stream_response_content
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'));
}