Ejemplo n.º 1
0
Archivo: DAO.php Proyecto: Hildy/cerb5
 /**
  * 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($columns, $params, $limit = 10, $page = 0, $sortBy = null, $sortAsc = null, $withCounts = true)
 {
     $db = DevblocksPlatform::getDatabaseService();
     $fields = SearchFields_CommunityTool::getFields();
     // Sanitize
     if (!isset($fields[$sortBy])) {
         $sortBy = null;
     }
     list($tables, $wheres) = parent::_parseSearchParams($params, $columns, $fields, $sortBy);
     $start = $page * $limit;
     // [JAS]: 1-based [TODO] clean up + document
     $total = -1;
     $select_sql = sprintf("SELECT " . "ct.id as %s, " . "ct.name as %s, " . "ct.code as %s, " . "ct.extension_id as %s ", SearchFields_CommunityTool::ID, SearchFields_CommunityTool::NAME, SearchFields_CommunityTool::CODE, SearchFields_CommunityTool::EXTENSION_ID);
     $join_sql = "FROM community_tool ct ";
     // Custom field joins
     list($select_sql, $join_sql, $has_multiple_values) = self::_appendSelectJoinSqlForCustomFieldTables($tables, $params, 'ct.id', $select_sql, $join_sql);
     $where_sql = "" . (!empty($wheres) ? sprintf("WHERE %s ", implode(' AND ', $wheres)) : "");
     $sort_sql = !empty($sortBy) ? sprintf("ORDER BY %s %s ", $sortBy, $sortAsc || is_null($sortAsc) ? "ASC" : "DESC") : " ";
     $sql = $select_sql . $join_sql . $where_sql . ($has_multiple_values ? 'GROUP BY ct.id ' : '') . $sort_sql;
     // [TODO] Could push the select logic down a level too
     if ($limit > 0) {
         $rs = $db->SelectLimit($sql, $limit, $start) or die(__CLASS__ . '(' . __LINE__ . ')' . ':' . $db->ErrorMsg());
         /* @var $rs ADORecordSet */
     } else {
         $rs = $db->Execute($sql) or die(__CLASS__ . '(' . __LINE__ . ')' . ':' . $db->ErrorMsg());
         /* @var $rs ADORecordSet */
         $total = $rs->RecordCount();
     }
     $results = array();
     if (is_a($rs, 'ADORecordSet')) {
         while (!$rs->EOF) {
             $result = array();
             foreach ($rs->fields as $f => $v) {
                 $result[$f] = $v;
             }
             $object_id = intval($rs->fields[SearchFields_CommunityTool::ID]);
             $results[$object_id] = $result;
             $rs->MoveNext();
         }
     }
     // [JAS]: Count all
     if ($withCounts) {
         $count_sql = ($has_multiple_values ? "SELECT COUNT(DISTINCT ct.id) " : "SELECT COUNT(ct.id) ") . $join_sql . $where_sql;
         $total = $db->GetOne($count_sql);
     }
     return array($results, $total);
 }
Ejemplo n.º 2
0
 /**
  * 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_CommunityTool::getFields();
     // Sanitize
     if (!isset($fields[$sortBy])) {
         $sortBy = null;
     }
     list($tables, $wheres) = parent::_parseSearchParams($params, array(), $fields, $sortBy);
     $start = $page * $limit;
     // [JAS]: 1-based [TODO] clean up + document
     $sql = sprintf("SELECT " . "ct.id as %s, " . "ct.name as %s, " . "ct.code as %s, " . "ct.community_id as %s, " . "ct.extension_id as %s " . "FROM community_tool ct ", SearchFields_CommunityTool::ID, SearchFields_CommunityTool::NAME, SearchFields_CommunityTool::CODE, SearchFields_CommunityTool::COMMUNITY_ID, SearchFields_CommunityTool::EXTENSION_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_CommunityTool::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);
 }
Ejemplo n.º 3
0
 static function getFields()
 {
     return SearchFields_CommunityTool::getFields();
 }