/**
  * Cancel orders stayed in pending because customer not validated payment form
  */
 public function cancelOrdersInPending()
 {
     $methodCodes = array();
     //Select only method with cancel orders enabled
     foreach (Mage::helper('hipay')->getHipayMethods() as $code => $model) {
         if (Mage::getStoreConfigFlag('payment/' . $code . "/cancel_pending_order")) {
             $methodCodes[] = $code;
         }
     }
     if (count($methodCodes) < 1) {
         return $this;
     }
     //Limited time in minutes
     $limitedTime = 30;
     $date = new Zend_Date();
     /* @var $collection Mage_Sales_Model_Resource_Order_Collection */
     $collection = Mage::getResourceModel('sales/order_collection');
     $collection->addFieldToSelect(array('entity_id', 'increment_id', 'store_id', 'state'))->addFieldToFilter('main_table.state', Mage_Sales_Model_Order::STATE_NEW)->addFieldToFilter('op.method', array('in' => array_values($methodCodes)))->addAttributeToFilter('created_at', array('to' => $date->subMinute($limitedTime)->toString('Y-MM-dd HH:mm:ss')))->join(array('op' => 'sales/order_payment'), 'main_table.entity_id=op.parent_id', array('method'));
     /* @var $order Mage_Sales_Model_Order */
     foreach ($collection as $order) {
         if ($order->canCancel()) {
             try {
                 $order->cancel();
                 $order->addStatusToHistory($order->getStatus(), Mage::helper('hipay')->__("Order canceled automatically by cron because order is pending since %d minutes", $limitedTime));
                 $order->save();
             } catch (Exception $e) {
                 Mage::logException($e);
             }
         }
     }
     return $this;
 }
Example #2
0
 /**
  * test looseBehaviour
  */
 public function testLoose()
 {
     $date = new Zend_Date(0, 'de_DE');
     try {
         $date->set(null, Zend_Date::YEAR);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     $date->set(10, 'de_DE');
     $this->assertEquals(10, $date->getTimestamp());
     try {
         $date->add(null, Zend_Date::YEAR);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     $date->add(10, 'de_DE');
     $this->assertEquals(20, $date->getTimestamp());
     try {
         $date->sub(null, Zend_Date::YEAR);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     $date->sub(10, 'de_DE');
     $this->assertEquals(10, $date->getTimestamp());
     try {
         $date->compare(null, Zend_Date::YEAR);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->equals(null, Zend_Date::YEAR);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->isEarlier(null, Zend_Date::YEAR);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->isLater(null, Zend_Date::YEAR);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setTime(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addTime(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subTime(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareTime(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setDate(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addDate(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subDate(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareDate(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setIso(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addIso(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subIso(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareIso(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setArpa(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addArpa(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subArpa(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareArpa(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setYear(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addYear(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subYear(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareYear(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setMonth(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addMonth(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subMonth(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareMonth(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setDay(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addDay(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subDay(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareDay(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setWeekday(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addWeekday(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subWeekday(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareWeekday(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setDayOfYear(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addDayOfYear(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subDayOfYear(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareDayOfYear(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setHour(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addHour(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subHour(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareHour(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setMinute(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addMinute(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subMinute(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareMinute(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setSecond(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addSecond(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subSecond(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareSecond(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setWeek(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addWeek(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subWeek(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareWeek(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
 }
 /**
  * Action for forgetting a password
  *
  */
 public function passwordResetAction()
 {
     if (Zend_Auth::getInstance()->hasIdentity()) {
         $this->_helper->redirector->gotoRoute(array(), 'default', true);
         return;
     }
     $userKey = $this->_getParam('key', null);
     if (is_null($userKey)) {
         throw new Ot_Exception_Input('msg-error-noKeyFound');
     }
     $loginOptions = Zend_Registry::get('applicationLoginOptions');
     $key = $loginOptions['forgotpassword']['key'];
     $iv = $loginOptions['forgotpassword']['iv'];
     $cipher = $loginOptions['forgotpassword']['cipher'];
     $string = pack("H*", $userKey);
     $decryptKey = trim(mcrypt_decrypt($cipher, $key, $string, MCRYPT_MODE_CBC, $iv));
     if (!preg_match('/[^@]*@[^-]*-[0-9]*/', $decryptKey)) {
         throw new Ot_Exception_Input('msg-error-invalidKey');
     }
     $userId = preg_replace('/\\-.*/', '', $decryptKey);
     $ts = preg_replace('/^[^-]*-/', '', $decryptKey);
     $timestamp = new Zend_Date($ts);
     $now = new Zend_Date();
     $now->subMinute((int) $loginOptions['forgotpassword']['numberMinutesKeyIsActive']);
     if ($timestamp->getTimestamp() < $now->getTimestamp()) {
         throw new Ot_Exception_Input('msg-error-keyExpired');
     }
     $realm = preg_replace('/^[^@]*@/', '', $userId);
     $username = preg_replace('/@.*/', '', $userId);
     // Set up the auth adapter
     $authAdapter = new Ot_Model_DbTable_AuthAdapter();
     $adapter = $authAdapter->find($realm);
     if (is_null($adapter)) {
         throw new Ot_Exception_Data($this->view->translate('ot-login-signup:realmNotFound', array('<b>' . $realm . '</b>')));
     }
     if ($adapter->enabled == 0) {
         throw new Ot_Exception_Access('msg-error-authNotSupported');
     }
     $className = (string) $adapter->class;
     $auth = new $className();
     if (!$auth->manageLocally()) {
         throw new Ot_Exception_Access('msg-error-authNotSupported');
     }
     $account = new Ot_Model_DbTable_Account();
     $thisAccount = $account->getByUsername($username, $realm);
     if (is_null($thisAccount)) {
         throw new Ot_Exception_Data('msg-error-userAccountNotFound');
     }
     $form = new Ot_Form_PasswordReset();
     if ($this->_request->isPost()) {
         if ($form->isValid($_POST)) {
             if ($form->getValue('password') == $form->getValue('passwordConf')) {
                 $data = array('accountId' => $thisAccount->accountId, 'password' => md5($form->getValue('password')));
                 $account->update($data, null);
                 $this->_helper->messenger->addSuccess('msg-info-passwordReset');
                 $loggerOptions = array('attributeName' => 'accountId', 'attributeId' => $data['accountId']);
                 $this->_helper->log(Zend_Log::INFO, 'User reset their password', $loggerOptions);
                 $this->_helper->redirector->gotoRoute(array('realm' => $realm), 'login', true);
             } else {
                 $this->_helper->messenger->addError('msg-error-passwordsNotMatch');
             }
         } else {
             $this->_helper->messenger->addError('msg-error-invalidFormInfo');
         }
     }
     $this->view->headScript()->appendFile($this->view->baseUrl() . '/public/scripts/ot/jquery.plugin.passStrength.js');
     $this->_helper->pageTitle('ot-login-passwordReset:title');
     $this->view->assign(array('form' => $form));
 }
 /**
  * 
  * @param type $horarios
  * @param type $intervalo
  */
 private function setHorarios($salao_id, $dia_semana, $horario_fechamento, $horario_abertura)
 {
     $horarios = ($horario_fechamento - $horario_abertura) * 2;
     $date = date('Y-m-d') . ' ' . $horario_abertura;
     $zendDate = new Zend_Date($date);
     $horario = $zendDate->subMinute(30);
     for ($i = 0; $i <= $horarios; $i++) {
         $horario = $zendDate->addMinute(30)->get(Zend_Date::TIME_SHORT);
         $insertHorario = array('salao_id' => $salao_id, 'salao_horario_dia_semana' => $dia_semana, 'salao_horario' => $horario);
         $modelSalaoHorario = new Model_DbTable_SalaoHorario();
         if (!$modelSalaoHorario->insert($insertHorario)) {
             throw new Exception("Falha ao cadastrar os horários");
         }
     }
 }
 /**
  * 在线人数曲线
  */
 public function chartAction()
 {
     $data = array();
     // 当前时间戳
     $nowOffsetTimestamp = Zend_Date::now()->subMinute(abs($this->_getParam('offset')))->getTimestamp();
     foreach ($this->_getParam('allowedGameTypes') as $gameType) {
         if (ZtChart_Model_GameType::isQule($gameType)) {
             // 取Qule游戏的数据
             $qule = new ZtChart_Model_Qule();
             // 取当前偏移量的数据
             $nowData = $qule->getGamedata(array('gametype' => $gameType, 'zoneid' => $this->_getParam('zoneid'), 'loadnumber' => $this->_getParam('range'), 'querydate' => $nowOffsetTimestamp));
             if (array_key_exists('data', $nowData) && !empty($nowData['data'])) {
                 foreach ($nowData['data'] as $item) {
                     $data['datetime'][] = $item[0];
                     $data['data'][0][] = $item[1];
                 }
             }
             // 取同比偏移量的数据
             if ($this->_hasParam('pdate')) {
                 foreach (explode(',', $this->_getParam('pdate')) as $pdate) {
                     $sameOffsetTimestamp = ZtChart_Model_Assemble_Datetime::getPredefinedStartTimestamp($pdate, $nowOffsetTimestamp);
                     $sameData = $qule->getGamedata(array('gametype' => $gameType, 'zoneid' => $this->_getParam('zoneid'), 'loadnumber' => $this->_getParam('range'), 'querydate' => $sameOffsetTimestamp));
                     if (array_key_exists('data', $sameData) && !empty($sameData['data'])) {
                         foreach ($sameData['data'] as $item) {
                             $data['data'][$pdate][] = $item[1];
                         }
                     }
                 }
             }
         } else {
             // 取InfoServer中的数据
             try {
                 if (ZtChart_Model_DbTable_Infoserver::isSingleAdapter($gameType)) {
                     // 游戏只有一个数据库的情况
                     $infoserver = ZtChart_Model_DbTable_Infoserver::factory($gameType);
                     // 取当前偏移量的数据
                     $nowOffsetDate = new Zend_Date($nowOffsetTimestamp);
                     $startNowOffsetTimestamp = $nowOffsetDate->subMinute($this->_getParam('range'))->getTimestamp();
                     for ($i = 0; $i < $this->_getParam('range'); $i++) {
                         $data['datetime'][$i] = $startNowOffsetTimestamp + $i * 60;
                         $data['tmp'][$i] = date('H:i', $data['datetime'][$i]);
                     }
                     foreach ($infoserver->fetchSumGroup($startNowOffsetTimestamp) as $item) {
                         if (in_array(date('H:i', $item[0]), $data['tmp'])) {
                             $data['data'][0][] = $item[1];
                         } else {
                             $data['data'][0][] = -1;
                         }
                     }
                     $data['data'][0] = array_pad($data['data'][0], $this->_getParam('range'), -1);
                     // 取同比偏移量的数据
                     if ($this->_hasParam('pdate')) {
                         foreach (explode(',', $this->_getParam('pdate')) as $pdate) {
                             $startSameOffsetTimestamp = ZtChart_Model_Assemble_Datetime::getPredefinedStartTimestamp($pdate, $startNowOffsetTimestamp);
                             $infoserver->setTablename($startSameOffsetTimestamp);
                             foreach ($infoserver->fetchSumGroup($startSameOffsetTimestamp, $this->_getParam('range')) as $item) {
                                 if (in_array(date('H:i', $item[0]), $data['tmp'])) {
                                     $data['data'][$pdate][] = $item[1];
                                 } else {
                                     $data['data'][$pdate][] = -1;
                                 }
                             }
                             $data['data'][$pdate] = array_pad($data['data'][$pdate], $this->_getParam('range'), -1);
                         }
                     }
                     unset($data['tmp']);
                 } else {
                     // @todo 游戏含有多个数据库的情况
                 }
             } catch (Zend_Db_Exception $e) {
                 ZtChart_Model_Logger::err($e->getMessage());
                 continue;
             }
         }
     }
     $this->_helper->json($data);
 }