Example #1
0
 /**
  * returns the count of newly added subscribers between dates
  *
  * @param string $date_start YYYY-MM-DD date format
  * @param string $date_end YYYY-MM-DD date format
  * @param array $sub_ids OPTIONAL filter sub ids
  * @param boolean $internal OPTIONAL filter internal
  */
 public function registeredBetween($date_start, $date_end, $sub_ids = array(), $internal = null)
 {
     // include the hours, minutes and seconds on the date range
     $date_start = $date_start . ' 00:00:00';
     $date_end = $date_end . ' 23:59:59';
     // handle caching. Only if NOT within the current date
     $cache = Zend_Registry::get('cache');
     $key = __METHOD__ . '_' . $date_start . '_' . $date_end . '_' . implode("_", $sub_ids) . '_' . $internal;
     $cache_key = Base_Utils_String::slug($key);
     if ($date_end < date('Y-m-d', time()) && ($data = $cache->load($cache_key))) {
         return $data;
     }
     // get database adapter
     $db = Zend_Registry::get('db');
     // define select query
     $select = $db->select()->from(array('cu' => 'common_users'), array('count' => 'COUNT(cu.id)'))->where('cu.date_created >= ?', $date_start)->where('cu.date_created <= ?', $date_end);
     if (!empty($sub_ids)) {
         $select->where('cu.sub_id IN (?)', $sub_ids);
     }
     if ($internal != '') {
         $select->where('cu.internal = ?', $internal);
     }
     $count = $db->fetchOne($select);
     $cache->save($count, $cache_key);
     return $count;
 }
 public function pendingOrdersAction()
 {
     $this->_helper->viewRenderer->setNoRender(true);
     $this->getResponse()->setHeader('Content-Type', 'text/html');
     $cache = Zend_Registry::get('cache');
     $date_start = date('Y-m-d') . ' 00:00:00';
     $date_end = date('Y-m-d') . ' 23:59:59';
     $key = __METHOD__ . '_' . $date_start . '_' . $date_end . '_' . 'pendingOrders';
     $cache_key = Base_Utils_String::slug($key);
     if ($cache_date_end < date('Y-m-d', time()) && ($result = $cache->load($cache_key))) {
         $this->getResponse()->setBody(Zend_Json::encode($result));
         return;
     }
     // init variables
     $coModel = Base::getModel('Common_Orders');
     $select = $coModel->select()->setIntegrityCheck(false)->from(array('co' => 'common_orders'), array('count' => 'count(co.id)'))->where("co.status = 'PENDING'");
     $order = $coModel->fetchRow($select);
     if (!$order) {
         $result['errcode'] = 1;
         $result['errmsg'] = "errmsg";
     } else {
         $result = array('errcode' => 0, 'errmsg' => 'OK', 'data' => $order->count, 'link' => '/common/orders?status=PENDING');
         $cache->save($result, $cache_key);
     }
     $this->getResponse()->setBody(Zend_Json::encode($result));
 }