public function indexAction()
 {
     // numero da semana anterior
     $zendDate = new Zend_Date();
     $semana = $zendDate->get(Zend_Date::WEEK) - 1;
     $dia_semana = $zendDate->get(Zend_Date::WEEKDAY_DIGIT);
     $zendDate->subDay(7);
     $dia_semana_inicio = $dia_semana - 1;
     $dia_semana_fim = 7 - $dia_semana;
     $periodo_inicial = $zendDate->subDay($dia_semana_inicio)->get("dd/MM/YYYY");
     $periodo_final = $zendDate->addDay($dia_semana_fim)->get('dd/MM/YYYY');
     $periodo = $periodo_inicial . ' à ' . $periodo_final;
     // busca as visualizacoes da semana
     $modelSalaoVisualizacao = new Model_DbTable_SalaoVisualizacao();
     $visualizacoes = $modelSalaoVisualizacao->visualizacoes($semana);
     try {
         foreach ($visualizacoes as $visualizacao) {
             $pluginMail = new Plugin_Mail();
             $pluginMail->setDataMail('visualizacao', $visualizacao);
             $pluginMail->setDataMail('periodo', $periodo);
             $pluginMail->send("salao-visualizacao.phtml", "Relatório de Visualizações", $visualizacao->salao_email);
         }
         echo 'emails enviados';
     } catch (Zend_Mail_Exception $ex) {
         die('email');
     } catch (Exception $ex) {
         Zend_Debug::dump($ex->getMessage());
     }
 }
Example #2
0
 /**
  * Retrieve Bestseller product to show in frontend
  * @return mixed
  */
 public function myBest()
 {
     $storeId = Mage::app()->getStore()->getId();
     $HandleArray = Mage::app()->getLayout()->getUpdate()->getHandles();
     $CategoryHandle = 'catalog_category_view';
     $SourceConfig = Mage::getStoreConfig('sm_bestseller/sm_bestseller_source');
     if ($SourceConfig && !empty($SourceConfig)) {
         $SourceType = $SourceConfig['timeperiod'];
         $date = new Zend_Date();
         /**
          * Select time range to retrive bestseller
          */
         if ($SourceType && $SourceType == 'specify') {
             $fromDate = $date->setDate($SourceConfig['fromdate'])->get('Y-MM-dd');
             $toDate = $date->setDate($SourceConfig['todate'])->get('Y-MM-dd');
         } else {
             /**
              * use switch to return begin of week, month, year...
              */
             switch ($SourceType) {
                 case 'subWeek':
                     $toDate = $date->subDay($date->getDate()->get('e'))->getDate()->get('Y-MM-dd');
                     break;
                 case 'subMonth':
                     $toDate = $date->setDay(1)->getDate()->get('Y-MM-dd');
                     break;
                 case 'subYear':
                     $toDate = $date->subDay($date->getDate()->get('D'))->getDate()->get('Y-MM-dd');
                     break;
                 default:
                     $toDate = $date->getDate()->get('Y-MM-dd');
             }
             // end switch
             $subType = $SourceType;
             $unit = $SourceConfig['unit'] ? $SourceConfig['unit'] : 1;
             $fromDate = $date->{$subType}($unit)->getDate()->get('Y-MM-dd');
         }
         // end else
         /**
          * Limit maximum product retrieve
          */
         $limit = $SourceConfig['limitproduct'];
         if ($limit > 0 && ctype_digit($limit)) {
             $this->setProductsCount($limit);
         }
         $products = Mage::getResourceModel('reports/product_collection')->addOrderedQty($fromDate, $toDate)->addAttributeToSelect('*')->addAttributeToSelect(array('name', 'price', 'small_image'))->setStoreId($storeId)->addStoreFilter($storeId)->setOrder('ordered_qty', 'desc');
         // most best sellers on top
         Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
         Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
         $products->setPageSize($limit)->setCurPage(1);
         if (in_array($CategoryHandle, $HandleArray)) {
             $CategoryId = Mage::getModel('catalog/layer')->getCurrentCategory()->getId();
             $CategoryModel = Mage::getModel('catalog/category')->load($CategoryId);
             $products->addCategoryFilter($CategoryModel);
         }
         return $products;
     }
     // end if sourceconfig
 }
Example #3
0
 /**
  * Test the network provided
  * @param $affiliateNetwork
  * @return none
  */
 public static function testNetwork($network)
 {
     //Start date, the first two months ago
     $startDate = new Zend_Date();
     $startDate->setDay(1);
     $startDate->subMonth(2);
     $startDate->setHour(00);
     $startDate->setMinute(00);
     $startDate->setSecond(00);
     //Yesterday, some networks don't give us the data for the same day, then is the safer way to have our data
     $endDate = new Zend_Date();
     $endDate->subDay(1);
     $endDate->setHour(23);
     $endDate->setMinute(59);
     $endDate->setSecond(59);
     //are we connected?
     if ($network->checkConnection()) {
         //Get all the payments for this network.
         $paymentsList = $network->getPaymentHistory();
         echo "Total Number of payments: " . count($paymentsList) . "\n\n";
         //Get all the Merhcants
         $merchantList = $network->getMerchantList(array());
         echo "Number of merchants: " . count($merchantList) . "\n\n";
         // Building the array of merchant Id we want to retrieve data from.
         $merchantIdList = array();
         foreach ($merchantList as $merchant) {
             $merchantIdList[] = $merchant['cid'];
         }
         //If we have joined any merchant
         if (!empty($merchantIdList)) {
             //Split the dates monthly, Most of the network don't allow us to retrieve more than a month data
             $dateArray = Oara_Utilities::monthsOfDifference($startDate, $endDate);
             for ($i = 0; $i < count($dateArray); $i++) {
                 // Calculating the start and end date for the current month
                 $monthStartDate = clone $dateArray[$i];
                 $monthEndDate = null;
                 if ($i != count($dateArray) - 1) {
                     $monthEndDate = clone $dateArray[$i];
                     $monthEndDate->setDay(1);
                     $monthEndDate->addMonth(1);
                     $monthEndDate->subDay(1);
                 } else {
                     $monthEndDate = $endDate;
                 }
                 $monthEndDate->setHour(23);
                 $monthEndDate->setMinute(59);
                 $monthEndDate->setSecond(59);
                 echo "\n importing from " . $monthStartDate->toString("dd-MM-yyyy HH:mm:ss") . " to " . $monthEndDate->toString("dd-MM-yyyy HH:mm:ss") . "\n";
                 $transactionList = $network->getTransactionList($merchantIdList, $monthStartDate, $monthEndDate);
                 echo "Number of transactions: " . count($transactionList) . "\n\n";
                 $overviewList = $network->getOverviewList($transactionList, $merchantIdList, $monthStartDate, $monthEndDate);
                 echo "Number register on the overview: " . count($overviewList) . "\n\n";
             }
         }
         echo "Import finished \n\n";
     } else {
         echo "Error connecting to the network, check credentials\n\n";
     }
 }
 public function addOldLockedFilter()
 {
     $today = new Zend_Date();
     $today->subDay(3);
     $oldDateTimeString = $today->toString(AW_Core_Model_Abstract::DB_DATETIME_FORMAT);
     $this->getSelect()->where("is_locked>0 AND lock_changed_date<'" . $oldDateTimeString . "'");
     return $this;
 }
Example #5
0
 public function getOldPromotions($subDay = 30)
 {
     $date = new Zend_Date();
     $now = $date->toString('y-MM-dd');
     $date->subDay($subDay);
     $before = $date->toString('y-MM-dd');
     $where = join(' AND ', array($this->_db->quoteInto('end_at < ?', $now), $this->_db->quoteInto('end_at > ?', $before)));
     return $this->fetchAll($where);
 }
Example #6
0
 public function cleanHistory()
 {
     $date = new Zend_Date();
     $date->subDay(3);
     $collection = Mage::getModel('feedexport/feed_history')->getCollection()->addFieldToFilter('created_at', array('lt' => $date->toString('Y-MM-dd H:mm:s')));
     foreach ($collection as $entry) {
         $entry->delete();
     }
     return $this;
 }
Example #7
0
 public function isLocked()
 {
     if (!$this->getId() or $this->getNumberOfError() < 3) {
         return false;
     }
     $lastError = $this->getLastError();
     $now = new Zend_Date();
     $yesterday = $now->subDay(1)->toString('y-MM-dd HH:mm:ss');
     return $lastError > $yesterday;
 }
Example #8
0
 /**
  * Check the connection
  */
 public function checkConnection()
 {
     //If not login properly the construct launch an exception
     $connection = true;
     $yesterday = new \Zend_Date();
     $yesterday->subDay(2);
     $urls = array();
     $urls[] = new Oara_Curl_Request("https://publisher.ebaypartnernetwork.com/PublisherReportsTx?pt=2&start_date={$yesterday->toSTring("M/d/yyyy")}&end_date={$yesterday->toSTring("M/d/yyyy")}&user_name={$this->_credentials['user']}&user_password={$this->_credentials['password']}&advIdProgIdCombo=&tx_fmt=2&submit_tx=Download", array());
     $exportReport = $this->_client->get($urls);
     if (preg_match("/DOCTYPE html PUBLIC/", $exportReport[0])) {
         $connection = false;
     }
     return $connection;
 }
Example #9
0
 public function isValid($startDay)
 {
     $start = (string) $startDay;
     // If start day is empty return true, Campaings-model set this day
     if (empty($start)) {
         return true;
     } else {
         $start = new Zend_Date($start, Zend_Date::ISO_8601);
     }
     $this->_setValue($start);
     $thisDay = date("Y-m-d", time());
     $thisDay = new Zend_Date($thisDay, Zend_Date::ISO_8601);
     $thisDay->subDay(1);
     if ($start->compare($thisDay) == 1) {
         return true;
     }
     $this->_error(self::NOT_MATCH);
     return false;
 }
Example #10
0
 public function isValid($endDay, $startDay = null)
 {
     $end = (string) $endDay;
     // If end day is empty return true, Campaings-model set 0000-00-00
     if (empty($end) || $end == '0000-00-00') {
         return true;
     } else {
         $end = new Zend_Date($end, Zend_Date::ISO_8601);
     }
     $this->_setValue($end);
     /* context is an array with the entire set of form values in our case,
      * the value we are interested in is $context["$this->dateField"],
      * (start day field) which should before as $value (end date field)
      */
     if (is_array($startDay)) {
         if (isset($startDay["{$this->dateField}"])) {
             // If start day is empty, set this day
             if (empty($startDay["{$this->dateField}"])) {
                 $start = date("Y-m-d", time());
             } else {
                 $start = $startDay["{$this->dateField}"];
             }
             $start = new Zend_Date($start, Zend_Date::ISO_8601);
             if ($end->compare($start) == 1) {
                 return true;
             }
         } else {
             // If admin is editing started campaign check that new end date is this day or after
             $thisDay = date("Y-m-d", time());
             $thisDay = new Zend_Date($thisDay, Zend_Date::ISO_8601);
             $thisDay->subDay(1);
             if ($end->compare($thisDay) == 1) {
                 return true;
             }
         }
     }
     $this->_error(self::NOT_MATCH);
     return false;
 }
 /**
  * 取得某个预定义时间段
  * 
  * @static
  * @param integer $interval
  * @param string $forceUnit
  * @param integer $timestamp
  * @return array
  */
 public static function getPredefinedRange($interval, $forceUnit = null, $timestamp = null)
 {
     if (empty($timestamp)) {
         $timestamp = time();
     }
     $start = new Zend_Date($timestamp);
     $end = new Zend_Date($timestamp);
     switch ($interval) {
         case self::TODAY:
             $start->setHour(0)->setMinute(0)->setSecond(0);
             $unit = Zend_Date::HOUR;
             break;
         case self::YESTODAY:
             $start->subDay(1)->setHour(0)->setMinute(0)->setSecond(0);
             $end = clone $start;
             $end->addDay(1);
             $unit = Zend_Date::HOUR;
             break;
         case self::TOMORROW:
             $start->addDay(1)->setHour(0)->setMinute(0)->setSecond(0);
             $end = clone $start;
             $end->addDay(1);
             $unit = Zend_Date::HOUR;
             break;
         case self::THIS_MONTH:
             $start->setDay(1)->setHour(0)->setMinute(0)->setSecond(0);
             $unit = Zend_Date::DAY;
             break;
         case self::THIS_YEAR:
             $start->setMonth(1)->setDay(1)->setHour(0)->setMinute(0)->setSecond(0);
             $end->addMonth(1)->setDay(1)->setHour(0)->setMinute(0)->setSecond(0);
             $unit = Zend_Date::DAY;
             break;
         case self::THIS_SEASON:
             $start->setMonth(3 * floor(($start->toValue('M') - 1) / 3) + 1)->setDay(1)->setHour(0)->setMinute(0)->setSecond(0);
             $unit = Zend_Date::DAY;
         case self::RECENT_24HOUR:
             $start->subHour(24);
             $unit = Zend_Date::HOUR;
             break;
         case self::RECENT_48HOUR:
             $start->subHour(48);
             $unit = Zend_Date::HOUR;
             break;
         case self::RECENT_1WEEK:
             $start->subWeek(1);
             $unit = Zend_Date::DAY;
             break;
         case self::RECENT_1MONTH:
             $start->subMonth(1);
             $unit = Zend_Date::DAY;
             break;
         case self::RECENT_24MONTH:
             $start->subMonth(24);
             $unit = Zend_Date::DAY;
             break;
         case self::LAST_1MONTH:
             $start->subMonth(1)->setDay(1)->setHour(0)->setMinute(0)->setSecond(0);
             $end = clone $start;
             $end->addMonth(1);
             $unit = Zend_Date::DAY;
             break;
         case self::LAST_1YEAR:
             $start->subYear(1)->setMonth(1)->setDay(1)->setHour(0)->setMinute(0)->setSecond(0);
             $end = clone $start;
             $end->addYear(1);
             $unit = Zend_Date::DAY;
             break;
         case self::ENTIRE_DAY:
             $start->setDate(self::ERA_DATE, self::ZF_DATE_FORMAT)->setTime(self::ERA_TIME, self::ZF_TIME_FORMAT);
             $end->addDay(1);
             $unit = Zend_Date::DAY;
             break;
         default:
             $unit = Zend_Date::SECOND;
     }
     if (!empty($forceUnit)) {
         $unit = $forceUnit;
     }
     $start = max(self::truncateDatetime($start, $unit), self::truncateDatetime(self::ERA_DATETIME, $unit));
     $end = max(self::truncateDatetime($end, $unit), self::truncateDatetime(self::ERA_DATETIME, $unit));
     return compact('start', 'end', 'unit');
 }
Example #12
0
 /**
  * Display the list of the importation files
  * Initiates actions for import and export of data.
  *
  * @return void
  */
 public function listFilesAction()
 {
     if ($this->view->aclIsAllowed($this->_moduleTitle, 'edit', true)) {
         $this->_findCsvFiles('list');
         $tables = array('FilesImport' => array('FI_ID', 'FI_FileName', 'FI_LastModif', 'FI_LastAccess'));
         $field_list = array('FI_ID' => array('width' => '50px'), 'FI_LastModif' => array('width' => '150px'), 'FI_LastAccess' => array('width' => '150px'));
         if ($this->_importType) {
             $field_list['FI_Type'] = array('width' => '50px');
         }
         $this->view->params = $this->_getAllParams();
         $pageID = $this->_getParam('pageID');
         $langId = $this->_registry->languageID;
         $lines = new ImportExportObject();
         $select = $lines->getAllByType($langId, $this->_importType);
         $oDate = new Zend_Date(time());
         $validDate = $oDate->subDay($this->_interval, Zend_Date::DAY);
         $validDate = $oDate->toString('Y-M-d H:m:s');
         $options = array('commands' => array($this->view->link($this->view->url(array('controller' => $this->_name, 'action' => $this->_defaultAction)), $this->view->getCibleText('button_import_all'), array('class' => 'action_submit import'))), 'disable-export-to-excel' => $this->_exportExcel, 'disable-export-to-pdf' => $this->_exportPdf, 'disable-export-to-csv' => $this->_exportCsv, 'filters' => array('max_days_interval' => array('label' => 'Filtre 1', 'default_value' => $validDate, 'associatedTo' => 'FI_LastModif', 'whereClause' => ' > ', 'choices' => array('' => '', 'isvalid' => $this->view->getCibleText('filter_files_to_import')))), 'action_panel' => array('width' => '50', 'actions' => array('import' => array('label' => $this->view->getCibleText('button_import'), 'url' => $this->view->baseUrl() . "/" . $this->_moduleTitle . "/" . $this->_name . "/" . $this->_defaultAction . "/" . $this->_paramId . "/%ID%/" . $pageID, 'findReplace' => array('search' => '%ID%', 'replace' => 'FI_ID')))));
         $mylist = new Cible_Paginator($select, $tables, $field_list, $options);
         $this->view->assign('mylist', $mylist);
     }
 }
Example #13
0
 /**
  * Return interval (two GMT Zend_Date).
  *
  * @param $code
  * @param bool $timezone
  *
  * @return Varien_Object
  */
 public function getInterval($code, $timezone = false)
 {
     $timestamp = Mage::getSingleton('core/date')->gmtTimestamp();
     if ($timezone) {
         $timestamp = Mage::app()->getLocale()->date($timestamp);
     }
     $from = new Zend_Date($timestamp, null, Mage::app()->getLocale()->getLocaleCode());
     $to = clone $from;
     $dateInterval = null;
     switch ($code) {
         case self::TODAY:
             $from->setTime('00:00:00');
             $to->setTime('23:59:59');
             break;
         case self::YESTERDAY:
             $from->subDay(1)->setTime('00:00:00');
             $to->subDay(1)->setTime('23:59:59');
             break;
         case self::THIS_MONTH:
             $from->setDay(1)->setTime('00:00:00');
             $to->setDay(1)->addDay($to->get(Zend_Date::MONTH_DAYS) - 1)->setTime('23:59:59');
             break;
         case self::PREVIOUS_MONTH:
             $from->setDay(1)->subMonth(1)->setTime('00:00:00');
             $to->setDay(1)->setTime('23:59:59')->subMonth(1)->addDay($to->get(Zend_Date::MONTH_DAYS) - 1);
             break;
         case self::THIS_QUARTER:
             $month = intval($from->get(Zend_Date::MONTH) / 4) * 3 + 1;
             $from->setDay(1)->setMonth($month)->setTime('00:00:00');
             $to->setDay(1)->setMonth($month)->addMonth(3)->subDay(1)->setTime('23:59:59');
             break;
         case self::PREVIOUS_QUARTER:
             $month = intval($from->get(Zend_Date::MONTH) / 4) * 3 + 1;
             $from->setDay(1)->setMonth($month)->setTime('00:00:00')->subMonth(3);
             $to->setDay(1)->setMonth($month)->addMonth(3)->subDay(1)->setTime('23:59:59')->subMonth(3);
             break;
         case self::THIS_YEAR:
             $from->setDay(1)->setMonth(1)->setTime('00:00:00');
             $to->setDay(1)->setMonth(1)->addDay($to->get(Zend_Date::LEAPYEAR) ? 365 : 364)->setTime('23:59:59');
             break;
         case self::PREVIOUS_YEAR:
             $from->setDay(1)->setMonth(1)->setTime('00:00:00')->subYear(1);
             $to->setDay(1)->setMonth(1)->addDay($to->get(Zend_Date::LEAPYEAR) ? 365 : 364)->setTime('23:59:59')->subYear(1);
             break;
         case self::LAST_24H:
             $from->subDay(1);
             break;
         case self::THIS_WEEK:
             $weekday = $from->get(Zend_Date::WEEKDAY_DIGIT);
             #0-6
             $from->setTime('00:00:00')->subDay($weekday);
             $to->setTime('23:59:59')->addDay(6 - $weekday);
             break;
         case self::PREVIOUS_WEEK:
             $weekday = $from->get(Zend_Date::WEEKDAY_DIGIT);
             #0-6
             $from->setTime('00:00:00')->subDay($weekday)->subWeek(1);
             $to->setTime('23:59:59')->addDay(6 - $weekday)->subWeek(1);
             break;
         case self::LAST_7D:
             $from->subDay(7);
             break;
         case self::LAST_30D:
             $from->subDay(30);
             break;
         case self::LAST_3M:
             $from->subMonth(3);
             break;
         case self::LAST_12M:
             $from->subYear(1);
             break;
         case self::LIFETIME:
             $from->subYear(10);
             $to->addYear(10);
             break;
     }
     return new Varien_Object(array('from' => $from, 'to' => $to));
 }
Example #14
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 #15
0
 /**
  * Test for Yesterday
  */
 public function testYesterday()
 {
     $locale = new Zend_Locale('de_AT');
     $date = new Zend_Date(Zend_Date::now());
     $d2 = new Zend_Date(1010101010, $locale);
     $date->subDay(1);
     $this->assertFalse($d2->isYesterday());
     $this->assertTrue($date->isYesterday());
 }
Example #16
0
 public function prepareMail()
 {
     // Get the current date
     $now = new Zend_Date(Mage::getModel('core/date')->gmtTimestamp());
     // Get the setting for the start of history
     $history = new Zend_Date(Mage::getStoreConfig('reminder/generalsettings/startingdate'));
     // Get the settings whether to use the order creation or update date
     $orderusecreation = Mage::getStoreConfig('reminder/timesettings/orderusecreation');
     // Get the active stores
     $storesfilter = explode(',', Mage::getStoreConfig('reminder/enablesettings/storesenabled'));
     // Get all orders from the Magento database
     $collection = Mage::getResourceModel('sales/order_grid_collection')->addAttributeToSelect('*')->addFieldToFilter('store_id', array('in' => $storesfilter))->addAttributeToFilter('created_at', array('from' => $history, 'to' => $now, 'datetime' => true));
     #->addAttributeToFilter( 'status', array( 'in' => $statusfilter ) )
     // Iterate over all the orders
     $remindermodel = Mage::getModel('reminder/reminder');
     $orders = $collection->getItems();
     $count_all = count($orders);
     $count_considered1 = 0;
     $count_considered2 = 0;
     $count_match = 0;
     foreach ($orders as $order) {
         // Get settings for the status filter
         $statusfilter = explode(',', Mage::getStoreConfig('reminder/generalsettings/orderstatuses', $order->getStoreId()));
         // Only consider orders with the right status
         $statusok = in_array($order->getStatus(), $statusfilter);
         if ($statusok) {
             $count_considered1 += 1;
             // Get settings for weekend days
             $weekendsexclude = Mage::getStoreConfig('reminder/timesettings/weekendsexclude', $order->getStoreId());
             // Get settings for the payment filters
             $paymentfilter = explode(',', Mage::getStoreConfig('reminder/generalsettings/orderpayments', $order->getStoreId()));
             // Get settings for onaccount customers
             $firstnotificationonaccount = Mage::getStoreConfig('reminder/timesettings/firstnotificationonaccount', $order->getStoreId());
             $firstonaccount = new Zend_Date(Mage::getModel('core/date')->gmtTimestamp());
             $firstonaccount = $firstonaccount->subDay($firstnotificationonaccount);
             $secondnotificationonaccount = Mage::getStoreConfig('reminder/timesettings/secondnotificationonaccount', $order->getStoreId());
             $secondonaccount = new Zend_Date(Mage::getModel('core/date')->gmtTimestamp());
             $secondonaccount = $secondonaccount->subDay($secondnotificationonaccount);
             $nthonaccount = Mage::getStoreConfig('reminder/timesettings/nthonaccount', $order->getStoreId());
             $cancelonaccountsettings = Mage::getStoreConfig('reminder/timesettings/cancelonaccount', $order->getStoreId());
             $cancelonaccount = new Zend_Date(Mage::getModel('core/date')->gmtTimestamp());
             $cancelonaccount = $cancelonaccount->subDay($cancelonaccountsettings);
             // Get settings for prepaid customers
             $firstnotificationprepaid = Mage::getStoreConfig('reminder/timesettings/firstnotificationprepaid', $order->getStoreId());
             $firstprepaid = new Zend_Date(Mage::getModel('core/date')->gmtTimestamp());
             $firstprepaid = $firstprepaid->subDay($firstnotificationprepaid);
             $secondnotificationprepaid = Mage::getStoreConfig('reminder/timesettings/secondnotificationprepaid', $order->getStoreId());
             $secondprepaid = new Zend_Date(Mage::getModel('core/date')->gmtTimestamp());
             $secondprepaid = $secondprepaid->subDay($secondnotificationprepaid);
             $nthprepaid = Mage::getStoreConfig('reminder/timesettings/nthprepaid', $order->getStoreId());
             $cancelprepaidsettings = Mage::getStoreConfig('reminder/timesettings/cancelprepaid', $order->getStoreId());
             $cancelprepaid = new Zend_Date(Mage::getModel('core/date')->gmtTimestamp());
             $cancelprepaid = $cancelprepaid->subDay($cancelprepaidsettings);
             // Get the order from the 'reminder' database
             $reminderorders = $remindermodel->getCollection()->addFieldToFilter('increment_id', $order->getIncrementId())->getItems();
             // If it doesn't exist yet, create it
             if (empty($reminderorders)) {
                 $this->createReminderEntry($order, $remindermodel);
                 $reminderorders = $remindermodel->getCollection()->addFieldToFilter('increment_id', $order->getIncrementId())->getItems();
             }
             // Process the order as present in the 'reminder' database
             foreach ($reminderorders as $reminderorder) {
                 // Make sure that the order is not filtered out - otherwise don't do any processing
                 if ($reminderorder->getStatus() == 'enabled' && $order->getBillingAddress() != null && in_array($order->getPayment()->getMethod(), $paymentfilter)) {
                     $count_considered2 += 1;
                     // Obtain the age (weekends excluded)
                     if ($weekendsexclude == 'enabled') {
                         // Obtain the age
                         $now_bis = new Zend_Date(Mage::getModel('core/date')->gmtTimestamp());
                         if ($orderusecreation == 'enabled') {
                             $start_date = new Zend_Date($order->getCreatedAt(), 'yyyy-MM-dd');
                         } else {
                             $start_date = new Zend_Date($order->getUpdatedAt(), 'yyyy-MM-dd');
                         }
                         $age = $now_bis->sub($start_date)->toValue();
                         $days = ceil($age / 60 / 60 / 24);
                         // Calculate the weekenddays
                         $end_date = new Zend_Date($start_date);
                         $dayscounter = $days;
                         $weekenddays = 0;
                         while ($dayscounter > 0) {
                             $weekdaydigit = $end_date->toValue(Zend_Date::WEEKDAY_DIGIT);
                             if ($weekdaydigit == 0 || $weekdaydigit == 6) {
                                 $weekenddays++;
                             }
                             $end_date->addDay(1);
                             $dayscounter--;
                         }
                     } else {
                         $weekenddays = 0;
                     }
                     // Get the date of the order
                     if ($orderusecreation == 'enabled') {
                         $orderdate = new Zend_Date($order->getCreatedAt(), 'yyyy-MM-dd');
                     } else {
                         $orderdate = new Zend_Date($order->getUpdatedAt(), 'yyyy-MM-dd');
                     }
                     $orderdate = $orderdate->addDay($weekenddays);
                     $orderdate = $orderdate->getTimestamp();
                     //  Find out if the order is part of the on-account customers
                     $onaccount = Mage::getStoreConfig('reminder/generalsettings/groupsonaccount', $order->getStoreId());
                     if (in_array($order->getCustomerGroupId(), explode(',', $onaccount))) {
                         // First reminder for on-account customers
                         if ($reminderorder->getReminders() == 0) {
                             if ($firstonaccount->getTimestamp() > $orderdate) {
                                 $this->prepareReminder($order, $remindermodel);
                                 $count_match += 1;
                             }
                         } elseif ($reminderorder->getReminders() == 1) {
                             if ($secondonaccount->getTimestamp() > $orderdate) {
                                 $this->prepareReminder($order, $remindermodel);
                                 $count_match += 1;
                             }
                         } else {
                             $newdate = new Zend_Date($secondonaccount);
                             $limit = $newdate->subDay(($reminderorder->getReminders() - 1) * $nthonaccount);
                             if ($limit->getTimestamp() > $orderdate) {
                                 $this->prepareReminder($order, $remindermodel);
                                 $count_match += 1;
                             }
                         }
                         // Auto-cancel an order if it is too old (on-account)
                         if ($cancelonaccount->getTimestamp() > $orderdate) {
                             $order_bis = Mage::getModel('sales/order')->loadByIncrementId($order->getIncrementId());
                             if ($order_bis->canCancel()) {
                                 Mage::log('[kinento-reminder] Canceling order ' . $order_bis->getIncrementId() . ' (' . $cancelonaccount->getTimestamp() . ' > ' . $orderdate . ')', null, 'kinento.log', true);
                                 $order_bis->cancel();
                                 $order_bis->addStatusToHistory($order_bis->getStatus(), 'Canceled by Order Reminders', false);
                                 $order_bis->save();
                                 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('reminder')->__('Order %d canceled', $order_bis->getIncrementId()));
                             } else {
                                 Mage::log('[kinento-reminder] Could not cancel order ' . $order_bis->getIncrementId() . ' (' . $cancelonaccount->getTimestamp() . ' > ' . $orderdate . ')', null, 'kinento.log', true);
                                 Mage::getSingleton('adminhtml/session')->addNotice(Mage::helper('reminder')->__('Unable to cancel order %d', $order_bis->getIncrementId()));
                             }
                         }
                     } else {
                         // First reminder for prepaid customers
                         if ($reminderorder->getReminders() == 0) {
                             if ($firstprepaid->getTimestamp() > $orderdate) {
                                 $this->prepareReminder($order, $remindermodel);
                                 $count_match += 1;
                             }
                         } elseif ($reminderorder->getReminders() == 1) {
                             if ($secondprepaid->getTimestamp() > $orderdate) {
                                 $this->prepareReminder($order, $remindermodel);
                                 $count_match += 1;
                             }
                         } else {
                             $newdate = new Zend_Date($secondprepaid);
                             $limit = $newdate->subDay(($reminderorder->getReminders() - 1) * $nthprepaid);
                             if ($limit->getTimestamp() > $orderdate) {
                                 $this->prepareReminder($order, $remindermodel);
                                 $count_match += 1;
                             }
                         }
                         // Auto-cancel an order if it is too old (prepaid)
                         if ($cancelprepaid->getTimestamp() > $orderdate) {
                             $order_bis = Mage::getModel('sales/order')->loadByIncrementId($order->getIncrementId());
                             if ($order_bis->canCancel()) {
                                 Mage::log('[kinento-reminder] Canceling order ' . $order_bis->getIncrementId() . ' (' . $cancelprepaid->getTimestamp() . ' > ' . $orderdate . ')', null, 'kinento.log', true);
                                 $order_bis->cancel();
                                 $order_bis->addStatusToHistory($order_bis->getStatus(), 'Canceled by Order Reminders', false);
                                 $order_bis->save();
                                 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('reminder')->__('Order %d canceled', $order_bis->getIncrementId()));
                             } else {
                                 Mage::log('[kinento-reminder] Could not cancel order ' . $order_bis->getIncrementId() . ' (' . $cancelprepaid->getTimestamp() . ' > ' . $orderdate . ')', null, 'kinento.log', true);
                                 Mage::getSingleton('adminhtml/session')->addNotice(Mage::helper('reminder')->__('Unable to cancel order %d', $order_bis->getIncrementId()));
                             }
                         }
                     }
                 }
             }
         }
     }
     Mage::log('', null, 'kinento.log', true);
     Mage::log('[kinento-reminder] Orders ' . $count_all . ' (total), ' . $count_considered1 . ' (after status filter), ' . $count_considered2 . ' (after other filters), ' . $count_match . ' (after time filter)', null, 'kinento.log', true);
     Mage::getSingleton('adminhtml/session')->addNotice(Mage::helper('reminder')->__('%d order(s) searched, %d match the criteria', $count_all, $count_match));
 }
Example #17
0
 /**
  * @param array $statistics (array('2014-01-01' => 2,'2014-01-02' => 0))
  * @param int $periodType
  *
  * @return array (array('2014-01' => 2))
  */
 public function getGroupedByPeriod($statistics, $periodType)
 {
     if ($periodType == self::PERIOD_DAY_TYPE) {
         return $statistics;
     }
     ksort($statistics);
     //get first key
     $intervalDate = new Zend_Date(key($statistics), Varien_Date::DATE_INTERNAL_FORMAT);
     //reset day to 1
     $intervalDate->setDay(1);
     if ($periodType == self::PERIOD_WEEK_TYPE) {
         //for week period need set start interval like 2014-01-07
         $firstWeekDay = (int) Mage::getStoreConfig('general/locale/firstday') == 0 ? 7 : (int) Mage::getStoreConfig('general/locale/firstday');
         $intervalDate->setWeekday($firstWeekDay);
         if ($intervalDate->toString(Varien_Date::DATE_INTERNAL_FORMAT) == key($statistics)) {
             $intervalDate->addWeek(1);
         }
         $intervalDate->subDay(1);
     }
     $result = array();
     foreach ($statistics as $key => $value) {
         if (!$this->_isInPeriodInterval($intervalDate, $key, $periodType)) {
             $this->_setPeriodIntervalIndex($intervalDate, $key, $periodType);
         }
         $intervalIndex = $intervalDate->toString($this->_getPeriodIntervalDateFormat($periodType));
         if ($periodType == self::PERIOD_WEEK_TYPE) {
             $_prevWeek = clone $intervalDate;
             $_prevWeek->subWeek(1);
             $_prevWeek->addDay(1);
             $_prevWeekIndex = $_prevWeek->toString($this->_getPeriodIntervalDateFormat($periodType));
             $result[$_prevWeekIndex . '/' . $intervalIndex] = (array_key_exists($_prevWeekIndex . '/' . $intervalIndex, $result) ? $result[$_prevWeekIndex . '/' . $intervalIndex] : 0) + $this->_getValue($value);
         } else {
             $result[$intervalIndex] = (array_key_exists($intervalIndex, $result) ? $result[$intervalIndex] : 0) + $this->_getValue($value);
         }
     }
     return $result;
 }
Example #18
0
 public function prepareMail()
 {
     // Get the current date
     $now = new Zend_Date(Mage::getModel('core/date')->gmtTimestamp());
     // Get the setting for the start of history
     $history = new Zend_Date(Mage::getStoreConfig('invoicereminder/generalsettings/startingdate'));
     // Get settings for the status and payment method filters
     $statusfilter = explode(',', Mage::getStoreConfig('invoicereminder/generalsettings/invoicestatuses'));
     // Get the data from the Magento database
     $collection = Mage::getResourceModel('sales/order_invoice_grid_collection')->addAttributeToSelect('*')->addAttributeToFilter('state', array('in' => $statusfilter))->addAttributeToFilter('created_at', array('from' => $history, 'to' => $now, 'datetime' => true));
     // Iterate over all the invoices
     $invoiceremindermodel = Mage::getModel('invoicereminder/invoicereminder');
     $invoices = $collection->getItems();
     foreach ($invoices as $invoice) {
         // Load the corresponding order
         $order = Mage::getModel('sales/order')->loadByIncrementId($invoice->getOrderIncrementId());
         // Get settings for the payment filters
         $paymentfilter = explode(',', Mage::getStoreConfig('invoicereminder/generalsettings/invoicepayments', $order->getStoreId()));
         // Get settings for onaccount customers
         $firstnotificationonaccount = Mage::getStoreConfig('invoicereminder/timesettings/firstnotificationonaccount', $order->getStoreId());
         $firstonaccount = new Zend_Date(Mage::getModel('core/date')->gmtTimestamp());
         $firstonaccount = $firstonaccount->subDay($firstnotificationonaccount);
         $secondnotificationonaccount = Mage::getStoreConfig('invoicereminder/timesettings/secondnotificationonaccount', $order->getStoreId());
         $secondonaccount = new Zend_Date(Mage::getModel('core/date')->gmtTimestamp());
         $secondonaccount = $secondonaccount->subDay($secondnotificationonaccount);
         $nthonaccount = Mage::getStoreConfig('invoicereminder/timesettings/nthonaccount', $order->getStoreId());
         // Get settings for prepaid customers
         $firstnotificationprepaid = Mage::getStoreConfig('invoicereminder/timesettings/firstnotificationprepaid', $order->getStoreId());
         $firstprepaid = new Zend_Date(Mage::getModel('core/date')->gmtTimestamp());
         $firstprepaid = $firstprepaid->subDay($firstnotificationprepaid);
         $secondnotificationprepaid = Mage::getStoreConfig('invoicereminder/timesettings/secondnotificationprepaid', $order->getStoreId());
         $secondprepaid = new Zend_Date(Mage::getModel('core/date')->gmtTimestamp());
         $secondprepaid = $secondprepaid->subDay($secondnotificationprepaid);
         $nthprepaid = Mage::getStoreConfig('invoicereminder/timesettings/nthprepaid', $order->getStoreId());
         // Get the invoice from the 'invoicereminder' database
         $reminderinvoices = $invoiceremindermodel->getCollection()->addFieldToFilter('increment_id', $invoice->getIncrementId())->getItems();
         // If it doesn't exist yet, create it
         if (empty($reminderinvoices)) {
             $this->createInvoicereminderEntry($invoice, $invoiceremindermodel);
             $reminderinvoices = $invoiceremindermodel->getCollection()->addFieldToFilter('increment_id', $invoice->getIncrementId())->getItems();
         }
         // Process the invoice as present in the 'invoicereminder' database
         foreach ($reminderinvoices as $reminderinvoice) {
             // Make sure that the invoice is not filtered out - otherwise don't do any processing
             if ($reminderinvoice->getStatus() == 'enabled' && $order->getBillingAddress() != null && in_array($order->getPayment()->getMethod(), $paymentfilter)) {
                 // Get the date of the invoice
                 $invoicedate = strtotime($invoice->getCreatedAt());
                 //  Find out if the invoice is part of the on-account customers
                 $onaccount = Mage::getStoreConfig('invoicereminder/generalsettings/groupsonaccount', $order->getStoreId());
                 if (in_array($order->getCustomerGroupId(), explode(',', $onaccount))) {
                     // First reminder for on-account customers
                     if ($reminderinvoice->getInvoicereminders() == 0) {
                         if ($firstonaccount->getTimestamp() > $invoicedate) {
                             $this->prepareReminder($invoice, $invoiceremindermodel, $order);
                         }
                     } elseif ($reminderinvoice->getInvoicereminders() == 1) {
                         if ($secondonaccount->getTimestamp() > $invoicedate) {
                             $this->prepareReminder($invoice, $invoiceremindermodel, $order);
                         }
                     } else {
                         $newdate = new Zend_Date($secondonaccount);
                         $limit = $newdate->subDay(($reminderinvoice->getInvoicereminders() - 1) * $nthonaccount);
                         if ($limit->getTimestamp() > $invoicedate) {
                             $this->prepareReminder($invoice, $invoiceremindermodel, $order);
                         }
                     }
                 } else {
                     // First reminder for prepaid customers
                     if ($reminderinvoice->getInvoicereminders() == 0) {
                         if ($firstprepaid->getTimestamp() > $invoicedate) {
                             $this->prepareReminder($invoice, $invoiceremindermodel, $order);
                         }
                     } elseif ($reminderinvoice->getInvoicereminders() == 1) {
                         if ($secondprepaid->getTimestamp() > $invoicedate) {
                             $this->prepareReminder($invoice, $invoiceremindermodel, $order);
                         }
                     } else {
                         $newdate = new Zend_Date($secondprepaid);
                         $limit = $newdate->subDay(($reminderinvoice->getInvoicereminders() - 1) * $nthprepaid);
                         if ($limit->getTimestamp() > $invoicedate) {
                             $this->prepareReminder($invoice, $invoiceremindermodel, $order);
                         }
                     }
                 }
             }
         }
     }
 }
Example #19
0
 /**
  * Writes the Job object to the database. If an ID is provided this method will try to update a data set. If there
  * is no ID given, the system will create a new data set.
  *
  * @param Enlight_Components_Cron_Job $job
  * @return Enlight_Components_Cron_Adapter_Adapter
  */
 public function write(Enlight_Components_Cron_Job $job)
 {
     $data = array();
     $where = null;
     foreach ($this->_columns as $key => $value) {
         switch ($key) {
             case 'data':
                 $data[$key] = serialize($job->{$key});
                 break;
             default:
                 $data[$key] = $job->{$key};
         }
     }
     if (is_null($job->getId())) {
         $next = $job->getNext();
         if (empty($next)) {
             $job->setNext(new Zend_Date());
         }
         $start = $job->getStart();
         if (empty($start)) {
             $zd = new Zend_Date();
             $job->setStart($zd->subDay(1));
         }
         $end = $job->getEnd();
         if (empty($end)) {
             $zd = new Zend_Date();
             $job->setEnd($zd->subDay(1));
         }
         $this->insert($data);
     } else {
         $where = $this->getAdapter()->quoteInto($this->getAdapter()->quoteIdentifier($this->_primary) . ' = ?', $job->getId());
         $this->update($data, $where);
     }
     return $this;
 }
Example #20
0
	/**
	 * We expect user's logon date to be greater than or equal to the account's creation date
	 * @expectedException Doctrine_Record_Exception
	 */
	public function testConstraintLoggedAtTimestamp() {
		$log_date = new Zend_Date($this->user->created_at);
		$log_date->subDay(1);
		$this->user->log_date = $log_date->get(Zend_Date::W3C);
		$this->user->save();
	}
 /**
  * search for orders to review per website
  */
 private function searchOrdersForReview()
 {
     $websites = $this->_helper->getwebsites(true);
     foreach ($websites as $website) {
         $apiEnabled = $this->_helper->isEnabled($website);
         if ($apiEnabled && $this->_helper->getWebsiteConfig(\Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_SYNC_ORDER_ENABLED, $website) && $this->_reviewHelper->getOrderStatus($website) && $this->_reviewHelper->getDelay($website)) {
             $storeIds = $website->getStoreIds();
             if (empty($storeIds)) {
                 continue;
             }
             $orderStatusFromConfig = $this->_reviewHelper->getOrderStatus($website);
             $delayInDays = $this->_reviewHelper->getDelay($website);
             $campaignCollection = $this->_campaignCollection->create()->addFieldToFilter('event_name', 'Order Review')->load();
             $campaignOrderIds = $campaignCollection->getColumnValues('order_increment_id');
             $fromTime = new \Zend_Date();
             $fromTime->subDay($delayInDays);
             $toTime = clone $fromTime;
             $to = $toTime->toString('YYYY-MM-dd HH:mm:ss');
             $from = $fromTime->subHour(2)->toString('YYYY-MM-dd HH:mm:ss');
             $created = array('from' => $from, 'to' => $to, 'date' => true);
             $collection = $this->_orderCollection->create()->addFieldToFilter('main_table.status', $orderStatusFromConfig)->addFieldToFilter('main_table.created_at', $created)->addFieldToFilter('main_table.store_id', array('in' => $storeIds));
             if (!empty($campaignOrderIds)) {
                 $collection->addFieldToFilter('main_table.increment_id', array('nin' => $campaignOrderIds));
             }
             //process rules on collection
             $collection = $this->_rulesFactory->create()->process($collection, \Dotdigitalgroup\Email\Model\Rules::REVIEW, $website->getId());
             if ($collection->getSize()) {
                 $this->_reviewCollection[$website->getId()] = $collection;
             }
         }
     }
 }
Example #22
0
 /**
  * @param $filter
  *
  * @return mixed
  */
 protected function _processFilter($filter)
 {
     $period = AW_Helpdesk3_Block_Adminhtml_Statistic_Agent_View_Chart::PERIOD_LAST_THIRTY_DAYS;
     if (array_key_exists('period', $filter)) {
         $period = intval($filter['period']);
     }
     $filter['period'] = $period;
     $fromDate = new Zend_Date();
     $toDate = new Zend_Date();
     $fromDate->setHour(23)->setMinute(59)->setSecond(59);
     $toDate->setHour(23)->setMinute(59)->setSecond(59);
     switch ($period) {
         case AW_Helpdesk3_Block_Adminhtml_Statistic_Agent_View_Chart::PERIOD_TODAY:
             break;
         case AW_Helpdesk3_Block_Adminhtml_Statistic_Agent_View_Chart::PERIOD_YESTERDAY:
             $fromDate->subDay(1);
             $toDate->subDay(1);
             break;
         case AW_Helpdesk3_Block_Adminhtml_Statistic_Agent_View_Chart::PERIOD_THIS_WEEK:
             $firstDayOfWeek = (int) Mage::getStoreConfig('general/locale/firstday');
             if ($firstDayOfWeek === 0) {
                 $firstDayOfWeek = 7;
             }
             $fromDate->setWeekday($firstDayOfWeek);
             if ($firstDayOfWeek > (int) $fromDate->toString('e')) {
                 $fromDate->subWeek(1);
             }
             break;
         case AW_Helpdesk3_Block_Adminhtml_Statistic_Agent_View_Chart::PERIOD_LAST_WEEK:
             $fromDate->subWeek(1);
             $toDate->subWeek(1);
             $firstDayOfWeek = (int) Mage::getStoreConfig('general/locale/firstday');
             if ($firstDayOfWeek === 0) {
                 $firstDayOfWeek = 7;
             }
             $fromDate->setWeekday($firstDayOfWeek);
             if ($firstDayOfWeek > (int) $fromDate->toString('e')) {
                 $fromDate->subWeek(1);
             }
             $lastDayOfWeek = $firstDayOfWeek - 1;
             if ($lastDayOfWeek < 1) {
                 $lastDayOfWeek = 7;
             }
             $toDate->setWeekday($lastDayOfWeek);
             break;
         case AW_Helpdesk3_Block_Adminhtml_Statistic_Agent_View_Chart::PERIOD_THIS_MONTH:
             $fromDate->setDay(1);
             break;
         case AW_Helpdesk3_Block_Adminhtml_Statistic_Agent_View_Chart::PERIOD_LAST_MONTH:
             $fromDate->subMonth(1)->setDay(1);
             $toDate->setDay(1)->subDay(1);
             break;
         case AW_Helpdesk3_Block_Adminhtml_Statistic_Agent_View_Chart::PERIOD_LAST_SIX_MONTHS:
             $fromDate->subMonth(6);
             break;
         case AW_Helpdesk3_Block_Adminhtml_Statistic_Agent_View_Chart::PERIOD_CUSTOM:
             $_reversed = false;
             $_now = new Zend_Date(null, 'dd/MM/y');
             try {
                 $_fromDate = new Zend_Date($filter['from_date'], 'dd/MM/y');
             } catch (Exception $e) {
                 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('aw_hdu3')->__('Please select correct "From" date value'));
                 $_fromDate = clone $_now;
             }
             try {
                 $_toDate = new Zend_Date($filter['to_date'], 'dd/MM/y');
                 if ($_fromDate->compare($_toDate) > 0) {
                     $_reversed = true;
                 }
             } catch (Exception $e) {
                 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('aw_hdu3')->__('Please select correct "To" date value'));
                 $_toDate = clone $_now;
             }
             if ($_reversed) {
                 $fromDate = $_toDate;
                 $toDate = $_fromDate;
             } else {
                 $fromDate = $_fromDate;
                 $toDate = $_toDate;
             }
             break;
         case AW_Helpdesk3_Block_Adminhtml_Statistic_Agent_View_Chart::PERIOD_LAST_SEVEN_DAYS:
             $fromDate->subDay(6);
             break;
         case AW_Helpdesk3_Block_Adminhtml_Statistic_Agent_View_Chart::PERIOD_LAST_THIRTY_DAYS:
             $fromDate->subDay(29);
             break;
     }
     $filter['from_date'] = $fromDate;
     $filter['to_date'] = $toDate;
     if (!array_key_exists('group', $filter)) {
         $filter['group'] = AW_Helpdesk3_Block_Adminhtml_Statistic_Agent_View_Chart::GROUP_BY_WEEK;
     }
     if (!array_key_exists('agents[]', $filter)) {
         $filter['agents[]'] = $this->_getAgentIds();
     }
     if (!array_key_exists('report', $filter)) {
         $filter['report'] = AW_Helpdesk3_Block_Adminhtml_Statistic_Agent_View_Chart::REPORT_FIRST_REPLY_AVG_TIME;
     }
     return $filter;
 }
Example #23
0
 /**
  * getStatus - Check if campaign is open, closed or not started
  *
  * @author Mikko Korpinen
  * @param int $id_cmp
  * @return string (not_started, open, ended)
  */
 public function getStatus($id_cmp)
 {
     $notStarted = "not_started";
     $open = "open";
     $closed = "ended";
     $thisDate = date("Y-m-d", time());
     $thisDate = new Zend_Date($thisDate, Zend_Date::ISO_8601);
     $select = $this->select()->where('id_cmp = ?', $id_cmp)->limit(1);
     $row = $this->fetchAll($select)->current();
     $startDate = $row['start_time_cmp'];
     $startDate = new Zend_Date($startDate, Zend_Date::ISO_8601);
     $startDate->subDay(1);
     $endDate = $row['end_time_cmp'];
     if ($endDate === '0000-00-00') {
         if ($thisDate->compare($startDate) == 1) {
             return $open;
         } else {
             return $notStarted;
         }
     } else {
         $endDate = new Zend_Date($endDate, Zend_Date::ISO_8601);
         $endDate->addDay(1);
         if ($thisDate->compare($startDate) == 1 && $thisDate->compare($endDate) == -1) {
             return $open;
         } else {
             $startDate->addDay(1);
             if ($thisDate->compare($startDate) == -1) {
                 return $notStarted;
             } else {
                 return $closed;
             }
         }
     }
 }