3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
37 * This class is used to retrieve and display a range of
38 * contacts that match the given criteria (specifically for
39 * results of advanced search options.
42 class CRM_Grant_Selector_Search
extends CRM_Core_Selector_Base
implements CRM_Core_Selector_API
{
45 * This defines two actions- View and Edit.
50 static $_links = NULL;
53 * we use desc to remind us what that column is, name is used in the tpl
58 static $_columnHeaders;
61 * Properties of contact we're interested in displaying
65 static $_properties = array(
75 'grant_amount_requested',
76 'grant_amount_granted',
77 'grant_application_received_date',
78 'grant_report_received',
79 'grant_money_transfer_date',
83 * are we restricting ourselves to a single contact
88 protected $_single = FALSE;
91 * are we restricting ourselves to a single contact
96 protected $_limit = NULL;
99 * what context are we being invoked from
104 protected $_context = NULL;
107 * queryParams is the array returned by exportValues called on
108 * the HTML_QuickForm_Controller for that page.
113 public $_queryParams;
116 * represent the type of selector
124 * The additional clause that we restrict the search with
128 protected $_grantClause = NULL;
140 * @param array $queryParams array of parameters for query
141 * @param int $action - action of search basic or advanced.
142 * @param string $grantClause if the caller wants to further restrict the search
143 * @param boolean $single are we dealing only with one contact?
144 * @param int $limit how many participations do we want returned
146 * @return CRM_Contact_Selector
149 function __construct(&$queryParams,
150 $action = CRM_Core_Action
::NONE
,
156 // submitted form values
157 $this->_queryParams
= &$queryParams;
160 $this->_single
= $single;
161 $this->_limit
= $limit;
162 $this->_context
= $context;
164 $this->_grantClause
= $grantClause;
167 $this->_action
= $action;
169 $this->_query
= new CRM_Contact_BAO_Query($this->_queryParams
, NULL, NULL, FALSE, FALSE,
170 CRM_Contact_BAO_Query
::MODE_GRANT
172 $this->_query
->_distinctComponentClause
= " civicrm_grant.id";
173 $this->_query
->_groupByComponentClause
= " GROUP BY civicrm_grant.id ";
178 * This method returns the links that are given for each search row.
179 * currently the links added for each row are
188 static function &links($key = NULL) {
189 $cid = CRM_Utils_Request
::retrieve('cid', 'Integer', $this);
190 $extraParams = ($key) ?
"&key={$key}" : NULL;
192 if (!(self
::$_links)) {
193 self
::$_links = array(
194 CRM_Core_Action
::VIEW
=> array(
195 'name' => ts('View'),
196 'url' => 'civicrm/contact/view/grant',
197 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=view&context=%%cxt%%&selectedChild=grant' . $extraParams,
198 'title' => ts('View Grant'),
200 CRM_Core_Action
::UPDATE
=> array(
201 'name' => ts('Edit'),
202 'url' => 'civicrm/contact/view/grant',
203 'qs' => 'reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
204 'title' => ts('Edit Grant'),
209 $deleteExtra = ts('Are you sure you want to delete this grant?');
212 CRM_Core_Action
::DELETE
=> array('name' => ts('Delete'),
213 'url' => 'civicrm/contact/view/grant',
214 'qs' => 'action=delete&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=grant' . $extraParams,
215 'extra' => 'onclick = "if (confirm(\'' . $deleteExtra . '\') ) this.href+=\'&confirmed=1\'; else return false;"',
216 'title' => ts('Delete Grant'),
219 self
::$_links = self
::$_links +
$delLink;
222 return self
::$_links;
227 * getter for array of the parameters required for creating pager.
232 function getPagerParams($action, &$params) {
233 $params['status'] = ts('Grant') . ' %%StatusMessage%%';
234 $params['csvString'] = NULL;
236 $params['rowCount'] = $this->_limit
;
239 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
242 $params['buttonTop'] = 'PagerTopButton';
243 $params['buttonBottom'] = 'PagerBottomButton';
248 * Returns total number of rows for the query.
252 * @return int Total number of rows
255 function getTotalCount($action) {
256 return $this->_query
->searchQuery(0, 0, NULL,
265 * returns all the rows in the given offset and rowCount *
267 * @param enum $action the action being performed
268 * @param int $offset the row number to start from
269 * @param int $rowCount the number of rows to return
270 * @param string $sort the sql string that describes the sort order
271 * @param enum $output what should the result set include (web/email/csv)
273 * @return int the total number of rows for this action
275 function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
276 $result = $this->_query
->searchQuery($offset, $rowCount, $sort,
283 // process the result of the query
286 //CRM-4418 check for view, edit, delete
287 $permissions = array(CRM_Core_Permission
::VIEW
);
288 if (CRM_Core_Permission
::check('edit grants')) {
289 $permissions[] = CRM_Core_Permission
::EDIT
;
291 if (CRM_Core_Permission
::check('delete in CiviGrant')) {
292 $permissions[] = CRM_Core_Permission
::DELETE
;
294 $mask = CRM_Core_Action
::mask($permissions);
296 while ($result->fetch()) {
298 // the columns we are interested in
299 foreach (self
::$_properties as $property) {
300 if (isset($result->$property)) {
301 $row[$property] = $result->$property;
305 if ($this->_context
== 'search') {
306 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->grant_id
;
309 $row['action'] = CRM_Core_Action
::formLink(self
::links($this->_key
),
312 'id' => $result->grant_id
,
313 'cid' => $result->contact_id
,
314 'cxt' => $this->_context
,
318 'grant.selector.row',
323 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
324 $result->contact_sub_type
: $result->contact_type
, FALSE, $result->contact_id
335 * @return array $qill which contains an array of strings
339 // the current internationalisation is bad, but should more or less work
340 // for most of "European" languages
341 public function getQILL() {
342 return $this->_query
->qill();
346 * returns the column headers as an array of tuples:
347 * (name, sortName (key to the sort array))
349 * @param string $action the action being performed
350 * @param enum $output what should the result set include (web/email/csv)
352 * @return array the column headers that need to be displayed
355 public function &getColumnHeaders($action = NULL, $output = NULL) {
356 if (!isset(self
::$_columnHeaders)) {
357 self
::$_columnHeaders = array(
358 array('name' => ts('Status'),
359 'sort' => 'grant_status',
360 'direction' => CRM_Utils_Sort
::DONTCARE
,
363 'name' => ts('Type'),
364 'sort' => 'grant_type_id',
365 'direction' => CRM_Utils_Sort
::DONTCARE
,
368 'name' => ts('Requested'),
369 'sort' => 'grant_amount_total',
370 'direction' => CRM_Utils_Sort
::DONTCARE
,
373 'name' => ts('Granted'),
374 'sort' => 'grant_amount_granted',
375 'direction' => CRM_Utils_Sort
::DONTCARE
,
378 'name' => ts('Application Received'),
379 'sort' => 'grant_application_received_date',
380 'direction' => CRM_Utils_Sort
::DONTCARE
,
383 'name' => ts('Report Received'),
384 'sort' => 'grant_report_received',
385 'direction' => CRM_Utils_Sort
::DONTCARE
,
388 'name' => ts('Money Transferred'),
389 'sort' => 'money_transfer_date',
390 'direction' => CRM_Utils_Sort
::DONTCARE
,
392 array('desc' => ts('Actions')),
395 if (!$this->_single
) {
397 array('desc' => ts('Contact Type')),
399 'name' => ts('Name'),
400 'sort' => 'sort_name',
401 'direction' => CRM_Utils_Sort
::ASCENDING
,
404 self
::$_columnHeaders = array_merge($pre, self
::$_columnHeaders);
407 return self
::$_columnHeaders;
410 function &getQuery() {
411 return $this->_query
;
415 * name of export file.
417 * @param string $output type of output
419 * @return string name of the file
421 function getExportFileName($output = 'csv') {
422 return ts('CiviCRM Grant Search');