本文整理汇总了PHP中Streams::leave方法的典型用法代码示例。如果您正苦于以下问题:PHP Streams::leave方法的具体用法?PHP Streams::leave怎么用?PHP Streams::leave使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Streams
的用法示例。
在下文中一共展示了Streams::leave方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: unsubscribe
/**
* Unsubscribe from one or more streams, to stop receiving notifications.
* Pooststs "Streams/unsubscribe" message to the streams.
* Also posts "Streams/unsubscribed" messages to user's "Streams/participating" stream.
* Does not change the actual subscription, but only the participant row.
* (When subscribing again, the existing subscription will be used.)
* @method unsubscribe
* @static
* @param {string} $asUserId The id of the user that is joining. Pass null here to use the logged-in user's id.
* @param {string} $publisherId The id of the user publishing all the streams
* @param {array} $streams An array of Streams_Stream objects or stream names
* @param {array} [$options=array()]
* @param {boolean} [$options.leave] set to true to also leave the streams
* @param {boolean} [$options.skipAccess] if true, skip access check for whether user can join and subscribe
* @return {array} Returns an array of Streams_Participant rows, if any were in the database.
*/
static function unsubscribe($asUserId, $publisherId, $streams, $options = array())
{
$streams2 = self::_getStreams($asUserId, $publisherId, $streams);
$streamNames = array();
foreach ($streams2 as $s) {
$streamNames[] = $s->name;
}
if (empty($options['skipAccess'])) {
self::_accessExceptions($streams2, $streamNames, 'join');
}
$skipAccess = Q::ifset($options, 'skipAccess', false);
if (empty($options['leave'])) {
$criteria = array('publisherId' => $publisherId, 'streamName' => $streamNames, 'userId' => $asUserId);
Streams_Participant::update()->set(array('subscribed' => 'no'))->where($criteria)->execute();
$participants = Streams_Participant::select('*')->where($criteria)->fetchDbRows();
} else {
$participants = Streams::leave($asUserId, $publisherId, $streams2, compact('skipAccess'));
}
$messages = array();
$pMessages = array();
foreach ($streamNames as $sn) {
$stream = $streams2[$sn];
if ($participant = Q::ifset($participants, $sn, null)) {
if ($participant instanceof Streams_Participant) {
$participant = $participant->toArray();
}
}
// Send a message to Node
Q_Utils::sendToNode(array("Q/method" => "Streams/Stream/unsubscribe", "participant" => Q::json_encode($participant), "stream" => Q::json_encode($stream->toArray())));
// Stream messages to post
$messages[$publisherId][$sn] = array('type' => 'Streams/unsubscribe');
$pMessages[] = array('type' => 'Streams/unsubscribed', 'instructions' => array('publisherId' => $publisherId, 'streamName' => $sn));
}
Streams_Message::postMessages($asUserId, $messages, true);
Streams_Message::postMessages($asUserId, array($asUserId => array('Streams/participating' => $pMessages)), true);
return $participants;
}
示例2: leave
/**
* If the user is participating in the stream, sets state of participant row
* as "left" and posts a "Streams/leave" type message to the stream.
* Also posts "Streams/left" message on user's "Streams/participating" stream
* @method leave
* @param $options=array() {array} An associative array of options.
* @param {string} [$options.userId] The user who is leaving the stream. Defaults to the logged-in user.
* @param {string} [$options.skipAccess] If true, skip access check for whether user can join
* @param $participant=null {reference}
* Optional reference to a participant object that will be filled
* to point to the participant object, if any.
* @return {Streams_Participant|null}
*/
function leave($options = array(), &$participant = null)
{
$userId = $this->_verifyUser($options);
$participants = Streams::leave($userId, $this->publisherId, array($this->name), $options);
return $participants ? reset($participants) : null;
}