Skip to content

Commit

Permalink
Merge pull request #13732 from mattwire/refactor_smartgroupquery_upper1
Browse files Browse the repository at this point in the history
dev/core#748 Move UPPER() from sql to php domain
  • Loading branch information
seamuslee001 authored Feb 28, 2019
2 parents b7fe18b + 52cda5d commit f680a12
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 18 deletions.
2 changes: 1 addition & 1 deletion CRM/Activity/Selector/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ public function &getColumnHeaders($action = NULL, $output = NULL) {
* @return mixed
*/
public function alphabetQuery() {
return $this->_query->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE);
return $this->_query->alphabetQuery();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion CRM/Case/Selector/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ public function &getColumnHeaders($action = NULL, $output = NULL) {
* @return mixed
*/
public function alphabetQuery() {
return $this->_query->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE);
return $this->_query->alphabetQuery();
}

/**
Expand Down
30 changes: 20 additions & 10 deletions CRM/Contact/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,7 @@ public function query($count = FALSE, $sortByChar = FALSE, $groupContacts = FALS
}
}
elseif ($sortByChar) {
$select = 'SELECT DISTINCT UPPER(LEFT(contact_a.sort_name, 1)) as sort_name';
$select = 'SELECT DISTINCT LEFT(contact_a.sort_name, 1) as sort_name';
$from = $this->_simpleFromClause;
}
elseif ($groupContacts) {
Expand Down Expand Up @@ -4896,6 +4896,22 @@ public function searchQuery(
return $dao;
}

/**
* Create and query the db for a contact search.
*
* @return CRM_Core_DAO
*/
public function alphabetQuery() {
$query = $this->getSearchSQL(NULL, NULL, NULL, FALSE, FALSE, TRUE);

$dao = CRM_Core_DAO::executeQuery($query);

// We can always call this - it will only re-enable if it was originally enabled.
CRM_Core_DAO::reenableFullGroupByMode();

return $dao;
}

/**
* Fetch a list of contacts for displaying a search results page
*
Expand Down Expand Up @@ -6249,25 +6265,19 @@ protected function prepareOrderBy($sort, $sortByChar, $sortOrder, $additionalFro
}
}
elseif ($sortByChar) {
$orderByArray = array("UPPER(LEFT(contact_a.sort_name, 1)) asc");
$orderBy = " sort_name asc";
}
else {
$orderBy = " contact_a.sort_name ASC, contact_a.id";
}
}
if (!$orderBy && empty($orderByArray)) {
if (!$orderBy) {
return [NULL, $additionalFromClause];
}
// Remove this here & add it at the end for simplicity.
$order = trim($orderBy);
$orderByArray = explode(',', $order);

// hack for order clause
if (!empty($orderByArray)) {
$order = implode(', ', $orderByArray);
}
else {
$orderByArray = explode(',', $order);
}
foreach ($orderByArray as $orderByClause) {
$orderByClauseParts = explode(' ', trim($orderByClause));
$field = $orderByClauseParts[0];
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contact/Selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ public function getQuery() {
* @return CRM_Contact_DAO_Contact
*/
public function alphabetQuery() {
return $this->_query->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE);
return $this->_query->alphabetQuery();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/Selector/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ public function &getColumnHeaders($action = NULL, $output = NULL) {
* @return mixed
*/
public function alphabetQuery() {
return $this->_query->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE);
return $this->_query->alphabetQuery();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion CRM/Event/Selector/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ public function &getColumnHeaders($action = NULL, $output = NULL) {
* @return mixed
*/
public function alphabetQuery() {
return $this->_query->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE);
return $this->_query->alphabetQuery();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion CRM/Mailing/Selector/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ public function &getColumnHeaders($action = NULL, $output = NULL) {
* @return mixed
*/
public function alphabetQuery() {
return $this->_query->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE);
return $this->_query->alphabetQuery();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion CRM/Member/Selector/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ public function &getColumnHeaders($action = NULL, $output = NULL) {
* @return mixed
*/
public function alphabetQuery() {
return $this->_query->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE);
return $this->_query->alphabetQuery();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion CRM/Utils/PagerAToZ.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public static function getDynamicCharacters(&$query, $isDAO) {

$dynamicAlphabets = array();
while ($result->fetch()) {
$dynamicAlphabets[] = $result->sort_name;
$dynamicAlphabets[] = strtoupper($result->sort_name);
}
return $dynamicAlphabets;
}
Expand Down

0 comments on commit f680a12

Please sign in to comment.