Пример #1
0
 public function isValid($value)
 {
     $isValid = true;
     $options = iterator_to_array($value);
     $this->setOptions($options);
     $EmailValidator = new EmailAddress();
     //var_dump($options);exit;
     if (!$EmailValidator->isValid($options['username'])) {
         $this->error("请填写有效邮箱");
         $isValid = false;
     }
     $LengthValidator = new \Zend\Validator\StringLength(['min' => 6, 'max' => 12]);
     if (!$LengthValidator->isValid($options['password'])) {
         $this->error("密码必须为6-12位");
     }
     if ($options['password'] !== $options['password1']) {
         $this->error("两次密码不一致");
         var_dump($this);
         echo "----";
         var_dump($this->getMessages());
         exit;
     }
 }
Пример #2
0
 /**
  * @param \User\Model\User $user
  * @return array
  */
 public function validateSignupInfo(\User\Model\User $user)
 {
     $error = array();
     $validateRequire = new \Zend\Validator\StringLength(array('min' => 6));
     $validateEmail = new \Zend\Validator\EmailAddress();
     $validateUsername = new \Zend\Validator\Db\NoRecordExists(array('table' => 'users', 'field' => 'username', 'adapter' => $this->getServiceLocator()->get('dbAdapter')));
     $validateUserEmail = new \Zend\Validator\Db\NoRecordExists(array('table' => 'users', 'field' => 'email', 'adapter' => $this->getServiceLocator()->get('dbAdapter')));
     if (!$validateUsername->isValid($user->getUsername())) {
         $error['username'] = self::DULICATE_USERNAME;
     }
     if (!$validateRequire->isValid($user->getUsername())) {
         $error['username'] = self::USERNAME_REQUIRED;
     }
     if (!$validateRequire->isValid($user->getPassword())) {
         $error['password'] = self::PASSWORD_REQUIRED;
     }
     if (!$validateUserEmail->isValid($user->getEmail())) {
         $error['email'] = self::DULICATE_USEREMAIL;
     }
     if (!$validateEmail->isValid($user->getEmail())) {
         $error['email'] = self::INVALID_EMAIL_FORMAT;
     }
     return $error;
 }
Пример #3
0
 public function index17Action()
 {
     echo "<h3 style='color:red;font-weight:bold'>" . __METHOD__ . "</h3>";
     //lap-trinh-2.php
     //laptrinh-2.html
     $validator = new \Zend\Validator\StringLength(10, 15);
     $validator->setMessages(array(\zend\Validator\StringLength::INVALID => "Dữ liệu không hơp lệ", \zend\Validator\StringLength::TOO_SHORT => "Chiều dài của '%value%' phải lớn hơn %min%", \zend\Validator\StringLength::TOO_LONG => "Chiều dài của '%value%' phải nhỏ hon %max%"));
     $input = "trongle";
     if (!$validator->isValid($input)) {
         $message = $validator->getMessages();
         echo current($message);
     } else {
         echo "ok";
     }
     return false;
 }
Пример #4
0
 /**
  * Call
  */
 public function call()
 {
     //print_r('MiddlewareTest middleware call method------');
     //print_r($this->next);
     //Read flash messaging from previous request if available
     //$this->loadMessages();
     //Prepare flash messaging for current request
     //$env = $this->app->environment();
     //$env['slim.flash'] = $this;
     // Create a validator chain and add validators to it
     $validatorChain = new \Zend\Validator\ValidatorChain();
     $validatorChain->attach(new \Zend\Validator\StringLength(array('min' => 6, 'max' => 12)))->attach(new \Zend\I18n\Validator\Alnum());
     // Validate the username
     if ($validatorChain->isValid("testteeewwwwwwwwwwwww__")) {
         // username passed validation
     } else {
         // username failed validation; print reasons
         /* foreach ($validatorChain->getMessages() as $message) {
                echo "$message\n";
            }*/
         //$this->app->redirect('/error');
         //$this->app->error();
         //$this->app->halt(500, "info status test!!!!");
         /*$this->app->contentType('application/json');
           $this->app->halt(500, '{"error":"Something went wrong"}');
           $this->app->stop();*/
         //exit();
         //$this->app->run();
         /*$response = $this->app->response();
         
                     //Generate Response headers
                     $response->header('Content-Type', "application/json");
                     $response->status(DEFAULT_RESPONSE_CODE);                  
                     $response->header('Content-Length', '500');
         
                     $responseBody = array('message'=> $message);
                     $response->body(json_encode($responseBody));
         
         
                     $response->send();*/
         //ob_clean();
         $publicHash = '3441df0babc2a2dda551d7cd39fb235bc4e09cd1e4556bf261bb49188f548348';
         $privateHash = 'e249c439ed7697df2a4b045d97d4b9b7e1854c3ff8dd668c779013653913572e';
         $content = json_encode(array('test' => 'content'));
         //$this->app->setPublicHash('3441df0babc2a2dda551d7cd39fb235bc4e09cd1e4556bf261bb49188f548348');
         //
         //print_r("------public hash---------".$this->app->getPublicHash()."------public hash---------");
         /*$hash = hash_hmac('sha256', $content, $privateHash);
         
                     $headers = array(
                         'X-Public: '.$publicHash,
                         'X-Hash: '.$hash
                     );
                     //ob_flush();
                     
                     
                     $ch = curl_init('http://localhost/slim_redirect_test/index.php/redirected_path');
                     curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
                     curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
                     curl_setopt($ch,CURLOPT_POSTFIELDS,$content);
         
                     $result = curl_exec($ch);
                     curl_close($ch);*/
         //ob_end_flush();
         /*ob_end_clean();
           $newURL = 'http://localhost/slim_redirect_test/index.php/redirected_path';
           header("Location: {$newURL}");*/
     }
     $validator = new \Zend\Validator\Barcode('EAN13');
     $floatValidator = new \Zend\I18n\Validator\IsFloat();
     if ($floatValidator->isValid(5.3)) {
         //print_r ("--float test edildi onaylandı---");
         $intValidator = new \Zend\I18n\Validator\IsInt();
     }
     $intValidator->setMessage("test validation");
     if ($intValidator->isValid(5)) {
         //print_r ("--int test edildi onaylandı---");
         $validator = new \Zend\Validator\StringLength();
     }
     $validator->setMax(6);
     $validator->isValid("Test");
     // returns true
     $validator->isValid("Testing");
     // returns false
     /*print_r($validator->isValid("Test"));
       print_r("fffffffffffffffffffff----    ");
       print_r($validator->isValid("Testing"));*/
     if (!$validator->isValid("Testing")) {
         //print_r("---is not valid----");
         $logger = new \Zend\Log\Logger();
     }
     $writer = new \Zend\Log\Writer\Stream('php://output');
     /*$logger->addWriter($writer);
       $logger->log(\Zend\Log\Logger::INFO, 'Informational message');
       $this->app->log->debug("test loggg");*/
     $this->next->call();
     //$this->save();
 }
 //echo $filterAlpha->filter("This....!!!As is (my) content: 123");
 //  if (  strlen($filterAlpha->filter($vName)) != strlen($vName)  ) {
 if (!$validatorAlpha->isValid($vName)) {
     $vName = $filterAlpha->filter($vName);
     $controlMessage = $controlMessage . ' içerisinde alfabetik olmayan değer var!!! // ';
     $errorcode = 3;
     $hatasayisi = $hatasayisi + 1;
 }
 if (!$validatorNotEmptyString->isValid($vName)) {
     $result = $validatorNotEmptyString->isValid($vName);
     $controlMessage = $controlMessage . '  Boş Değer //';
     $errorcode = 2;
     $hatasayisi = $hatasayisi + 1;
 }
 $validatorStringLength->setMessages(array('stringLengthTooShort' => $messageName . 'en az ' . $validatorStringLength->getMin() . ' karakter olmak zorunda...', 'stringLengthTooLong' => $messageName . 'en fazla ' . $validatorStringLength->getMax() . ' karakter olmak zorunda...'));
 if (!$validatorStringLength->isValid($vName)) {
     $messages = $validatorStringLength->getMessages();
     $controlMessage = $controlMessage . current($messages);
     $errorcode = 1;
     $hatasayisi = $hatasayisi + 1;
 }
 //////////////////////////////////////////////////////////////////////////
 $vParent = trim($_GET['parent']);
 $messageName = 'Parent Değerinde ';
 $controlMessage1 = $messageName;
 if (!$validatorAlpha->isValid($vParent)) {
     $vParent = $filterAlpha->filter($vParent);
     $controlMessage1 = $controlMessage1 . ' içerisinde alfabetik olmayan değer var!!! // ';
     $errorcode = 6;
     $hatasayisi1 = $hatasayisi1 + 1;
 }
Пример #6
0
 /**
  * @author KienNN
  */
 public function officeemployeeAction()
 {
     list($adapter, $sql) = $this->createOfficeAdapter();
     $mathGender = array('1' => \Home\Model\Consts::GENDER_MALE, '2' => \Home\Model\Consts::GENDER_FEMALE);
     $mathMaritalStatus = array('4' => \Hrm\Model\Employee::RELATIONSHIP_SINGLE, '5' => \Hrm\Model\Employee::RELATIONSHIP_MARRIED, '6' => \Hrm\Model\Employee::RELATIONSHIP_DIVORCED);
     $mathNation = array('1' => 'Kinh', '2' => 'Dân tộc', '3' => 'Tày');
     $mathReligion = array('6' => 'Không', '7' => 'Cơ đốc giáo', '8' => 'Hồi giáo', '9' => 'Phật giáo', '10' => 'Thiên chúa giáo');
     $mathWorkingStatus = array('STOP_WORKING' => \Hrm\Model\Employee::WORKING_STATUS_RETIRED, 'WORKING' => \Hrm\Model\Employee::WORKING_STATUS_WORKING, 'NOT_WORKING' => \Hrm\Model\Employee::WORKING_STATUS_PAUSE, 'PRACTICE' => \Hrm\Model\Employee::WORKING_STATUS_TRIAL);
     $mathQuitReason = array('10' => \Hrm\Model\Employee::QUIT_REASON_WORK_ENVIRONMENT, '11' => \Hrm\Model\Employee::QUIT_REASON_HEALTHY, '12' => \Hrm\Model\Employee::QUIT_REASON_SALARY, '13' => \Hrm\Model\Employee::QUIT_REASON_WORK_PRESSURE, '14' => \Hrm\Model\Employee::QUIT_REASON_WORK_SUITABLE, '15' => \Hrm\Model\Employee::QUIT_REASON_FORCED_TO_RESIGN, '16' => \Hrm\Model\Employee::QUIT_REASON_FAMILY);
     $mathWorkPlaces = ['4' => 'Hà Nội', '5' => 'Hồ Chí Minh', '6' => 'Đà Nẵng'];
     $mathWorkCityId = ['4' => '2', '5' => '3', '6' => '65'];
     $mathWorkPosition = [];
     $select = $sql->select(['p' => 'positions']);
     $rows = $adapter->query($sql->buildSqlString($select), Adapter::QUERY_MODE_EXECUTE);
     if ($rows->count()) {
         foreach ($rows->toArray() as $row) {
             $mathWorkPosition[$row['ID']] = $row['title'];
         }
     }
     $mathWorkPositionTitle = ['1' => 'Phó Giám Đốc', '2' => 'Giám Đốc', '3' => 'Cộng tác viên', '4' => 'Nhân viên', '5' => 'Trưởng phòng', '6' => 'Trưởng nhóm', '7' => 'Quản lý', '8' => 'Nhân viên Partime', '9' => 'Tổng giám đốc', '10' => 'Phó tổng giám đốc', '11' => 'Chủ tịch HĐQT'];
     $select = $sql->select(['p' => 'personnels']);
     $select->order(['ID ASC']);
     $paginatorAdapter = new \Zend\Paginator\Adapter\DbSelect($select, $adapter);
     $paginator = new \Zend\Paginator\Paginator($paginatorAdapter);
     $paginator->setItemCountPerPage(50);
     $page = $this->getRequest()->getQuery('page', 1);
     $totalEmployee = $this->getRequest()->getQuery('totalEmployee', 0);
     $totalUpdate = $this->getRequest()->getQuery('totalUpdate', 0);
     $paginator->setCurrentPageNumber($page);
     $employeeMapper = $this->getServiceLocator()->get('\\Hrm\\Model\\EmployeeMapper');
     $departmentMapper = $this->getServiceLocator()->get('\\Company\\Model\\DepartmentMapper');
     $companyMapper = $this->getServiceLocator()->get('\\Company\\Model\\CompanyMapper');
     $titleMapper = $this->getServiceLocator()->get('\\Company\\Model\\TitleMapper');
     $userMapper = $this->getServiceLocator()->get('\\User\\Model\\UserMapper');
     $mobileFilter = new \Home\Filter\Mobile();
     $mobileValidate = new \Zend\Validator\StringLength();
     $mobileValidate->setMin(10);
     $mobileValidate->setMax(11);
     $companyIdsInGroup = $this->company()->getCompanyIdsInGroup();
     foreach ($paginator as $row) {
         $row = (array) $row;
         $employee = new \Hrm\Model\Employee();
         $employee->setCode($row['code']);
         $employee->addOption('companyIds', $companyIdsInGroup);
         $employeeMapper->isExistedCode($employee);
         // check nếu employee đã có trong hệ thống sẽ update lại 1 số thông tin
         $employee->setOneofficeId($row['ID']);
         if (!$employee->getFirstName() && $row['first_name']) {
             $employee->setFirstName($row['first_name'] ?: '');
         } elseif (!$employee->getFirstName()) {
             $employee->setFirstName('');
         }
         if (!$employee->getLastName() && $row['last_name']) {
             $employee->setLastName($row['last_name']);
         } elseif (!$employee->getLastName()) {
             $employee->setLastName('');
         }
         //if(!$employee->getFullName()){
         if ($row['name']) {
             $employee->setFullName($row['name']);
             list($lastName, $middleName, $firstName) = Format::splitFullName($employee->getFullName());
             $employee->setFirstName($firstName);
             $employee->setMiddleName($middleName);
             $employee->setLastName($lastName);
         } else {
             $employee->setFullName(Format::displaySetItems([$employee->getFirstName(), $employee->getMiddleName(), $employee->getLastName()], ' '));
         }
         //}
         if (!$employee->getGender() && isset($mathGender[$row['gender']])) {
             $employee->setGender($mathGender[$row['gender']]);
         } else {
             $employee->setGender(\Home\Model\Consts::GENDER_MALE);
         }
         if (!$employee->getMaritalStatus() && $row['marital_status'] && isset($mathMaritalStatus[$row['marital_status']])) {
             $employee->setMaritalStatus($mathMaritalStatus[$row['marital_status']]);
         } else {
             $employee->setMaritalStatus(\Hrm\Model\Employee::RELATIONSHIP_SINGLE);
         }
         if (!$employee->getBirthdate() && $row['birthday']) {
             $employee->setBirthdate($row['birthday']);
         }
         if (!$employee->getBirthplace() && $row['place_of_birth']) {
             $employee->setBirthplace($this->mathPlace($row['place_of_birth']));
         }
         /* if(!$employee->getHometown() && $row['home_address']){
         				if(!$row['home_address_state']){
         					$employee->setHometown($row['home_address']);
         				} else {
         					$home_address_state = $this->mathPlace($row['home_address_state']);
         					$employee->setHometown(Format::displaySetItems(
         							array($row['home_address'], $home_address_state), ', '));
         				}
         			} */
         if (!$employee->getIdentification() && $row['private_code']) {
             $employee->setIdentification($row['private_code']);
         }
         if ($row['private_code_place']) {
             $employee->setIdentificationPlace($this->mathPlace($row['private_code_place']));
         }
         if (!$employee->getIdentificationDate() && $row['private_code_date']) {
             $employee->setIdentificationDate($row['private_code_date']);
         }
         // fix cứng luôn, bên kia cũng ko có nhân sự nước ngoài
         if (!$employee->getCountryId()) {
             $employee->setCountryId(243);
         }
         if (!$employee->getNation() && $row['nationality'] && isset($mathNation[$row['nationality']])) {
             $employee->setNation($mathNation[$row['nationality']]);
         }
         if (!$employee->getReligion() && $row['religious'] && isset($mathReligion[$row['religious']])) {
             $employee->setReligion($mathReligion[$row['religious']]);
         }
         if (!$employee->getCreatedDateTime()) {
             $employee->setCreatedDateTime($row['date_created']);
         }
         //@TODO fix đã
         /* if(!$employee->getStartedDate() && $row['job_date_join']){
         				$employee->setStartedDate($row['job_date_join']);
         			} */
         // Ngày nhập hồ sơ
         if ($row['job_date_join']) {
             $employee->setReceiveContractDate($row['job_date_join']);
         } else {
             $employee->setReceiveContractDate(null);
         }
         // ngày vào thực tế
         if ($row['job_reldate_join']) {
             $employee->setStartedDate($row['job_reldate_join']);
         } else {
             $employee->setStartedDate(null);
         }
         // Nơi làm việc
         if ($row['work_place'] && isset($mathWorkCityId[$row['work_place']])) {
             $employee->setWorkingCityId($mathWorkCityId[$row['work_place']]);
         }
         //  nguyên quán - quê quán
         if ($row['origin_id']) {
             $employee->setHometown($this->mathPlace($row['origin_id']));
         }
         if (!$employee->getDepartmentId() && $row['department_id']) {
             $deparmentInfor = $this->matchDepartment($row['department_id']);
             if (!$employee->getCompanyId() && isset($deparmentInfor['companyId'])) {
                 $employee->setCompanyId($deparmentInfor['companyId']);
             }
             if (!$employee->getDepartmentId() && isset($deparmentInfor['departmentId'])) {
                 $employee->setDepartmentId($deparmentInfor['departmentId']);
             }
         }
         if (!$employee->getCompanyId()) {
             $employee->setCompanyId(10);
         }
         if ($employee->getCompanyId() != 1 && $row['job_title']) {
             if (isset($mathWorkPositionTitle[$row['job_title']])) {
                 $title = new \Company\Model\Title();
             }
             $title->setCompanyId($employee->getCompanyId());
             $title->setName($mathWorkPositionTitle[$row['job_title']]);
             if (!$titleMapper->isExisted($title)) {
                 $title->setCreatedById($this->user()->getIdentity());
                 $title->setCreatedDateTime(DateBase::getCurrentDateTime());
                 $titleMapper->save($title);
             }
             $employee->setTitleId($title->getId());
         }
         if (!$employee->getWorkingStatus() && $row['job_status'] && isset($mathWorkingStatus[$row['job_status']])) {
             $employee->setWorkingStatus($mathWorkingStatus[$row['job_status']]);
         }
         if (!$employee->getTaxCode() && $row['job_tax']) {
             $employee->setTaxCode($row['job_tax']);
         }
         if (!$employee->getQuitDate() && $row['job_date_out']) {
             $employee->setQuitDate($row['job_date_out']);
         }
         if (!$employee->getQuitReason() && $row['job_out_reason'] && isset($mathQuitReason[$row['job_out_reason']])) {
             $employee->setQuitReason($mathQuitReason[$row['job_out_reason']]);
         }
         if (!$employee->getEmail() && $row['email'] && strlen($row['email']) < 225) {
             $employee->setEmail($row['email']);
         }
         if (!$employee->getYahoo() && $row['yahoo'] && strlen($row['yahoo']) < 100) {
             $employee->setYahoo($row['yahoo']);
         }
         if (!$employee->getSkype() && $row['skype'] && strlen($row['skype']) < 100) {
             $employee->setSkype($row['skype']);
         }
         if (!$employee->getFacebook() && $row['facebook'] && strlen($row['facebook']) < 100) {
             $employee->setFacebook($row['facebook']);
         }
         if (!$employee->getMobile() && $row['mobile']) {
             $mobile = $mobileFilter->filter($row['mobile']);
             if ($mobile && $mobileValidate->isValid($mobile)) {
                 $employee->setMobile($mobile ?: null);
             }
         }
         if (!$employee->getMobile() && $row['phone']) {
             $phone = $mobileFilter->filter($row['phone']);
             if ($phone && $mobileValidate->isValid($phone)) {
                 $employee->setMobile($phone ?: null);
             }
         }
         if (!$employee->getPermanentAddress() && $row['home_address']) {
             if (!$row['home_address_state']) {
                 $employee->setPermanentAddress(substr($row['home_address'], 0, 225));
             } else {
                 $home_address_state = $this->mathPlace($row['home_address_state']);
                 $employee->setPermanentAddress(substr(Format::displaySetItems(array($row['home_address'], $home_address_state), ', '), 0, 225));
             }
         }
         if (!$employee->getTemporateAddress() && $row['current_address']) {
             if (!$row['current_address_state']) {
                 $employee->setTemporateAddress(substr($row['current_address'], 0, 225));
             } else {
                 $home_address_state = $this->mathPlace($row['current_address_state']);
                 $employee->setTemporateAddress(substr(Format::displaySetItems(array($row['current_address'], $home_address_state), ', '), 0, 225));
             }
         }
         if (!$employee->getBirthCertificate() && $row['birth_certificate']) {
             $employee->setBirthCertificate(\Hrm\Model\Employee::BIRTH_CERTIFICATE);
         }
         if ($employee->getExtraContent()) {
             $extraContent = json_decode($employee->getExtraContent(), true);
             if ($row['position_id'] && isset($mathWorkPosition[$row['position_id']])) {
                 $extraContent['workPosition'] = $mathWorkPosition[$row['position_id']];
             }
             $employee->setExtraContent(json_encode($extraContent));
         }
         // check nếu là employee mới mới update các thông tin phía sau, nếu ko save lại chạy tiếp
         if ($employee->getId()) {
             $employeeMapper->save($employee);
             $totalUpdate++;
             continue;
         }
         if (!$employee->getCreatedDateTime() && $row['date_created']) {
             if ($row['date_created'] != '0000-00-00 00:00:00') {
                 $employee->setCreatedDateTime($row['date_created']);
             } else {
                 $employee->setCreatedDateTime(DateBase::getCurrentDateTime());
             }
         } else {
             $employee->setCreatedDateTime(DateBase::getCurrentDateTime());
         }
         if (!$employee->getCreatedById()) {
             $employee->setCreatedById(1);
         }
         if ($row['department_id']) {
             $deparmentInfor = $this->matchDepartment($row['department_id']);
             if (!$employee->getCompanyId() && isset($deparmentInfor['companyId'])) {
                 $employee->setCompanyId($deparmentInfor['companyId']);
             }
             if (!$employee->getDepartmentId() && isset($deparmentInfor['departmentId'])) {
                 $employee->setDepartmentId($deparmentInfor['departmentId']);
             }
         }
         if (!$employee->getCompanyId()) {
             $employee->setCompanyId(10);
         }
         //tạo mới title nếu chưa có
         $employeeMapper->save($employee);
         $totalEmployee++;
     }
     $this->getViewModel()->setTerminal(true);
     $this->getViewModel()->setVariable('paginator', $paginator);
     $this->getViewModel()->setVariable('page', $page);
     $this->getViewModel()->setVariable('totalPages', $paginator->count() + 1);
     $this->getViewModel()->setVariable('totalEmployee', $totalEmployee);
     $this->getViewModel()->setVariable('totalUpdate', $totalUpdate);
     if ($page <= $paginator->count()) {
         $this->getViewModel()->setVariable('redirectUri', Uri::build('/system/tool/officeemployee', ['page' => $page + 1, 'totalEmployee' => $totalEmployee, 'totalUpdate' => $totalUpdate]));
     }
     return $this->getViewModel();
 }
Пример #7
0
 /**
  * Valid form such as subject, subtitle, category, slug etc.
  * 
  * @param array   $data      Posted data for validating
  * @param string  $article   
  * @param array   $elements  Displaying form defined by user
  * @return array 
  */
 protected function validateForm($data, $article = null, $elements = array())
 {
     $result = array('status' => self::RESULT_TRUE, 'message' => array(), 'data' => array());
     $config = Pi::config('', $this->getModule());
     $modelArticle = $this->getModel('article');
     // Validate subject
     if (in_array('subject', $elements)) {
         $subjectLength = new \Zend\Validator\StringLength(array('max' => $config['max_subject_length'], 'encoding' => 'utf-8'));
         if (empty($data['subject'])) {
             $result['status'] = self::RESULT_FALSE;
             $result['message']['subject'] = array('isEmpty' => __('Subject cannot be empty.'));
         } else {
             if (!$subjectLength->isValid($data['subject'])) {
                 $result['status'] = self::RESULT_FALSE;
                 $result['message']['subject'] = $subjectLength->getMessages();
             } else {
                 if ($modelArticle->checkSubjectExists($data['subject'], $article)) {
                     $result['status'] = self::RESULT_FALSE;
                     $result['message']['subject'] = array('duplicated' => __('Subject is used by another article.'));
                 }
             }
         }
     }
     // Validate slug
     if (in_array('slug', $elements) and !empty($data['slug'])) {
         if (!$subjectLength->isValid($data['slug'])) {
             $result['status'] = self::RESULT_FALSE;
             $result['message']['slug'] = $subjectLength->getMessages();
         }
     }
     // Validate subtitle
     if (in_array('subtitle', $elements)) {
         $subtitleLength = new \Zend\Validator\StringLength(array('max' => $config['max_subtitle_length'], 'encoding' => 'utf-8'));
         if (isset($data['subtitle']) && !$subtitleLength->isValid($data['subtitle'])) {
             $result['status'] = self::RESULT_FALSE;
             $result['message']['subtitle'] = $subtitleLength->getMessages();
         }
     }
     // Validate summary
     if (in_array('summary', $elements)) {
         $summaryLength = new \Zend\Validator\StringLength(array('max' => $config['max_summary_length'], 'encoding' => 'utf-8'));
         if (isset($data['summary']) && !$summaryLength->isValid($data['summary'])) {
             $result['status'] = self::RESULT_FALSE;
             $result['message']['summary'] = $summaryLength->getMessages();
         }
     }
     // Validate category
     if (in_array('category', $elements) and empty($data['category'])) {
         $result['status'] = self::RESULT_FALSE;
         $result['message']['category'] = array('isEmpty' => __('Category cannot be empty.'));
     }
     return $result;
 }
Пример #8
0
<?php

# Requerir archivo base..
require_once 'base.php';
# Instancia de Zendframwork/zend-validation.
$filter = new Zend\Validator\StringLength(array('min' => 4, 'max' => 32));
# Peticion POST.
$app->post('/', function ($request) use($db, $app, $main, $filter) {
    # Optener variables.
    $json = json_decode($request->getBody());
    $usuario = filter_var($json->user, FILTER_SANITIZE_STRING);
    $password = filter_var($json->pass, FILTER_SANITIZE_STRING);
    // Validar datos.
    if ($filter->isValid($usuario) && $filter->isValid($password)) {
        $sql = $db->select(array('u.id id', 'u.per_cuil usuario', 'u.app app', 'ju.usu_pass password', 'ju.usu_estado estado', 'jp.per_nombres nombre', 'jp.per_apellidos apellido'))->from('usuarios u')->join('jujuy_usuarios ju', 'ju.per_cuil', '=', 'u.per_cuil')->join('jujuy_personas jp', 'jp.per_cuil', '=', 'u.per_cuil')->where('u.per_cuil', '=', $usuario)->where('ju.usu_pass', '=', $password)->where('ju.usu_estado', '=', 1)->where('u.app', '=', 'adminpre');
        $query = $sql->execute();
        $user = $query->fetch();
        if (is_array($user) && count($user) && $user['id']) {
            // Buscar categorias de partes de prensa.
            $sql = $db->select(array("upper(replace(pc.nombre,'-',' ')) nombre", 'pc.id categoria'))->from('bloque_prensa bp')->join('partes_categoria pc', 'pc.id', '=', 'bp.partes_categoria_id')->where('bp.jujuy_usuarios_per_cuil', '=', $usuario);
            $query = $sql->execute();
            $categorias = $query->fetchAll();
            if (count($categorias)) {
                $date = new DateTime();
                $_SESSION['loggedin'] = true;
                $_SESSION['loggeddate'] = $date->getTimestamp();
                $_SESSION['user'] = array('id' => $user['id'], 'nombre' => $user['nombre'] . ' ' . $user['apellido'], 'categorias' => $categorias);
                echo json_encode(array('result' => true, 'user' => $_SESSION['user']), JSON_FORCE_OBJECT);
            } else {
                $main->error404();
            }