本文整理匯總了PHP中Model_Ad::api_pagination方法的典型用法代碼示例。如果您正苦於以下問題:PHP Model_Ad::api_pagination方法的具體用法?PHP Model_Ad::api_pagination怎麽用?PHP Model_Ad::api_pagination使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Model_Ad
的用法示例。
在下文中一共展示了Model_Ad::api_pagination方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: action_index
/**
* Handle GET requests.
*/
public function action_index()
{
try {
if (is_numeric($this->request->param('id'))) {
$this->action_get();
} else {
$output = array();
$ads = new Model_Ad();
//any status but needs to see your ads ;)
$ads->where('id_user', '=', $this->user->id_user);
//by default sort by published date
if (empty($this->_sort)) {
$this->_sort['published'] = 'desc';
}
//filter results by param, verify field exists and has a value and sort the results
$ads->api_filter($this->_filter_params)->api_sort($this->_sort);
//how many? used in header X-Total-Count
$count = $ads->count_all();
//pagination with headers
$pagination = $ads->api_pagination($count, $this->_params['items_per_page']);
$ads = $ads->cached()->find_all();
//as array
foreach ($ads as $ad) {
$a = $ad->as_array();
$a['price'] = i18n::money_format($ad->price);
$a['thumb'] = $ad->get_first_image();
$a['customfields'] = Model_Field::get_by_category($ad->id_category);
foreach ($a['customfields'] as $key => $values) {
$a['customfields'][$key]['value'] = $a[$key];
}
$a['url'] = Route::url('ad', array('category' => $ad->category->seoname, 'seotitle' => $ad->seotitle));
$output[] = $a;
}
$this->rest_output(array('ads' => $output), 200, $count, $pagination !== FALSE ? $pagination : NULL);
}
} catch (Kohana_HTTP_Exception $khe) {
$this->_error($khe);
}
}
示例2: action_index
/**
* Handle GET requests.
*/
public function action_index()
{
try {
if (is_numeric($this->request->param('id'))) {
$this->action_get();
} else {
$output = array();
$ads = new Model_Ad();
$ads->where('status', '=', Model_Ad::STATUS_PUBLISHED);
//search with lat and long!! nice!
if (isset($this->_params['latitude']) and isset($this->_params['longitude'])) {
$ads->select(array(DB::expr('degrees(acos(sin(radians(' . $this->_params['latitude'] . ')) * sin(radians(`latitude`)) + cos(radians(' . $this->_params['latitude'] . ')) * cos(radians(`latitude`)) * cos(radians(abs(' . $this->_params['longitude'] . ' - `longitude`))))) * 69.172'), 'distance'))->where('latitude', 'IS NOT', NULL)->where('longitude', 'IS NOT', NULL);
//we unset the search by lat and long if not will be duplicated
unset($this->_filter_params['latitude']);
unset($this->_filter_params['longitude']);
}
//only published ads
$ads->where('status', '=', Model_Ad::STATUS_PUBLISHED);
//if ad have passed expiration time dont show
if (core::config('advertisement.expire_date') > 0) {
$ads->where(DB::expr('DATE_ADD( published, INTERVAL ' . core::config('advertisement.expire_date') . ' DAY)'), '>', Date::unix2mysql());
}
//make a search with q? param
if (isset($this->_params['q']) and strlen($this->_params['q'])) {
if (core::config('general.search_by_description') == TRUE) {
$ads->where_open()->where('title', 'like', '%' . $this->_params['q'] . '%')->or_where('description', 'like', '%' . $this->_params['q'] . '%')->where_close();
} else {
$ads->where('title', 'like', '%' . $this->_params['q'] . '%');
}
}
//getting all the ads of a category.
if (isset($this->_filter_params['id_category']) and is_numeric($this->_filter_params['id_category']['value'])) {
$category = new Model_Category($this->_filter_params['id_category']['value']);
if ($category->loaded()) {
$ads->where('id_category', 'in', $category->get_siblings_ids());
unset($this->_filter_params['id_category']);
}
}
//getting all the ads of a location.
if (isset($this->_filter_params['id_location']) and is_numeric($this->_filter_params['id_location']['value'])) {
$location = new Model_Location($this->_filter_params['id_location']['value']);
if ($location->loaded()) {
$ads->where('id_location', 'in', $location->get_siblings_ids());
unset($this->_filter_params['id_location']);
}
}
//filter results by param, verify field exists and has a value
$ads->api_filter($this->_filter_params);
//how many? used in header X-Total-Count
$count = $ads->count_all();
//by default sort by published date
if (empty($this->_sort)) {
$this->_sort['published'] = 'desc';
}
//after counting sort values
$ads->api_sort($this->_sort);
//we add the order by in case was specified, this is not a column so we need to do it manually
if (isset($this->_sort['distance']) and isset($this->_params['latitude']) and isset($this->_params['longitude'])) {
$ads->order_by('distance', $this->_sort['distance']);
}
//pagination with headers
$pagination = $ads->api_pagination($count, $this->_params['items_per_page']);
$ads = $ads->cached()->find_all();
//as array
foreach ($ads as $ad) {
$a = $ad->as_array();
$a['price'] = i18n::money_format($ad->price);
$a['thumb'] = $ad->get_first_image();
$a['customfields'] = Model_Field::get_by_category($ad->id_category);
//sorting by distance, lets add it!
if (isset($ad->distance)) {
$a['distance'] = i18n::format_measurement($ad->distance);
}
$a['url'] = Route::url('ad', array('category' => $ad->category->seoname, 'seotitle' => $ad->seotitle));
$output[] = $a;
}
$this->rest_output(array('ads' => $output), 200, $count, $pagination !== FALSE ? $pagination : NULL);
}
} catch (Kohana_HTTP_Exception $khe) {
$this->_error($khe);
}
}