3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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_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
87 protected $_single = FALSE;
90 * Are we restricting ourselves to a single contact
94 protected $_limit = NULL;
97 * What context are we being invoked from
101 protected $_context = NULL;
104 * QueryParams is the array returned by exportValues called on
105 * the HTML_QuickForm_Controller for that page.
109 public $_queryParams;
112 * Represent the type of selector
119 * The additional clause that we restrict the search with
123 protected $_memberClause = NULL;
135 * @param array $queryParams
136 * Array of parameters for query.
137 * @param \const|int $action - action of search basic or advanced.
138 * @param string $memberClause
139 * If the caller wants to further restrict the search (used in memberships).
140 * @param bool $single
141 * Are we dealing only with one contact?.
143 * How many memberships do we want returned.
145 * @param string $context
147 * @return \CRM_Member_Selector_Search
150 function __construct(&$queryParams,
151 $action = CRM_Core_Action
::NONE
,
152 $memberClause = NULL,
157 // submitted form values
158 $this->_queryParams
= &$queryParams;
160 $this->_single
= $single;
161 $this->_limit
= $limit;
162 $this->_context
= $context;
164 $this->_memberClause
= $memberClause;
167 $this->_action
= $action;
169 $this->_query
= new CRM_Contact_BAO_Query($this->_queryParams
,
170 CRM_Member_BAO_Query
::defaultReturnProperties(CRM_Contact_BAO_Query
::MODE_MEMBER
,
174 CRM_Contact_BAO_Query
::MODE_MEMBER
176 $this->_query
->_distinctComponentClause
= " civicrm_membership.id";
177 $this->_query
->_groupByComponentClause
= " GROUP BY civicrm_membership.id ";
181 * This method returns the links that are given for each search row.
182 * currently the links added for each row are
187 * @param string $status
188 * @param null $isPaymentProcessor
189 * @param null $accessContribution
191 * @param null $context
192 * @param bool $isCancelSupported
197 function &links($status = 'all',
198 $isPaymentProcessor = NULL,
199 $accessContribution = NULL,
202 $isCancelSupported = FALSE
205 if ($context == 'search') {
206 $extraParams .= '&compContext=membership';
209 $extraParams .= "&key={$qfKey}";
212 if (!self
::$_links['view']) {
213 self
::$_links['view'] = array(
214 CRM_Core_Action
::VIEW
=> array(
215 'name' => ts('View'),
216 'url' => 'civicrm/contact/view/membership',
217 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=view&context=%%cxt%%&selectedChild=member' . $extraParams,
218 'title' => ts('View Membership'),
222 if (!isset(self
::$_links['all']) ||
!self
::$_links['all']) {
224 CRM_Core_Action
::UPDATE
=> array(
225 'name' => ts('Edit'),
226 'url' => 'civicrm/contact/view/membership',
227 'qs' => 'reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
228 'title' => ts('Edit Membership'),
230 CRM_Core_Action
::DELETE
=> array(
231 'name' => ts('Delete'),
232 'url' => 'civicrm/contact/view/membership',
233 'qs' => 'reset=1&action=delete&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
234 'title' => ts('Delete Membership'),
236 CRM_Core_Action
::RENEW
=> array(
237 'name' => ts('Renew'),
238 'url' => 'civicrm/contact/view/membership',
239 'qs' => 'reset=1&action=renew&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
240 'title' => ts('Renew Membership'),
242 CRM_Core_Action
::FOLLOWUP
=> array(
243 'name' => ts('Renew-Credit Card'),
244 'url' => 'civicrm/contact/view/membership',
245 'qs' => 'action=renew&reset=1&cid=%%cid%%&id=%%id%%&context=%%cxt%%&mode=live' . $extraParams,
246 'title' => ts('Renew Membership Using Credit Card'),
249 if (!$isPaymentProcessor ||
!$accessContribution) {
250 //unset the renew with credit card when payment
251 //processor is not available or user not permitted to make contributions
252 unset($extraLinks[CRM_Core_Action
::FOLLOWUP
]);
255 self
::$_links['all'] = self
::$_links['view'] +
$extraLinks;
258 if ($isCancelSupported) {
259 self
::$_links['all'][CRM_Core_Action
::DISABLE
] = array(
260 'name' => ts('Cancel Auto-renewal'),
261 'url' => 'civicrm/contribute/unsubscribe',
262 'qs' => 'reset=1&mid=%%id%%&context=%%cxt%%' . $extraParams,
263 'title' => 'Cancel Auto Renew Subscription',
266 elseif (isset(self
::$_links['all'][CRM_Core_Action
::DISABLE
])) {
267 unset(self
::$_links['all'][CRM_Core_Action
::DISABLE
]);
270 return self
::$_links[$status];
274 * Getter for array of the parameters required for creating pager.
277 * @param array $params
279 public function getPagerParams($action, &$params) {
280 $params['status'] = ts('Member') . ' %%StatusMessage%%';
281 $params['csvString'] = NULL;
283 $params['rowCount'] = $this->_limit
;
286 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
289 $params['buttonTop'] = 'PagerTopButton';
290 $params['buttonBottom'] = 'PagerBottomButton';
294 * Returns total number of rows for the query.
298 * @return int Total number of rows
300 public function getTotalCount($action) {
301 return $this->_query
->searchQuery(0, 0, NULL,
310 * Returns all the rows in the given offset and rowCount
312 * @param enum $action
313 * The action being performed.
315 * The row number to start from.
316 * @param int $rowCount
317 * The number of rows to return.
318 * @param string $sort
319 * The sql string that describes the sort order.
320 * @param enum $output
321 * What should the result set include (web/email/csv).
323 * @return int the total number of rows for this action
325 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
326 // check if we can process credit card registration
327 $processors = CRM_Core_PseudoConstant
::paymentProcessor(FALSE, FALSE,
328 "billing_mode IN ( 1, 3 )"
330 if (count($processors) > 0) {
331 $this->_isPaymentProcessor
= TRUE;
334 $this->_isPaymentProcessor
= FALSE;
337 // Only show credit card membership signup and renewal if user has CiviContribute permission
338 if (CRM_Core_Permission
::access('CiviContribute')) {
339 $this->_accessContribution
= TRUE;
342 $this->_accessContribution
= FALSE;
346 $allCampaigns = CRM_Campaign_BAO_Campaign
::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
348 $result = $this->_query
->searchQuery($offset, $rowCount, $sort,
355 // process the result of the query
358 //CRM-4418 check for view, edit, delete
359 $permissions = array(CRM_Core_Permission
::VIEW
);
360 if (CRM_Core_Permission
::check('edit memberships')) {
361 $permissions[] = CRM_Core_Permission
::EDIT
;
363 if (CRM_Core_Permission
::check('delete in CiviMember')) {
364 $permissions[] = CRM_Core_Permission
::DELETE
;
366 $mask = CRM_Core_Action
::mask($permissions);
368 while ($result->fetch()) {
371 // the columns we are interested in
372 foreach (self
::$_properties as $property) {
373 if (property_exists($result, $property)) {
374 $row[$property] = $result->$property;
378 //carry campaign on selectors.
379 $row['campaign'] = CRM_Utils_Array
::value($result->member_campaign_id
, $allCampaigns);
380 $row['campaign_id'] = $result->member_campaign_id
;
382 if (!empty($row['member_is_test'])) {
383 $row['membership_type'] = $row['membership_type'] . " (test)";
386 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->membership_id
;
388 if (!isset($result->owner_membership_id
)) {
389 // unset renew and followup link for deceased membership
390 $currentMask = $mask;
391 if ($result->membership_status
== 'Deceased') {
392 $currentMask = $currentMask & ~CRM_Core_Action
::RENEW
& ~CRM_Core_Action
::FOLLOWUP
;
395 $isCancelSupported = CRM_Member_BAO_Membership
::isCancelSubscriptionSupported($row['membership_id']);
396 $row['action'] = CRM_Core_Action
::formLink(self
::links('all',
397 $this->_isPaymentProcessor
,
398 $this->_accessContribution
,
405 'id' => $result->membership_id
,
406 'cid' => $result->contact_id
,
407 'cxt' => $this->_context
,
411 'membership.selector.row',
413 $result->membership_id
417 $row['action'] = CRM_Core_Action
::formLink(self
::links('view'), $mask,
419 'id' => $result->membership_id
,
420 'cid' => $result->contact_id
,
421 'cxt' => $this->_context
,
425 'membership.selector.row',
427 $result->membership_id
431 //does membership have auto renew CRM-7137.
433 if (isset($result->membership_recur_id
) && $result->membership_recur_id
&&
434 !CRM_Member_BAO_Membership
::isSubscriptionCancelled($row['membership_id'])
438 $row['auto_renew'] = $autoRenew;
440 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
$result->contact_sub_type
: $result->contact_type
, FALSE, $result->contact_id
450 * @return array $qill which contains an array of strings
453 // the current internationalisation is bad, but should more or less work
454 // for most of "European" languages
455 public function getQILL() {
456 return $this->_query
->qill();
460 * Returns the column headers as an array of tuples:
461 * (name, sortName (key to the sort array))
463 * @param string $action
464 * The action being performed.
465 * @param enum $output
466 * What should the result set include (web/email/csv).
468 * @return array the column headers that need to be displayed
470 public function &getColumnHeaders($action = NULL, $output = NULL) {
471 if (!isset(self
::$_columnHeaders)) {
472 self
::$_columnHeaders = array(
474 'name' => ts('Type'),
475 'sort' => 'membership_type',
476 'direction' => CRM_Utils_Sort
::DONTCARE
,
479 'name' => ts('Member Since'),
480 'sort' => 'join_date',
481 'direction' => CRM_Utils_Sort
::DESCENDING
,
484 'name' => ts('Start Date'),
485 'sort' => 'membership_start_date',
486 'direction' => CRM_Utils_Sort
::DONTCARE
,
489 'name' => ts('End Date'),
490 'sort' => 'membership_end_date',
491 'direction' => CRM_Utils_Sort
::DONTCARE
,
494 'name' => ts('Source'),
495 'sort' => 'membership_source',
496 'direction' => CRM_Utils_Sort
::DONTCARE
,
499 'name' => ts('Status'),
500 'sort' => 'membership_status',
501 'direction' => CRM_Utils_Sort
::DONTCARE
,
504 'name' => ts('Auto-renew?'),
506 array('desc' => ts('Actions')),
509 if (!$this->_single
) {
511 array('desc' => ts('Contact Type')),
513 'name' => ts('Name'),
514 'sort' => 'sort_name',
515 'direction' => CRM_Utils_Sort
::DONTCARE
,
518 self
::$_columnHeaders = array_merge($pre, self
::$_columnHeaders);
521 return self
::$_columnHeaders;
527 public function alphabetQuery() {
528 return $this->_query
->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE);
534 public function &getQuery() {
535 return $this->_query
;
539 * Name of export file.
541 * @param string $output
544 * @return string name of the file
546 public function getExportFileName($output = 'csv') {
547 return ts('CiviCRM Member Search');