Pommo_Subscribers::makeDB PHP Method

makeDB() public static method

return a subscriber object (array)
public static makeDB ( &$row, $pending = FALSE )
    public static function makeDB(&$row, $pending = FALSE)
    {
        $in = @array('id' => $row['subscriber_id'], 'email' => $row['email'], 'touched' => $row['time_touched'], 'registered' => $row['time_registered'], 'flag' => $row['flag'], 'ip' => $row['ip'], 'status' => $row['status']);
        if ($pending) {
            $o = array('pending_code' => $row['pending_code'], 'pending_array' => $row['pending_array'], 'pending_type' => $row['pending_type']);
            $in = array_merge($o, $in);
        }
        $o = $pending ? Pommo_Api::getParams(Pommo_Type::subscriberPending(), $in) : Pommo_Api::getParams(Pommo_Type::subscriber(), $in);
        return $o;
    }

Usage Example

コード例 #1
0
ファイル: Pommo_Subscribers.php プロジェクト: soonick/poMMo
 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;
 }