Ejemplo n.º 1
0
 /**
  * @param \User\Model\User $item
  */
 public function suggest($item)
 {
     $item->prepairSuggest();
     $select = $this->getDbSql()->select(array('u' => self::TABLE_NAME), array('id', 'username', 'fullName', 'email', 'role'));
     $select->columns(['id', 'username', 'fullName', 'email', 'role']);
     $select->where(['(u.username LIKE ? OR u.fullName LIKE ? OR u.email LIKE ?)' => ['%' . $item->getUsername() . '%', '%' . $item->getUsername() . '%', '%' . $item->getUsername() . '%']]);
     $select->where(['role  != ?' => User::ROLE_MENTOR]);
     //        $select->where(['role  != ?'=> User::ROLE_SUPERADMIN]);
     if ($item->getOption('ids')) {
         $select->where(['u.id' => $item->getOption('ids')]);
     }
     if ($item->getRole()) {
         $select->where(['u.role' => $item->getRole()]);
     }
     $select->limit(20);
     $query = $this->getDbSql()->buildSqlString($select);
     $rows = $this->getDbAdapter()->query($query, Adapter::QUERY_MODE_EXECUTE);
     $result = [];
     $userIds = [];
     if ($rows->count()) {
         foreach ($rows as $row) {
             $row = (array) $row;
             $row['label'] = $row['username'] . ' - ' . ($row['fullName'] ?: $row['email']);
             $result[] = $row;
             $userIds[$row['id']] = $row['id'];
         }
     }
     return $result;
 }
Ejemplo n.º 2
0
 public function addAction()
 {
     /** @var \Zend\Http\Request $request */
     $request = $this->getRequest();
     $sl = $this->getServiceLocator();
     /* @var $cityMapper \Address\Model\CityMapper */
     $cityMapper = $sl->get('Address\\Model\\CityMapper');
     $city = new \Address\Model\City();
     /* @var $districtMapper \Address\Model\DistrictMapper */
     $districtMapper = $sl->get('Address\\Model\\DistrictMapper');
     $district = new \Address\Model\District();
     $districts = array();
     if (!!($cityId = $request->getPost('cityId'))) {
         $district->setCityId($cityId);
         $districts = $districtMapper->fetchAll($district);
     }
     $form = new \System\Form\User\Add($this->getServiceLocator());
     $form->setCities($city->toSelectBoxArray($cityMapper->fetchAll()));
     $form->setDistricts($district->toSelectBoxArray($districts));
     if ($this->getRequest()->isPost()) {
         $data = $this->getRequest()->getPost();
         $form->setData($data);
         if ($form->isValid()) {
             $user = new User();
             $user->exchangeArray($form->getData());
             $user->setSalt($user->generateSalt());
             $user->setPassword($user->createPassword());
             if (!$user->getRole()) {
                 $user->setRole(User::ROLE_GUEST);
             }
             if ($user->getBirthdate()) {
                 $user->setBirthdate(DateBase::toCommonDate($user->getBirthdate()));
             }
             $user->setActive(1);
             $user->setCreatedById($this->user()->getIdentity());
             $user->setCreatedDate(DateBase::getCurrentDate());
             $user->setCreatedDateTime(DateBase::getCurrentDateTime());
             $userMapper = $this->getServiceLocator()->get('\\User\\Model\\UserMapper');
             $userMapper->save($user);
             if ($form->get('afterSubmit')->getValue()) {
                 return $this->redirect()->toUrl($form->get('afterSubmit')->getValue());
             }
         }
     }
     $viewModel = new ViewModel();
     $viewModel->setVariable('form', $form);
     return $viewModel;
 }