コード例 #1
0
 public function __construct()
 {
     $input = new \Zend\InputFilter\Input('prenom');
     $input->setRequired(true);
     $filter = new \Zend\Filter\StringTrim();
     $input->getFilterChain()->attach($filter);
     $validator = new \Zend\Validator\StringLength();
     $validator->setMax(40);
     $input->getValidatorChain()->attach($validator);
     $validator = new \Zend\Validator\NotEmpty();
     $validator->setMessage('Le prénom est obligatoire', \Zend\Validator\NotEmpty::IS_EMPTY);
     $input->getValidatorChain()->attach($validator);
     $this->add($input);
 }
コード例 #2
0
 public function __construct($em)
 {
     $input = new \Zend\InputFilter\Input('prenom');
     $filter = new \Zend\Filter\StringTrim();
     $input->getFilterChain()->attach($filter);
     $validator = new \Zend\Validator\StringLength();
     $validator->setMax(40);
     $input->getValidatorChain()->attach($validator);
     $validator = new \Zend\Validator\NotEmpty();
     $validator->setMessage('Le prénom est obligatoire', \Zend\Validator\NotEmpty::IS_EMPTY);
     $input->getValidatorChain()->attach($validator);
     $this->add($input);
     $input = new \Zend\InputFilter\Input('email');
     $input->setRequired(false);
     $validator = new \DoctrineModule\Validator\NoObjectExists(array('object_repository' => $em->getRepository('AddressBook\\Entity\\Contact'), 'fields' => 'email'));
     $input->getValidatorChain()->attach($validator);
     //        $validator->setMessage("Cet email existe déjà", \DoctrineModule\Validator\NoObjectExists::ERROR_NO_OBJECT_FOUND);
     $this->add($input);
 }
コード例 #3
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();
 }
コード例 #4
0
 $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;
 }
 if (!$validatorNotEmptyString->isValid($vParent)) {
     $result = $validatorNotEmptyString->isValid($vParent);
     $controlMessage1 = $controlMessage1 . '  Boş Değer //';
     $errorcode = 5;
     $hatasayisi1 = $hatasayisi1 + 1;
 }
 $validatorStringLength->setMin(1);
 $validatorStringLength->setMax(20);
 $validatorStringLength->setMessages(array('stringLengthTooShort' => $controlMessage1 . 'en az ' . $validatorStringLength->getMin() . ' karakter olmak zorunda...', 'stringLengthTooLong' => $controlMessage1 . 'en fazla ' . $validatorStringLength->getMax() . ' karakter olmak zorunda...'));
 if (!$validatorStringLength->isValid($vParent)) {
     $messages = $validatorStringLength->getMessages();
     $controlMessage1 = $controlMessage1 . current($messages);
     $errorcode = 4;
     $hatasayisi1 = $hatasayisi1 + 1;
 }
 //////////////////////////////////////////////////////////////////////////
 $vRoot = trim($_GET['root']);
 $messageName = 'Root Değerinde ';
 $controlMessage2 = $messageName;
 if (!$validatorAlpha->isValid($vRoot)) {
     $vRoot = $filterAlpha->filter($vRoot);
     $controlMessage2 = $controlMessage2 . ' içerisinde alfabetik olmayan değer var!!! // ';
     $errorcode = 9;
コード例 #5
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();
 }