/** * Enter description here... * * @param DevblocksSearchCriteria[] $params * @param integer $limit * @param integer $page * @param string $sortBy * @param boolean $sortAsc * @param boolean $withCounts * @return array */ static function search($params, $limit = 10, $page = 0, $sortBy = null, $sortAsc = null, $withCounts = true) { $db = DevblocksPlatform::getDatabaseService(); $fields = SearchFields_Message::getFields(); // Sanitize if (!isset($fields[$sortBy])) { $sortBy = null; } list($tables, $wheres, $selects) = parent::_parseSearchParams($params, array(), $fields, $sortBy); $start = $page * $limit; // [JAS]: 1-based [TODO] clean up + document $sql = sprintf("SELECT " . "m.id as %s, " . "m.ticket_id as %s " . "FROM message m ", SearchFields_Message::ID, SearchFields_Message::TICKET_ID) . (isset($tables['mh']) ? "INNER JOIN message_header mh ON (mh.message_id=m.id)" : " ") . (isset($tables['mc']) ? "INNER JOIN message_content mc ON (mc.message_id=m.id)" : " ") . (!empty($wheres) ? sprintf("WHERE %s ", implode(' AND ', $wheres)) : "") . (!empty($sortBy) ? sprintf("ORDER BY %s %s", $sortBy, $sortAsc || is_null($sortAsc) ? "ASC" : "DESC") : ""); $rs = $db->SelectLimit($sql, $limit, $start) or die(__CLASS__ . '(' . __LINE__ . ')' . ':' . $db->ErrorMsg()); /* @var $rs ADORecordSet */ $results = array(); if (is_a($rs, 'ADORecordSet')) { while (!$rs->EOF) { $result = array(); foreach ($rs->fields as $f => $v) { $result[$f] = $v; } $ticket_id = intval($rs->fields[SearchFields_Message::ID]); $results[$ticket_id] = $result; $rs->MoveNext(); } } // [JAS]: Count all $total = -1; if ($withCounts) { $rs = $db->Execute($sql); $total = $rs->RecordCount(); } return array($results, $total); }
static function getFields() { return SearchFields_Message::getFields(); }