本文整理汇总了PHP中Streams::calculateAccess方法的典型用法代码示例。如果您正苦于以下问题:PHP Streams::calculateAccess方法的具体用法?PHP Streams::calculateAccess怎么用?PHP Streams::calculateAccess使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Streams
的用法示例。
在下文中一共展示了Streams::calculateAccess方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: calculateAccess
/**
* Set access data for the stream. Access data is calculated:
* <ol>
* <li>from read/write/admin level fields of the stream</li>
* <li>from labels. Streams_Access record may contain <publisherId>, <streamName>
* (allowed exact match or generic name "<streamType>/") and
* <ofContactLabel>. If <publisherId> is recorded in Users_Contact
* to have either current user or <ofContactLabel> as contact, access claculation is
* considering such record.</li>
* <li>from user. Stream_Access record may contain <publisherId>, <streamName>
* (allowed exact match or generic name "<streamType>/") and
* <ofUserId>. Such record is considered in access calculation.</li>
* </ol>
* @method calculateAccess
* @param {string} $asUserId=null The user relative to whom the access is calculated
* If this matches the publisherId, just sets full access and calls publishedByFetcher(true).
* If this is '', only returns the streams anybody can see.
* If this is null, the logged-in user's id is used, or '' if no one is logged in
* @param {boolean} $recalculate=false Pass true here to force recalculating even if access was already calculated
* @param {string} [$actualPublisherId] for internal use only
* @chainable
*/
function calculateAccess($asUserId = null, $recalculate = false, $actualPublisherId = null)
{
Streams::calculateAccess($asUserId, $this->publisherId, array($this), $recalculate, $actualPublisherId);
return $this;
}
示例2: fetch
/**
* Fetches streams from the database.
* @method fetch
* @static
* @param {string} $asUserId
* Set this to the user for which you are fetching the streams.
* If this matches the publisherId, just returns the streams.
* If this is '', only returns the streams anybody can see.
* Otherwise, return the streams joined with the calculated access settings.
* If you pass null here, then either the logged-in user's id or '' will be used.
* @param {string} $publisherId
* The id of the user publishing these streams
* @param {string|array|Db_Range} $name
* The name of the stream to fetch. Can end in "/" for template streams.
* Also it can be an array of stream names, or a custom Db_Range for stream names
* @param {string} [$fields='*']
* Comma delimited list of fields to retrieve in the stream.
* Must include at least "publisherId" and "name".
* since make up the primary key of the stream table.
* @param {array} [$options=array()]
* Provide additional query options like 'limit', 'offset', 'orderBy', 'where' etc.
* See Db_Query_Mysql::options().
* @param {boolean} [$options.refetch] Ignore cache of previous calls to fetch,
* and save a new cache if necessary.
* @param {boolean} [$options.dontCache] Do not cache the results of
* fetching the streams
* @return {array}
* Returns an array of Streams_Stream objects with access info calculated
* specifically for $asUserId . Make sure to call the methods
* testReadLevel(), testWriteLevel() and testAdminLevel()
* on these streams before using them on the user's behalf.
*/
static function fetch($asUserId, $publisherId, $name, $fields = '*', $options = array())
{
if (!isset($asUserId)) {
$asUserId = Users::loggedInUser();
if (!$asUserId) {
$asUserId = "";
}
}
if ($asUserId instanceof Users_User) {
$asUserId = $asUserId->id;
}
if ($publisherId instanceof Users_User) {
$publisherId = $publisherId->id;
}
if (empty($publisherId) or empty($name)) {
return array();
}
if (is_array($fields)) {
$options = $fields;
$fields = '*';
}
$allCached = array();
if (empty($options['refetch'])) {
$arr = is_array($name) ? $name : array($name);
$namesToFetch = array();
foreach ($arr as $n) {
if (isset(self::$fetch[$asUserId][$publisherId][$n][$fields])) {
$allCached[$n] = self::$fetch[$asUserId][$publisherId][$n][$fields];
} else {
$namesToFetch[] = $n;
}
}
if (!is_array($name)) {
$namesToFetch = $namesToFetch ? $namesToFetch[0] : null;
}
} else {
$namesToFetch = $name;
}
$criteria = array('publisherId' => $publisherId, 'name' => $namesToFetch);
// Get streams and set their default access info
$allRetrieved = $namesToFetch ? Streams_Stream::select($fields)->where($criteria)->ignoreCache()->options($options)->fetchDbRows(null, '', 'name') : array();
$streams = $allCached ? array_merge($allCached, $allRetrieved) : $allRetrieved;
Streams::calculateAccess($asUserId, $publisherId, $streams, false);
if (is_array($name) and count($name) > 1) {
// put the streams back in the same internal PHP array order
// and in the process honor any duplicate names that might have been passed
$temp = $streams;
$streams = array();
foreach ($name as $n) {
$streams[$n] = isset($temp[$n]) ? $temp[$n] : null;
}
}
$types = array();
foreach ($streams as $stream) {
if ($stream) {
$types[$stream->type] = true;
}
}
$types = array_keys($types);
self::afterFetchExtended($publisherId, $streams);
foreach ($types as $type) {
$cached = array();
$retrieved = array();
foreach ($allCached as $n => $s) {
if ($s->type === $type) {
$cached[$n] = $s;
}
}
//.........这里部分代码省略.........