3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
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
45 * @param array $query The query object
46 * @param string $sortByCharacter The character that we are potentially sorting on
50 * @return string The html formatted string
54 static function getAToZBar(&$query, $sortByCharacter, $isDAO = FALSE) {
55 $AToZBar = self
::createLinks($query, $sortByCharacter, $isDAO);
60 * Function to return the all the static characters
62 * @return array $staticAlphabets is a array of static characters
66 static function getStaticCharacters() {
67 $staticAlphabets = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
68 return $staticAlphabets;
72 * Function to return the all the dynamic characters
77 * @return array $dynamicAlphabets is a array of dynamic characters
81 static function getDynamicCharacters(&$query, $isDAO) {
86 $result = $query->alphabetQuery();
92 $dynamicAlphabets = array();
93 while ($result->fetch()) {
94 $dynamicAlphabets[] = $result->sort_name
;
96 return $dynamicAlphabets;
102 * @param array $query The form values for search
103 * @param string $sortByCharacter The character that we are potentially sorting on
107 * @return array with links
111 static function createLinks(&$query, $sortByCharacter, $isDAO) {
112 $AToZBar = self
::getStaticCharacters();
113 $dynamicAlphabets = self
::getDynamicCharacters($query, $isDAO);
115 if (!$dynamicAlphabets) {
119 $AToZBar = array_merge($AToZBar, $dynamicAlphabets);
120 sort($AToZBar, SORT_STRING
);
121 $AToZBar = array_unique($AToZBar);
123 //get the current path
124 $path = CRM_Utils_System
::currentPath();
127 if (isset($query->_formValues
)) {
128 $qfKey = CRM_Utils_Array
::value('qfKey', $query->_formValues
);
131 $qfKey = CRM_Utils_Request
::retrieve('qfKey', 'String', $this, FALSE, NULL, $_REQUEST);
135 foreach ($AToZBar as $key => $link) {
136 if ($link === NULL) {
141 if (in_array($link, $dynamicAlphabets)) {
143 if ($link == $sortByCharacter) {
144 $element['class'] = "active";
145 $klass = 'class="active"';
147 $url = CRM_Utils_System
::url($path, "force=1&qfKey=$qfKey&sortByCharacter=");
148 // we do it this way since we want the url to be encoded but not the link character
149 // since that seems to mess up drupal utf-8 encoding etc
150 $url .= urlencode($link);
151 $element['item'] = sprintf('<a href="%s" %s>%s</a>',
158 $element['item'] = $link;
160 $aToZBar[] = $element;
164 '<a href="%s">%s</a>',
165 CRM_Utils_System
::url(
167 "force=1&qfKey=$qfKey&sortByCharacter=all"
171 $aToZBar[] = array('item' => $url);