public function detailAction() { $id = $this->params()->fromQuery('id'); $user = new User(); $user->setId($id); /** @var \User\Model\UserMapper $userMapper */ $userMapper = $this->getServiceLocator()->get('User\\Model\\UserMapper'); if (!$user->getId() || !$userMapper->get($user->getId())) { return $this->page404(); } if (!$this->params()->fromQuery('created') || !DateBase::validateDate($this->params()->fromQuery('created'), DateBase::DISPLAY_DATE_FORMAT)) { return $this->page404(); } $user = $userMapper->get($id); /** @var \Admin\Model\MessagesMG $mess */ $mess = new MessagesMG(); $mess->setSender($user->getUsername()); $mess->setCreated($this->params()->fromQuery('created')); /** @var \Admin\Model\ReportMapper $reportMapper */ $reportMapper = $this->getServiceLocator()->get('Admin\\Model\\ReportMapper'); $data = $reportMapper->reportdetail($mess); $this->getViewModel()->setVariable('data', $data); $this->getViewModel()->setVariable('user', $user); return $this->getViewModel(); }
/** * @param \User\Model\User $user * @return true|false */ public function save($user) { $data = array('role' => $user->getRole(), 'username' => $user->getUsername() ?: null, 'email' => $user->getEmail() ?: null, 'password' => $user->getPassword() ?: null, 'salt' => $user->getSalt() ?: null, 'fullName' => $user->getFullName() ?: null, 'avatar' => $user->getAvatar() ?: null, 'gender' => $user->getGender() ?: null, 'birthdate' => $user->getBirthdate() ?: null, 'cityId' => $user->getCityId() ?: null, 'districtId' => $user->getDistrictId() ?: null, 'address' => $user->getAddress() ?: null, 'mobile' => $user->getMobile() ?: null, 'lastAccess' => $user->getLastAccess() ?: null, 'active' => $user->getActive() ?: null, 'activeKey' => $user->getActiveKey() ?: null, 'createdById' => $user->getCreatedById() ?: null, 'createdDate' => $user->getCreatedDate(), 'createdDateTime' => $user->getCreatedDateTime(), 'description' => $user->getDescription() ?: null, 'rate' => $user->getRate() ?: null, 'rating' => $user->getRating() ?: null, 'facebook' => $user->getFacebook() ?: null); $results = false; if (!($id = $user->getId())) { $insert = $this->getDbSql()->insert(self::TABLE_NAME); $insert->values($data); $query = $this->getDbSql()->buildSqlString($insert); $results = $this->getDbAdapter()->query($query, Adapter::QUERY_MODE_EXECUTE); $user->setId($results->getGeneratedValue()); } else { $update = $this->getDbSql()->update(self::TABLE_NAME); $update->set($data); $update->where(array("id" => (int) $user->getId())); $query = $this->getDbSql()->buildSqlString($update); $results = $this->getDbAdapter()->query($query, Adapter::QUERY_MODE_EXECUTE); } return $results; }
public function editAction() { $id = $this->params()->fromQuery('id'); $user = new User(); $user->setId($id); $user->setRole(User::ROLE_MENTOR); /** @var \User\Model\UserMapper $userMapper */ $userMapper = $this->getServiceLocator()->get('User\\Model\\UserMapper'); if (!$user->getId() || !$userMapper->getUser($user)) { return $this->page404(); } $form = new \Admin\Form\Expert\Expert($this->getServiceLocator()); $form->remove('afterSubmit'); $form->getInputFilter()->remove('userName'); $form->remove('userName'); $form->remove('userId'); $form->setData($user->toFormValues()); $this->getViewModel()->setVariables(['form' => $form]); return $this->getViewModel(); }
public function changeroleAction() { $id = $this->params()->fromPost('id', null); $role = $this->params()->fromPost('role', null); $facebook = $this->params()->fromPost('facebook', null); // var_dump($facebook);die; if ($id && ($role == 5 || $role == 200)) { $userMapper = $this->getServiceLocator()->get('User\\Model\\UserMapper'); $user = new User(); $user->setId($id); $user = $userMapper->get($user->getId()); if ($user->getEmail()) { $user->setRole($role); $user->setFacebook($facebook); $userMapper->save($user); $this->flashMessenger()->addMessage('Cập nhật thành công!'); $this->redirect()->toUrl("/admin/user"); } $this->flashMessenger()->addMessage('User không tồn tại!'); $this->redirect()->toUrl("/admin/user"); } $this->flashMessenger()->addMessage('Dữ liệu truyền vào không đúng!'); $this->redirect()->toUrl("/admin/user"); }
public function editAction() { $id = $this->params()->fromQuery('id'); $user = new User(); $user->setId($id); $user->setRole(User::ROLE_MENTOR); /** @var \User\Model\UserMapper $userMapper */ $userMapper = $this->getServiceLocator()->get('User\\Model\\UserMapper'); if (!$user->getId() || !$userMapper->getUser($user)) { return $this->page404(); } $form = new \Admin\Form\Expert\Expert($this->getServiceLocator(), 'edit'); $form->remove('afterSubmit'); $form->setData($user->toFormValues()); $expertsubject = new Expert\Subject(); $expertsubject->setExpertId($user->getId()); /** @var \Expert\Model\Expert\SubjectMapper $subjectExpertmapper */ $subjectExpertmapper = $this->getServiceLocator()->get('Expert\\Model\\Expert\\SubjectMapper'); $subjects = $subjectExpertmapper->fetchAllSubject($expertsubject); $subjectIdbs = []; if ($subjects) { $subjectIdbs = array_keys($subjects[$user->getId()]); } $form->get('subjectId')->setValue(implode(',', $subjectIdbs)); $form->get('userId')->setValue($user->getId()); $userName = $user->getFullName() ? $user->getUsername() . ' - ' . $user->getFullName() : $user->getUsername(); $form->get('userName')->setValue($userName); if ($this->getRequest()->isPost()) { $form->setData($this->getRequest()->getPost()); if ($form->isValid()) { $data = $form->getData(); $user->setDescription($data['description']); if (!$data['subjectId']) { $es = new Expert\Subject(); $es->setExpertId($user->getId()); $subjectExpertmapper->delete($es); } if ($data['subjectId']) { $subjectIdas = explode(',', $data['subjectId']); $subjectIdns = array_diff($subjectIdas, $subjectIdbs); foreach ($subjectIdns as $subjId) { $es = new Expert\Subject(); $es->setExpertId($user->getId()); $es->setSubjectId($subjId); $es->setCreatedById($this->user()->getIdentity()); $es->setCreatedDateTime(DateBase::getCurrentDateTime()); $subjectExpertmapper->save($es); } $subjectIdds = array_diff($subjectIdbs, $subjectIdas); foreach ($subjectIdds as $subjId) { $es = new Expert\Subject(); $es->setExpertId($user->getId()); $es->setSubjectId($subjId); $subjectExpertmapper->delete($es); } } $userMapper->updateUser($user); return $this->redirect()->toUrl('/admin/expert'); } } $this->getViewModel()->setVariables(['form' => $form]); return $this->getViewModel(); }
public function rowToObject($result) { $user = new UserModel(); $user->setId($result['id'])->setEmail($result['email'])->setFirstname($result['firstname'])->setLastname($result['lastname'])->setIsActive($result['isActive'])->setBirthdate(new DateTime($result['birthdate']))->setUsername($result['username'])->setPassword($result['password']); return $user; }
/** * @return JsonModel */ public function getnameAction() { if ($this->getRequest()->isPost()) { $userId = $this->getRequest()->getPost('userId'); $userMapper = $this->getServiceLocator()->get('\\User\\Model\\UserMapper'); /* @var $user \User\Model\User */ $user = new User(); $user->setId($userId); if ($userMapper->getUser($user)) { $json = new JsonModel(); $json->setVariables(['code' => 1, 'id' => $user->getId(), 'name' => $user->getUsername() . ' - ' . $user->getFullName(), 'fullName' => $user->getFullName()]); return $json; } else { $json = new JsonModel(); $json->setVariables(['code' => 0]); return $json; } } }