$groupTree = CRM_Core_BAO_CustomGroup::getTree('Activity', $form, NULL, NULL, '', NULL);
foreach ($groupTree as $key) {
- if ($key['extends'] == 'Activity') {
+ if (!empty($key['extends']) && $key['extends'] == 'Activity') {
$select .= ", " . $key['table_name'] . ".*";
$from .= " LEFT JOIN " . $key['table_name'] . " ON " . $key['table_name'] . ".entity_id = activity.id";
}
$sql .= 'ORDER BY contact_a.sort_name, activity.activity_date_time DESC, activity.activity_type_id, activity.status_id, activity.subject';
}
}
+ else {
+ $sql .= ' ORDER BY contact_a.sort_name';
+ }
if ($rowcount > 0 && $offset >= 0) {
$offset = CRM_Utils_Type::escape($offset, 'Int');
$from = $this->from();
if ($justIDs) {
- $select = 'contact_a.id as contact_id';
+ $select = $this->select();
+ $select .= ', contact.id as contact_id, sort_name';
}
else {
$select = $this->select();
ORDER BY donation_amount desc
";
- // CRM_Core_Error::debug('sql',$sql); exit();
+
+ if ($justIDs) {
+ CRM_Core_DAO::executeQuery("DROP TEMPORARY TABLE IF EXISTS CustomSearch_SYBNT_temp");
+ $query = "CREATE TEMPORARY TABLE CustomSearch_SYBNT_temp AS ({$sql})";
+ $dao = CRM_Core_DAO::executeQuery($query);
+ $sql = "SELECT contact_id FROM CustomSearch_SYBNT_temp";
+ }
+
return $sql;
}
* @return string
*/
function select() {
- if ($this->start_date_2 || $this->end_date_2) {
+ if (!empty($this->start_date_2) || !empty($this->end_date_2)) {
return "
sum(contrib_1.total_amount) + sum(contrib_2.total_amount) AS donation_amount,
count(contrib_1.id) + count(contrib_1.id) AS donation_count
*/
function from() {
$from = NULL;
- if ($this->start_date_2 || $this->end_date_2) {
+ if (!empty($this->start_date_2) || !empty($this->end_date_2)) {
$from .= " LEFT JOIN civicrm_contribution contrib_2 ON contrib_2.contact_id = contact.id ";
}
- if ($this->exclude_start_date ||
- $this->exclude_end_date ||
- $this->is_first_amount
+ if (!empty($this->exclude_start_date) ||
+ !empty($this->exclude_end_date) ||
+ !empty($this->is_first_amount)
) {
$from .= " LEFT JOIN XG_CustomSearch_SYBNT xg ON xg.contact_id = contact.id ";
}
function where($includeContactIDs = FALSE) {
$clauses = array();
- if ($this->start_date_1) {
+ if (!empty($this->start_date_1)) {
$clauses[] = "contrib_1.receive_date >= {$this->start_date_1}";
}
- if ($this->end_date_1) {
+ if (!empty($this->end_date_1)) {
$clauses[] = "contrib_1.receive_date <= {$this->end_date_1}";
}
- if ($this->start_date_2 ||
- $this->end_date_2
- ) {
+ if (!empty($this->start_date_2) || !empty($this->end_date_2)) {
$clauses[] = "contrib_2.is_test = 0";
- if ($this->start_date_2) {
+ if (!empty($this->start_date_2)) {
$clauses[] = "contrib_2.receive_date >= {$this->start_date_2}";
}
- if ($this->end_date_2) {
+ if (!empty($this->end_date_2)) {
$clauses[] = "contrib_2.receive_date <= {$this->end_date_2}";
}
}
- if ($this->exclude_start_date ||
- $this->exclude_end_date ||
- $this->is_first_amount
+ if (!empty($this->exclude_start_date) ||
+ !empty($this->exclude_end_date) ||
+ !empty($this->is_first_amount)
) {
// first create temp table to store contact ids
$sql .= " ORDER BY contact_id ASC";
}
}
+ else {
+ $sql .= " ORDER BY contact_a.id ASC";
+ }
if ($offset >= 0 && $rowcount > 0) {
$sql .= " LIMIT $offset, $rowcount ";
$form->assign('elements', array('group_id'));
}
+ function contactIDs($offset = 0, $rowcount = 0, $sort = NULL, $returnSQL = FALSE) {
+ return $this->all($offset, $rowcount, $sort, FALSE, TRUE);
+ }
+
/**
* @param int $offset
* @param int $rowcount
) {
if ($justIDs) {
$selectClause = "contact_a.id as contact_id";
+ $sort = 'contact_a.id';
}
else {
$selectClause = "
return $summary;
}
+ function contactIDs($offset = 0, $rowcount = 0, $sort = NULL, $returnSQL = FALSE) {
+ return $this->all($offset, $rowcount, $sort, FALSE, TRUE);
+ }
+
/**
* @param int $offset
* @param int $rowcount
) {
if ($justIDs) {
$selectClause = "contact_a.id as contact_id";
+ $sort = 'contact_a.id';
}
else {
$selectClause = "
FROM $from
WHERE $where
";
- //for only contact ids ignore order and group by.
- if (!$onlyIDs) {
- $sql .= " GROUP BY contact_a.id";
- // Define ORDER BY for query in $sort, with default value
- if (!empty($sort)) {
- if (is_string($sort)) {
- $sort = CRM_Utils_Type::escape($sort, 'String');
- $sql .= " ORDER BY $sort ";
- }
- else {
- $sql .= " ORDER BY " . trim($sort->orderBy());
- }
+
+ $sql .= " GROUP BY contact_a.id";
+ // Define ORDER BY for query in $sort, with default value
+ if (!empty($sort)) {
+ if (is_string($sort)) {
+ $sort = CRM_Utils_Type::escape($sort, 'String');
+ $sql .= " ORDER BY $sort ";
}
else {
- $sql .= "";
+ $sql .= " ORDER BY " . trim($sort->orderBy());
}
}
+ else {
+ $sql .= "";
+ }
return $sql;
}
return $summary;
}
+ function contactIDs($offset = 0, $rowcount = 0, $sort = NULL, $returnSQL = FALSE) {
+ return $this->all($offset, $rowcount, $sort, FALSE, TRUE);
+ }
+
/**
* @param int $offset
* @param int $rowcount
) {
if ($justIDs) {
$selectClause = "contact_a.id as contact_id";
+ $sort = "contact_a.id";
}
else {
$selectClause = "
if (is_a($this, 'CRM_Contact_Selector_Custom')) {
$sql = $this->_search->contactIDs($start, $end, $sort, TRUE);
$replaceSQL = "SELECT contact_a.id as contact_id";
+
+ if (is_a($this->_search, 'CRM_Contact_Form_Search_Custom_FullText') ||
+ is_a($this->_search, 'CRM_Contact_Form_Search_Custom_ContribSYBNT')
+ ) {
+ $replaceSQL = "SELECT contact_id";
+ }
+
$coreSearch = FALSE;
}
// For core searches use the searchQuery method
// the prev next cache in this situation
// the other alternative of running the FULL query will just be incredibly inefficient
// and slow things down way too much on large data sets / complex queries
-
$insertSQL = "
INSERT INTO civicrm_prevnext_cache ( entity_table, entity_id1, entity_id2, cacheKey, data )
SELECT 'civicrm_contact', contact_a.id, contact_a.id, '$cacheKey', contact_a.display_name
";
+ if (property_exists($this, '_search') &&
+ (is_a($this->_search, 'CRM_Contact_Form_Search_Custom_FullText') ||
+ is_a($this->_search, 'CRM_Contact_Form_Search_Custom_ContribSYBNT'))
+ ) {
+ $insertSQL = "
+INSERT INTO civicrm_prevnext_cache ( entity_table, entity_id1, entity_id2, cacheKey, data )
+SELECT 'civicrm_contact', contact_id, contact_id, '$cacheKey', sort_name
+";
+ }
+
$sql = str_replace($replaceSQL, $insertSQL, $sql);
$errorScope = CRM_Core_TemporaryErrorScope::ignoreException();
*
*/
static function &links() {
+ list($key) = func_get_args();
+ $extraParams = ($key) ? "&key={$key}" : NULL;
+
if (!(self::$_links)) {
self::$_links = array(
CRM_Core_Action::VIEW => array(
'name' => ts('View'),
'url' => 'civicrm/contact/view',
- 'qs' => 'reset=1&cid=%%id%%',
+ 'qs' => "reset=1&cid=%%id%%{$extraParams}",
'title' => ts('View Contact Details'),
),
CRM_Core_Action::UPDATE => array(
$columns = $this->_search->columns();
$columnNames = array_values($columns);
- $links = self::links();
+ $links = self::links($this->_key);
$permissions = array(CRM_Core_Permission::getPermission());
if (CRM_Core_Permission::check('delete contacts')) {
* @param $rows
*/
function addActions(&$rows) {
- $links = self::links();
+ $links = self::links($this->_key);
$permissions = array(CRM_Core_Permission::getPermission());
if (CRM_Core_Permission::check('delete contacts')) {