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.
117 * @throws \CRM_Core_Exception
119 public static function createLinks(&$query, $sortByCharacter, $isDAO) {
120 $AToZBar = self
::getStaticCharacters();
121 $dynamicAlphabets = self
::getDynamicCharacters($query, $isDAO);
123 if (!$dynamicAlphabets) {
127 $AToZBar = array_merge($AToZBar, $dynamicAlphabets);
128 sort($AToZBar, SORT_STRING
);
129 $AToZBar = array_unique($AToZBar);
131 // get the current path
132 $path = CRM_Utils_System
::currentPath();
135 if (isset($query->_formValues
)) {
136 $qfKey = $query->_formValues
['qfKey'] ??
NULL;
139 $qfKey = CRM_Utils_Request
::retrieve('qfKey', 'String');
143 foreach ($AToZBar as $key => $link) {
144 if ($link === NULL) {
148 $element = ['class' => ''];
149 if (in_array($link, $dynamicAlphabets)) {
151 if ($link == $sortByCharacter) {
152 $element['class'] = "active";
153 $klass = 'class="active"';
159 if (($query->_context ??
'') === 'amtg') {
160 // See https://lab.civicrm.org/dev/core/-/issues/2333
161 // Seems to be needed in add to group flow.
162 $urlParams['_qf_Basic_display'] = 1;
164 $urlParams['sortByCharacter'] = '';
165 $url = CRM_Utils_System
::url($path, $urlParams);
166 // we do it this way since we want the url to be encoded but not the link character
167 // since that seems to mess up drupal utf-8 encoding etc
168 $url .= urlencode($link);
169 $element['item'] = sprintf('<a href="%s" %s>%s</a>',
176 $element['item'] = $link;
178 $aToZBar[] = $element;
182 '<a href="%s">%s</a>',
183 CRM_Utils_System
::url(
185 "force=1&qfKey=$qfKey&sortByCharacter=all"
189 $aToZBar[] = ['item' => $url, 'class' => ''];