本文整理汇总了PHP中Model_Category::get_multidimensional方法的典型用法代码示例。如果您正苦于以下问题:PHP Model_Category::get_multidimensional方法的具体用法?PHP Model_Category::get_multidimensional怎么用?PHP Model_Category::get_multidimensional使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model_Category
的用法示例。
在下文中一共展示了Model_Category::get_multidimensional方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: before
/**
* Automatically executed before the widget action. Can be used to set
* class properties, do authorization checks, and execute other custom code.
*
* @return void
*/
public function before()
{
// get all categories
if ($this->categories != FALSE) {
$this->cat_items = Model_Category::get_as_array();
$this->cat_order_items = Model_Category::get_multidimensional();
}
// get all locations
if ($this->locations != FALSE) {
$this->loc_items = Model_Location::get_as_array();
$this->loc_order_items = Model_Location::get_multidimensional();
}
if ($this->price != FALSE) {
$this->price = TRUE;
}
// user
if (Auth::instance()->logged_in()) {
//subscriber
// check if user is already subscribed
$user_id = Auth::instance()->get_user()->id_user;
$obj_subscriber = new Model_Subscribe();
$subscriber = $obj_subscriber->where('id_user', '=', $user_id)->limit(1)->find();
if ($subscriber->loaded()) {
$this->subscriber = TRUE;
}
//if user logged in pass email and id
$this->user_email = Auth::instance()->get_user()->email;
$this->user_id = $user_id;
} else {
$this->user_id = 0;
}
//min - max price selected
$this->min_price = $this->min_price;
$this->max_price = $this->max_price;
}
示例2: action_new
public function action_new()
{
Breadcrumbs::add(Breadcrumb::factory()->set_title(__('New field')));
$this->template->title = __('New Custom Field for Advertisement');
//find all, for populating form select fields
$categories = Model_Category::get_as_array();
$order_categories = Model_Category::get_multidimensional();
if ($_POST) {
if (count(Model_Field::get_all()) > 65) {
Alert::set(Alert::ERROR, __('You have reached the maximum number of custom fields allowed.'));
HTTP::redirect(Route::url('oc-panel', array('controller' => 'fields', 'action' => 'index')));
}
$name = URL::title(Core::post('name'));
$field = new Model_Field();
try {
$options = array('label' => Core::post('label'), 'tooltip' => Core::post('tooltip'), 'required' => Core::post('required') == 'on' ? TRUE : FALSE, 'searchable' => Core::post('searchable') == 'on' ? TRUE : FALSE, 'admin_privilege' => Core::post('admin_privilege') == 'on' ? TRUE : FALSE, 'show_listing' => Core::post('show_listing') == 'on' ? TRUE : FALSE);
if ($field->create($name, Core::post('type'), Core::post('values'), Core::post('categories'), $options)) {
Core::delete_cache();
Alert::set(Alert::SUCCESS, sprintf(__('Field %s created'), $name));
} else {
Alert::set(Alert::WARNING, sprintf(__('Field %s already exists'), $name));
}
} catch (Exception $e) {
throw HTTP_Exception::factory(500, $e->getMessage());
}
HTTP::redirect(Route::url('oc-panel', array('controller' => 'fields', 'action' => 'index')));
}
$this->template->content = View::factory('oc-panel/pages/fields/new', array('categories' => $categories, 'order_categories' => $order_categories));
}
示例3: before
/**
* Automatically executed before the widget action. Can be used to set
* class properties, do authorization checks, and execute other custom code.
*
* @return void
*/
public function before()
{
// get all categories
if ($this->advanced != FALSE) {
$this->cat_items = Model_Category::get_as_array();
$this->cat_order_items = Model_Category::get_multidimensional();
$this->selected_category = NULL;
if (core::request('category')) {
$this->selected_category = core::request('category');
} elseif (Model_Category::current()->loaded()) {
$this->selected_category = core::config('general.search_multi_catloc') ? array(Model_Category::current()->seoname) : Model_Category::current()->seoname;
}
// get all locations
$this->loc_items = Model_Location::get_as_array();
$this->loc_order_items = Model_Location::get_multidimensional();
$this->selected_location = NULL;
if (core::request('location')) {
$this->selected_location = core::request('location');
} elseif (Model_Location::current()->loaded()) {
$this->selected_location = core::config('general.search_multi_catloc') ? array(Model_Location::current()->seoname) : Model_Location::current()->seoname;
}
}
if ($this->custom != FALSE) {
$fields = Model_Field::get_all();
$this->custom_fields = $fields;
}
}
示例4: before
/**
* Automatically executed before the widget action. Can be used to set
* class properties, do authorization checks, and execute other custom code.
*
* @return void
*/
public function before()
{
// get all categories
if ($this->advanced != FALSE) {
$this->cat_items = Model_Category::get_as_array();
$this->cat_order_items = Model_Category::get_multidimensional();
}
if ($this->custom != FALSE) {
$fields = Model_Field::get_all();
$this->custom_fields = $fields;
}
}
示例5: action_index
/**
* overwrites the default crud index
* @param string $view nothing since we don't use it
* @return void
*/
public function action_index($view = NULL)
{
//HTTP::redirect(Route::url('oc-panel',array('controller' => 'category','action'=>'dashboard')));
//template header
$this->template->title = __('Categories');
Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Categories')));
$this->template->styles = array('css/sortable.css' => 'screen');
$this->template->scripts['footer'][] = 'js/jquery-sortable-min.js';
$this->template->scripts['footer'][] = 'js/oc-panel/categories.js';
$cats = Model_Category::get_as_array();
$order = Model_Category::get_multidimensional();
$this->template->content = View::factory('oc-panel/pages/categories/index', array('cats' => $cats, 'order' => $order));
}
示例6: action_index
/**
* overwrites the default crud index
* @param string $view nothing since we don't use it
* @return void
*/
public function action_index($view = NULL)
{
//HTTP::redirect(Route::url('oc-panel',array('controller' => 'category','action'=>'dashboard')));
//template header
$this->template->title = __('Categories');
Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Categories')));
$this->template->styles = array('css/sortable.css' => 'screen', '//cdn.jsdelivr.net/bootstrap.tagsinput/0.3.9/bootstrap-tagsinput.css' => 'screen');
$this->template->scripts['footer'][] = 'js/jquery-sortable-min.js';
$this->template->scripts['footer'][] = 'js/oc-panel/categories.js';
$this->template->scripts['footer'][] = '//cdn.jsdelivr.net/bootstrap.tagsinput/0.3.9/bootstrap-tagsinput.min.js';
$cats = Model_Category::get_as_array();
$order = Model_Category::get_multidimensional();
$hide_homepage_categories = json_decode(core::config('general.hide_homepage_categories'), TRUE);
$this->template->content = View::factory('oc-panel/pages/categories/index', array('cats' => $cats, 'order' => $order, 'hide_homepage_categories' => $hide_homepage_categories));
}
示例7: action_update
public function action_update()
{
$name = $this->request->param('id');
$menu_data = Menu::get_item($name);
Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Edit Menu') . ' ' . $menu_data['title']));
$this->template->title = __('Edit Menu');
$this->template->styles = array('css/sortable.css' => 'screen');
$this->template->scripts['footer'][] = 'js/jquery-sortable-min.js';
$this->template->scripts['footer'][] = 'js/oc-panel/menu.js';
//find all, for populating form select fields
$categories = Model_Category::get_as_array();
$order_categories = Model_Category::get_multidimensional();
if ($_POST) {
if (Menu::update($name, Core::post('title'), Core::post('url'), Core::post('target'), Core::post('icon'))) {
Alert::set(Alert::SUCCESS, __('Menu updated'));
} else {
Alert::set(Alert::ERROR, __('Menu not updated'));
}
HTTP::redirect(Route::url('oc-panel', array('controller' => 'menu', 'action' => 'index')));
}
// d($categories);
$this->template->content = View::factory('oc-panel/pages/menu/update', array('menu_data' => $menu_data, 'name' => $name, 'categories' => $categories, 'order_categories' => $order_categories));
}
示例8: action_update
/**
* Edit advertisement: Update
*
* All post fields are validated
*/
public function action_update()
{
//template header
$this->template->title = __('Edit advertisement');
$this->template->meta_description = __('Edit advertisement');
Controller::$full_width = TRUE;
//local files
if (Theme::get('cdn_files') == FALSE) {
$this->template->styles = array('css/jquery.sceditor.default.theme.min.css' => 'screen');
$this->template->scripts['footer'] = array('js/jquery.sceditor.bbcode.min.js', 'js/jquery.chained.min.js', '//maps.google.com/maps/api/js?sensor=false&libraries=geometry&v=3.7', '//cdn.jsdelivr.net/gmaps/0.4.15/gmaps.min.js', 'js/oc-panel/edit_ad.js');
} else {
$this->template->styles = array('css/jquery.sceditor.default.theme.min.css' => 'screen');
$this->template->scripts['footer'] = array('js/jquery.sceditor.bbcode.min.js', 'js/jquery.chained.min.js', '//maps.google.com/maps/api/js?sensor=false&libraries=geometry&v=3.7', '//cdn.jsdelivr.net/gmaps/0.4.15/gmaps.min.js', 'js/oc-panel/edit_ad.js');
}
Breadcrumbs::add(Breadcrumb::factory()->set_title(__('My ads'))->set_url(Route::url('oc-panel', array('controller' => 'myads', 'action' => 'index'))));
$form = new Model_Ad($this->request->param('id'));
if (Auth::instance()->get_user()->id_user == $form->id_user or Auth::instance()->get_user()->id_role == Model_Role::ROLE_ADMIN or Auth::instance()->get_user()->id_role == Model_Role::ROLE_MODERATOR) {
$original_category = $form->category;
$extra_payment = core::config('payment');
$cat = new Model_Category();
$loc = new Model_Location();
//find all, for populating form select fields
$categories = Model_Category::get_as_array();
$order_categories = Model_Category::get_multidimensional();
$parent_category = Model_Category::get_by_deep();
//get locations
$locations = Model_Location::get_as_array();
$order_locations = Model_Location::get_multidimensional();
$loc_parent_deep = Model_Location::get_by_deep();
if ($this->request->post()) {
// deleting single image by path
if (is_numeric($deleted_image = core::post('img_delete'))) {
$form->delete_image($deleted_image);
//TODO! usage of the api?
die;
}
// end of img delete
$data = $this->request->post();
//to make it backward compatible with older themes: UGLY!!
if (isset($data['category']) and is_numeric($data['category'])) {
$data['id_category'] = $data['category'];
unset($data['category']);
}
if (isset($data['location']) and is_numeric($data['location'])) {
$data['id_location'] = $data['location'];
unset($data['location']);
}
$return = $form->save_ad($data);
//there was an error on the validation
if (isset($return['validation_errors']) and is_array($return['validation_errors'])) {
foreach ($return['validation_errors'] as $f => $err) {
Alert::set(Alert::ALERT, $err);
}
} elseif (isset($return['error'])) {
Alert::set($return['error_type'], $return['error']);
} elseif (isset($return['message'])) {
// IMAGE UPLOAD
// in case something wrong happens user is redirected to edit advert.
$filename = NULL;
for ($i = 0; $i < core::config("advertisement.num_images"); $i++) {
if (isset($_FILES['image' . $i])) {
$filename = $form->save_image($_FILES['image' . $i]);
}
}
if ($filename !== NULL) {
$form->last_modified = Date::unix2mysql();
try {
$form->save();
} catch (Exception $e) {
throw HTTP_Exception::factory(500, $e->getMessage());
}
}
Alert::set(Alert::SUCCESS, $return['message']);
//redirect user to pay
if (isset($return['checkout_url']) and !empty($return['checkout_url'])) {
$this->redirect($return['checkout_url']);
}
}
$this->redirect(Route::url('oc-panel', array('controller' => 'myads', 'action' => 'update', 'id' => $form->id_ad)));
}
//get all orders
$orders = new Model_Order();
$orders = $orders->where('id_user', '=', $form->id_user)->where('status', '=', Model_Order::STATUS_CREATED)->where('id_ad', '=', $form->id_ad)->find_all();
Breadcrumbs::add(Breadcrumb::factory()->set_title("Update"));
$this->template->content = View::factory('oc-panel/profile/edit_ad', array('ad' => $form, 'locations' => $locations, 'order_locations' => $order_locations, 'categories' => $categories, 'order_categories' => $order_categories, 'order_parent_deep' => $parent_category, 'loc_parent_deep' => $loc_parent_deep, 'extra_payment' => $extra_payment, 'orders' => $orders, 'fields' => Model_Field::get_all()));
} else {
Alert::set(Alert::ERROR, __('You dont have permission to access this link'));
$this->redirect(Route::url('default'));
}
}
示例9: action_advanced_search
//.........这里部分代码省略.........
}
}
$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')))) {
// handle comma (,) used in some countries for prices
$price_min = (double) $price_min;
}
// round((float)$price_min,2)
if (is_numeric($price_max = str_replace(',', '.', core::get('price-max')))) {
// handle comma (,) used in some countries for prices
$price_max = (double) $price_max;
}
// round((float)$price_max,2)
if ($price_min and $price_max) {
if ($price_min > $price_max) {
// swap 2 values
$price_min = $price_max + $price_min - ($price_max = $price_min);
}
$ads->where('price', 'BETWEEN', array($price_min, $price_max));
} elseif ($price_min) {
$ads->where('price', '>=', $price_min);
} elseif ($price_max) {
$ads->where('price', '<=', $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 . '%');
}
}
}
// 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('advertisement.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();
} else {
$ads = NULL;
}
}
$this->template->bind('content', $content);
$this->template->content = View::factory('pages/ad/advanced_search', array('ads' => $ads, 'categories' => Model_Category::get_as_array(), 'order_categories' => Model_Category::get_multidimensional(), 'locations' => Model_Location::get_as_array(), 'order_locations' => Model_Location::get_multidimensional(), 'pagination' => $pagination, 'user' => $user, 'fields' => Model_Field::get_all()));
}
示例10: action_update
public function action_update()
{
//template header
$this->template->title = __('Edit Product');
Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Edit Product')));
$this->template->styles = array('css/sortable.css' => 'screen', '//cdn.jsdelivr.net/bootstrap.datepicker/0.1/css/datepicker.css' => 'screen', '//cdn.jsdelivr.net/jquery.fileupload/9.5.2/css/jquery.fileupload.css' => 'screen', 'css/jasny-bootstrap.min.css' => 'screen');
$this->template->scripts['footer'] = array('//cdn.jsdelivr.net/bootstrap.datepicker/0.1/js/bootstrap-datepicker.js', 'js/jasny-bootstrap.min.js', 'js/oc-panel/products.js', 'js/jquery-sortable-min.js', '//cdn.jsdelivr.net/jquery.fileupload/9.5.2/js/vendor/jquery.ui.widget.js', '//cdn.jsdelivr.net/jquery.fileupload/9.5.2/js/jquery.iframe-transport.js', '//cdn.jsdelivr.net/jquery.fileupload/9.5.2/js/jquery.fileupload.js');
$cats = Model_Category::get_as_array();
$order = Model_Category::get_multidimensional();
$obj_product = new Model_Product($this->request->param('id'));
if ($obj_product->loaded()) {
// get currencies from product, returns array
$currency = $obj_product::get_currency();
$this->template->content = View::factory('oc-panel/pages/products/update', array('product' => $obj_product, 'categories' => $cats, 'order_categories' => $order, 'currency' => $currency));
if ($product = $this->request->post()) {
// save product file
if (isset($_FILES['file_name'])) {
if ($file = $_FILES['file_name']) {
$file = $obj_product->save_product($file);
if ($file != FALSE) {
$obj_product->file_name = $file;
} else {
Alert::set(Alert::INFO, __('Product is not uploaded.'));
}
}
}
// deleting single image by path
$deleted_image = core::post('img_delete');
if (is_numeric($deleted_image)) {
$img_path = $obj_product->gen_img_path($obj_product->id_product, $obj_product->created);
$img_seoname = $obj_product->seotitle;
// delete image from Amazon S3
if (core::config('image.aws_s3_active')) {
require_once Kohana::find_file('vendor', 'amazon-s3-php-class/S3', 'php');
$s3 = new S3(core::config('image.aws_access_key'), core::config('image.aws_secret_key'));
//delete original image
$s3->deleteObject(core::config('image.aws_s3_bucket'), $img_path . $img_seoname . '_' . $deleted_image . '.jpg');
//delete formated image
$s3->deleteObject(core::config('image.aws_s3_bucket'), $img_path . 'thumb_' . $img_seoname . '_' . $deleted_image . '.jpg');
//re-ordering image file names
for ($i = $deleted_image; $i < $obj_product->has_images; $i++) {
//rename original image
$s3->copyObject(core::config('image.aws_s3_bucket'), $img_path . $img_seoname . '_' . ($i + 1) . '.jpg', core::config('image.aws_s3_bucket'), $img_path . $img_seoname . '_' . $i . '.jpg', S3::ACL_PUBLIC_READ);
$s3->deleteObject(core::config('image.aws_s3_bucket'), $img_path . $img_seoname . '_' . ($i + 1) . '.jpg');
//rename formated image
$s3->copyObject(core::config('image.aws_s3_bucket'), $img_path . 'thumb_' . $img_seoname . '_' . ($i + 1) . '.jpg', core::config('image.aws_s3_bucket'), $img_path . 'thumb_' . $img_seoname . '_' . $i . '.jpg', S3::ACL_PUBLIC_READ);
$s3->deleteObject(core::config('image.aws_s3_bucket'), $img_path . 'thumb_' . $img_seoname . '_' . ($i + 1) . '.jpg');
}
}
if (!is_dir($img_path)) {
return FALSE;
} else {
//delete original image
@unlink($img_path . $img_seoname . '_' . $deleted_image . '.jpg');
//delete formated image
@unlink($img_path . 'thumb_' . $img_seoname . '_' . $deleted_image . '.jpg');
//re-ordering image file names
for ($i = $deleted_image; $i < $obj_product->has_images; $i++) {
rename($img_path . $img_seoname . '_' . ($i + 1) . '.jpg', $img_path . $img_seoname . '_' . $i . '.jpg');
rename($img_path . 'thumb_' . $img_seoname . '_' . ($i + 1) . '.jpg', $img_path . 'thumb_' . $img_seoname . '_' . $i . '.jpg');
}
}
$obj_product->has_images = $obj_product->has_images > 0 ? $obj_product->has_images - 1 : 0;
$obj_product->updated = Date::unix2mysql();
try {
$obj_product->save();
} catch (Exception $e) {
throw HTTP_Exception::factory(500, $e->getMessage());
}
$this->redirect(Route::url('oc-panel', array('controller' => 'product', 'action' => 'update', 'id' => $obj_product->id_product)));
}
// end of img delete
//delete product file
$product_delete = core::post('product_delete');
if ($product_delete) {
$p_path = $obj_product->get_file($obj_product->file_name);
if (!is_file($p_path)) {
return FALSE;
} else {
@chmod($p_path, 0755);
//delete product
unlink($p_path);
$obj_product->file_name = '';
$obj_product->save();
$this->redirect(Route::url('oc-panel', array('controller' => 'product', 'action' => 'update', 'id' => $obj_product->id_product)));
}
}
$product['status'] = (!isset($_POST['status']) or core::post('status') === NULL) ? Model_Product::STATUS_NOACTIVE : Model_Product::STATUS_ACTIVE;
$product['updated'] = Date::unix2mysql();
//we do this so we assure use the entire day , nasty
$product['offer_valid'] .= ' 23:59:59';
$product['featured'] .= ' 23:59:59';
// each field in edit product
foreach ($product as $field => $value) {
// do not include submit
if ($field != 'submit' and $field != 'notify') {
// check if its different, and set it is
if ($value != $obj_product->{$field}) {
$obj_product->{$field} = $value;
// if title is changed, make new seotitle
//.........这里部分代码省略.........
示例11: action_index
/**
*
* NEW ADVERTISEMENT
*
*/
public function action_index()
{
//Detect early spam users, show him alert
if (core::config('general.black_list') == TRUE and Model_User::is_spam(Core::post('email')) === TRUE) {
Alert::set(Alert::ALERT, __('Your profile has been disable for posting, due to recent spam content! If you think this is a mistake please contact us.'));
$this->redirect('default');
}
//advertisement.only_admin_post
if (Core::config('advertisement.only_admin_post') == 1 and (!Auth::instance()->logged_in() or Auth::instance()->logged_in() and Auth::instance()->get_user()->id_role != Model_Role::ROLE_ADMIN)) {
$this->redirect('default');
}
if (Core::post('ajaxValidateCaptcha')) {
$this->auto_render = FALSE;
$this->template = View::factory('js');
if (captcha::check('publish_new', TRUE)) {
$this->template->content = 'true';
} else {
$this->template->content = 'false';
}
return;
}
//template header
$this->template->title = __('Publish new advertisement');
$this->template->meta_description = __('Publish new advertisement');
$this->template->styles = array('css/jquery.sceditor.default.theme.min.css' => 'screen', 'css/jasny-bootstrap.min.css' => 'screen', '//cdn.jsdelivr.net/sweetalert/0.1.2/sweet-alert.min.css' => 'screen');
$this->template->scripts['footer'][] = 'js/jquery.sceditor.bbcode.min.js';
$this->template->scripts['footer'][] = 'js/jasny-bootstrap.min.js';
$this->template->scripts['footer'][] = 'js/jquery.chained.min.js';
$this->template->scripts['footer'][] = '//cdn.jsdelivr.net/sweetalert/0.1.2/sweet-alert.min.js';
$this->template->scripts['footer'][] = '//cdnjs.cloudflare.com/ajax/libs/ouibounce/0.0.10/ouibounce.min.js';
if (core::config('advertisement.map_pub_new')) {
$this->template->scripts['footer'][] = '//maps.google.com/maps/api/js?sensor=false&libraries=geometry&v=3.7';
$this->template->scripts['footer'][] = '//cdn.jsdelivr.net/gmaps/0.4.15/gmaps.min.js';
}
$this->template->scripts['footer'][] = 'js/new.js?v=' . Core::VERSION;
// redirect to login, if conditions are met
if (core::config('advertisement.login_to_post') == TRUE and !Auth::instance()->logged_in()) {
Alert::set(Alert::INFO, __('Please, login before posting advertisement!'));
HTTP::redirect(Route::url('oc-panel', array('controller' => 'auth', 'action' => 'login')));
}
//find all, for populating form select fields
$categories = Model_Category::get_as_array();
$order_categories = Model_Category::get_multidimensional();
$order_parent_deep = Model_Category::get_by_deep();
// NO categories redirect ADMIN to categories panel
if (count($order_categories) == 0) {
if (Auth::instance()->logged_in() and Auth::instance()->get_user()->id_role == Model_Role::ROLE_ADMIN) {
Alert::set(Alert::INFO, __('Please, first create some categories.'));
$this->redirect(Route::url('oc-panel', array('controller' => 'category', 'action' => 'index')));
} else {
Alert::set(Alert::INFO, __('Posting advertisements is not yet available.'));
$this->redirect('default');
}
}
//get locations
$locations = Model_Location::get_as_array();
$order_locations = Model_Location::get_multidimensional();
$loc_parent_deep = Model_Location::get_by_deep();
// bool values from DB, to show or hide this fields in view
$form_show = array('captcha' => core::config('advertisement.captcha'), 'website' => core::config('advertisement.website'), 'phone' => core::config('advertisement.phone'), 'location' => core::config('advertisement.location'), 'address' => core::config('advertisement.address'), 'price' => core::config('advertisement.price'));
$id_category = NULL;
$selected_category = new Model_Category();
//if theres a category by post or by get
if (Core::request('category') !== NULL) {
if (is_numeric(Core::request('category'))) {
$selected_category->where('id_category', '=', core::request('category'))->limit(1)->find();
} else {
$selected_category->where('seoname', '=', core::request('category'))->limit(1)->find();
}
if ($selected_category->loaded()) {
$id_category = $selected_category->id_category;
}
}
$id_location = NULL;
$selected_location = new Model_Location();
//if theres a location by post or by get
if (Core::request('location') !== NULL) {
if (is_numeric(Core::request('location'))) {
$selected_location->where('id_location', '=', core::request('location'))->limit(1)->find();
} else {
$selected_location->where('seoname', '=', core::request('location'))->limit(1)->find();
}
if ($selected_location->loaded()) {
$id_location = $selected_location->id_location;
}
}
//render view publish new
$this->template->content = View::factory('pages/ad/new', array('categories' => $categories, 'order_categories' => $order_categories, 'order_parent_deep' => $order_parent_deep, 'locations' => $locations, 'order_locations' => $order_locations, 'loc_parent_deep' => $loc_parent_deep, 'form_show' => $form_show, 'id_category' => $id_category, 'selected_category' => $selected_category, 'id_location' => $id_location, 'selected_location' => $selected_location, 'fields' => Model_Field::get_all()));
if ($this->request->post()) {
if (captcha::check('publish_new')) {
$data = $this->request->post();
$validation = Validation::factory($data);
//validate location since its optional
if (core::config('advertisement.location')) {
if (count($locations) > 1) {
//.........这里部分代码省略.........
示例12: 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));
}
示例13: action_advanced_search
//.........这里部分代码省略.........
} elseif (is_array($value)) {
if (!empty($value = array_filter($value))) {
$ads->where($key, 'IN', $value);
}
}
}
}
//filter by user
if (count($cf_user_fields) > 0) {
$users = new Model_User();
foreach ($cf_user_fields as $key => $value) {
if (is_numeric($value)) {
$users->where($key, '=', $value);
} elseif (is_string($value)) {
$users->where($key, 'like', '%' . $value . '%');
} elseif (is_array($value)) {
if (!empty($value = array_filter($value))) {
$ads->where($key, 'IN', $value);
}
}
}
$users = $users->find_all();
if ($users->count() > 0) {
$ads->where('id_user', 'in', $users->as_array());
} else {
$ads->where('id_user', '=', 0);
}
}
// 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('advertisement.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));
/**
* order depending on the sort parameter
*/
switch (core::request('sort', core::config('advertisement.sort_by'))) {
//title z->a
case 'title-asc':
$ads->order_by('title', 'asc')->order_by('published', 'desc');
break;
//title a->z
//title a->z
case 'title-desc':
$ads->order_by('title', 'desc')->order_by('published', 'desc');
break;
//cheaper first
//cheaper first
case 'price-asc':
$ads->order_by('price', 'asc')->order_by('published', 'desc');
break;
//expensive first
//expensive first
case 'price-desc':
$ads->order_by('price', 'desc')->order_by('published', 'desc');
break;
//featured
//featured
case 'featured':
$ads->order_by('featured', 'desc')->order_by('published', 'desc');
break;
//rating
//rating
case 'rating':
$ads->order_by('rate', 'desc')->order_by('published', 'desc');
break;
//favorited
//favorited
case 'favorited':
$ads->order_by('favorited', 'desc')->order_by('published', 'desc');
break;
//distance
//distance
case 'distance':
if (Model_User::get_userlatlng() and core::config('general.auto_locate')) {
$ads->order_by('distance', 'asc')->order_by('published', 'asc');
}
break;
//oldest first
//oldest first
case 'published-asc':
$ads->order_by('published', 'asc');
break;
//newest first
//newest first
case 'published-desc':
default:
$ads->order_by('published', 'desc');
break;
}
//we sort all ads with few parameters
$ads = $ads->limit($pagination->items_per_page)->offset($pagination->offset)->find_all();
} else {
$ads = NULL;
}
}
$this->template->bind('content', $content);
$this->template->content = View::factory('pages/ad/advanced_search', array('ads' => $ads, 'categories' => Model_Category::get_as_array(), 'order_categories' => Model_Category::get_multidimensional(), 'locations' => Model_Location::get_as_array(), 'order_locations' => Model_Location::get_multidimensional(), 'pagination' => $pagination, 'user' => $user, 'fields' => Model_Field::get_all(), 'total_ads' => $res_count));
}