Пример #1
0
 /**
  * Check the article limit of PEPPER category
  *
  * 'ART_PEPPER_LIM' 2
  *
  * @param int $parent_ids values of cat-id in post-data
  * @param int $child_id ID of child category
  * @return boolean result of validation
  *
  * @since 1.0
  * @version 1.0
  * @access public
  * @author Nguyen Van Hiep
  */
 public static function _validation_art_limit($parent_ids, $child_id = null)
 {
     Validation::active()->set_message('art_limit', __('message.over_art_limit'));
     if (!isset($parent_ids) or !in_array(C_PEPPER, $parent_ids)) {
         return true;
     }
     $is_child = Model_ArtCat::is_child_art($child_id, C_PEPPER);
     $art_count = Model_ArtCat::number_of_arts(C_PEPPER, Input::post('lang'));
     if ($is_child or $art_count < ART_PEPPER_LIM) {
         return true;
     }
     return false;
 }
Пример #2
0
 /**
  * Delete Slider Image
  *
  * @param int $id Image ID
  *
  * @author Nguyen Van Hiep
  * @access public
  *
  * @version 1.0
  * @since 1.0
  */
 public function action_delete($id = null, $current_cat_view = '', $current_lang_view = '')
 {
     if ($current_cat_view != 'cat' and $current_lang_view != 'lang') {
         $current_cat_view = "cat={$current_cat_view}&lang={$current_lang_view}";
     } elseif ($current_cat_view != 'cat') {
         $current_cat_view = "cat={$current_cat_view}&lang=";
     } elseif ($current_lang_view != 'lang') {
         $current_cat_view = "cat=&lang={$current_lang_view}";
     } else {
         $current_cat_view = "cat=&lang=";
     }
     $a = Model_Article::find($id);
     if (!$a) {
         Session::set_flash('error', __('message.art_not_exists'));
         Response::redirect("admin/article?{$current_cat_view}");
     }
     // Delete image
     if (Fuel\Core\File::exists($this->dir . $a->thumb)) {
         File::delete($this->dir . $a->thumb);
     }
     Model_ArtCat::del_art_cat($id);
     if ($a->delete()) {
         Session::set_flash('success', __('message.art_deleted'));
         Response::redirect("admin/article?{$current_cat_view}");
     } else {
         Session::set_flash('error', __('message.cannot_del_art'));
     }
 }
Пример #3
0
 /**
  * Check if cat. CANNOT be deleted
  *
  * @param int $id cat. id
  * @return array $relatedcat names of related cat.s if the cat. CANNOT be deleted,
  *         boolean FALSE if the cat. CAN be deleted
  *
  * @access protected
  * @author Nguyen Van Hiep
  */
 protected function unable_del($id)
 {
     $relatedcats = array();
     $relatedarts = array();
     $cats = Model_Categories::get_child_cats($id);
     $cat_arts = Model_ArtCat::get_related_articles($id);
     foreach ($cats as $item) {
         $text = Security::clean($item->name, array('htmlentities', 'xss_clean'));
         $relatedcats[] = Html::anchor('/admin/categories/edit/' . $item->id, $text);
     }
     if (count($relatedcats) > 0) {
         array_unshift($relatedcats, '- ' . __('cat.categories') . ':');
     }
     foreach ($cat_arts as $art) {
         $text = Security::strip_tags($art->ac2a->title);
         $relatedarts[] = Html::anchor('/admin/article/edit/' . $art->art_id, $text);
     }
     if (count($relatedarts) > 0) {
         array_unshift($relatedarts, '- ' . __('art.arts') . ':');
     }
     $ret = array_merge($relatedcats, $relatedarts);
     if (count($ret) > 0) {
         return $ret;
     } else {
         return false;
     }
 }
Пример #4
0
 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;
 }
Пример #5
0
 /**
  * Get Number of articles of a category
  *
  * params int $cat_id Category-ID
  * @return int Number of articles of a category
  *
  * @version 1.0
  * @since 1.0
  * @access public
  * @author Nguyen Van hiep
  * @author Dao Anh Minh
  */
 public static function count_arts_in_cat($cat_id = '', $lang = '')
 {
     if (empty($cat_id)) {
         if (empty($lang)) {
             $count = Model_Article::query()->count();
         } else {
             $count = Model_Article::query()->where('lang', $lang)->count();
         }
     } else {
         if (empty($lang)) {
             $count = Model_ArtCat::query()->where('cat_id', $cat_id)->count();
         } else {
             $count = Model_ArtCat::query()->related('ac2a')->where('cat_id', $cat_id)->where('ac2a.lang', $lang)->count();
         }
     }
     return $count;
 }