本文整理汇总了PHP中Subscription::limit方法的典型用法代码示例。如果您正苦于以下问题:PHP Subscription::limit方法的具体用法?PHP Subscription::limit怎么用?PHP Subscription::limit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Subscription
的用法示例。
在下文中一共展示了Subscription::limit方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _getNthSub
/**
* Get the Nth most recent subscription for this user
*
* @param User $user The user to get subscriptions for
* @param integer $n How far to count back
*
* @return Subscription a subscription or null
*/
private function _getNthSub($user, $n)
{
$sub = new Subscription();
$sub->subscriber = $user->id;
$sub->orderBy('created DESC');
$sub->limit($n - 1, 1);
if ($sub->find(true)) {
return $sub;
} else {
return null;
}
}
示例2: getSubscriptionIDs
private static function getSubscriptionIDs($get_type, $profile_id, $offset, $limit)
{
switch ($get_type) {
case 'subscribed':
$by_type = 'subscriber';
break;
case 'subscriber':
$by_type = 'subscribed';
break;
default:
throw new Exception('Bad type argument to getSubscriptionIDs');
}
$cacheKey = 'subscription:by-' . $by_type . ':' . $profile_id;
$queryoffset = $offset;
$querylimit = $limit;
if ($offset + $limit <= self::CACHE_WINDOW) {
// Oh, it seems it should be cached
$ids = self::cacheGet($cacheKey);
if (is_array($ids)) {
return array_slice($ids, $offset, $limit);
}
// Being here indicates we didn't find anything cached
// so we'll have to fill it up simultaneously
$queryoffset = 0;
$querylimit = self::CACHE_WINDOW;
}
$sub = new Subscription();
$sub->{$by_type} = $profile_id;
$sub->selectAdd($get_type);
$sub->whereAdd("{$get_type} != {$profile_id}");
$sub->orderBy('created DESC');
$sub->limit($queryoffset, $querylimit);
if (!$sub->find()) {
return array();
}
$ids = $sub->fetchAll($get_type);
// If we're simultaneously filling up cache, remember to slice
if ($queryoffset === 0 && $querylimit === self::CACHE_WINDOW) {
self::cacheSet($cacheKey, $ids);
return array_slice($ids, $offset, $limit);
}
return $ids;
}
示例3: realBySubscribed
private static function realBySubscribed($subscribedId, $offset, $limit)
{
$sub = new Subscription();
$sub->subscribed = $subscribedId;
$sub->whereAdd('subscriber != ' . $subscribedId);
$sub->orderBy('created DESC');
$sub->limit($offset, $limit);
$sub->find();
$subs = array();
while ($sub->fetch()) {
$subs[] = clone $sub;
}
return $subs;
}
示例4: subscriptions
function subscriptions($apidata, $other_attr, $user_attr, $onlyIDs = false)
{
$this->auth_user = $apidata['user'];
$user = $this->get_user($apidata['api_arg'], $apidata);
if (!$user) {
$this->clientError('Not Found', 404, $apidata['content-type']);
return;
}
$page = $this->trimmed('page');
if (!$page || !is_numeric($page)) {
$page = 1;
}
$profile = $user->getProfile();
if (!$profile) {
$this->serverError(_('User has no profile.'));
return;
}
$sub = new Subscription();
$sub->{$user_attr} = $profile->id;
$since = strtotime($this->trimmed('since'));
if ($since) {
$d = date('Y-m-d H:i:s', $since);
$sub->whereAdd("created > '{$d}'");
}
$sub->orderBy('created DESC');
if (!$onlyIDs) {
$sub->limit(($page - 1) * 100, 100);
}
$others = array();
if ($sub->find()) {
while ($sub->fetch()) {
$others[] = Profile::staticGet($sub->{$other_attr});
}
} else {
// user has no followers
}
$type = $apidata['content-type'];
$this->init_document($type);
if ($onlyIDs) {
$this->showIDs($others, $type);
} else {
$this->show_profiles($others, $type);
}
$this->end_document($type);
}