3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
30 * @copyright CiviCRM LLC (c) 2004-2019
34 * This class is for displaying alphabetical bar
36 class CRM_Utils_PagerAToZ
{
39 * Returns the alphabetic array for sorting by character.
43 * @param string $sortByCharacter
44 * The character that we are potentially sorting on.
49 * The html formatted string
51 public static function getAToZBar(&$query, $sortByCharacter, $isDAO = FALSE) {
52 $AToZBar = self
::createLinks($query, $sortByCharacter, $isDAO);
57 * Return the all the static characters.
60 * is an array of static characters
62 public static function getStaticCharacters() {
91 return $staticAlphabets;
95 * Return the all the dynamic characters.
101 * is an array of dynamic characters
103 public static function getDynamicCharacters(&$query, $isDAO) {
108 $result = $query->alphabetQuery();
114 $dynamicAlphabets = [];
115 while ($result->fetch()) {
116 $dynamicAlphabets[] = strtoupper($result->sort_name
);
118 return $dynamicAlphabets;
124 * @param array $query
125 * The form values for search.
126 * @param string $sortByCharacter
127 * The character that we are potentially sorting on.
134 public static function createLinks(&$query, $sortByCharacter, $isDAO) {
135 $AToZBar = self
::getStaticCharacters();
136 $dynamicAlphabets = self
::getDynamicCharacters($query, $isDAO);
138 if (!$dynamicAlphabets) {
142 $AToZBar = array_merge($AToZBar, $dynamicAlphabets);
143 sort($AToZBar, SORT_STRING
);
144 $AToZBar = array_unique($AToZBar);
146 // get the current path
147 $path = CRM_Utils_System
::currentPath();
150 if (isset($query->_formValues
)) {
151 $qfKey = CRM_Utils_Array
::value('qfKey', $query->_formValues
);
154 // CRM-20943 Can only pass variables by reference and also cannot use $this so using $empty setting to NULL which is default.
155 $emptyVariable = NULL;
156 $qfKey = CRM_Utils_Request
::retrieve('qfKey', 'String', $emptyVariable, FALSE, NULL, $_REQUEST);
160 foreach ($AToZBar as $key => $link) {
161 if ($link === NULL) {
166 if (in_array($link, $dynamicAlphabets)) {
168 if ($link == $sortByCharacter) {
169 $element['class'] = "active";
170 $klass = 'class="active"';
172 $url = CRM_Utils_System
::url($path, "force=1&qfKey=$qfKey&sortByCharacter=");
173 // we do it this way since we want the url to be encoded but not the link character
174 // since that seems to mess up drupal utf-8 encoding etc
175 $url .= urlencode($link);
176 $element['item'] = sprintf('<a href="%s" %s>%s</a>',
183 $element['item'] = $link;
185 $aToZBar[] = $element;
189 '<a href="%s">%s</a>',
190 CRM_Utils_System
::url(
192 "force=1&qfKey=$qfKey&sortByCharacter=all"
196 $aToZBar[] = ['item' => $url];