本文整理汇总了PHP中ArrayList::limit方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayList::limit方法的具体用法?PHP ArrayList::limit怎么用?PHP ArrayList::limit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayList
的用法示例。
在下文中一共展示了ArrayList::limit方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testLimit
public function testLimit() {
$list = new ArrayList(array(
array('Key' => 1), array('Key' => 2), array('Key' => 3)
));
$this->assertEquals($list->limit(2,1)->toArray(), array(
array('Key' => 2), array('Key' => 3)
));
}
示例2: sequenceGridListItems
/**
* @param \DataList|\ArrayList $items
* @param $filters
* @param array $parameters
*/
public function sequenceGridListItems(&$items, $filters, &$parameters = [])
{
$limit = isset($parameters['PageLength']) ? $parameters['PageLength'] : null;
// filter items for each filter to current page length
if ($limit) {
$start = GridList::service()->Filters()->start() ?: 0;
$out = new \ArrayList();
$currentFilter = GridList::service()->constraint(Constraints::FilterVar);
if ($currentFilter && $currentFilter != 'all') {
if ($filter = GridListFilter::get()->filter(['ModelTag' => $currentFilter])->first()) {
$out->merge($items->limit($limit, $start));
}
} else {
foreach ($filters as $filter) {
$filtered = new \ArrayList();
foreach ($items as $item) {
if ($item instanceof Block) {
// only push blocks first page
if ($start == 0) {
$filtered->push($item);
}
} else {
if ($currentFilter == 'all') {
$filtered->push($item);
} else {
if ($item->GridListFilters()->find('ID', $filter->ID)) {
$filtered->push($item);
}
}
}
}
// merge limited filtered items back in
$out->merge($filtered->limit($limit, $start));
}
}
$items = $out;
}
}
示例3: getVideoFeed
/**
* Returns a collection of Vimeo videos for a given method.
* @param string
* @param array
* @param integer
* @return DataObjectSet or boolean false
*/
function getVideoFeed($method = NULL, $call_params = array(), $page_limit = 10)
{
if (!self::$api_key || !self::$api_secret_key) {
user_error('Fatal error: Invalid API keyand/or secret specified!');
return false;
}
// Prepare oauth arguments
$oauth_params = array('oauth_consumer_key' => self::$api_key, 'oauth_version' => '1.0', 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_timestamp' => time(), 'oauth_nonce' => $this->_generateNonce());
$page = $call_params['start'] == 0 ? 1 : $call_params['start'] / $page_limit + 1;
if (self::$token) {
$oauth_params['oauth_token'] = self::$token;
}
$api_params = array('format' => 'php', 'full_response' => 1, 'per_page' => $page_limit, 'page' => $page);
if (!empty($method)) {
$api_params['method'] = $method;
}
// Merge args
foreach ($call_params as $k => $v) {
if (strpos($k, 'oauth_') === 0) {
$oauth_params[$k] = $v;
} else {
$api_params[$k] = $v;
}
}
// Generate the signature
$oauth_params['oauth_signature'] = $this->_generateSignature(array_merge($oauth_params, $api_params), self::$api_base_url);
// Merge all args
$params = array_merge($oauth_params, $api_params);
$this->setQueryString($params);
$response = $this->request();
$videos = unserialize($response->getBody());
if (isset($videos->videos)) {
$results = new ArrayList();
foreach ($videos->videos->video as $video) {
$data = $this->_extractVideoInfo($video);
/*
* @todo Add sorting
*/
$results->push(new ArrayData($data));
}
// since we manually created the dataobjectset, we need to set the pager info manually, too.
$results->limit($call_params['start'], $page_limit, intval($videos->videos->total));
} else {
$results = false;
}
return $results;
}
示例4: getLatestTweets
function getLatestTweets()
{
require Director::baseFolder() . '/twitter-feed/libs/tmhOAuth.php';
require Director::baseFolder() . '/twitter-feed/libs/tmhUtilities.php';
$tmhOAuth = new tmhOAuth(array('consumer_key' => self::get_consumer_key(), 'consumer_secret' => self::get_consumer_secret(), 'user_token' => self::get_user_token(), 'user_secret' => self::get_user_secret(), 'curl_ssl_verifypeer' => false));
$code = $tmhOAuth->request('GET', $tmhOAuth->url('1.1/statuses/user_timeline'), array('screen_name' => self::get_username(), 'count' => self::get_tweetcount() + 10, 'exclude_replies' => true));
$response = $tmhOAuth->response['response'];
$tweets = json_decode($response, true);
if ($this->_errorCheck($tweets)) {
return false;
}
$output = new ArrayList();
foreach ($tweets as &$tweet) {
$tweet['text'] = $this->tweetConvert($tweet['text']);
$time = SS_Datetime::create('SS_Datetime');
$time->setValue($tweet['created_at']);
$tweet['created_at'] = $time;
//
$tweet['username'] = self::get_username();
$output->push(new ArrayData($tweet));
}
return $output->limit(self::get_tweetcount());
}