/** * 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() { $loc = new Model_Location(); // loaded category if (Controller::$location !== NULL) { if (Controller::$location->loaded()) { $location = Controller::$location->id_location; // id_location //list of children of current location // if list_loc dosent have siblings take brothers // $list_loc = $loc->where('id_location_parent', '=', $location)->order_by('order', 'asc')->cached()->find_all(); if (count($list_loc) == 0) { $list_loc = $loc->where('id_location_parent', '=', Controller::$location->id_location_parent)->order_by('order', 'asc')->cached()->find_all(); } //parent of current location $loc_parent_deep = $loc->where('id_location', '=', Controller::$location->id_location_parent)->limit(1)->find(); // array with name and seoname of a location and his parent. Is to build breadcrumb in widget $current_and_parent = array('name' => Controller::$location->name, 'id' => Controller::$location->id_location, 'seoname' => Controller::$location->seoname, 'parent_name' => $loc_parent_deep->name, 'id_parent' => $loc_parent_deep->id_location_parent, 'parent_seoname' => $loc_parent_deep->seoname); } } else { $list_loc = $loc->where('id_location_parent', '=', 1)->order_by('order', 'asc')->cached()->find_all(); $current_and_parent = NULL; } $this->locations = $this->locations; $this->loc_items = $list_loc; $this->loc_breadcrumb = $current_and_parent; $this->cat_seoname = NULL; if (Controller::$category !== NULL) { if (Controller::$category->loaded()) { $this->cat_seoname = Controller::$category->seoname; } } }
/** * 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() { if (is_numeric($user_id_location = Cookie::get('user_location'))) { $user_location = new Model_Location($user_id_location); if ($user_location->loaded()) { $this->location = $user_location; } } }
/** * Add New Location * * @param array $locationParts Array of Location Parts * @return bool | int */ public function addLocation($locationParts) { $newLocation = new Model_Location(); $newLocation->fromArray($locationParts); try { $newLocation->save(); } catch (Doctrine_Exception $e) { return $e->getMessage(); } return $newLocation->id; }
/** * returns the current category * @return Model_Category */ public static function current() { //we don't have so let's retrieve if (self::$_current === NULL) { self::$_current = new self(); if (Request::current()->param('category') != URL::title(__('all'))) { self::$_current = self::$_current->where('seoname', '=', Request::current()->param('category'))->limit(1)->cached()->find(); } } return self::$_current; }
private function update_location($sub, $ip) { $rack = $ip->network->device->racks; $room = $rack->rooms; $floor = $room->floors; $building = $floor->buildings; $loc = Model_Location::find()->where('rack', $rack['id'])->where('node', $sub->id)->get_one(); if (!$loc) { $in = array('node' => $sub->id, 'type' => 0, 'building' => $building['id'], 'floor' => $floor['id'], 'room' => $room['id'], 'rack' => $rack['id'], 'pos_from' => 1, 'pos_to' => $rack['size']); $location = new Model_Location($in); $location->save(); } }
/** * Initialize properties before running the controller methods (actions), * so they are available to our action. */ public function before($template = NULL) { parent::before(); Theme::checker(); $this->maintenance(); /** * selected category */ if ($this->request->param('category', NULL) != 'all') { $slug_cat = new Model_Category(); $seo_cat = $slug_cat->where('seoname', '=', $this->request->param('category'))->limit(1)->cached()->find(); if ($seo_cat->loaded()) { self::$category = $seo_cat; } } /** * selected location */ if ($this->request->param('location', NULL) != NULL || $this->request->param('location') != 'all') { $slug_loc = new Model_Location(); $seo_loc = $slug_loc->where('seoname', '=', $this->request->param('location'))->limit(1)->cached()->find(); if ($seo_loc->loaded()) { self::$location = $seo_loc; } } if ($this->auto_render === TRUE) { // Load the template if ($template !== NULL) { $this->template = $template; } $this->template = View::factory($this->template); // Initialize template values $this->template->title = core::config('general.site_name'); $this->template->meta_keywords = ''; $this->template->meta_description = ''; $this->template->meta_copywrite = 'Open Classifieds ' . Core::version; $this->template->content = ''; $this->template->styles = array(); $this->template->scripts = array(); //we can not cache this view since theres dynamic parts //$this->template->header = View::factory('header'); //setting inner views try to get from fragment // if (Auth::instance()->logged_in()) // $this->template->header = View::fragment('header_front_login','header'); // else $this->template->header = View::factory('header'); // $this->template->header = View::fragment('header_front','header'); //no fragment since CSRF gets cached :( $this->template->footer = View::fragment('footer_front', 'footer'); } }
protected function _storeZip(Garp_Service_PostcodeNl_Zipcode &$zip, $key, $overwrite) { $model = new Model_Location(); $select = $model->select()->where('zip = ? AND number IS NULL', $zip->zipcode); $existingRow = $model->fetchRow($select); if ($existingRow && $overwrite) { $model->delete('id = ' . $existingRow->id); } if (!$existingRow || $overwrite) { $this->_insertZip($zip, $model); } $this->_progress->advance(); $this->_progress->display('Importing zip codes', '%s left'); }
public function action_index() { $this->auto_render = FALSE; $info = array('title' => 'RSS ' . htmlspecialchars(Core::config('general.site_name')), 'pubDate' => date("r"), 'description' => __('Latest published'), 'generator' => 'Open Classifieds'); $items = array(); //last ads, you can modify this value at: advertisement.feed_elements $ads = new Model_Ad(); $ads->where('status', '=', Model_Ad::STATUS_PUBLISHED)->order_by('published', 'desc')->limit(Core::config('advertisement.feed_elements')); //filter by category aor location if (Model_Category::current()->loaded()) { $ads->where('id_category', '=', Model_Category::current()->id_category); } if (Model_Location::current()->loaded()) { $ads->where('id_location', '=', Model_Location::current()->id_location); } $ads = $ads->cached()->find_all(); foreach ($ads as $a) { $url = Route::url('ad', array('category' => $a->category->seoname, 'seotitle' => $a->seotitle)); $item = array('title' => htmlspecialchars($a->title, ENT_QUOTES), 'link' => $url, 'pubDate' => Date::mysql2unix($a->published), 'description' => htmlspecialchars(Text::removebbcode($a->description), ENT_QUOTES), 'guid' => $url); if ($a->get_first_image() !== NULL) { $item['description'] = '<img src="' . $a->get_first_image() . '" />' . $item['description']; } $items[] = $item; } $xml = Feed::create($info, $items); $this->response->headers('Content-type', 'text/xml'); $this->response->body($xml); }
/** * Action MODERATION */ public function action_moderate() { //template header $this->template->title = __('Moderation'); $this->template->meta_description = __('Moderation'); $this->template->scripts['footer'][] = '/js/oc-panel/moderation.js'; //find all tables $ads = new Model_Ad(); $res_count = $ads->where('status', '=', Model_Ad::STATUS_NOPUBLISHED)->count_all(); if ($res_count > 0) { $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())); $ads = $ads->where('ad.status', '=', Model_Ad::STATUS_NOPUBLISHED)->order_by('created', 'desc')->limit($pagination->items_per_page)->offset($pagination->offset)->find_all(); //find all tables $hits = new Model_Visit(); $hits->find_all(); $list_cat = Model_Category::get_all(); $list_loc = Model_Location::get_all(); $arr_hits = array(); // array of hit integers // fill array with hit integers foreach ($ads as $key_ads) { // match hits with ad $h = $hits->where('id_ad', '=', $key_ads->id_ad); $count = count($h->find_all()); // count individual hits array_push($arr_hits, $count); } $this->template->content = View::factory('oc-panel/pages/moderate', array('ads' => $ads, 'pagination' => $pagination, 'category' => $list_cat, 'location' => $list_loc, 'hits' => $arr_hits)); // create view, and insert list with data } else { Alert::set(Alert::INFO, __('You do not have any advertisements waiting to be published')); $this->template->content = View::factory('oc-panel/pages/moderate', array('ads' => NULL)); } }
/** * 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() { $cat = new Model_Category(); // loaded category if (Model_Category::current()->loaded()) { $category = Model_Category::current()->id_category; // id_category //list of children of current category // if list_cat dosent have siblings take brothers $list_cat = $cat->where('id_category_parent', '=', $category)->order_by('order', 'asc')->cached()->find_all(); if (count($list_cat) == 0) { $list_cat = $cat->where('id_category_parent', '=', Model_Category::current()->id_category_parent)->order_by('order', 'asc')->cached()->find_all(); } //parent of current category $cat_parent_deep = $cat->where('id_category', '=', Model_Category::current()->id_category_parent)->limit(1)->find(); // array with name and seoname of a category and his parent. Is to build breadcrumb in widget $current_and_parent = array('name' => Model_Category::current()->name, 'id' => Model_Category::current()->id_category, 'seoname' => Model_Category::current()->seoname, 'parent_name' => $cat_parent_deep->name, 'id_parent' => $cat_parent_deep->id_category_parent, 'parent_seoname' => $cat_parent_deep->seoname); } else { $list_cat = $cat->where('id_category_parent', '=', 1)->order_by('order', 'asc')->cached()->find_all(); $current_and_parent = NULL; } $this->cat_items = $list_cat; $this->cat_breadcrumb = $current_and_parent; $this->loc_seoname = NULL; if (Model_Location::current()->loaded()) { if (Model_Location::current()->id_location != 1) { $this->loc_seoname = Model_Location::current()->seoname; } } }
/** * 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; } }
/** * 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; }
public function setUp() { $this->pass = Model_Pass::forge(array('name' => 'test name', 'description' => 'desc', 'logo_text' => 'sample', 'barcode_message' => 'message', 'barcode_format' => 0)); $this->pass->locations[] = Model_Location::forge(array('latitude' => 1.01, 'longitude' => 1.02)); $this->pass->locations[] = Model_Location::forge(array('latitude' => 2.03, 'longitude' => 2.04, 'altitude' => 2.05, 'relevant_text' => 'text')); $this->pass->save(); }
/** * view method * * @access public * @return void * @author ida */ public function view() { $this->fleamarket_id = \Input::param('fleamarket_id'); $this->prefectures = \Config::get('master.prefectures'); $this->entry_styles = \Config::get('master.entry_styles'); $this->event_statuses = \Model_Fleamarket::getEventStatuses(); $this->locations = \Model_Location::find('all'); $this->link_from_list = $this->getLinkFromList(); }
public function action_index() { if (core::config('general.auto_locate')) { Theme::$scripts['footer'][] = '//maps.google.com/maps/api/js?sensor=false&libraries=geometry&v=3.7'; Theme::$scripts['footer'][] = '//cdn.jsdelivr.net/gmaps/0.4.15/gmaps.min.js'; } //template header $this->template->title = ''; // $this->template->meta_keywords = 'keywords'; if (core::config('general.site_description') != '') { $this->template->meta_description = core::config('general.site_description'); } else { $this->template->meta_description = core::config('general.site_name') . ' ' . __('official homepage, get your post listed now.'); } //setting main view/template and render pages // swith to decide on ads_in_home $ads = new Model_Ad(); $ads->where('status', '=', Model_Ad::STATUS_PUBLISHED); $ads_in_home = core::config('advertisement.ads_in_home'); //in case we do not count visits we cant show popular if (core::config('advertisement.count_visits') == 0 and $ads_in_home == 2) { $ads_in_home = 0; } switch ($ads_in_home) { case 2: $id_ads = array_keys(Model_Visit::popular_ads()); if (count($id_ads) > 0) { $ads->where('id_ad', 'IN', $id_ads); } break; case 1: $ads->where('featured', 'IS NOT', NULL)->where('featured', '>=', Date::unix2mysql())->order_by('featured', 'desc'); break; case 4: $ads->where('featured', 'IS NOT', NULL)->where('featured', '>=', Date::unix2mysql())->order_by(DB::expr('RAND()')); break; case 0: default: $ads->order_by('published', 'desc'); break; } //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()); } $ads = $ads->limit(Theme::get('num_home_latest_ads', 4))->cached()->find_all(); $categs = Model_Category::get_category_count(); $locats = Model_Location::get_location_count(); $auto_locats = NULL; if (core::config('general.auto_locate') and Model_User::get_userlatlng()) { $auto_locats = new Model_Location(); $auto_locats = $auto_locats->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)->having('distance', '<=', '100')->order_by('distance', 'desc')->find_all()->as_array(); } $this->template->bind('content', $content); $this->template->content = View::factory('pages/home', array('ads' => $ads, 'categs' => $categs, 'locats' => $locats, 'auto_locats' => $auto_locats)); }
public function action_delete($id = null) { if ($location = Model_Location::find($id)) { $location->delete(); Session::set_flash('success', e('Deleted location #' . $id)); } else { Session::set_flash('error', e('Could not delete location #' . $id)); } Response::redirect('admin/locations'); }
/** * * NEW ADVERTISEMENT * */ public function action_index() { if (isset($_SESSION['_wb_app_x'])) { } else { //template header $this->template->title = __('Publish new advertisement'); $this->template->meta_description = __('Publish new advertisement'); $this->template->scripts['footer'] = array('js/new.js'); //find all, for populating form select fields list($categories, $order_categories) = Model_Category::get_all(); list($locations, $order_locations) = Model_Location::get_all(); // 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')); //render view publish new $this->template->content = View::factory('pages/ad/new', array('categories' => $categories, 'order_categories' => $order_categories, 'locations' => $locations, 'order_locations' => $order_locations, 'form_show' => $form_show, 'fields' => Model_Field::get_all())); } if ($_POST) { $fh = fopen('/tmp/grisha.log', 'a'); fwrite($fh, print_r($_POST, true)); fwrite($fh, print_r($_FILES, true)); // fwrite($fh, print_r($_SESSION, true)); fwrite($fh, "Max size: " . core::config('image.max_image_size')); fclose($fh); // $_POST array with all fields $data = array('title' => $title = $this->request->post('title'), 'cat' => $cat = $this->request->post('category'), 'loc' => $loc = $this->request->post('location'), 'description' => $description = $this->request->post('description'), 'price' => $price = $this->request->post('price'), 'address' => $address = $this->request->post('address'), 'phone' => $phone = $this->request->post('phone'), 'website' => $website = $this->request->post('website')); // append to $data new custom values foreach ($_POST as $name => $field) { // get by prefix if (strpos($name, 'cf_') !== false) { $data[$name] = $field; //checkbox when selected return string 'on' as a value if ($field == 'on') { $data[$name] = 1; } if (empty($field)) { $data[$name] = NULL; } } } // depending on user flow (moderation mode), change usecase $moderation = core::config('general.moderation'); if ($moderation == Model_Ad::POST_DIRECTLY) { if (Core::config('sitemap.on_post') == TRUE) { Sitemap::generate(); } $status = Model_Ad::STATUS_PUBLISHED; $this->save_new_ad($data, $status, $published = TRUE, $moderation, $form_show['captcha']); } elseif ($moderation == Model_Ad::MODERATION_ON || $moderation == Model_Ad::PAYMENT_ON || $moderation == Model_Ad::EMAIL_CONFIRMATION || $moderation == Model_Ad::EMAIL_MODERATION || $moderation == Model_Ad::PAYMENT_MODERATION) { $status = Model_Ad::STATUS_NOPUBLISHED; $this->save_new_ad($data, $status, $published = FALSE, $moderation, $form_show['captcha']); } } }
/** * Handle GET requests. */ public function action_all() { try { if (is_numeric($this->request->param('id'))) { $this->action_get(); } else { $this->rest_output(Model_Location::get_as_array()); } } catch (Kohana_HTTP_Exception $khe) { $this->_error($khe); } }
public function action_index() { if ($this->id) { $val2 = \Validation::forge('data'); $val2->add_field('name', 'subnet name', 'required|min_length[1]|max_length[50]'); if ($val2->run()) { $this->name = $val2->validated('name'); $data = \Input::post('data'); $m = explode(',', $data); $stat = $this->checkForInhert($m); if ($stat['stat']) { $in = array('node' => $this->name, 'type' => 0, 'building' => $m[0], 'floor' => $m[1], 'room' => $m[2], 'rack' => $m[3], 'pos_from' => $m[4], 'pos_to' => $m[5]); $location = new Model_Location($in); $location->save(); $o = $this->structure(); echo json_encode(array('stat' => $stat, 'data' => $o)); } else { echo json_encode(array('stat' => $stat)); } } } }
/** * CRUD controller: DELETE */ public function action_delete() { $this->auto_render = FALSE; $location = new Model_Location($this->request->param('id')); //update the elements related to that ad if ($location->loaded()) { //update all the siblings this location has and set the location parent $query = DB::update('locations')->set(array('id_location_parent' => $location->id_location_parent))->where('id_location_parent', '=', $location->id_location)->execute(); //update all the ads this location has and set the location parent $query = DB::update('ads')->set(array('id_location' => $location->id_location_parent))->where('id_location', '=', $location->id_location)->execute(); try { $location->delete(); $this->template->content = 'OK'; Alert::set(Alert::SUCCESS, __('Location deleted')); } catch (Exception $e) { Alert::set(Alert::ERROR, $e->getMessage()); } } else { Alert::set(Alert::SUCCESS, __('Location not deleted')); } Request::current()->redirect(Route::url('oc-panel', array('controller' => 'location', 'action' => 'index'))); }
/** * gets the fragment name, unique using i18n theme and skin and cat and loc * @param string $name * @return string */ public static function fragment_name($name) { $cat_seoname = ''; if (Model_Category::current()->loaded()) { $cat_seoname = '_category_' . Model_Category::current()->seoname; } $loc_seoname = ''; if (Model_Location::current()->loaded()) { $loc_seoname = '_location_' . Model_Location::current()->seoname; } return 'fragment_' . $name . '_' . i18n::lang() . '_' . Theme::$theme . $cat_seoname . $loc_seoname; //.Theme::$skin }
public function action_index() { $cat = new Model_Category(); $list_cat = $cat->find_all(); // get all to print at sidebar view $loc = new Model_Location(); $list_loc = $loc->find_all(); // get all to print at sidebar view $user = Auth::instance()->get_user(); $ads = new Model_Ad(); Controller::$full_width = TRUE; $my_adverts = $ads->where('id_user', '=', $user->id_user); $res_count = $my_adverts->count_all(); if ($res_count > 0) { $pagination = Pagination::factory(array('view' => 'oc-panel/crud/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())); Breadcrumbs::add(Breadcrumb::factory()->set_title(__('My ads'))->set_url(Route::url('oc-panel', array('controller' => 'myads', 'action' => 'index')))); Breadcrumbs::add(Breadcrumb::factory()->set_title(sprintf(__("Page %d"), $pagination->current_page))); $ads = $my_adverts->order_by('published', 'desc')->limit($pagination->items_per_page)->offset($pagination->offset)->find_all(); $this->template->content = View::factory('oc-panel/profile/ads', array('ads' => $ads, 'pagination' => $pagination, 'category' => $list_cat, 'location' => $list_loc, 'user' => $user)); } else { $this->template->content = View::factory('oc-panel/profile/ads', array('ads' => $ads, 'pagination' => NULL, 'category' => NULL, 'location' => NULL, 'user' => $user)); } }
/** * 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(); // get all locations $this->loc_items = Model_Location::get_as_array(); $this->loc_order_items = Model_Location::get_multidimensional(); } if ($this->custom != FALSE) { $fields = Model_Field::get_all(); $this->custom_fields = $fields; } }
/** * Initialize properties before running the controller methods (actions), * so they are available to our action. */ public function before($template = NULL) { parent::before(); Theme::checker(); $this->maintenance(); $this->private_site(); /** * selected category */ self::$category = Model_Category::current(); /** * selected location */ self::$location = Model_Location::current(); //Gets a coupon if selected Model_Coupon::current(); if ($this->auto_render === TRUE) { // Load the template if ($template !== NULL) { $this->template = $template; } $this->template = View::factory($this->template); // Initialize template values $this->template->title = core::config('general.site_name'); $this->template->meta_keywords = ''; $this->template->meta_description = ''; $this->template->meta_copyright = 'Open Classifieds ' . Core::VERSION; $this->template->meta_copywrite = $this->template->meta_copyright; //legacy for old themes $this->template->content = ''; $this->template->styles = array(); $this->template->scripts = array(); $this->template->amphtml = NULL; $this->template->header = View::factory('header'); $this->template->footer = View::factory('footer'); // header_front_login fragment since CSRF gets cached :( // possible workaround ? @see http://kohanaframework.org/3.0/guide/kohana/fragments // if (Auth::instance()->logged_in()) // $this->template->header = View::fragment('header_front_login','header'); // else // $this->template->header = View::fragment('header_front','header'); //$this->template->footer = View::fragment('footer_front','footer'); } }
/** * 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) { // loaded category list($categories, $order_categories) = Model_Category::get_all(); $arr_cat = array(); foreach ($categories as $cat => $value) { if ($value['id'] != 1) { $arr_cat[$value['id']] = $value['name']; } } $this->cat_items = $categories; $this->cat_order_items = $order_categories; } // get all locations if ($this->locations != FALSE) { list($locations, $order_locations) = Model_Location::get_all(); $this->loc_items = $locations; $this->loc_order_items = $order_locations; } 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; }
/** * 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) { // loaded category list($categories, $order_categories) = Model_Category::get_all(); $arr_cat = array(); foreach ($categories as $cat => $value) { if ($value['id'] != 1) { $arr_cat[$value['id']] = $value['name']; } } $this->cat_items = $categories; $this->cat_order_items = $order_categories; // get all locations list($locations, $order_locations) = Model_Location::get_all(); $this->loc_items = $locations; $this->loc_order_items = $order_locations; } if ($this->custom != FALSE) { $fields = Model_Field::get_all(); $this->custom_fields = $fields; } }
/** * creates an ad from a row of import * @param class adsimport $adi * @return boolean */ private function create_ad($adi) { //new advertisement $ad = new Model_Ad(); //create user? if ($adi->id_user == NULL or !is_numeric($adi->id_user)) { //create the user $user = Model_User::create_user($adi->user_email, $adi->user_name); //check if in the table other users with same email set the id_user, then gets faster ;) try { DB::update('adsimport')->set(array('id_user' => $user->id_user))->where('user_email', '=', $adi->user_email)->execute(); } catch (Exception $e) { } //set id user to the new ad $ad->id_user = $user->id_user; } else { $ad->id_user = $adi->id_user; } //create category? if ($adi->id_category == NULL or !is_numeric($adi->id_category)) { //create the category $cat = Model_Category::create_name($adi->category); //check if in the table other cats with same name set the id_category, then gets faster ;) try { DB::update('adsimport')->set(array('id_category' => $cat->id_category))->where('category', '=', $adi->category)->execute(); } catch (Exception $e) { } //set id user to the new ad $ad->id_category = $cat->id_category; } else { $ad->id_category = $adi->id_category; } //create location? if (isset($adi->location) and !empty($adi->location) and ($adi->id_location == NULL or !is_numeric($adi->id_location))) { //create the location $loc = Model_Location::create_name($adi->location); //check if in the table other cats with same name set the id_location, then gets faster ;) try { DB::update('adsimport')->set(array('id_location' => $loc->id_location))->where('location', '=', $adi->location)->execute(); } catch (Exception $e) { } //set id user to the new ad $ad->id_location = $loc->id_location; } elseif (is_numeric($adi->id_location)) { $ad->id_location = $adi->id_location; } $ad->title = $adi->title; $ad->seotitle = $ad->gen_seo_title($adi->title); $ad->description = Text::html2bb($adi->description); $ad->published = $adi->date; $ad->created = $adi->date; $ad->price = $adi->price; $ad->address = $adi->address; $ad->phone = $adi->phone; $ad->website = $adi->website; $ad->status = Model_Ad::STATUS_PUBLISHED; try { $ad->save(); } catch (Exception $e) { return FALSE; } //save images if (($has_images = $this->process_images($ad, $adi)) > 0) { $ad->has_images = $has_images; try { $ad->save(); } catch (Exception $e) { return FALSE; } } //mark it as done try { DB::update('adsimport')->set(array('processed' => 1))->where('id_import', '=', $adi->id_import)->execute(); return TRUE; } catch (Exception $e) { return FALSE; } }
public static function Floor($model, $method) { if ($method == 'before_delete') { $locations = Model_Location::find()->where('floor', $model->id)->get(); foreach ($locations as $loc) { $loc->delete(); } } }
/** * 会場検索 * * ダイアログ表示のHTMLを返答する * * @access public * @param * @return string * @author ida */ public function action_searchlocation() { $this->template = ''; $prefecture_id = \Input::post('prefecture_id'); $name = \Input::post('name'); $query = \Model_Location::query()->select('location_id', 'name', 'address'); if ($prefecture_id) { $query->where(array('prefecture_id' => $prefecture_id)); } if ($name) { $query->where(array('name', 'LIKE', '%' . $name . '%')); } $locations = $query->get(); $view_model = \ViewModel::forge('admin/fleamarket/searchlocation'); $view_model->set('location_list', $locations, false); return $view_model; }
<?php if (count($ads)) { ?> <div class="btn-group pull-right"> <?php if (core::config('advertisement.map') == 1) { ?> <a href="<?php echo Route::url('map'); ?> ?category=<?php echo Model_Category::current()->loaded() ? Model_Category::current()->seoname : NULL; ?> &location=<?php echo Model_Location::current()->loaded() ? Model_Location::current()->seoname : NULL; ?> " class="btn btn-default btn-sm <?php echo core::cookie('list/grid') == 0 ? 'active' : ''; ?> "> <span class="glyphicon glyphicon-globe"></span> <?php echo __('Map'); ?> </a> <?php } ?> <button type="button" id="sort" data-sort="<?php echo core::request('sort');