public function suggestcategoryAction() { $q = $this->getRequest()->getPost('q'); $category = new Subject\Category(); $category->setName($q); $jsonModel = new JsonModel(); if (!$q) { $jsonModel->setVariables(['code' => 1, 'data' => []]); return $jsonModel; } /** @var \Subject\Model\Subject\CategoryMapper $categoryMapper */ $categoryMapper = $this->getServiceLocator()->get('Subject\\Model\\Subject\\CategoryMapper'); $jsonModel->setVariables(['code' => 1, 'data' => $categoryMapper->suggest($category)]); return $jsonModel; }
public function categoryAction() { $form = new \Admin\Form\Subject\CategoryFilter($this->getServiceLocator()); $form->setData($this->params()->fromQuery()); $this->getViewModel()->setVariable('form', $form); if ($form->isValid()) { $category = new Subject\Category(); $category->exchangeArray($form->getData()); $categoryMapper = $this->getServiceLocator()->get('Subject\\Model\\Subject\\CategoryMapper'); /*@var $categoryMapper \Subject\Model\Subject\CategoryMapper */ $paginator = $categoryMapper->search($category); $this->getViewModel()->setVariable('paginator', $paginator); } return $this->getViewModel(); }
public function listAction() { $categoryId = $this->params()->fromQuery('id'); /** @var \Subject\Model\Subject\CategoryMapper $categoryMapper */ $categoryMapper = $this->getServiceLocator()->get('Subject\\Model\\Subject\\CategoryMapper'); /** @var \Subject\Model\Subject\Category $category */ $category = new Category(); $category->setId($categoryId); if (!$category->getId() || !$categoryMapper->get($category)) { return $this->page404(); } /** @var \Subject\Model\Subject $subject */ $subject = new Subject(); $subject->setCategoryId($category->getId()); /** @var \Subject\Model\SubjectMapper $subjectMapper */ $subjectMapper = $this->getServiceLocator()->get('Subject\\Model\\SubjectMapper'); $subjects = $subjectMapper->featchAll($subject); $this->getViewModel()->setVariables(['subjects' => $subjects]); return $this->getViewModel(); }
public function listAction() { $categoryId = $this->params()->fromQuery('id'); /** @var \Subject\Model\Subject\CategoryMapper $categoryMapper */ $categoryMapper = $this->getServiceLocator()->get('Subject\\Model\\Subject\\CategoryMapper'); /** @var \Subject\Model\Subject\Category $category */ if (!$categoryId) { return $this->page404(); } /** @var \Subject\Model\Subject $subject */ $subject = new Subject(); if (count(explode(',', $categoryId)) > 1) { $count = 0; foreach (explode(',', $categoryId) as $sId) { $category = new Category(); $category->setId($sId); if (!$categoryMapper->get($category)) { $count++; } else { $categoryIds[] = $sId; } } if ($count == count(explode(',', $categoryId))) { return $this->page404(); } $subject->addOption('categoryIds', $categoryIds); } else { $category = new Category(); $category->setId($categoryId); if (!$category->getId() || !$categoryMapper->get($category)) { return $this->page404(); } $subject->setCategoryId($category->getId()); } /** @var \Subject\Model\SubjectMapper $subjectMapper */ $subjectMapper = $this->getServiceLocator()->get('Subject\\Model\\SubjectMapper'); $subjects = $subjectMapper->featchAll($subject); $this->getViewModel()->setVariables(['subjects' => $subjects]); return $this->getViewModel(); }
/** * @author DuongNQ * @param \Subject\Model\Subject\Category $cate */ public function isExisted($cate) { if (!$cate->getName()) { return null; } $select = $this->getDbSql()->select(array('d' => self::TABLE_NAME)); $select->where(['name' => $cate->getName()]); if ($cate->getId()) { $select->where(['id != ?' => $cate->getId()]); } $select->limit(1); $query = $this->getDbSql()->buildSqlString($select); $results = $this->getDbAdapter()->query($query, Adapter::QUERY_MODE_EXECUTE); if ($results->count()) { $cate->exchangeArray((array) $results->current()); return true; } return false; }
/** * @author DuongNQ * @param \Subject\Model\Subject $sub */ public function search($sub, $options) { $select = $this->getDbSql()->select(array('s' => self::TABLE_NAME)); $select->order(['s.id' => 'DESC']); $paginator = $this->preparePaginator($select, $options, new Subject()); $categoryIds = array(); $categories = array(); /** @var /Subject/Model/Subject $subject */ foreach ($paginator as $subject) { $categoryIds[] = $subject->getCategoryId(); } if ($categoryIds) { $select = $this->getDbSql()->select(['ca' => Subject\CategoryMapper::TABLE_NAME]); $select->where(['ca.id' => $categoryIds]); $query = $this->getDbSql()->buildSqlString($select); $result = $this->getDbAdapter()->query($query, Adapter::QUERY_MODE_EXECUTE); if (count($result)) { $resultArray = $result->toArray(); foreach ($resultArray as $u) { $category = new Subject\Category(); $categories[$u['id']] = $category->exchangeArray($u); } } } /** @var /Subject/Model/Subject $subject */ foreach ($paginator->getCurrentModels() as $subject) { $categoryId = $subject->getCategoryId(); $subject->addOption('category', isset($categories[$categoryId]) ? $categories[$categoryId] : null); } return $paginator; }
/** * @return array|null */ public function fetchAll() { $dbAdapter = $this->getDbAdapter(); $select = $this->getDbSql()->select(['ca' => self::TABLE_NAME]); $select->where(['ca.status' => Subject::STATUS_ACTIVE]); $query = $this->getDbSql()->buildSqlString($select); $results = $dbAdapter->query($query, $dbAdapter::QUERY_MODE_EXECUTE); if ($results) { $categories = array(); foreach ($results as $row) { $ct = new Category(); $ct->exchangeArray((array) $row); $categories[] = $ct; } return $categories; } return null; }
public function editcategoryAction() { /** @var $categoryMapper \Subject\Model\Subject\CategoryMapper */ $categoryMapper = $this->getServiceLocator()->get('Subject\\Model\\Subject\\CategoryMapper'); $category = new Subject\Category(); $id = $this->params()->fromQuery('id'); $category->setId($id); if (!$category->getId() || !$categoryMapper->get($category)) { return $this->page404(); } $form = new \Admin\Form\Subject\Category($this->getServiceLocator()); $form->remove('afterSubmit'); $form->setData($category->toFormValues()); if ($this->getRequest()->isPost()) { $form->setData($this->getRequest()->getPost()); if ($form->isValid()) { $category->exchangeArray($form->getData()); $categoryMapper->save($category); return $this->redirect()->toUrl('/admin/subject/category'); } } $this->getViewModel()->setVariables(['form' => $form]); return $this->getViewModel(); }