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(); }
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 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(); }
/** * * @param \User\Model\User $item * @param unknown $options */ public function search($item, $options) { $select = $this->getDbSql()->select(array('u' => self::TABLE_NAME)); if ($item->getId()) { $select->where(['u.id' => $item->getId()]); } if ($item->getUsername()) { $select->where(['(u.username LIKE ? OR u.fullName LIKE ?)' => ['%' . $item->getUsername() . '%', '%' . $item->getUsername() . '%']]); } if ($item->getEmail()) { $select->where(['(u.email LIKE ?)' => '%' . $item->getEmail() . '%']); } if ($item->getActive()) { if ($item->getActive() > 0) { $select->where(['u.active' => 1]); } else { $select->where(['(u.active IS NULL OR u.active != ?)' => 1]); } } if ($item->getRole()) { $select->where(['u.role' => $item->getRole()]); } $select->order(['u.id' => 'DESC']); $paginator = $this->preparePaginator($select, $options, new User()); $userIds = []; $districIds = []; $cityIds = []; $ids = []; foreach ($paginator as $user) { /*@var $user \User\Model\User */ if ($user->getCreatedById()) { $userIds[$user->getCreatedById()] = $user->getCreatedById(); } if ($user->getDistrictId()) { $districIds[$user->getDistrictId()] = $user->getDistrictId(); } if ($user->getCityId()) { $cityIds[$user->getCityId()] = $user->getCityId(); } $ids[] = $user->getId(); } $dbAdapter = $this->getDbAdapter(); $users = []; if (count($userIds)) { $select = $this->getDbSql()->select(array('u' => self::TABLE_NAME)); $select->where(['u.id' => $userIds]); $query = $this->getDbSql()->buildSqlString($select); $rows = $dbAdapter->query($query, $dbAdapter::QUERY_MODE_EXECUTE); if ($rows->count()) { foreach ($rows as $row) { $createdBy = new User(); $createdBy->exchangeArray((array) $row); $users[$createdBy->getId()] = $createdBy; } } } $cities = []; if (count($cityIds)) { $select = $this->getDbSql()->select(array('c' => \Address\Model\CityMapper::TABLE_NAME)); $select->where(['id' => $cityIds]); $query = $this->getDbSql()->buildSqlString($select); $rows = $dbAdapter->query($query, $dbAdapter::QUERY_MODE_EXECUTE); if ($rows->count()) { foreach ($rows as $row) { $city = new \Address\Model\City(); $city->exchangeArray((array) $row); $cities[$city->getId()] = $city; } } } $districs = []; if (count($districIds)) { $select = $this->getDbSql()->select(array('c' => \Address\Model\DistrictMapper::TABLE_NAME)); $select->where(['id' => $districIds]); $query = $this->getDbSql()->buildSqlString($select); $rows = $dbAdapter->query($query, $dbAdapter::QUERY_MODE_EXECUTE); if ($rows->count()) { foreach ($rows as $row) { $distric = new \Address\Model\District(); $distric->exchangeArray((array) $row); $districs[$distric->getId()] = $distric; } } } if (count($paginator->getCurrentModels())) { foreach ($paginator->getCurrentModels() as $user) { if ($user->getCreatedById() && isset($users[$user->getCreatedById()])) { $user->addOption('createdBy', $users[$user->getCreatedById()]); } if ($user->getCityId() && isset($cities[$user->getCityId()])) { $user->setCity($cities[$user->getCityId()]); } if ($user->getDistrictId() && isset($districs[$user->getDistrictId()])) { $user->setDistrict($districs[$user->getDistrictId()]); } } } return $paginator; }
/** * @param \User\Model\User $user * @return boolean */ public function updateUser(\User\Model\User $user) { if (!$user->getId() && !$user->getEmail() && !$user->getUsername()) { return false; } /* @var $userMapper \User\Model\UserMapper */ $userMapper = $this->getServiceLocator()->get('User\\Model\\UserMapper'); if ($user->getPassword()) { $user->setSalt(substr(md5(rand(2000, 5000) . time() . rand(2000, 5000)), 0, 20)); $user->setPassword(md5($user->getSalt() . $user->getPassword())); } return $userMapper->updateUser($user); }
public function update(UserModel $user) { $sql = 'UPDATE user SET email=:email, username=:username, password=:password, firstname=:firstname, lastname=:lastname, birthdate=:birthdate, isActive=:isActive WHERE id=:id '; $this->getDb()->beginTransaction(); try { $stmt = $this->getDb()->prepare($sql); $stmt->execute(array('email' => $user->getEmail(), 'username' => $user->getUsername(), 'password' => $user->getPassword(), 'firstname' => $user->getFirstname(), 'lastname' => $user->getLastname(), 'birthdate' => $user->getBirthdate()->format('Y-m-d'), 'isActive' => $user->getIsActive(), 'id' => (int) $user->getId())); $this->getDb()->commit(); } catch (PDOException $e) { $this->getDb()->rollBack(); throw $e; } }
public function update(UserModel $user) { $query = sprintf(" UPDATE `user` " . "SET " . "`email`='%s'," . "`username`='%s'," . "`password`='%s'," . "`firstname`='%s'," . "`lastname`='%s'," . "`birthday`='%s'," . "`isActive`='%s'" . " WHERE user 'id' = " . $user->getId(), mysql_real_escape_string($user->getEmail()), mysql_real_escape_string($user->getUsername()), mysql_real_escape_string($user->getPassword()), mysql_real_escape_string($user->getFirstname()), mysql_real_escape_string($user->getLastname(), mysql_real_escape_string($user->getBirthdate()), mysql_real_escape_string($user->getIsActive()))); echo $query; $this->getDb()->exec($query); }
public function setCurrentUser(User $user) { $session = $this->getSession(); $session->set(self::SESSION_CURRENT_USER, $user->getId()); }