Example #1
0
 public function getSavedTime()
 {
     $seconds = intval(Mage::helper('asyncindex')->getVariable('time'));
     $time = new Zend_Date();
     $time->setTime('00:00:00');
     $time->addSecond($seconds);
     return $time->toString('HH') . ' hr ' . $time->toString('mm') . ' min ' . $time->toString('ss') . ' sec';
 }
Example #2
0
 protected function _incSec($datetime)
 {
     $date = new Zend_Date($datetime, null, $this->_helper()->getLocale()->getLocaleCode());
     $date->addSecond(1);
     return $date->toString(self::MYSQL_ZEND_DATE_FORMAT);
 }
Example #3
0
 /**
  * authenticate() - defined by Zend_Auth_Adapter_Interface.  This method is called to
  * attempt an authentication.  Previous to this call, this adapter would have already
  * been configured with all necessary information to successfully connect to a database
  * table and attempt to find a record matching the provided identity.
  *
  * @throws Zend_Auth_Adapter_Exception if answering the authentication query is impossible
  * @return Zend_Auth_Result
  */
 public function authenticate()
 {
     $result = parent::authenticate();
     if ($result->isValid()) {
         $this->updateExpiry();
         $this->updateSessionId();
     } else {
         $datetime = new Zend_Date();
         $datetime->addSecond($this->lockSeconds);
         $this->setLockedUntil($datetime);
     }
     return $result;
 }
Example #4
0
    /**
     * authenticate() - defined by Zend_Auth_Adapter_Interface.  This method is called to
     * attempt an authentication.  Previous to this call, this adapter would have already
     * been configured with all necessary information to successfully connect to a database
     * table and attempt to find a record matching the provided identity.
     *
     * @throws Zend_Auth_Adapter_Exception if answering the authentication query is impossible
     * @return Zend_Auth_Result
     */
    public function authenticate()
    {
        $result = parent::authenticate();

        $select = $this->_zendDb->select();
        $select->from($this->_tableName);
        $select->where($this->_zendDb->quoteIdentifier($this->_identityColumn, true) . ' = ?', $this->_identity);
        $user = $this->_zendDb->fetchRow($select, array(), Zend_Db::FETCH_OBJ);

        if ($result->isValid()) {
            // Check if user role is active
            $sql = 'SELECT enabled FROM s_core_auth_roles WHERE id = ?';
            if ($this->_zendDb->fetchOne($sql, array($user->roleID)) == false) {
                return new Zend_Auth_Result(
                    Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND,
                    $this->_identity, array()
                );
            }
            $this->updateExpiry();
            $this->updateSessionId();
        } else {
            // If more then 4 previous failed logins lock account for n * failedlogins seconds
            if ($user->failedlogins >= 4) {
                $lockedUntil = new Zend_Date();
                $lockedUntil->addSecond($this->lockSeconds * $user->failedlogins);
                $this->setLockedUntil($lockedUntil);
            }
            // Increase number of failed logins
            $this->setFailedLogins($user->failedlogins + 1);
            if(isset($lockedUntil)) {
                return new Zend_Auth_Result(
                    -4,
                    $this->_identity,
                    array('lockedUntil' => $lockedUntil)
                );
            }
        }
        return $result;
    }
Example #5
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
     }
 }
Example #6
0
 /**
  * Make correction for store timezone
  *
  * @param string $datetime
  * @return string
  */
 public function timezoneFactory($datetime)
 {
     $newdate = $datetime;
     try {
         $dateObj = new Zend_Date($datetime, Zend_Date::ISO_8601);
         $dateObj->setTimezone('GMT');
         $newdate = $dateObj->addSecond($this->getTimeZoneOffset())->toString(self::MYSQL_ZEND_DATE_FORMAT);
     } catch (Exception $e) {
         Mage::logException($e->getMessage());
     }
     return $newdate;
 }
Example #7
0
 public function addDays($numDays)
 {
     $date = new \Zend_Date($this->_date, self::FORMAT);
     $this->_date = $date->addSecond(60 * 60 * 24 * (int) $numDays)->toString(self::FORMAT);
     return $this;
 }
Example #8
0
    /**
     * Returns all Shipping Costs
     *
     * @return array
     */
    public function getShippingCostsAction()
    {
        $dispatchID = $this->Request()->getParam('dispatchID', null);
        $limit      = $this->Request()->getParam('limit', 20);
        $offset     = $this->Request()->getParam('start', 0);
        $sort       = $this->Request()->getParam('sort', array(array('property' => 'dispatch.name', 'direction' => 'ASC')));

        $filter = $this->Request()->getParam('filter', null);
        if (is_array($filter) && isset($filter[0]['value'])) {
            $filter = $filter[0]['value'];
        }

        $query = $this->getRepository()->getShippingCostsQuery($dispatchID, $filter, $sort, $limit, $offset);

        $shippingCosts       = $query->getArrayResult();
        $shippingCostsResult = array();
        foreach ($shippingCosts as $shippingCost) {

            if (!empty($shippingCost['bindTimeFrom'])) {
                $date = new Zend_Date();
                $date->setMinute(0);
                $date->setHour(0);
                $date->setSecond(0);
                $shippingCost['bindTimeFrom'] = $date->addSecond($shippingCost['bindTimeFrom'])->toString("HH:mm");
            }

            if (!empty($shippingCost['bindTimeTo'])) {
                $date = new Zend_Date();
                $date->setMinute(0);
                $date->setHour(0);
                $date->setSecond(0);
                $shippingCost['bindTimeTo'] = $date->addSecond($shippingCost['bindTimeTo'])->toString("HH:mm");
            }
            $shippingCostsResult[]  = $shippingCost;
        }

        //returns the total count of the query
        $totalResult = $this->getManager()->getQueryCount($query);
        $this->View()->assign(array('success' => true, 'data' => $shippingCostsResult, 'total' => $totalResult));
    }
Example #9
0
 protected function _calculateDateFromOffsetDays(Date $referenceDate, $referenceDateOffset)
 {
     $referenceDate = new \Zend_Date((string) $referenceDate, Date::FORMAT);
     $referenceDateOffset = (int) $referenceDateOffset;
     if ($referenceDateOffset >= 0) {
         return $referenceDate->addSecond(60 * 60 * 24 * $referenceDateOffset)->toString(Date::FORMAT);
     }
     return $referenceDate->subSecond(60 * 60 * 24 * $referenceDateOffset * -1)->toString(Date::FORMAT);
 }
Example #10
0
 public function incSec($datetime)
 {
     $date = new Zend_Date($datetime, self::MYSQL_ZEND_DATE_FORMAT, $this->getLocale()->getLocaleCode());
     $date->addSecond(1);
     return $date->toString(self::MYSQL_ZEND_DATE_FORMAT);
 }
Example #11
0
$view = $application->getBootstrap()->getResource('View');
// init request
$request = new Zend_Controller_Request_Http();
$request->setControllerName('partner-usage');
$request->setActionName('export-csv');
$fromDate = new Zend_Date();
$fromDate->setHour(0);
$fromDate->setMinute(0);
$fromDate->setSecond(0);
$fromDate->setDay(1);
$fromDate->addMonth(-1);
$request->setParam('from_date', $fromDate->getTimestamp());
// beginning of last month
$toDate = new Zend_Date($fromDate);
$toDate->addMonth(1);
$toDate->addSecond(-1);
$request->setParam('to_date', $toDate->getTimestamp());
// end of last month
// init response
$response = new Zend_Controller_Response_Cli();
// dispatch
$frontController->getDispatcher()->dispatch($request, $response);
// send mail
$config = Zend_Registry::get('config');
$sentToArray = explode(',', $config->settings->monthlyUsageSendTo);
$mail = new Zend_Mail();
$mail->setSubject($view->translate('Monthly Report'));
$mail->setFrom($config->settings->monthlyUsageSendFrom);
$mail->setBodyText($view->translate('CSV file attached.'));
// the attachment
$attachment = new Zend_Mime_Part($response->getBody());