本文整理汇总了PHP中Model_Category::get_siblings_ids方法的典型用法代码示例。如果您正苦于以下问题:PHP Model_Category::get_siblings_ids方法的具体用法?PHP Model_Category::get_siblings_ids怎么用?PHP Model_Category::get_siblings_ids使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model_Category
的用法示例。
在下文中一共展示了Model_Category::get_siblings_ids方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_get
public function action_get()
{
try {
if (is_numeric($id_category = $this->request->param('id'))) {
$cat = array();
$category = new Model_Category($id_category);
if ($category->loaded()) {
$cat = $category->as_array();
$cat['price'] = i18n::money_format($category->price);
$cat['parents'] = $category->get_parents_ids();
$cat['siblings'] = $category->get_siblings_ids();
$cat['customfields'] = Model_Field::get_by_category($category->id_category);
$cat['icon'] = $category->get_icon();
$this->rest_output(array('category' => $cat));
} else {
$this->_error(__('Category not found'), 404);
}
} else {
$this->_error(__('Category not found'), 404);
}
} catch (Kohana_HTTP_Exception $khe) {
$this->_error($khe);
return;
}
}
示例2: action_index
public function action_index()
{
$this->before('/pages/maps');
$this->template->title = __('Map');
$this->template->height = Core::get('height', '100%');
$this->template->width = Core::get('width', '100%');
$this->template->zoom = Core::get('zoom', core::config('advertisement.map_zoom'));
$this->template->height_thumb = Core::config('image.height_thumb') / 4;
$this->template->width_thumb = Core::config('image.width_thumb') / 4;
if (Model_User::get_userlatlng()) {
$this->template->center_lon = $_COOKIE['mylng'];
$this->template->center_lat = $_COOKIE['mylat'];
} else {
$this->template->center_lon = Core::get('lon', core::config('advertisement.center_lon'));
$this->template->center_lat = Core::get('lat', core::config('advertisement.center_lat'));
}
$ads = new Model_Ad();
$ads->where('status', '=', Model_Ad::STATUS_PUBLISHED)->where('address', 'IS NOT', NULL)->where('latitude', 'IS NOT', NULL)->where('longitude', 'IS NOT', NULL);
//filter by category
if (core::get('category') !== NULL) {
$category = new Model_Category();
$category->where('seoname', '=', core::get('category'))->cached()->limit(1)->find();
if ($category->loaded()) {
$ads->where('id_category', 'IN', $category->get_siblings_ids());
}
}
//filter by location
if (core::get('location') !== NULL) {
$location = new Model_location();
$location->where('seoname', '=', core::get('location'))->cached()->limit(1)->find();
if ($location->loaded()) {
$ads->where('id_location', 'IN', $location->get_siblings_ids());
}
}
//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());
}
//if only 1 ad
if (is_numeric(core::get('id_ad'))) {
$ads = $ads->where('id_ad', '=', core::get('id_ad'));
}
$ads = $ads->order_by('published', 'desc')->limit(Core::config('advertisement.map_elements'))->find_all();
$this->template->ads = $ads;
}
示例3: 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);
}
}
示例4: action_advanced_search
public function action_advanced_search()
{
$this->template->scripts['footer'][] = 'js/jquery.toolbar.js';
$this->template->scripts['footer'][] = 'js/sort.js';
//template header
$this->template->title = __('Advanced Search');
$this->template->meta_description = __('Search in') . ' ' . core::config('general.site_name');
//breadcrumbs
Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Home'))->set_url(Route::url('default')));
Breadcrumbs::add(Breadcrumb::factory()->set_title($this->template->title));
$pagination = NULL;
$ads = NULL;
$user = Auth::instance()->get_user() == NULL ? NULL : Auth::instance()->get_user();
if ($this->request->query()) {
// variables
$search_advert = core::get('title');
$search_loc = core::get('location');
// filter by each variable
$ads = new Model_Ad();
// early filter
$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());
}
if (!empty($search_advert) or core::get('search') !== NULL and strlen(core::get('search')) >= 3) {
// if user is using search from header
if (core::get('search')) {
$search_advert = core::get('search');
}
$ads->where_open()->where('title', 'like', '%' . $search_advert . '%')->or_where('description', 'like', '%' . $search_advert . '%')->where_close();
}
$cf_fields = array();
foreach ($this->request->query() as $name => $field) {
// get by prefix
if (strpos($name, 'cf_') !== false) {
$cf_fields[$name] = $field;
//checkbox when selected return string 'on' as a value
if ($field == 'on') {
$cf_fields[$name] = 1;
} elseif (empty($field)) {
$cf_fields[$name] = NULL;
}
}
}
$category = NULL;
$location = NULL;
if (core::config('general.search_multi_catloc') and Theme::$is_mobile === FALSE) {
//filter by category
if (is_array(core::get('category'))) {
$cat_siblings_ids = array();
foreach (core::get('category') as $cat) {
if ($cat !== NULL) {
$category = new Model_Category();
$category->where('seoname', '=', $cat)->cached()->limit(1)->find();
if ($category->loaded()) {
$cat_siblings_ids = array_merge($cat_siblings_ids, $category->get_siblings_ids());
}
}
}
if (count($cat_siblings_ids) > 0) {
$ads->where('id_category', 'IN', $cat_siblings_ids);
}
}
//filter by location
if (is_array(core::get('location'))) {
$loc_siblings_ids = array();
foreach (core::get('location') as $loc) {
if ($loc !== NULL) {
$location = new Model_location();
$location->where('seoname', '=', $loc)->cached()->limit(1)->find();
if ($location->loaded()) {
$loc_siblings_ids = array_merge($loc_siblings_ids, $location->get_siblings_ids());
}
}
}
if (count($loc_siblings_ids) > 0) {
$ads->where('id_location', 'IN', $loc_siblings_ids);
}
}
} else {
if (core::get('category') !== NULL) {
$category = new Model_Category();
$category->where('seoname', '=', core::get('category'))->cached()->limit(1)->find();
if ($category->loaded()) {
$ads->where('id_category', 'IN', $category->get_siblings_ids());
}
}
$location = NULL;
//filter by location
if (core::get('location') !== NULL) {
$location = new Model_location();
$location->where('seoname', '=', core::get('location'))->cached()->limit(1)->find();
if ($location->loaded()) {
$ads->where('id_location', 'IN', $location->get_siblings_ids());
}
}
}
//filter by price(s)
if (is_numeric($price_min = str_replace(',', '.', core::get('price-min')))) {
//.........这里部分代码省略.........
示例5: update
/**
* updates custom field option, not the name or the type
* @param string $name
* @param string $values
* @param array $options
* @return bool
*/
public function update($name, $values = NULL, $categories = NULL, array $options)
{
if ($this->field_exists($name)) {
//save configs
$conf = new Model_Config();
$conf->where('group_name', '=', 'advertisement')->where('config_key', '=', 'fields')->limit(1)->find();
if ($conf->loaded()) {
$fields = json_decode($conf->config_value, TRUE);
if (!empty($values) and !is_array($values) and ($fields[$name]['type'] == 'select' or $fields[$name]['type'] == 'radio')) {
$values = array_map('trim', explode(',', $values));
}
//add child categories of selected categories
if (is_array($categories)) {
// get category siblings
foreach ($categories as $category) {
$category = new Model_Category($category);
if (($siblings = $category->get_siblings_ids()) != NULL) {
$categories = array_merge($categories, $siblings);
}
}
// remove duplicated categories
$categories = array_unique($categories);
}
//save at config
$fields[$name] = array('type' => $fields[$name]['type'], 'label' => $options['label'], 'tooltip' => $options['tooltip'], 'values' => $values, 'categories' => $categories, 'required' => $options['required'], 'searchable' => $options['searchable'], 'admin_privilege' => $options['admin_privilege'], 'show_listing' => $options['show_listing']);
$conf->config_value = json_encode($fields);
$conf->save();
}
return TRUE;
} else {
return FALSE;
}
}
示例6: action_search
public function action_search()
{
//template header
$this->template->title = __('Advanced Search');
$this->template->meta_description = __('Search in') . ' ' . Core::config('general.site_name');
$this->template->styles = array('//cdn.jsdelivr.net/bootstrap.datepicker/0.1/css/datepicker.css' => 'screen');
$this->template->scripts['footer'] = array('//cdn.jsdelivr.net/bootstrap.datepicker/0.1/js/bootstrap-datepicker.js');
//breadcrumbs
Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Home'))->set_url(Route::url('default')));
Breadcrumbs::add(Breadcrumb::factory()->set_title($this->template->title));
$categories = Model_Category::get_as_array();
$order_categories = Model_Category::get_multidimensional();
$pagination = NULL;
$products = NULL;
if ($this->request->query()) {
$products = new Model_Product();
$category = NULL;
//filter by category
if (core::get('category') !== NULL) {
$category = new Model_Category();
$category->where('seoname', '=', core::get('category'))->limit(1)->find();
if ($category->loaded()) {
$products->where('id_category', 'IN', $category->get_siblings_ids());
}
}
//filter by title description
if (core::get('search') !== NULL and strlen(core::get('search')) >= 3) {
$products->where_open()->where('title', 'like', '%' . core::get('search') . '%')->or_where('description', 'like', '%' . core::get('search') . '%')->where_close();
}
//filter by price
if (is_numeric(core::get('price-min')) and is_numeric(core::get('price-max'))) {
$products->where('price', 'BETWEEN', array(core::get('price-min'), core::get('price-max')));
}
//only published products
$products->where('status', '=', Model_Product::STATUS_ACTIVE);
$res_count = $products->count_all();
// check if there are some advet.-s
if ($res_count > 0) {
// pagination module
$pagination = Pagination::factory(array('view' => 'pagination', 'total_items' => $res_count, 'items_per_page' => core::config('general.products_per_page')))->route_params(array('controller' => $this->request->controller(), 'action' => $this->request->action(), 'category' => $category !== NULL ? $category->seoname : NULL));
Breadcrumbs::add(Breadcrumb::factory()->set_title(__("Page ") . $pagination->current_page));
//we sort all products with few parameters
$products = $products->order_by('created', 'desc')->limit($pagination->items_per_page)->offset($pagination->offset)->find_all();
}
}
$this->template->bind('content', $content);
$this->template->content = View::factory('pages/search', array('categories' => $categories, 'order_categories' => $order_categories, 'products' => $products, 'pagination' => $pagination));
}
示例7: action_advanced_search
public function action_advanced_search()
{
if (Theme::get('infinite_scroll')) {
$this->template->scripts['footer'][] = '//cdn.jsdelivr.net/jquery.infinitescroll/2.0b2/jquery.infinitescroll.js';
$this->template->scripts['footer'][] = 'js/listing.js';
}
if (core::config('general.auto_locate') or core::config('advertisement.map')) {
Theme::$scripts['async_defer'][] = '//maps.google.com/maps/api/js?libraries=geometry,places&v=3&key=' . core::config("advertisement.gm_api_key") . '&callback=initLocationsGMap';
}
$this->template->scripts['footer'][] = 'js/jquery.toolbar.js';
$this->template->scripts['footer'][] = 'js/sort.js';
//template header
$this->template->title = __('Advanced Search');
$this->template->meta_description = __('Search in') . ' ' . core::config('general.site_name');
//breadcrumbs
Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Home'))->set_url(Route::url('default')));
Breadcrumbs::add(Breadcrumb::factory()->set_title($this->template->title));
$pagination = NULL;
$ads = NULL;
$res_count = NULL;
$user = $this->user ? $this->user : NULL;
if ($this->request->query()) {
// variables
$search_advert = core::get('title');
$search_loc = core::get('location');
// filter by each variable
$ads = new Model_Ad();
//if sort by distance
if ((core::request('sort', core::config('advertisement.sort_by')) == 'distance' or core::request('userpos') == 1) and Model_User::get_userlatlng()) {
$ads->select(array(DB::expr('degrees(acos(sin(radians(' . $_COOKIE['mylat'] . ')) * sin(radians(`latitude`)) + cos(radians(' . $_COOKIE['mylat'] . ')) * cos(radians(`latitude`)) * cos(radians(abs(' . $_COOKIE['mylng'] . ' - `longitude`))))) * 111.321'), 'distance'))->where('latitude', 'IS NOT', NULL)->where('longitude', 'IS NOT', NULL);
}
// early filter
$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());
}
if (core::request('userpos') == 1 and Model_User::get_userlatlng()) {
if (is_numeric(Core::cookie('mydistance')) and Core::cookie('mydistance') <= 500) {
$location_distance = Core::config('general.measurement') == 'imperial' ? Num::round(Core::cookie('mydistance') * 1.60934) : Core::cookie('mydistance');
} else {
$location_distance = Core::config('general.measurement') == 'imperial' ? Num::round(Core::config('advertisement.auto_locate_distance') * 1.60934) : Core::config('advertisement.auto_locate_distance');
}
$ads->where(DB::expr('degrees(acos(sin(radians(' . $_COOKIE['mylat'] . ')) * sin(radians(`latitude`)) + cos(radians(' . $_COOKIE['mylat'] . ')) * cos(radians(`latitude`)) * cos(radians(abs(' . $_COOKIE['mylng'] . ' - `longitude`))))) * 111.321'), '<=', $location_distance);
}
if (!empty($search_advert) or core::get('search') !== NULL and strlen(core::get('search')) >= 3) {
// if user is using search from header
if (core::get('search')) {
$search_advert = core::get('search');
}
if (core::config('general.search_by_description') == TRUE) {
$ads->where_open()->where('title', 'like', '%' . $search_advert . '%')->or_where('description', 'like', '%' . $search_advert . '%')->where_close();
} else {
$ads->where('title', 'like', '%' . $search_advert . '%');
}
}
//cf filter arrays
$cf_fields = array();
$cf_user_fields = array();
foreach ($this->request->query() as $name => $field) {
if (isset($field) and $field != NULL) {
// get by prefix cf
if (strpos($name, 'cf_') !== FALSE and array_key_exists(str_replace('cf_', '', $name), Model_Field::get_all())) {
$cf_fields[$name] = $field;
//checkbox when selected return string 'on' as a value
if ($field == 'on') {
$cf_fields[$name] = 1;
} elseif (empty($field)) {
$cf_fields[$name] = NULL;
}
} elseif (strpos($name, 'cfuser_') !== FALSE and array_key_exists(str_replace('cfuser_', '', $name), Model_UserField::get_all())) {
$name = str_replace('cfuser_', 'cf_', $name);
$cf_user_fields[$name] = $field;
//checkbox when selected return string 'on' as a value
if ($field == 'on') {
$cf_user_fields[$name] = 1;
} elseif (empty($field)) {
$cf_user_fields[$name] = NULL;
}
}
}
}
$category = NULL;
$location = NULL;
if (core::config('general.search_multi_catloc') and Theme::$is_mobile === FALSE) {
//filter by category
if (is_array(core::get('category'))) {
$cat_siblings_ids = array();
foreach (core::get('category') as $cat) {
if ($cat !== NULL) {
$category = new Model_Category();
$category->where('seoname', '=', $cat)->cached()->limit(1)->find();
if ($category->loaded()) {
$cat_siblings_ids = array_merge($cat_siblings_ids, $category->get_siblings_ids());
}
}
}
if (count($cat_siblings_ids) > 0) {
$ads->where('id_category', 'IN', $cat_siblings_ids);
}
//.........这里部分代码省略.........
示例8: action_advanced_search
public function action_advanced_search()
{
//template header
$this->template->title = __('Advanced Search');
$this->template->meta_description = __('Advanced Search');
//breadcrumbs
Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Home'))->set_url(Route::url('default')));
Breadcrumbs::add(Breadcrumb::factory()->set_title($this->template->title));
$this->template->scripts['footer'] = array('js/search.js');
// $cat_obj = new Model_Category();
// $loc_obj = new Model_Location();
list($cat_obj, $order_categories) = Model_Category::get_all();
list($loc_obj, $order_locations) = Model_Location::get_all();
$pagination = NULL;
$ads = NULL;
$user = Auth::instance()->get_user() == NULL ? NULL : Auth::instance()->get_user();
if ($this->request->query()) {
// variables
$search_advert = core::get('title');
$search_loc = core::get('location');
// filter by each variable
$ads = new Model_Ad();
//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)'), '>', DB::expr('NOW()'));
}
if (!empty($search_advert) or core::get('search') !== NULL and strlen(core::get('search')) >= 3) {
// if user is using search from header
if (core::get('search')) {
$search_advert = core::get('search');
}
$ads->where_open()->where('title', 'like', '%' . $search_advert . '%')->or_where('description', 'like', '%' . $search_advert . '%')->where_close();
}
$cf_fields = array();
foreach ($this->request->query() as $name => $field) {
// get by prefix
if (strpos($name, 'cf_') !== false) {
$cf_fields[$name] = $field;
//checkbox when selected return string 'on' as a value
if ($field == 'on') {
$cf_fields[$name] = 1;
} elseif (empty($field)) {
$cf_fields[$name] = NULL;
}
}
}
$category = NULL;
//filter by category
if (core::get('category') !== NULL) {
$category = new Model_Category();
$category->where('seoname', '=', core::get('category'))->limit(1)->find();
if ($category->loaded()) {
$ads->where('id_category', 'IN', $category->get_siblings_ids());
}
}
$location = NULL;
//filter by location
if (core::get('location') !== NULL) {
$location = new Model_location();
$location->where('seoname', '=', core::get('location'))->limit(1)->find();
if ($location->loaded()) {
$ads->where('id_location', 'IN', $location->get_siblings_ids());
}
}
//filter by price
if (is_numeric(core::get('price-min')) and is_numeric(core::get('price-max'))) {
$ads->where('price', 'BETWEEN', array(core::get('price-min'), core::get('price-max')));
}
foreach ($cf_fields as $key => $value) {
if (isset($value) and $value != NULL) {
if (is_numeric($value)) {
$ads->where($key, '=', $value);
} elseif (is_string($value)) {
$ads->where($key, 'like', '%' . $value . '%');
}
}
}
$ads = $ads->where('status', '=', Model_Ad::STATUS_PUBLISHED);
// count them for pagination
$res_count = $ads->count_all();
if ($res_count > 0) {
// pagination module
$pagination = Pagination::factory(array('view' => 'pagination', 'total_items' => $res_count, 'items_per_page' => core::config('general.advertisements_per_page')))->route_params(array('controller' => $this->request->controller(), 'action' => $this->request->action(), 'category' => $category !== NULL ? $category->seoname : NULL));
Breadcrumbs::add(Breadcrumb::factory()->set_title(__("Page ") . $pagination->offset));
$ads = $ads->order_by('published', 'desc')->limit($pagination->items_per_page)->offset($pagination->offset)->find_all();
}
}
$this->template->bind('content', $content);
$this->template->content = View::factory('pages/ad/advanced_search', array('ads' => $ads, 'categories' => $cat_obj, 'order_categories' => $order_categories, 'locations' => $loc_obj, 'order_locations' => $order_locations, 'pagination' => $pagination, 'user' => $user, 'fields' => Model_Field::get_all()));
}