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
19 * This class is used to retrieve and display a range of
20 * contacts that match the given criteria (specifically for
21 * results of advanced search options.
24 class CRM_Grant_Selector_Search
extends CRM_Core_Selector_Base
implements CRM_Core_Selector_API
{
27 * This defines two actions- View and Edit.
31 public static $_links = NULL;
34 * We use desc to remind us what that column is, name is used in the tpl
38 public static $_columnHeaders;
41 * Properties of contact we're interested in displaying
44 public static $_properties = [
54 'grant_amount_requested',
55 'grant_amount_granted',
56 'grant_application_received_date',
57 'grant_report_received',
58 'grant_money_transfer_date',
62 * Are we restricting ourselves to a single contact.
66 protected $_single = FALSE;
69 * Are we restricting ourselves to a single contact.
73 protected $_limit = NULL;
76 * What context are we being invoked from.
80 protected $_context = NULL;
83 * QueryParams is the array returned by exportValues called on.
84 * the HTML_QuickForm_Controller for that page.
91 * Represent the type of selector.
98 * The additional clause that we restrict the search with.
102 protected $_grantClause = NULL;
114 * @param array $queryParams
115 * Array of parameters for query.
116 * @param \const|int $action - action of search basic or advanced.
117 * @param string $grantClause
118 * If the caller wants to further restrict the search.
119 * @param bool $single
120 * Are we dealing only with one contact?.
122 * How many participations do we want returned.
124 * @param string $context
126 * @return \CRM_Grant_Selector_Search
128 public function __construct(
130 $action = CRM_Core_Action
::NONE
,
136 // submitted form values
137 $this->_queryParams
= &$queryParams;
139 $this->_single
= $single;
140 $this->_limit
= $limit;
141 $this->_context
= $context;
143 $this->_grantClause
= $grantClause;
146 $this->_action
= $action;
148 $this->_query
= new CRM_Contact_BAO_Query($this->_queryParams
, NULL, NULL, FALSE, FALSE,
149 CRM_Contact_BAO_Query
::MODE_GRANT
151 $this->_query
->_distinctComponentClause
= " civicrm_grant.id";
152 $this->_query
->_groupByComponentClause
= " GROUP BY civicrm_grant.id ";
156 * This method returns the links that are given for each search row.
157 * currently the links added for each row are
162 * @param string|null $key
166 public static function &links($key = NULL) {
167 $cid = CRM_Utils_Request
::retrieve('cid', 'Integer');
168 $extraParams = ($key) ?
"&key={$key}" : NULL;
170 if (!(self
::$_links)) {
172 CRM_Core_Action
::VIEW
=> [
173 'name' => ts('View'),
174 'url' => 'civicrm/contact/view/grant',
175 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=view&context=%%cxt%%&selectedChild=grant' . $extraParams,
176 'title' => ts('View Grant'),
178 CRM_Core_Action
::UPDATE
=> [
179 'name' => ts('Edit'),
180 'url' => 'civicrm/contact/view/grant',
181 'qs' => 'reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
182 'title' => ts('Edit Grant'),
188 CRM_Core_Action
::DELETE
=> [
189 'name' => ts('Delete'),
190 'url' => 'civicrm/contact/view/grant',
191 'qs' => 'action=delete&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=grant' . $extraParams,
192 'title' => ts('Delete Grant'),
195 self
::$_links = self
::$_links +
$delLink;
198 return self
::$_links;
202 * Getter for array of the parameters required for creating pager.
205 * @param array $params
207 public function getPagerParams($action, &$params) {
208 $params['status'] = ts('Grant') . ' %%StatusMessage%%';
209 $params['csvString'] = NULL;
211 $params['rowCount'] = $this->_limit
;
214 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
217 $params['buttonTop'] = 'PagerTopButton';
218 $params['buttonBottom'] = 'PagerBottomButton';
222 * Returns total number of rows for the query.
227 * Total number of rows
229 public function getTotalCount($action) {
230 return $this->_query
->searchQuery(0, 0, NULL,
239 * Returns all the rows in the given offset and rowCount *
241 * @param string $action
242 * The action being performed.
244 * The row number to start from.
245 * @param int $rowCount
246 * The number of rows to return.
247 * @param string $sort
248 * The sql string that describes the sort order.
249 * @param string $output
250 * What should the result set include (web/email/csv).
253 * the total number of rows for this action
255 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
256 $result = $this->_query
->searchQuery($offset, $rowCount, $sort,
263 // process the result of the query
266 //CRM-4418 check for view, edit, delete
267 $permissions = [CRM_Core_Permission
::VIEW
];
268 if (CRM_Core_Permission
::check('edit grants')) {
269 $permissions[] = CRM_Core_Permission
::EDIT
;
271 if (CRM_Core_Permission
::check('delete in CiviGrant')) {
272 $permissions[] = CRM_Core_Permission
::DELETE
;
274 $mask = CRM_Core_Action
::mask($permissions);
276 while ($result->fetch()) {
278 // the columns we are interested in
279 foreach (self
::$_properties as $property) {
280 if (isset($result->$property)) {
281 $row[$property] = $result->$property;
285 if ($this->_context
== 'search') {
286 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->grant_id
;
289 $row['action'] = CRM_Core_Action
::formLink(self
::links($this->_key
),
292 'id' => $result->grant_id
,
293 'cid' => $result->contact_id
,
294 'cxt' => $this->_context
,
298 'grant.selector.row',
303 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
$result->contact_sub_type
: $result->contact_type
, FALSE, $result->contact_id
315 public function getQILL() {
316 return $this->_query
->qill();
320 * Returns the column headers as an array of tuples:
321 * (name, sortName (key to the sort array))
323 * @param string $action
324 * The action being performed.
325 * @param string $output
326 * What should the result set include (web/email/csv).
329 * the column headers that need to be displayed
331 public function &getColumnHeaders($action = NULL, $output = NULL) {
332 if (!isset(self
::$_columnHeaders)) {
333 self
::$_columnHeaders = [
335 'name' => ts('Status'),
336 'sort' => 'grant_status',
337 'direction' => CRM_Utils_Sort
::DONTCARE
,
340 'name' => ts('Type'),
341 'sort' => 'grant_type_id',
342 'direction' => CRM_Utils_Sort
::DONTCARE
,
345 'name' => ts('Requested'),
346 'sort' => 'grant_amount_total',
347 'direction' => CRM_Utils_Sort
::DONTCARE
,
350 'name' => ts('Granted'),
351 'sort' => 'grant_amount_granted',
352 'direction' => CRM_Utils_Sort
::DONTCARE
,
355 'name' => ts('Application Received'),
356 'sort' => 'grant_application_received_date',
357 'direction' => CRM_Utils_Sort
::DONTCARE
,
360 'name' => ts('Report Received'),
361 'sort' => 'grant_report_received',
362 'direction' => CRM_Utils_Sort
::DONTCARE
,
365 'name' => ts('Money Transferred'),
366 'sort' => 'money_transfer_date',
367 'direction' => CRM_Utils_Sort
::DONTCARE
,
369 ['desc' => ts('Actions')],
372 if (!$this->_single
) {
374 ['desc' => ts('Contact Type')],
376 'name' => ts('Name'),
377 'sort' => 'sort_name',
378 'direction' => CRM_Utils_Sort
::ASCENDING
,
381 self
::$_columnHeaders = array_merge($pre, self
::$_columnHeaders);
384 return self
::$_columnHeaders;
390 * @return CRM_Contact_BAO_Query
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');