コード例 #1
0
 /**
  * Find all Subscriptions
  * @param array $criteria
  * @param array $orderBy
  * @param array $paging
  * @return array 
  */
 public function fetchAll($criteria = array(), $orderBy = array(), &$paging = null)
 {
     /* @var $select Zend_Db_Select*/
     $select = $this->_dbTable->select();
     $select->setIntegrityCheck(false)->from(array('s' => 'contact_subscription'), array('s.*'));
     if (isset($criteria['status'])) {
         $select->where('s.status = ?', $criteria['status']);
     }
     if (isset($criteria['gender'])) {
         $select->where('s.gender = ?', $criteria['gender']);
     }
     if (isset($criteria['lang'])) {
         $select->where('s.lang = ?', $criteria['lang']);
     }
     if (isset($criteria['subscribed_from'])) {
         $select->where('s.subscribed_dt >= ?', $criteria['subscribed_from']);
     }
     if (isset($criteria['subscribed_to'])) {
         $select->where('s.subscribed_dt < ?', $criteria['subscribed_to']);
     }
     if (isset($criteria['unsubscribed_from'])) {
         $select->where('s.unsubscribed_dt >= ?', $criteria['unsubscribed_from']);
     }
     if (isset($criteria['unsubscribed_to'])) {
         $select->where('s.unsubscribed_dt < ?', $criteria['unsubscribed_to']);
     }
     if (is_array($orderBy) && count($orderBy) > 0) {
         $select->order($orderBy);
     }
     // init paginator
     if ($paging != null) {
         $resultSet = $this->_getPagingRows($paging, $select);
     } else {
         $resultSet = $this->_dbTable->fetchAll($select);
     }
     $subscriptions = array();
     if (0 == count($resultSet)) {
         return $subscriptions;
     }
     foreach ($resultSet as $row) {
         $rowArray = $row->toArray();
         $subscription = new Contact_Model_Subscription();
         $subscription->setOptions($rowArray);
         $subscriptions[] = $subscription;
     }
     return $subscriptions;
 }