public function action_search() { $view = View::forge('customer/search/search'); $view->search = array(); $view->keyword = Input::get('search-keyword', ''); if (!empty($view->keyword)) { $custom_keyword = Input::vn_str_filter($view->keyword); $search_count = $search_article = Model_ArtCat::query()->related('ac2a')->where(DB::expr("content_search_no_mark LIKE '%{$custom_keyword}%'"))->or_where(DB::expr("title_search LIKE '%{$custom_keyword}%'"))->count(); $config = array('pagination_url' => Uri::base() . "search?search-keyword={$custom_keyword}", 'total_items' => $search_count, 'per_page' => 10, 'uri_segment' => 'page', 'num_links' => 3); $pag = Pagination::forge('paging_search', $config); $search_cat = Model_Categories::query()->where(DB::expr("name_search LIKE '%{$custom_keyword}%'"))->order_by('name_search')->get(); foreach ($search_cat as $s) { $parent = Model_Categories::find($s->parent_id); $view->search[] = array('title' => strip_tags($s->name), 'desc' => strip_tags($s->desc), 'link' => Uri::base() . "{$parent->slug}/{$s->slug}.html"); } $search_article = Model_ArtCat::query()->related('ac2a')->where(DB::expr("content_search_no_mark LIKE '%{$custom_keyword}%'"))->or_where(DB::expr("title_search LIKE '%{$custom_keyword}%'"))->order_by('ac2a.title_search')->rows_offset($pag->offset)->rows_limit($pag->per_page)->get(); foreach ($search_article as $s) { // highlight keyword $content = $this->highlight($s->ac2a->content_search, $custom_keyword); // get cat slug if (!empty($s->ac2c->parent_id)) { $parent_cat_slug = Model_Categories::find($s->ac2c->parent_id); $view->search[] = array('title' => strip_tags($s->ac2a->title), 'desc' => $content, 'link' => Uri::base() . "{$s->ac2c->slug}/{$s->ac2a->slug}.html", 'cat' => array('name' => strip_tags($s->ac2c->name), 'desc' => $s->ac2c->desc, 'link' => Uri::base() . "{$parent_cat_slug->slug}/{$s->ac2c->slug}.html")); } else { $view->search[] = array('title' => strip_tags($s->ac2a->title), 'desc' => $content, 'link' => Uri::base() . "{$s->ac2c->slug}/{$s->ac2a->slug}.html"); } } $view->pag = $pag; } $this->template = \View::forge('customer/search/template'); // data to display menu $this->template->cats = Model_Categories::get_cats_home($this->lang); $this->template->pepper_arts = Model_Article::pepper_artilces($this->lang); $this->template->title = __('common.search'); $this->add_css('search.css'); $this->template->content = $view; }
/** * Find childs of category * * @params int $parent_id Parent-Cat. ID * @params string $lang Language * @return array childs of category * * @version 1.0 * @since 1.0 * @access public * @author Nguyen Van hiep */ public static function childs($parent_id, $lang) { $childs = Model_Categories::query()->where('parent_id', $parent_id)->where('active', true)->where('lang', $lang)->limit(5)->get(); return $childs; }
/** * Edit Category * * @param int $id cat. ID * * @author Nguyen Van Hiep * @access public * * @version 1.0 * @since 1.0 */ public function action_edit($id = null, $selected_lang = '') { $cat = Model_Categories::find($id); if (!$cat or $id < 4) { Session::set_flash('error', __('message.cat_not_exists')); Response::redirect('admin/categories'); } $view = View::forge('admin/categories/edit'); $view->cat = $cat; $view->error = array(); $view->cats = Model_Categories::get_cats(); $view->langs = $this->langs; $view->selected_lang = "lang={$selected_lang}"; $max = (int) Model_Categories::query()->max('order'); $view->max = $max + 1; if (Input::method() == 'POST') { $cat->name = Input::post('name'); $cat->name_search = strip_tags(Input::post('name')); $cat->slug = Input::post('slug'); $val = Model_Categories::validate('edit', $cat); Upload::process($this->config); $upload_errs = Upload::get_errors(); $input_file = Input::file(); // Check if upload new thumbnail or not foreach ($upload_errs as $key => $err) { if (empty($err['name'])) { unset($upload_errs[$key]); unset($input_file[$err['field']]); } } if ($val->run(Input::post()) && empty($upload_errs)) { // Check if order changed $varied = $cat->order == Input::post('order') ? false : true; $cat->order = Input::post('order') ? Input::post('order') : $cat->order; $cat->parent_id = Input::post('parent'); $cat->desc = Input::post('desc'); $cat->side = Input::post('side'); $cat->display_type = Input::post('dtype'); $cat->info = Input::post('info'); $cat->active = Input::post('active') ? true : false; $cat->art_display_by_order = Input::post('art_display_by_order') ? true : false; $cat->lang = Input::post('lang'); $this->save_cat($cat, $max, $varied); if (Input::post('delete_thumbnail', false)) { $this->delete_file($cat->id, $this->dir . $cat->bg); } else { if (!empty($input_file)) { $this->delete_file($cat->id, $this->dir . $cat->bg); $this->save_thumb($cat->id, true); } } Response::redirect("admin/categories?{$view->selected_lang}"); } else { $view->error = $val->error_message(); Session::set_flash('error', __('message.validation_error')); } } $this->template->title = __('cat.edit'); $this->template->content = $view; }