/** * * @param Zend_Date $iniDate * @return int */ public static function getMonth(Zend_Date $iniDate, $now = null) { $date = $now ? $now : new Zend_Date(); $difference = $date->sub($iniDate); $measure = new Zend_Measure_Time($difference->toValue(), Zend_Measure_Time::SECOND); $measure->convertTo(Zend_Measure_Time::MONTH); return round($measure->getValue()); }
protected function getDiff(Zend_Date $timeThen, $timeNow = null) { if (!$timeNow instanceof Zend_Date) { $timeNow = new Zend_Date(); } $difference = $timeNow->isLater($timeThen) ? $timeNow->sub($timeThen) : $timeThen->sub($timeNow); //$difference = $timeNow->sub($timeThen); $measure = new Zend_Measure_Time($difference->toValue(), Zend_Measure_Time::SECOND); if ($measure->compare(new Zend_Measure_Time(0)) == 0) { return $measure->convertTo(Zend_Measure_Time::SECOND, 0); } $units = array('SECOND' => array('1', 's'), 'MINUTE' => array('60', 'min'), 'HOUR' => array('3600', 'h'), 'DAY' => array('86400', 'day'), 'WEEK' => array('604800', 'week'), 'MONTH' => array('2628600', 'month'), 'YEAR' => array('31536000', 'year')); foreach ($units as $unitId => $unit) { if (is_array($unit) && $unit[0] / abs($measure->getValue(-1)) > 1) { break; } $convertTo = $unitId; } return $measure->convertTo($convertTo, 0); }
/** * * @return int|bool */ public function save() { $dbAdapter = Zend_Db_Table_Abstract::getDefaultAdapter(); $dbAdapter->beginTransaction(); try { $dateStart = new Zend_Date($this->_data['date_start']); $dateFinish = new Zend_Date($this->_data['date_finish']); $mapperRule = new Fefop_Model_Mapper_Rule(); $mapperRule->validate($this->_message, $this->_data, Fefop_Model_Mapper_Expense::CONFIG_PFPCI_RI); // Check if the initial date is later than finish date if ($dateStart->isLater($dateFinish)) { $this->_message->addMessage('Data loron keta liu data remata.'); $this->addFieldError('date_start')->addFieldError('date_finish'); return false; } // If there is no contract yet if (empty($this->_data['fk_id_fefop_contract'])) { $dataContract = array('module' => Fefop_Model_Mapper_Module::RI, 'district' => $this->_data['fk_id_adddistrict']); $mapperFefopContract = new Fefop_Model_Mapper_Contract(); $this->_data['fk_id_fefop_contract'] = $mapperFefopContract->save($dataContract); } $this->_data['amount'] = App_General_String::toFloat($this->_data['amount']); $this->_data['date_start'] = $dateStart->toString('yyyy-MM-dd'); $this->_data['date_finish'] = $dateFinish->toString('yyyy-MM-dd'); $dataForm = $this->_data; // Save the contract $dataForm['id_ri_contract'] = parent::_simpleSave(); // Save budget category $this->_saveExpenses($dataForm); if (empty($this->_data['id_ri_contract'])) { $history = 'REJISTU KONTRAKTU RI: %s'; } else { $history = 'ATUALIZA KONTRAKTU RI: %s'; } $history = sprintf($history, $dataForm['id_ri_contract']); $this->_sysAudit($history); if ($this->_data['amount'] > self::LIMIT_AMOUNT) { $this->_sendWarningAmount($dataForm['id_ri_contract']); } $diff = $dateFinish->sub($dateStart); $measure = new Zend_Measure_Time($diff->toValue(), Zend_Measure_Time::SECOND); $diffMonth = preg_replace('/[^0-9.]/i', '', $measure->convertTo(Zend_Measure_Time::MONTH, 0)); if ((double) $diffMonth > self::MOUNTH_LIMIT) { $this->_sendWarningDuration($dataForm['id_ri_contract']); } $dbAdapter->commit(); return $dataForm['id_ri_contract']; } catch (Exception $e) { $dbAdapter->rollBack(); $this->_message->addMessage($this->_config->messages->error, App_Message::ERROR); return false; } }
/** * */ public function calcDiffDaysAction() { $dateInit = new Zend_Date($this->_getParam('date_start')); $dateFinish = new Zend_Date($this->_getParam('date_finish')); $diff = $dateFinish->sub($dateInit); $measure = new Zend_Measure_Time($diff->toValue(), Zend_Measure_Time::SECOND); $diffDays = $measure->convertTo(Zend_Measure_Time::DAY, 0); $this->_helper->json(array('diff' => preg_replace('/[^0-9]/i', '', $diffDays) + 1)); }
/** * * @param int $feContract * @return string */ public function getFEGreaterDuration($feContract) { $view = Zend_Layout::getMvcInstance()->getView(); $link = '<a href="%s" target="_blank">%s</a>'; $feContractNum = Fefop_Model_Mapper_Contract::buildNumRow($feContract); $feLink = sprintf($link, $view->baseUrl('/fefop/fe-contract/edit/id/' . $feContract->id_fe_contract), $feContractNum); $measure = new Zend_Measure_Time(Fefop_Model_Mapper_FEContract::MOUNTH_LIMIT, Zend_Measure_Time::MONTH); $diffMonths = $measure->convertTo(Zend_Measure_Time::MONTH, 0); $dateInit = new Zend_Date($feContract->date_start); $dateFinish = new Zend_Date($feContract->date_finish); $diff = $dateFinish->sub($dateInit); $measure = new Zend_Measure_Time($diff->toValue(), Zend_Measure_Time::SECOND); $diiffMonth = $measure->convertTo(Zend_Measure_Time::MONTH, 0); return sprintf(self::FE_DURATION_GREATER, $feLink, $diffMonths, $diiffMonth); }
/** * */ public function fetchClassAction() { $mapperStudentClass = new StudentClass_Model_Mapper_StudentClass(); $studentClass = $mapperStudentClass->detailStudentClass($this->_getParam('id')); $data = array(); $data['fk_id_fefpstudentclass'] = $studentClass['id_fefpstudentclass']; $data['class_name'] = $studentClass['class_name']; $data['date_start'] = $this->view->date($studentClass['start_date']); $data['date_finish'] = $this->view->date($studentClass['schedule_finish_date']); $dateInit = new Zend_Date($studentClass['start_date']); $dateFinish = new Zend_Date($studentClass['schedule_finish_date']); $diff = $dateFinish->sub($dateInit); $measure = new Zend_Measure_Time($diff->toValue(), Zend_Measure_Time::SECOND); $diffDays = $measure->convertTo(Zend_Measure_Time::DAY, 0); $data['duration'] = preg_replace('/[^0-9]/i', '', $diffDays); $this->_helper->json($data); }
/** * * @param string $unit * @return mixed * @throws Exception */ protected function _getDiff($unit) { $start_date = null; $finish_date = null; switch (true) { case !empty($this->_dataModel['date_start']): $start_date = $this->_dataModel['date_start']; break; case !empty($this->_dataModel['start_date']): $start_date = $this->_dataModel['start_date']; break; } switch (true) { case !empty($this->_dataModel['date_finish']): $finish_date = $this->_dataModel['date_finish']; break; case !empty($this->_dataModel['finish_date']): $finish_date = $this->_dataModel['finish_date']; break; } if (empty($start_date) || empty($finish_date)) { $message = 'La hetan loron hahu no loron remata ba halo validasaun'; $this->_messageModel->addMessage($message, App_Message::ERROR); throw new Exception($message); } $dateStart = new Zend_Date($start_date); $dateFinish = new Zend_Date($finish_date); $diff = $dateFinish->sub($dateStart); $measure = null; switch ($unit) { case 'D': $measure = Zend_Measure_Time::DAY; break; case 'M': $measure = Zend_Measure_Time::MONTH; break; case 'Y': $measure = Zend_Measure_Time::YEAR; break; } $measureZend = new Zend_Measure_Time($diff->toValue(), Zend_Measure_Time::SECOND); $diffFinal = $measureZend->convertTo($measure, 0); return preg_replace('/[^0-9]/i', '', $diffFinal); }
/** * */ public function notifyFollowupCase() { $dbAdapter = Zend_Db_Table_Abstract::getDefaultAdapter(); $dbAdapter->beginTransaction(); try { $filters = array('status' => 1); $today = new Zend_Date(); $mapperCase = new Client_Model_Mapper_Case(); $rows = $mapperCase->listByFilters($filters); // Search the user who must receive notes to follow up cases $noteTypeMapper = new Admin_Model_Mapper_NoteType(); $users = $noteTypeMapper->getUsersByNoteType(Admin_Model_Mapper_NoteType::CASE_FOLLOW_UP); $noteModelMapper = new Default_Model_Mapper_NoteModel(); $noteMapper = new Default_Model_Mapper_Note(); foreach ($rows as $row) { $dateCase = new Zend_Date($row->date_start, 'dd/MM/yyyy'); $days = $today->sub($dateCase); $measure = new Zend_Measure_Time($days->toValue(), Zend_Measure_Time::SECOND); $diffDays = $measure->convertTo(Zend_Measure_Time::DAY, 0); $diff = (double) preg_replace('/[^0-9]/i', '', $diffDays); if ($diff % 15 != 0) { continue; } $usersWarning = $users; $usersWarning[] = $row->fk_id_counselor; $dataNote = array('title' => 'HALO AKOMPAÑAMENTU KAZU HO KLIENTE', 'level' => 0, 'message' => $noteModelMapper->getFollowUpCase($row->client), 'users' => $usersWarning); $noteMapper->setData($dataNote)->saveNote(); } $dbAdapter->commit(); return true; } catch (Exception $e) { $dbAdapter->rollBack(); echo "Error sending cases follow-ups notifications: " . $e->getMessage() . "\n"; return false; } }
protected function autenticateLdap() { try { $container = Core_Registry::getContainers(); $ldap = $container['ldap']->getPersist(); $config = \Zend_Registry::get('configs'); $samAccountNameQuery = "samAccountName={$this->getIdentity()}"; /** * Modifica o host para o servidor secundário. */ if ($this->_secondaryHost && isset($config['resources']['container']['ldap']['host']['secondary'])) { $options = $ldap->getOptions(); $options['host'] = $config['resources']['container']['ldap']['host']['secondary']; $ldap = new Zend_Ldap($options); } $admUsr = $config['authenticate']['username']; $admPwd = $config['authenticate']['password']; $ldap->bind($admUsr, $admPwd); $userLdapCount = $ldap->count($samAccountNameQuery); if ($userLdapCount <= 0) { throw new \Sica_Auth_Exception('MN175'); } $userLdap = current($ldap->search($samAccountNameQuery)->toArray()); $pwdLastSetLDAPTimestamp = isset($userLdap['pwdlastset'][0]) ? $userLdap['pwdlastset'][0] : 0; $pwdLastSetLDAPTimestamp_div = bcdiv($pwdLastSetLDAPTimestamp, '10000000'); $pwdLastSetLDAPTimestamp_sub = bcsub($pwdLastSetLDAPTimestamp_div, '11644473600'); $pwdLastSetDate = new \Zend_Date($pwdLastSetLDAPTimestamp_sub, \Zend_Date::TIMESTAMP); $measureTime = new \Zend_Measure_Time(\Zend_Date::now()->sub($pwdLastSetDate)->toValue(), \Zend_Measure_Time::SECOND); $measureTime->convertTo(\Zend_Measure_Time::DAY); $daysLeftToChangePwd = ceil($measureTime->getValue()); if ($daysLeftToChangePwd >= self::LDAP_MAX_PWD_LAST_SET_DAYS) { throw new \Sica_Auth_Exception('EXPIRED_PWD_MSG'); } $ldap->bind($this->getIdentity(), $this->getCredential()); return TRUE; } catch (\Sica_Auth_Exception $authExc) { $this->_authenticateResultInfo['code'] = Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND; $this->_authenticateResultInfo['messages'] = $authExc->getMessage(); return false; } catch (\Zend_Ldap_Exception $ldapExc) { $ldapCode = $ldapExc->getCode(); $message = sprintf('[SICA-e] LDAP Error in %s: "%s"', __METHOD__, $ldapExc->getMessage()); error_log($message); $message = sprintf('[Erro no LDAP] %s', $ldapExc->getMessage()); /** * Se não foi possível contactar o servidor LDAP e se não * for uma tentativa de autenticação no servidor secundário. */ if ($ldapCode == self::LDAP_CONST_CODE_CANT_CONTACT_SERVER && !$this->_secondaryHost) { #Tentativa de autenticação no servidor secundário. $this->_secondaryHost = TRUE; return $this->autenticateLdap(); } if ($ldapCode > 0) { $message = sprintf('LDAP0x%02x', $ldapCode); } if (false !== strpos($ldapExc->getMessage(), self::LDAP_CONST_NT_STATUS_PASSWORD_EXPIRED)) { $message = 'EXPIRED_PWD_MSG'; } $this->_authenticateResultInfo['code'] = Zend_Auth_Result::FAILURE_UNCATEGORIZED; $this->_authenticateResultInfo['messages'] = $message; return false; } }
/** * * @return int|bool */ public function save() { $dbAdapter = Zend_Db_Table_Abstract::getDefaultAdapter(); $dbAdapter->beginTransaction(); try { $this->_data['amount'] = 0; foreach ($this->_data['cost_expense'] as $cost) { $this->_data['amount'] += App_General_String::toFloat($cost); } $mapperRule = new Fefop_Model_Mapper_Rule(); $mapperRule->validate($this->_message, $this->_data, Fefop_Model_Mapper_Expense::CONFIG_PISE_FE); $dateStart = new Zend_Date($this->_data['date_start']); $dateFinish = new Zend_Date($this->_data['date_finish']); //$dateFormation = new Zend_Date( $this->_data['date_formation'] ); // Check if the initial date is later than finish date if ($dateStart->isLater($dateFinish)) { $this->_message->addMessage('Data loron keta liu data remata.'); $this->addFieldError('date_start')->addFieldError('date_finish'); return false; } // If there is no contract yet if (empty($this->_data['fk_id_fefop_contract'])) { $dataContract = array('module' => Fefop_Model_Mapper_Module::FE, 'district' => $this->_data['fk_id_adddistrict']); $mapperFefopContract = new Fefop_Model_Mapper_Contract(); $this->_data['fk_id_fefop_contract'] = $mapperFefopContract->save($dataContract); } $this->_data['date_start'] = $dateStart->toString('yyyy-MM-dd'); $this->_data['date_finish'] = $dateFinish->toString('yyyy-MM-dd'); //$this->_data['date_formation'] = $dateFormation->toString( 'yyyy-MM-dd' ); $dataForm = $this->_data; // If it has linkage with trainee if (!empty($dataForm['fk_id_trainee'])) { $dataTrainee = array('date_start' => $this->_data['date_start'], 'date_finish' => $this->_data['date_finish'], 'duration' => $this->_data['duration_month']); $where = array('id_trainee = ?' => $dataForm['fk_id_trainee']); $dbTrainee = App_Model_DbTable_Factory::get('JOBTrainingTrainee'); $dbTrainee->update($dataTrainee, $where); } // Save the contract $dataForm['id_fe_contract'] = parent::_simpleSave(); // Check if the duration is longer than 6 months $diff = $dateFinish->sub($dateStart); $measure = new Zend_Measure_Time($diff->toValue(), Zend_Measure_Time::SECOND); $diffMonth = preg_replace('/[^0-9.]/i', '', $measure->convertTo(Zend_Measure_Time::MONTH, 0)); // If it is longer, send a warning //if ( (float)$diffMonth > self::MOUNTH_LIMIT ) //$this->_sendWarningDuration( $dataForm['id_fe_contract'] ); // Save budget category $this->_saveExpenses($dataForm); // Check the beneficiary graduation $this->_checkBeneficiaryGraduation($dataForm); if (empty($this->_data['id_fe_contract'])) { $history = 'REJISTU KONTRAKTU RI: %s'; } else { $history = 'ATUALIZA KONTRAKTU RI: %s'; } $history = sprintf($history, $dataForm['id_fe_contract']); $this->_sysAudit($history); $dbAdapter->commit(); return $dataForm['id_fe_contract']; } catch (Exception $e) { $dbAdapter->rollBack(); $this->_message->addMessage($this->_config->messages->error, App_Message::ERROR); return false; } }