public static function get($p = array())
{
$defaults = array('active' => false, 'noBody' => false, 'id' => null, 'code' => null, 'sort' => null, 'order' => null, 'limit' => null, 'offset' => null);
if ($p['forHistory']) {
$forHistory = 1;
unset($p['forHistory']);
}
$p = Pommo_Api::getParams($defaults, $p);
$dbo =& Pommo::$_dbo;
$p['active'] = $p['active'] ? 1 : null;
if (is_numeric($p['limit']) && !is_numeric($p['offset'])) {
$p['offset'] = 0;
}
$o = array();
// We modify the query if the mailings are for the history section
if (1 == $forHistory) {
$field = "COUNT(h.subscriber_id) AS hits";
$join = "LEFT JOIN " . $dbo->table['mailings_hits'] . " h ON (h.mailing_id = m.mailing_id)";
} else {
$field = "GROUP_CONCAT(a.file_name) AS file_name";
$join = "LEFT JOIN " . $dbo->table['mailings_attachments'] . " ma ON (m.mailing_id = ma.mailing_id)\n LEFT JOIN " . $dbo->table['attachment_files'] . " a ON (ma.file_id = a.file_id)";
}
$select = "m.mailing_id,\n c.command,\n c.serial,\n c.securityCode,\n c.current_status,\n c.touched,\n fromname,\n fromemail,\n frombounce,\n subject,\n ishtml,\n mailgroup,\n subscriberCount,\n started,\n finished,\n sent,\n charset,\n status,\n track,\n " . $field;
if (!$p['noBody']) {
$select .= ", body, altbody";
}
$query = "SELECT {$select}\n FROM " . $dbo->table['mailings'] . " m\n LEFT JOIN " . $dbo->table['mailing_current'] . " c ON (m.mailing_id = c.current_id) " . $join . " WHERE\n 1\n [AND m.status=%I]\n [AND m.mailing_id IN(%C)]\n [AND c.securityCode='%S']\n GROUP BY mailing_id\n [ORDER BY %S] [%S]\n [LIMIT %I, %I]";
$query = $dbo->prepare($query, array($p['active'], $p['id'], $p['code'], $p['sort'], $p['order'], $p['offset'], $p['limit']));
while ($row = $dbo->getRows($query)) {
$o[$row['mailing_id']] = Pommo_Mailing::makeDB($row);
}
return $o;
}