Exemple #1
0
 /**
  * 列出所有文章分类
  *
  * @param $f3
  */
 public function ListCategory($f3)
 {
     // 检查缓存
     $cacheKey = md5(__NAMESPACE__ . '\\' . __CLASS__ . '\\' . __METHOD__);
     if ($f3->get('GET[nocache]')) {
         goto nocache;
     }
     $categoryArray = $f3->get($cacheKey);
     if (!empty($categoryArray)) {
         goto out;
     }
     nocache:
     // 没有缓存数据
     $categoryService = new CategoryService();
     $categoryArray = $categoryService->fetchArticleCategoryArray();
     $f3->set($cacheKey, $categoryArray, 300);
     //缓存 5 分钟
     out:
     if (!$f3->get('GET[nocache]')) {
         $f3->expire(60);
         // 客户端缓存 1 分钟
     }
     Ajax::header();
     echo Ajax::buildResult(null, null, $categoryArray);
 }
Exemple #2
0
 public function Edit($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_article_category_edit');
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $meta_id = $validator->digits()->validate('meta_id');
     $meta_id = $meta_id ?: 0;
     //  加载 分类信息
     $articleCategoryService = new ArticleCategoryService();
     $articleCategory = $articleCategoryService->loadArticleCategoryById($meta_id);
     if (Request::isRequestGet()) {
         goto out_assign;
     }
     // 安全性检查
     if ($meta_id > 0) {
         if ($articleCategory->isEmpty() || ArticleCategoryService::META_TYPE != $articleCategory->meta_type) {
             $this->addFlashMessage('非法ID[' . $meta_id . ']');
             goto out;
         }
     }
     unset($validator);
     $validator = new Validator($f3->get('POST'));
     $inputArray = array();
     $inputArray['meta_type'] = ArticleCategoryService::META_TYPE;
     $inputArray['meta_name'] = $validator->required()->validate('meta_name');
     $inputArray['meta_sort_order'] = $validator->digits()->validate('meta_sort_order');
     $inputArray['meta_desc'] = $validator->validate('meta_desc');
     if (!$this->validate($validator)) {
         goto out;
     }
     // 保存
     $articleCategory->copyFrom($inputArray);
     $articleCategory->save();
     $this->addFlashMessage('分类信息保存成功');
     // POST 成功从这里退出
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Article/Category/Edit', array('meta_id' => $articleCategory->meta_id), true));
     return;
     out_assign:
     $smarty->assign($articleCategory->toArray());
     out:
     $smarty->display('article_category_edit.tpl');
 }
Exemple #3
0
 public function Search($f3)
 {
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $pageNo = $validator->digits()->min(0)->validate('pageNo');
     $pageSize = $validator->digits()->min(0)->validate('pageSize');
     // 设置缺省值
     $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0;
     $pageSize = isset($pageSize) && $pageSize > 0 ? $pageSize : 10;
     // 搜索参数数组
     $searchFormQuery = array();
     $searchFormQuery['a.article_id'] = $validator->digits()->min(0)->filter('ValidatorIntValue')->validate('article_id');
     $searchFormQuery['a.title'] = $validator->validate('title');
     $searchFormQuery['a.description'] = $validator->validate('description');
     $searchFormQuery['a.cat_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('cat_id');
     $searchFormQuery['a.admin_user_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('admin_user_id');
     $searchFormQuery['a.is_open'] = $validator->digits()->min(0)->filter('ValidatorIntValue')->validate('is_open');
     if (!$this->validate($validator)) {
         goto out;
     }
     // 建立查询条件
     $searchParamArray = QueryBuilder::buildSearchParamArray($searchFormQuery);
     // 查询商品列表
     $totalCount = SearchHelper::count(SearchHelper::Module_Article, $searchParamArray);
     if ($totalCount <= 0) {
         // 没数据,可以直接退出了
         goto out;
     }
     // 页数超过最大值,返回第一页
     if ($pageNo * $pageSize >= $totalCount) {
         RouteHelper::reRoute($this, '/Article/Article/Search');
     }
     // 文章列表
     $articleArray = SearchHelper::search(SearchHelper::Module_Article, '*', $searchParamArray, array(array('a.article_id', 'desc')), $pageNo * $pageSize, $pageSize);
     // 取得 文章分类 id
     $categoryIdArray = array();
     foreach ($articleArray as $articleItem) {
         $categoryIdArray[] = $articleItem['cat_id'];
     }
     $categoryIdArray = array_unique($categoryIdArray);
     // 取得分类信息
     $articleCategoryService = new ArticleCategoryService();
     $categoryArray = $articleCategoryService->fetchCategoryArrayByIdArray($categoryIdArray);
     // 建立 cat_id  ---> cateogry 信息的反查表
     $categoryIdToCategoryArray = array();
     foreach ($categoryArray as $categoryItem) {
         $categoryIdToCategoryArray[$categoryItem['meta_id']] = $categoryItem;
     }
     // 放入分类信息
     foreach ($articleArray as &$articleItem) {
         if (isset($categoryIdToCategoryArray[$articleItem['cat_id']])) {
             // 很老的商品,分类信息可能已经不存在了
             $articleItem['cat_name'] = $categoryIdToCategoryArray[$articleItem['cat_id']]['meta_name'];
         }
     }
     unset($articleItem);
     // 给模板赋值
     $smarty->assign('totalCount', $totalCount);
     $smarty->assign('pageNo', $pageNo);
     $smarty->assign('pageSize', $pageSize);
     $smarty->assign('articleArray', $articleArray);
     out:
     $smarty->display('article_article_search.tpl');
 }