3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
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
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_Member_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(
72 'membership_start_date',
73 'membership_end_date',
77 'owner_membership_id',
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 $_memberClause = NULL;
140 * @param array $queryParams array of parameters for query
141 * @param int $action - action of search basic or advanced.
142 * @param string $memberClause if the caller wants to further restrict the search (used in memberships)
143 * @param boolean $single are we dealing only with one contact?
144 * @param int $limit how many memberships do we want returned
146 * @return CRM_Contact_Selector
148 */ function __construct(&$queryParams,
149 $action = CRM_Core_Action
::NONE
,
150 $memberClause = NULL,
155 // submitted form values
156 $this->_queryParams
= &$queryParams;
158 $this->_single
= $single;
159 $this->_limit
= $limit;
160 $this->_context
= $context;
162 $this->_memberClause
= $memberClause;
165 $this->_action
= $action;
167 $this->_query
= new CRM_Contact_BAO_Query($this->_queryParams
,
168 CRM_Member_BAO_Query
::defaultReturnProperties(CRM_Contact_BAO_Query
::MODE_MEMBER
,
172 CRM_Contact_BAO_Query
::MODE_MEMBER
174 $this->_query
->_distinctComponentClause
= " civicrm_membership.id";
175 $this->_query
->_groupByComponentClause
= " GROUP BY civicrm_membership.id ";
180 * This method returns the links that are given for each search row.
181 * currently the links added for each row are
191 function &links($status = 'all',
192 $isPaymentProcessor = NULL,
193 $accessContribution = NULL,
196 $isCancelSupported = FALSE
199 if ($context == 'search') {
200 $extraParams .= '&compContext=membership';
203 $extraParams .= "&key={$qfKey}";
206 if (!self
::$_links['view']) {
207 self
::$_links['view'] = array(
208 CRM_Core_Action
::VIEW
=> array(
209 'name' => ts('View'),
210 'url' => 'civicrm/contact/view/membership',
211 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=view&context=%%cxt%%&selectedChild=member' . $extraParams,
212 'title' => ts('View Membership'),
216 if (!isset(self
::$_links['all']) ||
!self
::$_links['all']) {
218 CRM_Core_Action
::UPDATE
=> array(
219 'name' => ts('Edit'),
220 'url' => 'civicrm/contact/view/membership',
221 'qs' => 'reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
222 'title' => ts('Edit Membership'),
224 CRM_Core_Action
::DELETE
=> array(
225 'name' => ts('Delete'),
226 'url' => 'civicrm/contact/view/membership',
227 'qs' => 'reset=1&action=delete&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
228 'title' => ts('Delete Membership'),
230 CRM_Core_Action
::RENEW
=> array(
231 'name' => ts('Renew'),
232 'url' => 'civicrm/contact/view/membership',
233 'qs' => 'reset=1&action=renew&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
234 'title' => ts('Renew Membership'),
236 CRM_Core_Action
::FOLLOWUP
=> array(
237 'name' => ts('Renew-Credit Card'),
238 'url' => 'civicrm/contact/view/membership',
239 'qs' => 'action=renew&reset=1&cid=%%cid%%&id=%%id%%&context=%%cxt%%&mode=live' . $extraParams,
240 'title' => ts('Renew Membership Using Credit Card'),
243 if (!$isPaymentProcessor ||
!$accessContribution) {
244 //unset the renew with credit card when payment
245 //processor is not available or user not permitted to make contributions
246 unset($extraLinks[CRM_Core_Action
::FOLLOWUP
]);
249 self
::$_links['all'] = self
::$_links['view'] +
$extraLinks;
252 if ($isCancelSupported) {
253 self
::$_links['all'][CRM_Core_Action
::DISABLE
] = array(
254 'name' => ts('Cancel Auto-renewal'),
255 'url' => 'civicrm/contribute/unsubscribe',
256 'qs' => 'reset=1&mid=%%id%%&context=%%cxt%%' . $extraParams,
257 'title' => 'Cancel Auto Renew Subscription',
260 elseif (isset(self
::$_links['all'][CRM_Core_Action
::DISABLE
])) {
261 unset(self
::$_links['all'][CRM_Core_Action
::DISABLE
]);
264 return self
::$_links[$status];
269 * getter for array of the parameters required for creating pager.
274 function getPagerParams($action, &$params) {
275 $params['status'] = ts('Member') . ' %%StatusMessage%%';
276 $params['csvString'] = NULL;
278 $params['rowCount'] = $this->_limit
;
281 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
284 $params['buttonTop'] = 'PagerTopButton';
285 $params['buttonBottom'] = 'PagerBottomButton';
290 * Returns total number of rows for the query.
294 * @return int Total number of rows
297 function getTotalCount($action) {
298 return $this->_query
->searchQuery(0, 0, NULL,
307 * returns all the rows in the given offset and rowCount
309 * @param enum $action the action being performed
310 * @param int $offset the row number to start from
311 * @param int $rowCount the number of rows to return
312 * @param string $sort the sql string that describes the sort order
313 * @param enum $output what should the result set include (web/email/csv)
315 * @return int the total number of rows for this action
317 function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
318 // check if we can process credit card registration
319 $processors = CRM_Core_PseudoConstant
::paymentProcessor(FALSE, FALSE,
320 "billing_mode IN ( 1, 3 )"
322 if (count($processors) > 0) {
323 $this->_isPaymentProcessor
= TRUE;
326 $this->_isPaymentProcessor
= FALSE;
329 // Only show credit card membership signup and renewal if user has CiviContribute permission
330 if (CRM_Core_Permission
::access('CiviContribute')) {
331 $this->_accessContribution
= TRUE;
334 $this->_accessContribution
= FALSE;
338 $allCampaigns = CRM_Campaign_BAO_Campaign
::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
340 $result = $this->_query
->searchQuery($offset, $rowCount, $sort,
347 // process the result of the query
350 //CRM-4418 check for view, edit, delete
351 $permissions = array(CRM_Core_Permission
::VIEW
);
352 if (CRM_Core_Permission
::check('edit memberships')) {
353 $permissions[] = CRM_Core_Permission
::EDIT
;
355 if (CRM_Core_Permission
::check('delete in CiviMember')) {
356 $permissions[] = CRM_Core_Permission
::DELETE
;
358 $mask = CRM_Core_Action
::mask($permissions);
360 while ($result->fetch()) {
363 // the columns we are interested in
364 foreach (self
::$_properties as $property) {
365 if (property_exists($result, $property)) {
366 $row[$property] = $result->$property;
370 //carry campaign on selectors.
371 $row['campaign'] = CRM_Utils_Array
::value($result->member_campaign_id
, $allCampaigns);
372 $row['campaign_id'] = $result->member_campaign_id
;
374 if (!empty($row['member_is_test'])) {
375 $row['membership_type'] = $row['membership_type'] . " (test)";
378 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->membership_id
;
380 if (!isset($result->owner_membership_id
)) {
381 // unset renew and followup link for deceased membership
382 $currentMask = $mask;
383 if ($result->membership_status
== 'Deceased') {
384 $currentMask = $currentMask & ~CRM_Core_Action
::RENEW
& ~CRM_Core_Action
::FOLLOWUP
;
387 $isCancelSupported = CRM_Member_BAO_Membership
::isCancelSubscriptionSupported($row['membership_id']);
388 $row['action'] = CRM_Core_Action
::formLink(self
::links('all',
389 $this->_isPaymentProcessor
,
390 $this->_accessContribution
,
397 'id' => $result->membership_id
,
398 'cid' => $result->contact_id
,
399 'cxt' => $this->_context
,
403 'membership.selector.row',
405 $result->membership_id
409 $row['action'] = CRM_Core_Action
::formLink(self
::links('view'), $mask,
411 'id' => $result->membership_id
,
412 'cid' => $result->contact_id
,
413 'cxt' => $this->_context
,
417 'membership.selector.row',
419 $result->membership_id
423 //does membership have auto renew CRM-7137.
425 if (isset($result->membership_recur_id
) && $result->membership_recur_id
&&
426 !CRM_Member_BAO_Membership
::isSubscriptionCancelled($row['membership_id'])
430 $row['auto_renew'] = $autoRenew;
432 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
433 $result->contact_sub_type
: $result->contact_type
, FALSE, $result->contact_id
444 * @return array $qill which contains an array of strings
448 // the current internationalisation is bad, but should more or less work
449 // for most of "European" languages
450 public function getQILL() {
451 return $this->_query
->qill();
455 * returns the column headers as an array of tuples:
456 * (name, sortName (key to the sort array))
458 * @param string $action the action being performed
459 * @param enum $output what should the result set include (web/email/csv)
461 * @return array the column headers that need to be displayed
464 public function &getColumnHeaders($action = NULL, $output = NULL) {
465 if (!isset(self
::$_columnHeaders)) {
466 self
::$_columnHeaders = array(
468 'name' => ts('Type'),
469 'sort' => 'membership_type_id',
470 'direction' => CRM_Utils_Sort
::DONTCARE
,
472 array('name' => ts('Member Since'),
473 'sort' => 'join_date',
474 'direction' => CRM_Utils_Sort
::DESCENDING
,
477 'name' => ts('Start Date'),
478 'sort' => 'membership_start_date',
479 'direction' => CRM_Utils_Sort
::DONTCARE
,
482 'name' => ts('End Date'),
483 'sort' => 'membership_end_date',
484 'direction' => CRM_Utils_Sort
::DONTCARE
,
487 'name' => ts('Source'),
488 'sort' => 'membership_source',
489 'direction' => CRM_Utils_Sort
::DONTCARE
,
492 'name' => ts('Status'),
493 'sort' => 'status_id',
494 'direction' => CRM_Utils_Sort
::DONTCARE
,
497 'name' => ts('Auto-renew?'),
499 array('desc' => ts('Actions')),
502 if (!$this->_single
) {
504 array('desc' => ts('Contact Type')),
506 'name' => ts('Name'),
507 'sort' => 'sort_name',
508 'direction' => CRM_Utils_Sort
::DONTCARE
,
511 self
::$_columnHeaders = array_merge($pre, self
::$_columnHeaders);
514 return self
::$_columnHeaders;
517 function alphabetQuery() {
518 return $this->_query
->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE);
521 function &getQuery() {
522 return $this->_query
;
526 * name of export file.
528 * @param string $output type of output
530 * @return string name of the file
532 function getExportFileName($output = 'csv') {
533 return ts('CiviCRM Member Search');