예제 #1
0
파일: User.php 프로젝트: m3uzz/module
 /**
  * 
  * @param string $psValue
  * @return \User\Entity\User
  */
 public function setStUsername($psValue)
 {
     $psValue = trim($psValue);
     if (!empty($psValue)) {
         $this->stUsername = String::escapeString($psValue);
     }
     return $this;
 }
예제 #2
0
파일: Person.php 프로젝트: m3uzz/module
 /**
  * 
  * @param int $pnValue
  * @return \Person\Entity\Person
  */
 public function setUser_id($pnValue)
 {
     $this->User_id = null;
     if (!empty($pnValue)) {
         $this->User_id = (int) String::escapeString($pnValue);
     }
     return $this;
 }
예제 #3
0
 public function getList($paParams, $pbCache = false)
 {
     $paParams['col'] = String::escapeString($paParams['col']);
     $paParams['ord'] = String::escapeString($paParams['ord']);
     $paParams['page'] = String::escapeString($paParams['page']);
     $paParams['rows'] = String::escapeString($paParams['rows']);
     $loQB = $this->getEntityManager()->createQueryBuilder();
     $loQB->from("{$this->_entityName}", 'a');
     $loQB->where("1=1");
     if (isset($paParams['status']) && is_numeric($paParams['status'])) {
         $loQB->andWhere("a.numStatus = {$paParams['status']}");
     }
     if (isset($paParams['active']) && is_numeric($paParams['active'])) {
         $loQB->andWhere("a.isActive = '{$paParams['active']}'");
     }
     if (!empty($paParams['dtPeriodInit']) && !empty($paParams['dtPeriodEnd'])) {
         $loQB->andWhere("(a.dtInsert BETWEEN '{$paParams['dtPeriodInit']}' AND '{$paParams['dtPeriodEnd']}')");
     } else {
         if (!empty($paParams['dtPeriodInit'])) {
             $loQB->andWhere("a.dtInsert >= '{$paParams['dtPeriodInit']}'");
         } elseif (!empty($paParams['dtPeriodEnd'])) {
             $loQB->andWhere("a.dtInsert <= '{$paParams['dtPeriodEnd']}'");
         }
     }
     if (!empty($paParams['stIP'])) {
         $loQB->andWhere("a.stIP = '{$paParams['stIP']}'");
     }
     if (!empty($paParams['User_id'])) {
         $loQB->andWhere("a.User_id = '{$paParams['User_id']}'");
     }
     if (isset($paParams['where'])) {
         if (is_array($paParams['where'])) {
             foreach ($paParams['where'] as $lsWhere) {
                 if (!empty($lsWhere)) {
                     $loQB->andWhere("{$lsWhere}");
                 }
             }
         } else {
             if (!empty($paParams['where'])) {
                 $loQB->andWhere("{$paParams['where']}");
             }
         }
     }
     $loQB->select("count('a') AS qt");
     $loQB->distinct();
     //Debug::display($loQB->getDql());
     $loQueryPaginator = $loQB->getQuery();
     $loQB->select('a');
     $lsOrderField = $paParams['col'];
     if (!preg_match("/^[a-z]+\\./", $lsOrderField)) {
         $lsOrderField = "a.{$lsOrderField}";
     }
     $loQB->orderBy("{$lsOrderField}", "{$paParams['ord']}");
     //Debug::display($loQB->getDql());
     $loQuery = $loQB->getQuery();
     if ($paParams['rows'] > 0) {
         $loQuery->setFirstResult($paParams['page']);
         $loQuery->setMaxResults($paParams['rows']);
     }
     if (!$pbCache) {
         $loQuery->expireResultCache(true);
     } else {
         $loQuery->setResultCacheDriver(new ApcCache());
         $loQuery->useResultCache(true);
         $loQuery->setResultCacheLifeTime(3600);
     }
     $laObjectResults = $loQuery->getResult();
     $laArrayResults = null;
     $lnTotalCount = 0;
     if (is_array($laObjectResults)) {
         foreach ($laObjectResults as $loRes) {
             $laArrayResults[] = $loRes->getFormatedData();
             $lnTotalCount++;
         }
     }
     if ($paParams['rows'] > 0) {
         $laPaginatorResult = $loQueryPaginator->getResult();
         if (isset($laPaginatorResult[0]['qt'])) {
             $lnTotalCount = $laPaginatorResult[0]['qt'];
         }
     }
     return array('resultSet' => $laArrayResults, 'totalCount' => $lnTotalCount);
 }
예제 #4
0
 /**
  *
  * @return \Onion\View\Model\ViewModel
  */
 public function forgottenPasswordAction()
 {
     $loForm = Application::factory($this->_sForgotten);
     $loForm->setObjectManager($this->getEntityManager());
     $loForm->setActionType('forgotten');
     $loForm->setEntity($this->_sEntity);
     $loForm->setForm();
     $lsSecurity = $this->requestPost('security', null);
     if ($this->requestIsPost() && $lsSecurity !== null) {
         $loForm->setInputFilter($loForm->getInputFilter());
         $loForm->setData($this->requestPost());
         if ($loForm->isValid()) {
             $laData = $loForm->getDataForm();
             $lsEmail = String::escapeString($laData['stEmail']);
             $loEntityManager = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
             $loUser = $loEntityManager->getRepository($this->_sEntity)->findOneBy(array('stEmail' => $lsEmail));
             $lsPassword = String::generatePassword();
             if ($this->sendPasswordByEmail($lsEmail, $lsPassword)) {
                 $loUser->setStPassword($lsPassword);
                 $loEntityManager->persist($loUser);
                 $loEntityManager->flush();
             }
         }
     }
     return new ViewModel(array('lsTitle' => $this->_sForgottenTitle, 'lsRoute' => $this->_sRoute, 'loForm' => $loForm));
 }
예제 #5
0
 public function isValid()
 {
     $lbValid = parent::isValid();
     if ($this->getActionType() == 'add') {
         $laFindBy = $this->getObjectManager()->getRepository($this->getEntity())->findBy(array('stName' => String::escapeString($this->data['stName'])));
         if (isset($laFindBy[0]) && is_object($laFindBy[0])) {
             $lbValid = false;
             $this->get('stName')->setMessages(array(Translator::i18n('Este nome de grupo já está sendo utilizado!')));
         }
     } else {
         $this->data['stName'] = $this->getEntityData()->get('stName');
     }
     return $lbValid;
 }
예제 #6
0
파일: UserForm.php 프로젝트: m3uzz/module
 public function isValidx()
 {
     $lbValid = parent::isValid();
     if ($this->getActionType() == 'add') {
         $loFound = $this->getObjectManager()->getRepository($this->_sEntity)->findOneBy(array('stUsername' => String::escapeString($this->data['stUsername'])));
         if (is_object($loFound)) {
             $lbValid = false;
             $this->get('stUsername')->setMessages(array(Translator::i18n('Este nome de usuário já está sendo utilizado!')));
         }
         $loFound = $this->getObjectManager()->getRepository($this->_sEntity)->findOneBy(array('stEmail' => String::escapeString($this->data['stEmail'])));
         if (is_object($loFound)) {
             $lbValid = false;
             $this->get('stEmail')->setMessages(array(Translator::i18n('Este email de contato já está sendo utilizado!')));
         }
         if ($this->data['stPassword'] != $this->data['stConfirmation']) {
             $lbValid = false;
             $this->get('stConfirmation')->setMessages(array(Translator::i18n('A confirmação da senha não confere!')));
         }
     } else {
         $this->data['stUsername'] = $this->getEntityData()->get('stUsername');
         $loFound = $this->getObjectManager()->getRepository($this->_sEntity)->findOneBy(array('stEmail' => String::escapeString($this->data['stEmail'])));
         if (is_object($loFound) && $loFound->get('id') != $this->data['id']) {
             $lbValid = false;
             $this->get('stEmail')->setMessages(array(Translator::i18n('Este email de contato já está sendo utilizado!')));
         }
         if (!empty($this->data['stOldPassword'])) {
             $lsPasswordGiven = String::encriptPassword($this->data['stOldPassword'], $this->getEntityData()->get('stPasswordSalt'));
             if ($lsPasswordGiven == $this->getEntityData()->get('stPassword')) {
                 if ($this->data['stOldPassword'] != $this->data['stPassword']) {
                     if ($this->data['stPassword'] != $this->data['stConfirmation']) {
                         $lbValid = false;
                         $this->get('stConfirmation')->setMessages(array(Translator::i18n('A confirmação não confere com a senha!')));
                     }
                 } else {
                     $lbValid = false;
                     $this->get('stPassword')->setMessages(array(Translator::i18n('A nova senha deve ser diferente da senha atual!')));
                 }
             } else {
                 $lbValid = false;
                 $this->get('stOldPassword')->setMessages(array(Translator::i18n('A senha atual não confere com a registrada!')));
             }
         } else {
             $this->data['stPassword'] = $this->getEntityData()->get('stPassword');
         }
     }
     return $lbValid;
 }
예제 #7
0
파일: Entity.php 프로젝트: m3uzz/onionfw
 /**
  * Populate from an array.
  *
  * @param array $paData
  */
 public function populate($paData = array())
 {
     if (is_array($paData)) {
         foreach ($paData as $lsProperty => $lmValue) {
             if (property_exists($this, $lsProperty)) {
                 $lsMethod = 'set' . ucfirst($lsProperty);
                 if (method_exists($this, $lsMethod)) {
                     $this->{$lsMethod}($lmValue);
                 } else {
                     $this->{$lsProperty} = String::escapeString($lmValue);
                 }
             }
         }
     }
 }
예제 #8
0
 public function search($paParams, $pbCache = false)
 {
     $paParams['col'] = String::escapeString($paParams['col']);
     $paParams['ord'] = String::escapeString($paParams['ord']);
     $paParams['rows'] = String::escapeString($paParams['rows']);
     $loQB = $this->getEntityManager()->createQueryBuilder();
     $loQB->from("{$this->_entityName}", 'a');
     $loQB->where("a.numStatus = {$paParams['status']}");
     $loQB->andWhere("a.isActive = '{$paParams['active']}'");
     if (isset($paParams['where'])) {
         if (is_array($paParams['where'])) {
             foreach ($paParams['where'] as $lsWhere) {
                 if (!empty($lsWhere)) {
                     $loQB->andWhere("{$lsWhere}");
                 }
             }
         } else {
             if (!empty($paParams['where'])) {
                 $loQB->andWhere("{$paParams['where']}");
             }
         }
     }
     $loQB->distinct();
     $loQB->select('a');
     $lsOrderField = $paParams['col'];
     if (!preg_match("/^[a-z]+\\./", $lsOrderField)) {
         $lsOrderField = "a.{$lsOrderField}";
     }
     $loQB->orderBy("{$lsOrderField}", "{$paParams['ord']}");
     //Debug::display($loQB->getDql());
     $loQuery = $loQB->getQuery();
     if ($paParams['rows'] > 0) {
         $loQuery->setMaxResults($paParams['rows']);
     }
     if (!$pbCache) {
         $loQuery->expireResultCache(true);
     } else {
         $loQuery->setResultCacheDriver(new ApcCache());
         $loQuery->useResultCache(true);
         $loQuery->setResultCacheLifeTime(3600);
     }
     $laObjectResults = $loQuery->getResult();
     $laArrayResults = null;
     $lnTotalCount = 0;
     if (is_array($laObjectResults)) {
         foreach ($laObjectResults as $loRes) {
             $laArrayResults[] = $loRes->getFormatedData();
             $lnTotalCount++;
         }
     }
     return array('resultSet' => $laArrayResults, 'totalCount' => $lnTotalCount);
 }
예제 #9
0
파일: Search.php 프로젝트: m3uzz/onionfw
 /**
  * 
  * @param string $psQuery
  * @param string $psOrder
  * @return boolean|string
  */
 public function createFullTextQuery($psQuery, $psOrder = "r")
 {
     $this->startTime();
     $this->_sOriginalQuery = trim(String::escapeString($psQuery));
     $lsOrderBy = "relevance DESC, dtInsert DESC";
     if ($psOrder == "d") {
         $lsOrderBy = "dtInsert DESC, relevance DESC";
     }
     if (empty($this->_sOriginalQuery) && $psOrder == "r") {
         $this->_nError = '1';
         return false;
     } elseif (!empty($this->_sOriginalQuery)) {
         $this->setSearchType();
         // $this->stopWords();
         $this->cutString();
         $this->createRLikeTerm();
         if ($this->_sSearchType != "expression") {
             $this->_sQuery = "'{$this->_sQuery}' IN BOOLEAN MODE";
         } else {
             $this->_sQuery = "'{$this->_sQuery}'";
         }
         $lsWhere = "AND MATCH ({$this->_sSearchFields}) AGAINST ({$this->_sQuery})";
         $lsRelevancia = "MATCH ({$this->_sSearchFields}) AGAINST ({$this->_sQuery})";
         if (is_array($this->_sSearchFields)) {
             $lsOr = "";
             foreach ($this->_sSearchFields as $lsKey => $lsField) {
                 $lsWhere .= $lsOr . "{$lsField} {$this->_sQuery}";
                 $lsOr = " OR ";
             }
         } elseif (!empty($this->_sSearchFields)) {
             $lsWhere .= "{$this->_sSearchFields} {$this->_sQuery}";
         }
     } else {
         $lsWhere = "";
     }
     return $this->_sWhere = $lsWhere;
 }