3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
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
48 * @return string The html formatted string
52 static function getAToZBar(&$query, $sortByCharacter, $isDAO = FALSE) {
53 $AToZBar = self
::createLinks($query, $sortByCharacter, $isDAO);
58 * Function to return the all the static characters
60 * @return array $staticAlphabets is a array of static characters
64 static function getStaticCharacters() {
65 $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');
66 return $staticAlphabets;
70 * Function to return the all the dynamic characters
72 * @return array $dynamicAlphabets is a array of dynamic characters
76 static function getDynamicCharacters(&$query, $isDAO) {
81 $result = $query->alphabetQuery();
87 $dynamicAlphabets = array();
88 while ($result->fetch()) {
89 $dynamicAlphabets[] = $result->sort_name
;
91 return $dynamicAlphabets;
97 * @param array $query The form values for search
98 * @param string $sortByCharacter The character that we are potentially sorting on
100 * @return array with links
104 static function createLinks(&$query, $sortByCharacter, $isDAO) {
105 $AToZBar = self
::getStaticCharacters();
106 $dynamicAlphabets = self
::getDynamicCharacters($query, $isDAO);
108 if (!$dynamicAlphabets) {
112 $AToZBar = array_merge($AToZBar, $dynamicAlphabets);
113 sort($AToZBar, SORT_STRING
);
114 $AToZBar = array_unique($AToZBar);
116 //get the current path
117 $path = CRM_Utils_System
::currentPath();
120 if (isset($query->_formValues
)) {
121 $qfKey = CRM_Utils_Array
::value('qfKey', $query->_formValues
);
124 $qfKey = CRM_Utils_Request
::retrieve('qfKey', 'String', $this, FALSE, NULL, $_REQUEST);
128 foreach ($AToZBar as $key => $link) {
129 if ($link === NULL) {
134 if (in_array($link, $dynamicAlphabets)) {
136 if ($link == $sortByCharacter) {
137 $element['class'] = "active";
138 $klass = 'class="active"';
140 $url = CRM_Utils_System
::url($path, "force=1&qfKey=$qfKey&sortByCharacter=");
141 // we do it this way since we want the url to be encoded but not the link character
142 // since that seems to mess up drupal utf-8 encoding etc
143 $url .= urlencode($link);
144 $element['item'] = sprintf('<a href="%s" %s>%s</a>',
151 $element['item'] = $link;
153 $aToZBar[] = $element;
157 '<a href="%s">%s</a>',
158 CRM_Utils_System
::url(
160 "force=1&qfKey=$qfKey&sortByCharacter=all"
164 $aToZBar[] = array('item' => $url);