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
56 public static function getAToZBar(&$query, $sortByCharacter, $isDAO = FALSE) {
57 $AToZBar = self
::createLinks($query, $sortByCharacter, $isDAO);
62 * Return the all the static characters
65 * is a array of static characters
68 public static function getStaticCharacters() {
69 $staticAlphabets = array(
97 return $staticAlphabets;
101 * Return the all the dynamic characters
107 * is a array of dynamic characters
110 public static function getDynamicCharacters(&$query, $isDAO) {
115 $result = $query->alphabetQuery();
121 $dynamicAlphabets = array();
122 while ($result->fetch()) {
123 $dynamicAlphabets[] = $result->sort_name
;
125 return $dynamicAlphabets;
131 * @param array $query
132 * The form values for search.
133 * @param string $sortByCharacter
134 * The character that we are potentially sorting on.
142 public static function createLinks(&$query, $sortByCharacter, $isDAO) {
143 $AToZBar = self
::getStaticCharacters();
144 $dynamicAlphabets = self
::getDynamicCharacters($query, $isDAO);
146 if (!$dynamicAlphabets) {
150 $AToZBar = array_merge($AToZBar, $dynamicAlphabets);
151 sort($AToZBar, SORT_STRING
);
152 $AToZBar = array_unique($AToZBar);
154 //get the current path
155 $path = CRM_Utils_System
::currentPath();
158 if (isset($query->_formValues
)) {
159 $qfKey = CRM_Utils_Array
::value('qfKey', $query->_formValues
);
162 $qfKey = CRM_Utils_Request
::retrieve('qfKey', 'String', $this, FALSE, NULL, $_REQUEST);
166 foreach ($AToZBar as $key => $link) {
167 if ($link === NULL) {
172 if (in_array($link, $dynamicAlphabets)) {
174 if ($link == $sortByCharacter) {
175 $element['class'] = "active";
176 $klass = 'class="active"';
178 $url = CRM_Utils_System
::url($path, "force=1&qfKey=$qfKey&sortByCharacter=");
179 // we do it this way since we want the url to be encoded but not the link character
180 // since that seems to mess up drupal utf-8 encoding etc
181 $url .= urlencode($link);
182 $element['item'] = sprintf('<a href="%s" %s>%s</a>',
189 $element['item'] = $link;
191 $aToZBar[] = $element;
195 '<a href="%s">%s</a>',
196 CRM_Utils_System
::url(
198 "force=1&qfKey=$qfKey&sortByCharacter=all"
202 $aToZBar[] = array('item' => $url);