Pommo_Subscribers::get PHP Method

get() public static method

returns an array of subscribers. Array key(s) correlates to subscriber id.
public static get ( $p = [], $search = ['field' => null, 'string' => null] )
    public static function get($p = array(), $search = array('field' => null, 'string' => null))
    {
        $defaults = array('status' => 'all', 'email' => null, 'sort' => null, 'order' => null, 'limit' => null, 'offset' => null, 'id' => null);
        $p = Pommo_Api::getParams($defaults, $p);
        $dbo = Pommo::$_dbo;
        if ($p['status'] == 'all') {
            $p['status'] = null;
        }
        if (is_numeric($p['limit']) && !is_numeric($p['offset'])) {
            $p['offset'] = 0;
        }
        $o = array();
        $query = "\n            SELECT\n                s.subscriber_id,\n                s.email,\n                s.time_touched,\n                s.time_registered,\n                s.flag,\n                INET_NTOA(s.ip) ip,\n                s.status,\n                p.pending_code,\n                p.pending_array,\n                p.pending_type" . (is_numeric($p['sort']) ? ", d.value" : '') . (is_numeric($search['field']) ? ", search.value" : '') . " FROM " . $dbo->table['subscribers'] . " s\n            LEFT JOIN " . $dbo->table['subscriber_pending'] . " p ON (s.subscriber_id = p.subscriber_id) " . (is_numeric($p['sort']) ? "LEFT JOIN (SELECT * FROM " . $dbo->table['subscriber_data'] . " WHERE field_id = " . (int) $p['sort'] . " ) AS d" . " ON (s.subscriber_id = d.subscriber_id)" : '') . (is_numeric($search['field']) ? "LEFT JOIN (SELECT value FROM " . $dbo->table['subscriber_data'] . " WHERE field_id = " . (int) $search['field'] . " ) AS search" . " ON (s.subscriber_id = search.subscriber_id)" : '') . " WHERE\n                1\n                [AND s.subscriber_id IN(%C)]\n                [AND s.status=%I]\n                [AND s.email IN (%Q)]\n                [AND %S LIKE '%%S%']\n                [ORDER BY %S] [%S]\n                [LIMIT %I, %I]";
        // Check if we're sorting against a field.
        //   If so, sort against the "value" column select.
        //   If it's a numeric field, cast the value (string) as an Integer by the DBE for proper sorting.
        if (is_numeric($p['sort'])) {
            require_once Pommo::$_baseDir . 'classes/Pommo_Fields.php';
            $numericFields = Pommo_Fields::getByType(array('date', 'number'));
            $p['sort'] = in_array($p['sort'], $numericFields) ? 'CAST(value as SIGNED)' : 'value';
        }
        // If we're searching/filtering, generate the proper SQL
        $searchSQL = NULL;
        if (!empty($search['field']) && !empty($search['string'])) {
            // make MySQL LIKE() compliant
            $search['string'] = addcslashes($search['string'], '%_');
            $search['field'] = is_numeric($search['field']) ? 'search.value' : 's.' . $search['field'];
        }
        $query = $dbo->prepare($query, array($p['id'], $p['status'], $p['email'], $search['field'], $search['string'], $p['sort'], $p['order'], $p['offset'], $p['limit']));
        while ($row = $dbo->getRows($query)) {
            $o[$row['subscriber_id']] = empty($row['pending_code']) ? Pommo_Subscribers::makeDB($row) : Pommo_Subscribers::makeDB($row, TRUE);
        }
        // fetch data
        if (!empty($o)) {
            // get any date fields for conversion. We can't use the MySQL 4.1/5
            // engine, as it doesn't support negative timestamps... !!!
            require_once Pommo::$_baseDir . 'classes/Pommo_Fields.php';
            $dates = Pommo_Fields::getByType('date');
            $query = "\n                SELECT\n                    field_id,\n                    value,\n                    subscriber_id\n                FROM\n                    " . $dbo->table['subscriber_data'] . "\n                WHERE\n                    subscriber_id IN(%c)";
            $query = $dbo->prepare($query, array(array_keys($o)));
            while ($row = $dbo->getRows($query)) {
                $o[$row['subscriber_id']]['data'][$row['field_id']] = in_array($row['field_id'], $dates) ? Pommo_Helper::timeToStr($row['value']) : $row['value'];
            }
        }
        return $o;
    }

Usage Example

コード例 #1
0
ファイル: Pommo_Groups.php プロジェクト: soonick/poMMo
 function members($p = array(), $filter = array('field' => null, 'string' => null))
 {
     require_once Pommo::$_baseDir . 'classes/Pommo_Subscribers.php';
     if (is_array($this->_memberIDs)) {
         $p['id'] =& $this->_memberIDs;
     } else {
         $p['status'] = $this->_status;
     }
     return Pommo_Subscribers::get($p, $filter);
 }
All Usage Examples Of Pommo_Subscribers::get