public function addAction() { $form = new \Admin\Form\Expert\Expert($this->getServiceLocator()); if ($this->getRequest()->isPost()) { $form->setData($this->getRequest()->getPost()); if ($form->isValid()) { $data = $form->getData(); /** @var \Expert\Model\Expert $expert */ $expert = new Expert(); $expert->exchangeArray($data); $expert->setCreatedById($this->user()->getIdentity()); $expert->setCreatedDateTime(DateBase::getCurrentDateTime()); $expert->setExtracontent(json_encode($data['subjectName'])); $user = new User(); /** @var \User\Model\UserMapper $userMapper */ $userMapper = $this->getServiceLocator()->get('User\\Model\\UserMapper'); $user = $userMapper->get($expert->getUserId()); $user->setRole(User::ROLE_MENTOR); $userMapper->updateUser($user); /** @var \Expert\Model\ExpertMapper $expertMapper */ $expertMapper = $this->getServiceLocator()->get('Expert\\Model\\ExpertMapper'); /** @var \Subject\Model\SubjectMapper $subjectMapper */ $subjectMapper = $this->getServiceLocator()->get('Subject\\Model\\SubjectMapper'); $expert = $expertMapper->save($expert); $subjectIds = explode(',', $data['subjectId']); foreach ($subjectIds as $subjectId) { $subject = new Subject(); $subject->setId($subjectId); if ($subjectMapper->get($subject)) { $subjectNames[] = $subject->getName(); $expertSubject = new Expert\Subject(); $expertSubject->setExpertId($expert->getId()); $expertSubject->setSubjectId($subjectId); $expertSubject->setCreatedById($this->user()->getIdentity()); $expertSubject->setCreatedDateTime(DateBase::getCurrentDateTime()); /** @var \Expert\Model\Expert\SubjectMapper $expertSubjectMapper */ $expertSubjectMapper = $this->getServiceLocator()->get('Expert\\Model\\Expert\\SubjectMapper'); $expertSubjectMapper->save($expertSubject); } } $expert->setExtracontent(json_encode(implode(',', $subjectNames))); $expertMapper->save($expert); if ($form->get('afterSubmit')->getValue()) { return $this->redirect()->toUrl($form->get('afterSubmit')->getValue()); } } } $this->getViewModel()->setVariable('form', $form); return $this->getViewModel(); }
public function suggestAction() { $q = $this->getRequest()->getPost('q'); $subject = new Subject(); $subject->setName($q); $jsonModel = new JsonModel(); if (!$q) { $jsonModel->setVariables(['code' => 1, 'data' => []]); return $jsonModel; } /** @var \Subject\Model\SubjectMapper $subjectMapper */ $subjectMapper = $this->getServiceLocator()->get('Subject\\Model\\SubjectMapper'); $jsonModel->setVariables(['code' => 1, 'data' => $subjectMapper->suggest($subject)]); return $jsonModel; }
public function viewAction() { $subjectId = $this->params()->fromQuery('id'); /** @var \Subject\Model\SubjectMapper $subjectMapper */ $subjectMapper = $this->getServiceLocator()->get('Subject\\Model\\SubjectMapper'); /** @var \Subject\Model\Subject $subject */ $subjectExpert = new \Expert\Model\Expert\Subject(); if (!$subjectId) { return $this->page404(); } if (count(explode(',', $subjectId)) > 1) { $count = 0; foreach (explode(',', $subjectId) as $sId) { $subject = new Subject(); $subject->setId($sId); if (!$subjectMapper->get($subject)) { $count++; } else { $subjectIds[] = $sId; } } if ($count == count(explode(',', $subjectId))) { return $this->page404(); } $subjectExpert->addOption('subjectIds', $subjectIds); } else { $subject = new Subject(); $subject->setId($subjectId); if (!$subjectMapper->get($subject)) { return $this->page404(); } $subjectExpert->setSubjectId($subject->getId()); } /** @var \Expert\Model\Expert\SubjectMapper $subjectExpertMapper */ $subjectExpertMapper = $this->getServiceLocator()->get('Expert\\Model\\Expert\\SubjectMapper'); $this->getViewModel()->setVariables(['experts' => $subjectExpertMapper->search($subjectExpert, null)]); $this->getViewModel()->setVariables(['subject' => $subject]); return $this->getViewModel(); }
/** * @author DuongNQ * $return \zend\View\Model\JsonModel */ public function loadsubjectAction() { if ($this->getRequest()->isPost()) { if ($this->getRequest()->getPost()->toArray()['subjectId'] != '') { $subjectIds = explode(',', $this->getRequest()->getPost()->toArray()['subjectId']); } /** @var \Subject\Model\SubjectMapper $subjectMapper */ $subjectMapper = $this->getServiceLocator()->get('\\Subject\\Model\\SubjectMapper'); $subjectNames = []; if (count($subjectIds) > 0) { foreach ($subjectIds as $subjectId) { $subject = new Subject(); $subject->setId($subjectId); $subject = $subjectMapper->get($subject); $subjectNames[$subjectId] = $subject->getName(); } } return new JsonModel($subjectNames); } else { return null; } }
public function addAction() { $form = new \Admin\Form\Subject\Subject($this->getServiceLocator()); if ($this->getRequest()->isPost()) { $form->setData($this->getRequest()->getPost()); if ($form->isValid()) { $data = $form->getData(); $subject = new Subject(); $subject->exchangeArray($data); $subject->setCreatedById($this->user()->getIdentity()); $subject->setCreatedDateTime(DateBase::getCurrentDateTime()); $subject->setStatus(Subject::STATUS_ACTIVE); $subjectMapper = $this->getServiceLocator()->get('Subject\\Model\\SubjectMapper'); $subjectMapper->save($subject); if ($form->get('afterSubmit')->getValue()) { return $this->redirect()->toUrl($form->get('afterSubmit')->getValue()); } } } $this->getViewModel()->setVariable('form', $form); return $this->getViewModel(); }
/** * todo trả lại một mảng tên và id môn học cho hàm search ở trang chủ * @return array * @param array $searchDatas */ public function fetchSearch($searchDatas) { $select = $this->getDbSql()->select(array('s' => self::TABLE_NAME)); if (is_array($searchDatas)) { foreach ($searchDatas as $subjectName) { $select->where(['s.name LIKE ?' => '%' . $subjectName . '%'], 'OR'); } } $query = $this->getDbSql()->buildSqlString($select); $results = $this->getDbAdapter()->query($query, Adapter::QUERY_MODE_EXECUTE); $subjects = array(); if (count($results)) { foreach ($results as $s) { $subject = new Subject(); $subject->exchangeArray((array) $s); $subjects[] = $subject; } } return $subjects; }
/** * @param \Subject\Model\Subject $item * @return array */ public function suggest($item) { $select = $this->getDbSql()->select(array('s' => self::TABLE_NAME), array('id', 'name')); if ($item != null) { $select->where(['(s.name LIKE ?)' => ['%' . $item->getName() . '%']]); $select->limit(20); } $query = $this->getDbSql()->buildSqlString($select); $rows = $this->getDbAdapter()->query($query, Adapter::QUERY_MODE_EXECUTE); $result = []; if ($rows->count()) { foreach ($rows as $row) { $row = (array) $row; $row['id'] = (int) $row['id']; $row['label'] = $row['name']; $result[] = $row; } } return $result; }