Example #1
0
 public function indexAction()
 {
     $limit = $this->request->getQuery('limit', 'int', 25);
     $limit = $limit > 100 ? 100 : $limit;
     $limit = $limit < 10 ? 10 : $limit;
     $order = $this->request->getQuery('order', 'string', '-created_at');
     $query = array('q' => $this->request->getQuery('q', 'string'), 'status' => $this->request->getQuery('status', 'string', 'published'), 'uid' => $this->request->getQuery('uid', 'int'), 'cid' => $this->request->getQuery('cid', 'int'), 'username' => $this->request->getQuery('username', 'string'), 'order' => $order, 'limit' => $limit, 'page' => $this->request->getQuery('page', 'int', 1));
     if ($query['cid']) {
         $this->view->setVar('category', Category::findFirst($query['cid']));
     }
     $post = new Post();
     $posts = $post->findPosts($query);
     $paginator = new \Eva\EvaEngine\Paginator(array("builder" => $posts, "limit" => $limit, "page" => $query['page']));
     $paginator->setQuery($query);
     $pager = $paginator->getPaginate();
     $this->view->setVar('pager', $pager);
     return $paginator;
 }
 public function getCategoryAction()
 {
     if (ApiController::access()) {
         if (isset($_POST['id'])) {
             $category = Category::findFirst($this->request->getPost('id'));
         } else {
             $category = Category::find();
         }
         if ($category != false) {
             foreach ($category as $row) {
                 $response[$row->name]['name'] = $row->name;
                 $response[$row->name]['description'] = $row->description;
             }
             echo json_encode($response);
         }
         $this->view->disable();
     }
 }
Example #3
0
 public function deleteAction()
 {
     //check permission
     $aParam = $this->getParam();
     $check = Category::findFirst("categoryid='" . $aParam['categoryid'] . "'");
     if ($check == true) {
         $this->execute(DATABASE, "DELETE FROM category WHERE parentid='" . $aParam['categoryid'] . "'");
         $this->execute(DATABASE, "DELETE FROM product WHERE categoryid='" . $aParam['categoryid'] . "'");
         $this->execute(DATABASE, "DELETE FROM comment WHERE categoryid='" . $aParam['categoryid'] . "'");
         if ($check->delete() == true) {
             return $this->showErrorJson(1);
         } else {
             return $this->showErrorJson(0, "Category", $aParam);
         }
     } else {
         return $this->showErrorJson(7, "Category", $aParam);
     }
 }
 public function indexAction()
 {
     $this->tag->setTitle('Quản lý danh mục');
     // Create category
     $params = $this->request->getPost();
     if ($this->request->isPost()) {
         if ($this->_validation($params)) {
             if ($this->_check($params['name'])) {
                 $category = new Category();
                 $category->name = $params['name'];
                 if (!isset($params['parent'])) {
                     $category->parent = 0;
                 } else {
                     $category->parent = $params['parent'];
                 }
                 $category->menu = 2;
                 $category->active = 1;
                 $category->save();
                 $this->flash->success('Danh mục được tạo mới thành công');
             }
         }
     }
     $category = Category::find();
     $arr = array();
     foreach ($category as $value) {
         $array = array('id' => $value->id, 'name' => $value->name, 'parent' => $value->parent, 'menu' => $value->menu, 'active' => $value->active);
         $arr[] = $array;
     }
     $data['category'] = $this->helper->buildArr($arr, 'name');
     $this->view->setVar('data', $data);
     // Change active,menu
     $id = isset($params['id']) ? $params['id'] : '';
     $active = isset($params['active']) ? $params['active'] : '';
     $menu = isset($params['menu']) ? $params['menu'] : '';
     if ($active == 1) {
         $active = 2;
     } else {
         if ($active == 2) {
             $active = 1;
         }
     }
     if ($menu == 1) {
         $menu = 2;
     } else {
         if ($menu == 2) {
             $menu = 1;
         }
     }
     if ($id != null) {
         $category = Category::findFirst($id);
         if ($active != '') {
             $category->active = $active;
         }
         if ($menu != '') {
             $category->menu = $menu;
         }
         $category->save();
     }
     // Popup edit
     // $cate_edit = isset($params['cate_edit']) ? $params['cate_edit'] : '';
     $cate_edit = $_REQUEST['cate_edit'];
     echo $cate_edit;
     // debug($params);
     // $categoryEdit = Category::findFirst($cate_edit);
     $this->view->setVar('category', $cate_edit);
 }