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