08ce2cf4f5a474614bc56a8164ad7da9c5eda648
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
37 * This class is for displaying alphabetical bar
40 class CRM_Utils_PagerAToZ
{
43 * Returns the alphabetic array for sorting by character
47 * @param string $sortByCharacter
48 * The character that we are potentially sorting on.
53 * The html formatted string
55 public static function getAToZBar(&$query, $sortByCharacter, $isDAO = FALSE) {
56 $AToZBar = self
::createLinks($query, $sortByCharacter, $isDAO);
61 * Return the all the static characters
64 * is a array of static characters
66 public static function getStaticCharacters() {
67 $staticAlphabets = array(
95 return $staticAlphabets;
99 * Return the all the dynamic characters
105 * is a array of dynamic characters
107 public static function getDynamicCharacters(&$query, $isDAO) {
112 $result = $query->alphabetQuery();
118 $dynamicAlphabets = array();
119 while ($result->fetch()) {
120 $dynamicAlphabets[] = $result->sort_name
;
122 return $dynamicAlphabets;
128 * @param array $query
129 * The form values for search.
130 * @param string $sortByCharacter
131 * The character that we are potentially sorting on.
138 public static function createLinks(&$query, $sortByCharacter, $isDAO) {
139 $AToZBar = self
::getStaticCharacters();
140 $dynamicAlphabets = self
::getDynamicCharacters($query, $isDAO);
142 if (!$dynamicAlphabets) {
146 $AToZBar = array_merge($AToZBar, $dynamicAlphabets);
147 sort($AToZBar, SORT_STRING
);
148 $AToZBar = array_unique($AToZBar);
150 //get the current path
151 $path = CRM_Utils_System
::currentPath();
154 if (isset($query->_formValues
)) {
155 $qfKey = CRM_Utils_Array
::value('qfKey', $query->_formValues
);
158 $qfKey = CRM_Utils_Request
::retrieve('qfKey', 'String', $this, FALSE, NULL, $_REQUEST);
162 foreach ($AToZBar as $key => $link) {
163 if ($link === NULL) {
168 if (in_array($link, $dynamicAlphabets)) {
170 if ($link == $sortByCharacter) {
171 $element['class'] = "active";
172 $klass = 'class="active"';
174 $url = CRM_Utils_System
::url($path, "force=1&qfKey=$qfKey&sortByCharacter=");
175 // we do it this way since we want the url to be encoded but not the link character
176 // since that seems to mess up drupal utf-8 encoding etc
177 $url .= urlencode($link);
178 $element['item'] = sprintf('<a href="%s" %s>%s</a>',
185 $element['item'] = $link;
187 $aToZBar[] = $element;
191 '<a href="%s">%s</a>',
192 CRM_Utils_System
::url(
194 "force=1&qfKey=$qfKey&sortByCharacter=all"
198 $aToZBar[] = array('item' => $url);