3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
14 * @copyright CiviCRM LLC https://civicrm.org/licensing
18 * This class is for displaying alphabetical bar
20 class CRM_Utils_PagerAToZ
{
23 * Returns the alphabetic array for sorting by character.
27 * @param string $sortByCharacter
28 * The character that we are potentially sorting on.
33 * The html formatted string
35 public static function getAToZBar(&$query, $sortByCharacter, $isDAO = FALSE) {
36 $AToZBar = self
::createLinks($query, $sortByCharacter, $isDAO);
41 * Return the all the static characters.
44 * is an array of static characters
46 public static function getStaticCharacters() {
75 return $staticAlphabets;
79 * Return the all the dynamic characters.
85 * is an array of dynamic characters
87 public static function getDynamicCharacters(&$query, $isDAO) {
92 $result = $query->alphabetQuery();
98 $dynamicAlphabets = [];
99 while ($result->fetch()) {
100 $dynamicAlphabets[] = strtoupper($result->sort_name
);
102 return $dynamicAlphabets;
108 * @param array $query
109 * The form values for search.
110 * @param string $sortByCharacter
111 * The character that we are potentially sorting on.
118 public static function createLinks(&$query, $sortByCharacter, $isDAO) {
119 $AToZBar = self
::getStaticCharacters();
120 $dynamicAlphabets = self
::getDynamicCharacters($query, $isDAO);
122 if (!$dynamicAlphabets) {
126 $AToZBar = array_merge($AToZBar, $dynamicAlphabets);
127 sort($AToZBar, SORT_STRING
);
128 $AToZBar = array_unique($AToZBar);
130 // get the current path
131 $path = CRM_Utils_System
::currentPath();
134 if (isset($query->_formValues
)) {
135 $qfKey = CRM_Utils_Array
::value('qfKey', $query->_formValues
);
138 // CRM-20943 Can only pass variables by reference and also cannot use $this so using $empty setting to NULL which is default.
139 $emptyVariable = NULL;
140 $qfKey = CRM_Utils_Request
::retrieve('qfKey', 'String', $emptyVariable, FALSE, NULL, $_REQUEST);
144 foreach ($AToZBar as $key => $link) {
145 if ($link === NULL) {
150 if (in_array($link, $dynamicAlphabets)) {
152 if ($link == $sortByCharacter) {
153 $element['class'] = "active";
154 $klass = 'class="active"';
156 $url = CRM_Utils_System
::url($path, "force=1&qfKey=$qfKey&sortByCharacter=");
157 // we do it this way since we want the url to be encoded but not the link character
158 // since that seems to mess up drupal utf-8 encoding etc
159 $url .= urlencode($link);
160 $element['item'] = sprintf('<a href="%s" %s>%s</a>',
167 $element['item'] = $link;
169 $aToZBar[] = $element;
173 '<a href="%s">%s</a>',
174 CRM_Utils_System
::url(
176 "force=1&qfKey=$qfKey&sortByCharacter=all"
180 $aToZBar[] = ['item' => $url];