3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
36 require_once 'CRM/Core/Selector/Base.php';
37 require_once 'CRM/Core/Selector/API.php';
39 require_once 'CRM/Utils/Pager.php';
40 require_once 'CRM/Utils/Sort.php';
42 require_once 'CRM/Grant/BAO/PaymentSearch.php';
45 * This class is used to retrieve and display a range of
46 * contacts that match the given criteria (specifically for
47 * results of advanced search options.
50 class CRM_Grant_Selector_PaymentSearch
extends CRM_Core_Selector_Base
implements CRM_Core_Selector_API
54 * This defines two actions- View and Edit.
59 static $_links = null;
62 * we use desc to remind us what that column is, name is used in the tpl
67 static $_columnHeaders;
70 * Properties of contact we're interested in displaying
74 static $_properties = array( 'id',
76 'payment_batch_number',
79 'payment_created_date',
84 * are we restricting ourselves to a single contact
89 protected $_single = false;
92 * are we restricting ourselves to a single contact
97 protected $_limit = null;
100 * what context are we being invoked from
105 protected $_context = null;
108 * queryParams is the array returned by exportValues called on
109 * the HTML_QuickForm_Controller for that page.
114 public $_queryParams;
117 * represent the type of selector
125 * The additional clause that we restrict the search with
129 protected $_grantClause = null;
141 * @param array $queryParams array of parameters for query
142 * @param int $action - action of search basic or advanced.
143 * @param string $grantClause if the caller wants to further restrict the search
144 * @param boolean $single are we dealing only with one contact?
145 * @param int $limit how many participations do we want returned
147 * @return CRM_Contact_Selector
150 function __construct(&$queryParams,
151 $action = CRM_Core_Action
::NONE
,
155 $context = 'search' )
157 // submitted form values
158 $this->_queryParams
=& $queryParams;
161 $this->_single
= $single;
162 $this->_limit
= $limit;
163 $this->_context
= $context;
165 $this->_grantClause
= $grantClause;
168 $this->_action
= $action;
170 $this->_query
= new CRM_Grant_BAO_PaymentSearch( $this->_queryParams
, null, null, false, false,
171 CRM_Grant_BAO_PaymentSearch
::MODE_GRANT_PAYMENT
);
174 $this->_query
->_distinctComponentClause
= " civicrm_payment.id";
175 $this->_query
->_groupByComponentClause
= " GROUP BY civicrm_payment.id";
177 }//end of constructor
181 * This method returns the links that are given for each search row.
182 * currently the links added for each row are
191 static function &links( $key = null )
193 $id = CRM_Utils_Request
::retrieve('id', 'Integer', $this);
194 $extraParams = ( $key ) ?
"&key={$key}" : null;
196 if (!(self
::$_links)) {
197 self
::$_links = array(
198 CRM_Core_Action
::VIEW
=> array(
199 'name' => ts('View'),
200 'url' => 'civicrm/grant/payment',
201 'qs' => 'reset=1&id=%%id%%&action=view&context=%%cxt%%&selectedChild=grant'.$extraParams,
202 'title' => ts('View Grant'),
204 CRM_Core_Action
::STOP
=> array(
205 'name' => ts('Stop'),
206 'url' => 'civicrm/grant/payment',
207 'qs' => 'reset=1&action=stop&id=%%id%%&context=%%cxt%%'.$extraParams,
208 'title' => ts('Edit Grant'),
210 CRM_Core_Action
::REPRINT
=> array(
211 'name' => ts('Reprint'),
212 'url' => 'civicrm/grant/payment',
213 'qs' => 'reset=1&action=reprint&id=%%id%%&context=%%cxt%%'.$extraParams,
214 'title' => ts('Edit Grant'),
216 CRM_Core_Action
::WITHDRAW
=> array(
217 'name' => ts('Withdraw'),
218 'url' => 'civicrm/grant/payment',
219 'qs' => 'reset=1&action=withdraw&id=%%id%%&context=%%cxt%%'.$extraParams,
220 'title' => ts('Edit Grant'),
224 self
::$_links = self
::$_links ;
229 return self
::$_links;
233 * getter for array of the parameters required for creating pager.
238 function getPagerParams($action, &$params)
240 $params['status'] = ts('Grant') . ' %%StatusMessage%%';
241 $params['csvString'] = null;
242 if ( $this->_limit
) {
243 $params['rowCount'] = $this->_limit
;
245 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
248 $params['buttonTop'] = 'PagerTopButton';
249 $params['buttonBottom'] = 'PagerBottomButton';
253 * Returns total number of rows for the query.
256 * @return int Total number of rows
259 function getTotalCount($action)
261 return $this->_query
->searchQuery( 0, 0, null,
265 $this->_grantClause
);
271 * returns all the rows in the given offset and rowCount *
272 * @param enum $action the action being performed
273 * @param int $offset the row number to start from
274 * @param int $rowCount the number of rows to return
275 * @param string $sort the sql string that describes the sort order
276 * @param enum $output what should the result set include (web/email/csv)
278 * @return int the total number of rows for this action
280 function &getRows($action, $offset, $rowCount, $sort, $output = null)
282 $result = $this->_query
->searchQuery( $offset, $rowCount, $sort,
286 $this->_grantClause
);
291 // process the result of the query
294 //CRM-4418 check for view, edit, delete
295 $permissions = array( CRM_Core_Permission
::VIEW
);
296 if ( CRM_Core_Permission
::check( 'edit grants' ) ) {
297 $permissions[] = CRM_Core_Permission
::EDIT
;
299 if ( CRM_Core_Permission
::check( 'delete in CiviGrant' ) ) {
300 $permissions[] = CRM_Core_Permission
::DELETE
;
302 $mask = CRM_Core_Action
::mask( $permissions );
305 while ( $result->fetch()) {
308 // the columns we are interested in
309 foreach (self
::$_properties as $property) {
310 if ( isset( $result->$property ) ) {
311 if ( $property == 'payment_status_id' ) {
312 require_once 'CRM/Core/OptionGroup.php';
313 $paymentStatus = CRM_Core_OptionGroup
::values( 'grant_payment_status' );
314 $row[$property] = $paymentStatus[$result->$property];
316 $row[$property] = $result->$property;
320 // if ($this->_context == 'search') {
321 // $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->id;
323 $this->id
= $result->id
;
324 $link = self
::links( $this->_key
);
325 if ( $result->payment_status_id
== 2 ||
$result->payment_status_id
== 4 ) {
326 unset($link[CRM_Core_Action
::STOP
]);
327 unset($link[CRM_Core_Action
::REPRINT
]);
328 unset($link[CRM_Core_Action
::WITHDRAW
]);
331 $row['action'] = CRM_Core_Action
::formLink( $link,
333 array( 'id' => $result->id
,
334 'cxt' => $this->_context
) );
343 * @return array $qill which contains an array of strings
347 // the current internationalisation is bad, but should more or less work
348 // for most of "European" languages
349 public function getQILL( )
351 return $this->_query
->qill( );
355 * returns the column headers as an array of tuples:
356 * (name, sortName (key to the sort array))
358 * @param string $action the action being performed
359 * @param enum $output what should the result set include (web/email/csv)
361 * @return array the column headers that need to be displayed
364 public function &getColumnHeaders( $action = null, $output = null )
366 if ( ! isset( self
::$_columnHeaders ) ) {
367 self
::$_columnHeaders = array(
368 array('name' => ts('Status'),
369 'sort' => 'payment_status_id',
370 'direction' => CRM_Utils_Sort
::DONTCARE
,
373 'name' => ts('Batch Number'),
374 'sort' => 'payment_batch_number',
375 'direction' => CRM_Utils_Sort
::DONTCARE
,
378 'name' => ts('Payment Number'),
379 'sort' => 'payment_number',
380 'direction' => CRM_Utils_Sort
::DONTCARE
,
383 'name' => ts('Date'),
384 'sort' => 'payment_created_date',
385 'direction' => CRM_Utils_Sort
::DONTCARE
,
388 'name' => ts('Payee name'),
389 'sort' => 'payable_to_name',
390 'direction' => CRM_Utils_Sort
::DONTCARE
,
393 'name' => ts('Amount'),
395 'direction' => CRM_Utils_Sort
::DONTCARE
,
397 array('desc' => ts('Actions') ),
400 return self
::$_columnHeaders;
403 function &getQuery( ) {
404 return $this->_query
;
408 * name of export file.
410 * @param string $output type of output
411 * @return string name of the file
413 function getExportFileName( $output = 'csv') {
414 return ts('CiviCRM Grant Search');