Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * A simple base class for objects that need to implement the selector api | |
31 | * interface. This class provides common functionality with regard to actions | |
32 | * and display names | |
33 | * | |
34 | * @package CRM | |
06b69b18 | 35 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
36 | * $Id$ |
37 | * | |
38 | */ | |
39 | class CRM_Core_Selector_Base { | |
40 | ||
41 | /** | |
100fef9d | 42 | * The sort order which is computed from the columnHeaders |
6a488035 TO |
43 | * |
44 | * @var array | |
45 | */ | |
46 | protected $_order; | |
47 | ||
48 | /** | |
49 | * The permission mask for this selector | |
50 | * | |
51 | * @var string | |
52 | */ | |
53 | protected $_permission = NULL; | |
54 | ||
55 | /** | |
56 | * The qfKey of the underlying search | |
57 | * | |
58 | * @var string | |
59 | */ | |
60 | protected $_key; | |
61 | ||
62 | /** | |
fe482240 | 63 | * This function gets the attribute for the action that. |
6a488035 TO |
64 | * it matches. |
65 | * | |
317fceb4 | 66 | * @param string $match the action to match against |
67 | * @param string $attribute the attribute to return ( name, link, title ) | |
6a488035 | 68 | * |
a6c01b45 CW |
69 | * @return string |
70 | * the attribute that matches the action if any | |
6a488035 | 71 | */ |
00be9182 | 72 | public function getActionAttribute($match, $attribute = 'name') { |
6a488035 TO |
73 | $links = &$this->links(); |
74 | ||
75 | foreach ($link as $action => $item) { | |
76 | if ($match & $action) { | |
77 | return $item[$attribute]; | |
78 | } | |
79 | } | |
80 | return NULL; | |
81 | } | |
82 | ||
83 | /** | |
84 | * This is a static virtual function returning reference on links array. Each | |
85 | * inherited class must redefine this function | |
86 | * | |
87 | * links is an array of associative arrays. Each element of the array | |
88 | * has at least 3 fields | |
89 | * | |
90 | * name : the name of the link | |
91 | * url : the URI to be used for this link | |
92 | * qs : the parameters to the above url along with any dynamic substitutions | |
93 | * title : A more descriptive name, typically used in breadcrumbs / navigation | |
94 | */ | |
00be9182 | 95 | public static function &links() { |
6a488035 TO |
96 | return NULL; |
97 | } | |
98 | ||
99 | /** | |
fe482240 | 100 | * Compose the template file name from the class name. |
6a488035 | 101 | * |
6a0b768e TO |
102 | * @param string $action |
103 | * The action being performed. | |
6a488035 | 104 | * |
a6c01b45 CW |
105 | * @return string |
106 | * template file name | |
6a488035 | 107 | */ |
00be9182 | 108 | public function getTemplateFileName($action = NULL) { |
6a488035 TO |
109 | return (str_replace('_', DIRECTORY_SEPARATOR, CRM_Utils_System::getClassName($this)) . ".tpl"); |
110 | } | |
111 | ||
112 | /** | |
100fef9d | 113 | * Getter for the sorting direction for the fields which will be displayed on the form. |
6a488035 | 114 | * |
317fceb4 | 115 | * @param string $action the action being performed |
6a488035 | 116 | * |
a6c01b45 CW |
117 | * @return array |
118 | * the elements that can be sorted along with their properties | |
6a488035 | 119 | */ |
00be9182 | 120 | public function &getSortOrder($action) { |
6a488035 TO |
121 | $columnHeaders = &$this->getColumnHeaders(NULL); |
122 | ||
123 | if (!isset($this->_order)) { | |
124 | $this->_order = array(); | |
125 | $start = 2; | |
126 | $firstElementNotFound = TRUE; | |
127 | if (!empty($columnHeaders)) { | |
128 | foreach ($columnHeaders as $k => $header) { | |
129 | $header = &$columnHeaders[$k]; | |
130 | if (array_key_exists('sort', $header)) { | |
131 | if ($firstElementNotFound && $header['direction'] != CRM_Utils_Sort::DONTCARE) { | |
132 | $this->_order[1] = &$header; | |
133 | $firstElementNotFound = FALSE; | |
134 | } | |
135 | else { | |
136 | $this->_order[$start++] = &$header; | |
137 | } | |
138 | } | |
139 | unset($header); | |
140 | } | |
141 | } | |
142 | if ($firstElementNotFound) { | |
143 | // CRM_Core_Error::fatal( "Could not find a valid sort directional element" ); | |
144 | } | |
145 | } | |
146 | return $this->_order; | |
147 | } | |
148 | ||
149 | /** | |
fe482240 | 150 | * Setter for permission. |
6a488035 TO |
151 | * |
152 | * @var string | |
6a488035 TO |
153 | */ |
154 | public function setPermission($permission) { | |
155 | $this->_permission = $permission; | |
156 | } | |
157 | ||
158 | /** | |
100fef9d | 159 | * Get the display text in plain language for the search |
6a488035 TO |
160 | * to display on the results page |
161 | * | |
1054415f CW |
162 | * FIXME: the current internationalisation is bad, but should more or less work |
163 | * on most of "European" languages | |
164 | * | |
165 | * @return array | |
166 | * array of strings | |
6a488035 TO |
167 | */ |
168 | public function getQill() { | |
169 | return NULL; | |
170 | } | |
171 | ||
a0ee3941 EM |
172 | /** |
173 | * @return null | |
174 | */ | |
6a488035 TO |
175 | public function getSummary() { |
176 | return NULL; | |
177 | } | |
178 | ||
a0ee3941 EM |
179 | /** |
180 | * @param $key | |
181 | */ | |
6a488035 TO |
182 | public function setKey($key) { |
183 | $this->_key = $key; | |
184 | } | |
185 | ||
a0ee3941 EM |
186 | /** |
187 | * @return string | |
188 | */ | |
6a488035 TO |
189 | public function getKey() { |
190 | return $this->_key; | |
191 | } | |
96025800 | 192 | |
6a488035 | 193 | } |