3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
21 * This class is used to retrieve and display a range of
22 * contacts that match the given criteria (specifically for
23 * results of advanced search options.
26 class CRM_Grant_Selector_Search
extends CRM_Core_Selector_Base
implements CRM_Core_Selector_API
{
29 * This defines two actions- View and Edit.
33 public static $_links = NULL;
36 * We use desc to remind us what that column is, name is used in the tpl
40 public static $_columnHeaders;
43 * Properties of contact we're interested in displaying
46 public static $_properties = [
56 'grant_amount_requested',
57 'grant_amount_granted',
58 'grant_application_received_date',
59 'grant_report_received',
60 'grant_money_transfer_date',
64 * Are we restricting ourselves to a single contact.
68 protected $_single = FALSE;
71 * Are we restricting ourselves to a single contact.
75 protected $_limit = NULL;
78 * What context are we being invoked from.
82 protected $_context = NULL;
85 * QueryParams is the array returned by exportValues called on.
86 * the HTML_QuickForm_Controller for that page.
93 * Represent the type of selector.
100 * The additional clause that we restrict the search with.
104 protected $_grantClause = NULL;
116 * @param array $queryParams
117 * Array of parameters for query.
118 * @param \const|int $action - action of search basic or advanced.
119 * @param string $grantClause
120 * If the caller wants to further restrict the search.
121 * @param bool $single
122 * Are we dealing only with one contact?.
124 * How many participations do we want returned.
126 * @param string $context
128 * @return \CRM_Grant_Selector_Search
130 public function __construct(
132 $action = CRM_Core_Action
::NONE
,
138 // submitted form values
139 $this->_queryParams
= &$queryParams;
141 $this->_single
= $single;
142 $this->_limit
= $limit;
143 $this->_context
= $context;
145 $this->_grantClause
= $grantClause;
148 $this->_action
= $action;
150 $this->_query
= new CRM_Contact_BAO_Query($this->_queryParams
, NULL, NULL, FALSE, FALSE,
151 CRM_Contact_BAO_Query
::MODE_GRANT
153 $this->_query
->_distinctComponentClause
= " civicrm_grant.id";
154 $this->_query
->_groupByComponentClause
= " GROUP BY civicrm_grant.id ";
158 * This method returns the links that are given for each search row.
159 * currently the links added for each row are
164 * @param string|null $key
168 public static function &links($key = NULL) {
169 $cid = CRM_Utils_Request
::retrieve('cid', 'Integer');
170 $extraParams = ($key) ?
"&key={$key}" : NULL;
172 if (!(self
::$_links)) {
174 CRM_Core_Action
::VIEW
=> [
175 'name' => ts('View'),
176 'url' => 'civicrm/contact/view/grant',
177 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=view&context=%%cxt%%&selectedChild=grant' . $extraParams,
178 'title' => ts('View Grant'),
180 CRM_Core_Action
::UPDATE
=> [
181 'name' => ts('Edit'),
182 'url' => 'civicrm/contact/view/grant',
183 'qs' => 'reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
184 'title' => ts('Edit Grant'),
190 CRM_Core_Action
::DELETE
=> [
191 'name' => ts('Delete'),
192 'url' => 'civicrm/contact/view/grant',
193 'qs' => 'action=delete&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=grant' . $extraParams,
194 'title' => ts('Delete Grant'),
197 self
::$_links = self
::$_links +
$delLink;
200 return self
::$_links;
204 * Getter for array of the parameters required for creating pager.
207 * @param array $params
209 public function getPagerParams($action, &$params) {
210 $params['status'] = ts('Grant') . ' %%StatusMessage%%';
211 $params['csvString'] = NULL;
213 $params['rowCount'] = $this->_limit
;
216 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
219 $params['buttonTop'] = 'PagerTopButton';
220 $params['buttonBottom'] = 'PagerBottomButton';
224 * Returns total number of rows for the query.
229 * Total number of rows
231 public function getTotalCount($action) {
232 return $this->_query
->searchQuery(0, 0, NULL,
241 * Returns all the rows in the given offset and rowCount *
243 * @param string $action
244 * The action being performed.
246 * The row number to start from.
247 * @param int $rowCount
248 * The number of rows to return.
249 * @param string $sort
250 * The sql string that describes the sort order.
251 * @param string $output
252 * What should the result set include (web/email/csv).
255 * the total number of rows for this action
257 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
258 $result = $this->_query
->searchQuery($offset, $rowCount, $sort,
265 // process the result of the query
268 //CRM-4418 check for view, edit, delete
269 $permissions = [CRM_Core_Permission
::VIEW
];
270 if (CRM_Core_Permission
::check('edit grants')) {
271 $permissions[] = CRM_Core_Permission
::EDIT
;
273 if (CRM_Core_Permission
::check('delete in CiviGrant')) {
274 $permissions[] = CRM_Core_Permission
::DELETE
;
276 $mask = CRM_Core_Action
::mask($permissions);
278 while ($result->fetch()) {
280 // the columns we are interested in
281 foreach (self
::$_properties as $property) {
282 if (isset($result->$property)) {
283 $row[$property] = $result->$property;
287 if ($this->_context
== 'search') {
288 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->grant_id
;
291 $row['action'] = CRM_Core_Action
::formLink(self
::links($this->_key
),
294 'id' => $result->grant_id
,
295 'cid' => $result->contact_id
,
296 'cxt' => $this->_context
,
300 'grant.selector.row',
305 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
$result->contact_sub_type
: $result->contact_type
, FALSE, $result->contact_id
317 public function getQILL() {
318 return $this->_query
->qill();
322 * Returns the column headers as an array of tuples:
323 * (name, sortName (key to the sort array))
325 * @param string $action
326 * The action being performed.
327 * @param string $output
328 * What should the result set include (web/email/csv).
331 * the column headers that need to be displayed
333 public function &getColumnHeaders($action = NULL, $output = NULL) {
334 if (!isset(self
::$_columnHeaders)) {
335 self
::$_columnHeaders = [
337 'name' => ts('Status'),
338 'sort' => 'grant_status',
339 'direction' => CRM_Utils_Sort
::DONTCARE
,
342 'name' => ts('Type'),
343 'sort' => 'grant_type_id',
344 'direction' => CRM_Utils_Sort
::DONTCARE
,
347 'name' => ts('Requested'),
348 'sort' => 'grant_amount_total',
349 'direction' => CRM_Utils_Sort
::DONTCARE
,
352 'name' => ts('Granted'),
353 'sort' => 'grant_amount_granted',
354 'direction' => CRM_Utils_Sort
::DONTCARE
,
357 'name' => ts('Application Received'),
358 'sort' => 'grant_application_received_date',
359 'direction' => CRM_Utils_Sort
::DONTCARE
,
362 'name' => ts('Report Received'),
363 'sort' => 'grant_report_received',
364 'direction' => CRM_Utils_Sort
::DONTCARE
,
367 'name' => ts('Money Transferred'),
368 'sort' => 'money_transfer_date',
369 'direction' => CRM_Utils_Sort
::DONTCARE
,
371 ['desc' => ts('Actions')],
374 if (!$this->_single
) {
376 ['desc' => ts('Contact Type')],
378 'name' => ts('Name'),
379 'sort' => 'sort_name',
380 'direction' => CRM_Utils_Sort
::ASCENDING
,
383 self
::$_columnHeaders = array_merge($pre, self
::$_columnHeaders);
386 return self
::$_columnHeaders;
392 public function &getQuery() {
393 return $this->_query
;
397 * Name of export file.
399 * @param string $output
405 public function getExportFileName($output = 'csv') {
406 return ts('CiviCRM Grant Search');