3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
35 * This class is used to retrieve and display a range of
36 * contacts that match the given criteria (specifically for
37 * results of advanced search options.
39 class CRM_Member_Selector_Search
extends CRM_Core_Selector_Base
implements CRM_Core_Selector_API
{
42 * This defines two actions- View and Edit.
46 static $_links = NULL;
49 * We use desc to remind us what that column is, name is used in the tpl
53 static $_columnHeaders;
56 * Properties of contact we're interested in displaying
59 static $_properties = array(
66 'membership_start_date',
67 'membership_end_date',
71 'owner_membership_id',
77 * Are we restricting ourselves to a single contact
81 protected $_single = FALSE;
84 * Are we restricting ourselves to a single contact
88 protected $_limit = NULL;
91 * What context are we being invoked from
95 protected $_context = NULL;
98 * QueryParams is the array returned by exportValues called on
99 * the HTML_QuickForm_Controller for that page.
103 public $_queryParams;
106 * Represent the type of selector.
113 * The additional clause that we restrict the search with.
117 protected $_memberClause = NULL;
129 * @param array $queryParams
130 * Array of parameters for query.
131 * @param \const|int $action - action of search basic or advanced.
132 * @param string $memberClause
133 * If the caller wants to further restrict the search (used in memberships).
134 * @param bool $single
135 * Are we dealing only with one contact?.
137 * How many memberships do we want returned.
139 * @param string $context
141 * @return \CRM_Member_Selector_Search
143 public function __construct(
145 $action = CRM_Core_Action
::NONE
,
146 $memberClause = NULL,
151 // submitted form values
152 $this->_queryParams
= &$queryParams;
154 $this->_single
= $single;
155 $this->_limit
= $limit;
156 $this->_context
= $context;
158 $this->_memberClause
= $memberClause;
161 $this->_action
= $action;
163 $this->_query
= new CRM_Contact_BAO_Query($this->_queryParams
,
164 CRM_Member_BAO_Query
::defaultReturnProperties(CRM_Contact_BAO_Query
::MODE_MEMBER
,
168 CRM_Contact_BAO_Query
::MODE_MEMBER
170 $this->_query
->_distinctComponentClause
= " civicrm_membership.id";
171 $this->_query
->_groupByComponentClause
= " GROUP BY civicrm_membership.id ";
175 * This method returns the links that are given for each search row.
177 * Currently the links added for each row are
182 * @param string $status
183 * @param bool $isPaymentProcessor
184 * @param null $accessContribution
186 * @param null $context
187 * @param bool $isCancelSupported
191 public static function &links(
193 $isPaymentProcessor = NULL,
194 $accessContribution = NULL,
197 $isCancelSupported = FALSE
200 if ($context == 'search') {
201 $extraParams .= '&compContext=membership';
204 $extraParams .= "&key={$qfKey}";
207 if (!self
::$_links['view']) {
208 self
::$_links['view'] = array(
209 CRM_Core_Action
::VIEW
=> array(
210 'name' => ts('View'),
211 'url' => 'civicrm/contact/view/membership',
212 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=view&context=%%cxt%%&selectedChild=member' . $extraParams,
213 'title' => ts('View Membership'),
217 if (!isset(self
::$_links['all']) ||
!self
::$_links['all']) {
219 CRM_Core_Action
::UPDATE
=> array(
220 'name' => ts('Edit'),
221 'url' => 'civicrm/contact/view/membership',
222 'qs' => 'reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
223 'title' => ts('Edit Membership'),
225 CRM_Core_Action
::DELETE
=> array(
226 'name' => ts('Delete'),
227 'url' => 'civicrm/contact/view/membership',
228 'qs' => 'reset=1&action=delete&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
229 'title' => ts('Delete Membership'),
231 CRM_Core_Action
::RENEW
=> array(
232 'name' => ts('Renew'),
233 'url' => 'civicrm/contact/view/membership',
234 'qs' => 'reset=1&action=renew&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
235 'title' => ts('Renew Membership'),
237 CRM_Core_Action
::FOLLOWUP
=> array(
238 'name' => ts('Renew-Credit Card'),
239 'url' => 'civicrm/contact/view/membership',
240 'qs' => 'action=renew&reset=1&cid=%%cid%%&id=%%id%%&context=%%cxt%%&mode=live' . $extraParams,
241 'title' => ts('Renew Membership Using Credit Card'),
244 if (!$isPaymentProcessor ||
!$accessContribution) {
245 //unset the renew with credit card when payment
246 //processor is not available or user not permitted to make contributions
247 unset($extraLinks[CRM_Core_Action
::FOLLOWUP
]);
250 self
::$_links['all'] = self
::$_links['view'] +
$extraLinks;
253 if ($isCancelSupported) {
254 self
::$_links['all'][CRM_Core_Action
::DISABLE
] = array(
255 'name' => ts('Cancel Auto-renewal'),
256 'url' => 'civicrm/contribute/unsubscribe',
257 'qs' => 'reset=1&mid=%%id%%&context=%%cxt%%' . $extraParams,
258 'title' => 'Cancel Auto Renew Subscription',
261 elseif (isset(self
::$_links['all'][CRM_Core_Action
::DISABLE
])) {
262 unset(self
::$_links['all'][CRM_Core_Action
::DISABLE
]);
265 return self
::$_links[$status];
269 * Getter for array of the parameters required for creating pager.
272 * @param array $params
274 public 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';
289 * Returns total number of rows for the query.
294 * Total number of rows
296 public function getTotalCount($action) {
297 return $this->_query
->searchQuery(0, 0, NULL,
306 * Returns all the rows in the given offset and rowCount.
308 * @param string $action
309 * The action being performed.
311 * The row number to start from.
312 * @param int $rowCount
313 * The number of rows to return.
314 * @param string $sort
315 * The sql string that describes the sort order.
316 * @param string $output
317 * What should the result set include (web/email/csv).
320 * the total number of rows for this action
322 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
323 // check if we can process credit card registration
324 $processors = CRM_Core_PseudoConstant
::paymentProcessor(FALSE, FALSE,
325 "billing_mode IN ( 1, 3 )"
327 if (count($processors) > 0) {
328 $this->_isPaymentProcessor
= TRUE;
331 $this->_isPaymentProcessor
= FALSE;
334 // Only show credit card membership signup and renewal if user has CiviContribute permission
335 if (CRM_Core_Permission
::access('CiviContribute')) {
336 $this->_accessContribution
= TRUE;
339 $this->_accessContribution
= FALSE;
343 $allCampaigns = CRM_Campaign_BAO_Campaign
::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
345 $result = $this->_query
->searchQuery($offset, $rowCount, $sort,
352 // process the result of the query
355 //CRM-4418 check for view, edit, delete
356 $permissions = array(CRM_Core_Permission
::VIEW
);
357 if (CRM_Core_Permission
::check('edit memberships')) {
358 $permissions[] = CRM_Core_Permission
::EDIT
;
360 if (CRM_Core_Permission
::check('delete in CiviMember')) {
361 $permissions[] = CRM_Core_Permission
::DELETE
;
363 $mask = CRM_Core_Action
::mask($permissions);
365 while ($result->fetch()) {
368 // the columns we are interested in
369 foreach (self
::$_properties as $property) {
370 if (property_exists($result, $property)) {
371 $row[$property] = $result->$property;
375 //carry campaign on selectors.
376 $row['campaign'] = CRM_Utils_Array
::value($result->member_campaign_id
, $allCampaigns);
377 $row['campaign_id'] = $result->member_campaign_id
;
379 if (!empty($row['member_is_test'])) {
380 $row['membership_type'] = $row['membership_type'] . " (test)";
383 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->membership_id
;
385 if (!isset($result->owner_membership_id
)) {
386 // unset renew and followup link for deceased membership
387 $currentMask = $mask;
388 if ($result->membership_status
== 'Deceased') {
389 $currentMask = $currentMask & ~CRM_Core_Action
::RENEW
& ~CRM_Core_Action
::FOLLOWUP
;
392 $isCancelSupported = CRM_Member_BAO_Membership
::isCancelSubscriptionSupported($row['membership_id']);
393 if (!isset($result->owner_membership_id
)) {
394 $links = self
::links('all',
395 $this->_isPaymentProcessor
,
396 $this->_accessContribution
,
403 $links = self
::links('view');
406 $finTypeId = CRM_Core_DAO
::getFieldValue('CRM_Member_DAO_MembershipType', $result->membership_type_id
, 'financial_type_id');
407 $finType = CRM_Contribute_PseudoConstant
::financialType($finTypeId);
408 if (CRM_Financial_BAO_FinancialType
::isACLFinancialTypeStatus()
409 && !CRM_Core_Permission
::check('edit contributions of type ' . $finType)
411 unset($links[CRM_Core_Action
::UPDATE
]);
413 if (CRM_Financial_BAO_FinancialType
::isACLFinancialTypeStatus() &&
414 !CRM_Core_Permission
::check('delete contributions of type ' . $finType)
416 unset($links[CRM_Core_Action
::DELETE
]);
418 $row['action'] = CRM_Core_Action
::formLink($links,
421 'id' => $result->membership_id
,
422 'cid' => $result->contact_id
,
423 'cxt' => $this->_context
,
427 'membership.selector.row',
429 $result->membership_id
433 $row['action'] = CRM_Core_Action
::formLink($links, $mask,
435 'id' => $result->membership_id
,
436 'cid' => $result->contact_id
,
437 'cxt' => $this->_context
,
441 'membership.selector.row',
443 $result->membership_id
447 //does membership have auto renew CRM-7137.
449 if (isset($result->membership_recur_id
) && $result->membership_recur_id
&&
450 !CRM_Member_BAO_Membership
::isSubscriptionCancelled($row['membership_id'])
454 $row['auto_renew'] = $autoRenew;
456 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
$result->contact_sub_type
: $result->contact_type
, FALSE, $result->contact_id
468 public function getQILL() {
469 return $this->_query
->qill();
473 * Returns the column headers as an array of tuples.
475 * (name, sortName (key to the sort array))
477 * @param string $action
478 * The action being performed.
479 * @param string $output
480 * What should the result set include (web/email/csv).
483 * the column headers that need to be displayed
485 public function &getColumnHeaders($action = NULL, $output = NULL) {
486 if (!isset(self
::$_columnHeaders)) {
487 self
::$_columnHeaders = array(
489 'name' => ts('Type'),
490 'sort' => 'membership_type',
491 'direction' => CRM_Utils_Sort
::DONTCARE
,
494 'name' => ts('Member Since'),
495 'sort' => 'join_date',
496 'direction' => CRM_Utils_Sort
::DESCENDING
,
499 'name' => ts('Start Date'),
500 'sort' => 'membership_start_date',
501 'direction' => CRM_Utils_Sort
::DONTCARE
,
504 'name' => ts('End Date'),
505 'sort' => 'membership_end_date',
506 'direction' => CRM_Utils_Sort
::DONTCARE
,
509 'name' => ts('Source'),
510 'sort' => 'membership_source',
511 'direction' => CRM_Utils_Sort
::DONTCARE
,
514 'name' => ts('Status'),
515 'sort' => 'membership_status',
516 'direction' => CRM_Utils_Sort
::DONTCARE
,
519 'name' => ts('Auto-renew?'),
521 array('desc' => ts('Actions')),
524 if (!$this->_single
) {
526 array('desc' => ts('Contact Type')),
528 'name' => ts('Name'),
529 'sort' => 'sort_name',
530 'direction' => CRM_Utils_Sort
::DONTCARE
,
533 self
::$_columnHeaders = array_merge($pre, self
::$_columnHeaders);
536 return self
::$_columnHeaders;
544 public function alphabetQuery() {
545 return $this->_query
->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE);
553 public function &getQuery() {
554 return $this->_query
;
558 * Name of export file.
560 * @param string $output
566 public function getExportFileName($output = 'csv') {
567 return ts('CiviCRM Member Search');