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.
23 class CRM_Member_Selector_Search
extends CRM_Core_Selector_Base
implements CRM_Core_Selector_API
{
26 * This defines two actions- View and Edit.
30 public static $_links = NULL;
33 * We use desc to remind us what that column is, name is used in the tpl
37 public static $_columnHeaders;
40 * Properties of contact we're interested in displaying
43 public static $_properties = [
49 'membership_join_date',
50 'membership_start_date',
51 'membership_end_date',
55 'owner_membership_id',
61 * Are we restricting ourselves to a single contact
65 protected $_single = FALSE;
68 * Are we restricting ourselves to a single contact
72 protected $_limit = NULL;
75 * What context are we being invoked from
79 protected $_context = NULL;
82 * QueryParams is the array returned by exportValues called on
83 * the HTML_QuickForm_Controller for that page.
90 * Represent the type of selector.
97 * The additional clause that we restrict the search with.
101 protected $_memberClause = NULL;
106 * @var CRM_Contact_BAO_Query
113 * @param array $queryParams
114 * Array of parameters for query.
115 * @param \const|int $action - action of search basic or advanced.
116 * @param string $memberClause
117 * If the caller wants to further restrict the search (used in memberships).
118 * @param bool $single
119 * Are we dealing only with one contact?.
121 * How many memberships do we want returned.
123 * @param string $context
125 * @return \CRM_Member_Selector_Search
127 public function __construct(
129 $action = CRM_Core_Action
::NONE
,
130 $memberClause = NULL,
135 // submitted form values
136 $this->_queryParams
= &$queryParams;
138 $this->_single
= $single;
139 $this->_limit
= $limit;
140 $this->_context
= $context;
142 $this->_memberClause
= $memberClause;
145 $this->_action
= $action;
147 $this->_query
= new CRM_Contact_BAO_Query($this->_queryParams
,
148 CRM_Member_BAO_Query
::defaultReturnProperties(CRM_Contact_BAO_Query
::MODE_MEMBER
,
152 CRM_Contact_BAO_Query
::MODE_MEMBER
154 $this->_query
->_distinctComponentClause
= " civicrm_membership.id";
155 $this->_query
->_groupByComponentClause
= " GROUP BY civicrm_membership.id ";
159 * This method returns the links that are given for each search row.
161 * Currently the links added for each row are
166 * @param string $status
167 * @param bool $isPaymentProcessor
168 * @param null $accessContribution
170 * @param null $context
171 * @param bool $isCancelSupported
175 public static function &links(
177 $isPaymentProcessor = NULL,
178 $accessContribution = NULL,
181 $isCancelSupported = FALSE
184 if ($context == 'search') {
185 $extraParams .= '&compContext=membership';
188 $extraParams .= "&key={$qfKey}";
191 if (empty(self
::$_links['view'])) {
192 self
::$_links['view'] = [
193 CRM_Core_Action
::VIEW
=> [
194 'name' => ts('View'),
195 'url' => 'civicrm/contact/view/membership',
196 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=view&context=%%cxt%%&selectedChild=member' . $extraParams,
197 'title' => ts('View Membership'),
201 if (!isset(self
::$_links['all']) ||
!self
::$_links['all']) {
203 CRM_Core_Action
::UPDATE
=> [
204 'name' => ts('Edit'),
205 'url' => 'civicrm/contact/view/membership',
206 'qs' => 'reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
207 'title' => ts('Edit Membership'),
209 CRM_Core_Action
::DELETE
=> [
210 'name' => ts('Delete'),
211 'url' => 'civicrm/contact/view/membership',
212 'qs' => 'reset=1&action=delete&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
213 'title' => ts('Delete Membership'),
215 CRM_Core_Action
::RENEW
=> [
216 'name' => ts('Renew'),
217 'url' => 'civicrm/contact/view/membership',
218 'qs' => 'reset=1&action=renew&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
219 'title' => ts('Renew Membership'),
221 CRM_Core_Action
::FOLLOWUP
=> [
222 'name' => ts('Renew-Credit Card'),
223 'url' => 'civicrm/contact/view/membership',
224 'qs' => 'action=renew&reset=1&cid=%%cid%%&id=%%id%%&context=%%cxt%%&mode=live' . $extraParams,
225 'title' => ts('Renew Membership Using Credit Card'),
228 if (!$isPaymentProcessor ||
!$accessContribution) {
229 //unset the renew with credit card when payment
230 //processor is not available or user not permitted to make contributions
231 unset($extraLinks[CRM_Core_Action
::FOLLOWUP
]);
234 self
::$_links['all'] = self
::$_links['view'] +
$extraLinks;
237 if ($isCancelSupported) {
238 self
::$_links['all'][CRM_Core_Action
::DISABLE
] = [
239 'name' => ts('Cancel Auto-renewal'),
240 'url' => 'civicrm/contribute/unsubscribe',
241 'qs' => 'reset=1&mid=%%id%%&context=%%cxt%%' . $extraParams,
242 'title' => ts('Cancel Auto Renew Subscription'),
245 elseif (isset(self
::$_links['all'][CRM_Core_Action
::DISABLE
])) {
246 unset(self
::$_links['all'][CRM_Core_Action
::DISABLE
]);
249 return self
::$_links[$status];
253 * Getter for array of the parameters required for creating pager.
256 * @param array $params
258 public function getPagerParams($action, &$params) {
259 $params['status'] = ts('Member') . ' %%StatusMessage%%';
260 $params['csvString'] = NULL;
262 $params['rowCount'] = $this->_limit
;
265 $params['rowCount'] = Civi
::settings()->get('default_pager_size');
268 $params['buttonTop'] = 'PagerTopButton';
269 $params['buttonBottom'] = 'PagerBottomButton';
273 * Returns total number of rows for the query.
278 * Total number of rows
280 public function getTotalCount($action) {
281 return $this->_query
->searchQuery(0, 0, NULL,
290 * Returns all the rows in the given offset and rowCount.
292 * @param string $action
293 * The action being performed.
295 * The row number to start from.
296 * @param int $rowCount
297 * The number of rows to return.
298 * @param string $sort
299 * The sql string that describes the sort order.
300 * @param string $output
301 * What should the result set include (web/email/csv).
304 * the total number of rows for this action
306 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
307 // check if we can process credit card registration
308 $processors = CRM_Core_PseudoConstant
::paymentProcessor(FALSE, FALSE,
309 "billing_mode IN ( 1, 3 )"
311 if (count($processors) > 0) {
312 $this->_isPaymentProcessor
= TRUE;
315 $this->_isPaymentProcessor
= FALSE;
318 // Only show credit card membership signup and renewal if user has CiviContribute permission
319 if (CRM_Core_Permission
::access('CiviContribute')) {
320 $this->_accessContribution
= TRUE;
323 $this->_accessContribution
= FALSE;
327 $allCampaigns = CRM_Campaign_BAO_Campaign
::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
329 $result = $this->_query
->searchQuery($offset, $rowCount, $sort,
336 // process the result of the query
339 //CRM-4418 check for view, edit, delete
340 $permissions = [CRM_Core_Permission
::VIEW
];
341 if (CRM_Core_Permission
::check('edit memberships')) {
342 $permissions[] = CRM_Core_Permission
::EDIT
;
344 if (CRM_Core_Permission
::check('delete in CiviMember')) {
345 $permissions[] = CRM_Core_Permission
::DELETE
;
347 $mask = CRM_Core_Action
::mask($permissions);
349 while ($result->fetch()) {
352 // the columns we are interested in
353 foreach (self
::$_properties as $property) {
354 if (property_exists($result, $property)) {
355 $row[$property] = $result->$property;
359 //carry campaign on selectors.
360 $row['campaign'] = $allCampaigns[$result->member_campaign_id
] ??
NULL;
361 $row['campaign_id'] = $result->member_campaign_id
;
363 if (!empty($row['member_is_test'])) {
364 $row['membership_type'] = CRM_Core_TestEntity
::appendTestText($row['membership_type']);
367 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->membership_id
;
369 if (!isset($result->owner_membership_id
)) {
370 // unset renew and followup link for deceased membership
371 $currentMask = $mask;
372 if ($result->membership_status
== 'Deceased') {
373 $currentMask = $currentMask & ~CRM_Core_Action
::RENEW
& ~CRM_Core_Action
::FOLLOWUP
;
376 $isCancelSupported = CRM_Member_BAO_Membership
::isCancelSubscriptionSupported($row['membership_id']);
377 $links = self
::links('all',
378 $this->_isPaymentProcessor
,
379 $this->_accessContribution
,
386 $finTypeId = CRM_Core_DAO
::getFieldValue('CRM_Member_DAO_MembershipType', $result->membership_type_id
, 'financial_type_id');
387 $finType = CRM_Contribute_PseudoConstant
::financialType($finTypeId);
388 if (CRM_Financial_BAO_FinancialType
::isACLFinancialTypeStatus()
389 && !CRM_Core_Permission
::check('edit contributions of type ' . $finType)
391 unset($links[CRM_Core_Action
::UPDATE
]);
393 if (CRM_Financial_BAO_FinancialType
::isACLFinancialTypeStatus() &&
394 !CRM_Core_Permission
::check('delete contributions of type ' . $finType)
396 unset($links[CRM_Core_Action
::DELETE
]);
398 $row['action'] = CRM_Core_Action
::formLink($links,
401 'id' => $result->membership_id
,
402 'cid' => $result->contact_id
,
403 'cxt' => $this->_context
,
407 'membership.selector.row',
409 $result->membership_id
413 $links = self
::links('view');
414 $row['action'] = CRM_Core_Action
::formLink($links, $mask,
416 'id' => $result->membership_id
,
417 'cid' => $result->contact_id
,
418 'cxt' => $this->_context
,
422 'membership.selector.row',
424 $result->membership_id
428 // Display Auto-renew status on page (0=disabled, 1=enabled, 2=enabled, but error
429 if (!empty($result->membership_recur_id
)) {
430 if (CRM_Member_BAO_Membership
::isSubscriptionCancelled($row['membership_id'])) {
431 $row['auto_renew'] = 2;
434 $row['auto_renew'] = 1;
438 $row['auto_renew'] = 0;
441 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
$result->contact_sub_type
: $result->contact_type
, FALSE, $result->contact_id
453 public function getQILL() {
454 return $this->_query
->qill();
458 * Returns the column headers as an array of tuples.
460 * (name, sortName (key to the sort array))
462 * @param string $action
463 * The action being performed.
464 * @param string $output
465 * What should the result set include (web/email/csv).
468 * the column headers that need to be displayed
470 public function &getColumnHeaders($action = NULL, $output = NULL) {
471 if (!isset(self
::$_columnHeaders)) {
472 self
::$_columnHeaders = [
474 'name' => ts('Type'),
475 'sort' => 'membership_type',
476 'direction' => CRM_Utils_Sort
::DONTCARE
,
479 'name' => ts('Member Since'),
480 'sort' => 'membership_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 ['desc' => ts('Actions')],
509 if (!$this->_single
) {
511 ['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;
529 public function alphabetQuery() {
530 return $this->_query
->alphabetQuery();
538 public function &getQuery() {
539 return $this->_query
;
543 * Name of export file.
545 * @param string $output
551 public function getExportFileName($output = 'csv') {
552 return ts('CiviCRM Member Search');