3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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
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.
49 static $_links = NULL;
52 * We use desc to remind us what that column is, name is used in the tpl
56 static $_columnHeaders;
59 * Properties of contact we're interested in displaying
62 static $_properties = array(
69 'membership_start_date',
70 'membership_end_date',
74 'owner_membership_id',
80 * Are we restricting ourselves to a single contact
84 protected $_single = FALSE;
87 * Are we restricting ourselves to a single contact
91 protected $_limit = NULL;
94 * What context are we being invoked from
98 protected $_context = NULL;
101 * QueryParams is the array returned by exportValues called on
102 * the HTML_QuickForm_Controller for that page.
106 public $_queryParams;
109 * Represent the type of selector.
116 * The additional clause that we restrict the search with.
120 protected $_memberClause = NULL;
132 * @param array $queryParams
133 * Array of parameters for query.
134 * @param \const|int $action - action of search basic or advanced.
135 * @param string $memberClause
136 * If the caller wants to further restrict the search (used in memberships).
137 * @param bool $single
138 * Are we dealing only with one contact?.
140 * How many memberships do we want returned.
142 * @param string $context
144 * @return \CRM_Member_Selector_Search
146 public function __construct(
148 $action = CRM_Core_Action
::NONE
,
149 $memberClause = NULL,
154 // submitted form values
155 $this->_queryParams
= &$queryParams;
157 $this->_single
= $single;
158 $this->_limit
= $limit;
159 $this->_context
= $context;
161 $this->_memberClause
= $memberClause;
164 $this->_action
= $action;
166 $this->_query
= new CRM_Contact_BAO_Query($this->_queryParams
,
167 CRM_Member_BAO_Query
::defaultReturnProperties(CRM_Contact_BAO_Query
::MODE_MEMBER
,
171 CRM_Contact_BAO_Query
::MODE_MEMBER
173 $this->_query
->_distinctComponentClause
= " civicrm_membership.id";
174 $this->_query
->_groupByComponentClause
= " GROUP BY civicrm_membership.id ";
178 * This method returns the links that are given for each search row.
179 * currently the links added for each row are
184 * @param string $status
185 * @param null $isPaymentProcessor
186 * @param null $accessContribution
188 * @param null $context
189 * @param bool $isCancelSupported
193 public static function &links(
195 $isPaymentProcessor = NULL,
196 $accessContribution = NULL,
199 $isCancelSupported = FALSE
202 if ($context == 'search') {
203 $extraParams .= '&compContext=membership';
206 $extraParams .= "&key={$qfKey}";
209 if (!self
::$_links['view']) {
210 self
::$_links['view'] = array(
211 CRM_Core_Action
::VIEW
=> array(
212 'name' => ts('View'),
213 'url' => 'civicrm/contact/view/membership',
214 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=view&context=%%cxt%%&selectedChild=member' . $extraParams,
215 'title' => ts('View Membership'),
219 if (!isset(self
::$_links['all']) ||
!self
::$_links['all']) {
221 CRM_Core_Action
::UPDATE
=> array(
222 'name' => ts('Edit'),
223 'url' => 'civicrm/contact/view/membership',
224 'qs' => 'reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
225 'title' => ts('Edit Membership'),
227 CRM_Core_Action
::DELETE
=> array(
228 'name' => ts('Delete'),
229 'url' => 'civicrm/contact/view/membership',
230 'qs' => 'reset=1&action=delete&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
231 'title' => ts('Delete Membership'),
233 CRM_Core_Action
::RENEW
=> array(
234 'name' => ts('Renew'),
235 'url' => 'civicrm/contact/view/membership',
236 'qs' => 'reset=1&action=renew&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
237 'title' => ts('Renew Membership'),
239 CRM_Core_Action
::FOLLOWUP
=> array(
240 'name' => ts('Renew-Credit Card'),
241 'url' => 'civicrm/contact/view/membership',
242 'qs' => 'action=renew&reset=1&cid=%%cid%%&id=%%id%%&context=%%cxt%%&mode=live' . $extraParams,
243 'title' => ts('Renew Membership Using Credit Card'),
246 if (!$isPaymentProcessor ||
!$accessContribution) {
247 //unset the renew with credit card when payment
248 //processor is not available or user not permitted to make contributions
249 unset($extraLinks[CRM_Core_Action
::FOLLOWUP
]);
252 self
::$_links['all'] = self
::$_links['view'] +
$extraLinks;
255 if ($isCancelSupported) {
256 self
::$_links['all'][CRM_Core_Action
::DISABLE
] = array(
257 'name' => ts('Cancel Auto-renewal'),
258 'url' => 'civicrm/contribute/unsubscribe',
259 'qs' => 'reset=1&mid=%%id%%&context=%%cxt%%' . $extraParams,
260 'title' => 'Cancel Auto Renew Subscription',
263 elseif (isset(self
::$_links['all'][CRM_Core_Action
::DISABLE
])) {
264 unset(self
::$_links['all'][CRM_Core_Action
::DISABLE
]);
267 return self
::$_links[$status];
271 * Getter for array of the parameters required for creating pager.
274 * @param array $params
276 public function getPagerParams($action, &$params) {
277 $params['status'] = ts('Member') . ' %%StatusMessage%%';
278 $params['csvString'] = NULL;
280 $params['rowCount'] = $this->_limit
;
283 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
286 $params['buttonTop'] = 'PagerTopButton';
287 $params['buttonBottom'] = 'PagerBottomButton';
291 * Returns total number of rows for the query.
296 * Total number of rows
298 public function getTotalCount($action) {
299 return $this->_query
->searchQuery(0, 0, NULL,
308 * Returns all the rows in the given offset and rowCount.
310 * @param string $action
311 * The action being performed.
313 * The row number to start from.
314 * @param int $rowCount
315 * The number of rows to return.
316 * @param string $sort
317 * The sql string that describes the sort order.
318 * @param string $output
319 * What should the result set include (web/email/csv).
322 * the total number of rows for this action
324 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
325 // check if we can process credit card registration
326 $processors = CRM_Core_PseudoConstant
::paymentProcessor(FALSE, FALSE,
327 "billing_mode IN ( 1, 3 )"
329 if (count($processors) > 0) {
330 $this->_isPaymentProcessor
= TRUE;
333 $this->_isPaymentProcessor
= FALSE;
336 // Only show credit card membership signup and renewal if user has CiviContribute permission
337 if (CRM_Core_Permission
::access('CiviContribute')) {
338 $this->_accessContribution
= TRUE;
341 $this->_accessContribution
= FALSE;
345 $allCampaigns = CRM_Campaign_BAO_Campaign
::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
347 $result = $this->_query
->searchQuery($offset, $rowCount, $sort,
354 // process the result of the query
357 //CRM-4418 check for view, edit, delete
358 $permissions = array(CRM_Core_Permission
::VIEW
);
359 if (CRM_Core_Permission
::check('edit memberships')) {
360 $permissions[] = CRM_Core_Permission
::EDIT
;
362 if (CRM_Core_Permission
::check('delete in CiviMember')) {
363 $permissions[] = CRM_Core_Permission
::DELETE
;
365 $mask = CRM_Core_Action
::mask($permissions);
367 while ($result->fetch()) {
370 // the columns we are interested in
371 foreach (self
::$_properties as $property) {
372 if (property_exists($result, $property)) {
373 $row[$property] = $result->$property;
377 //carry campaign on selectors.
378 $row['campaign'] = CRM_Utils_Array
::value($result->member_campaign_id
, $allCampaigns);
379 $row['campaign_id'] = $result->member_campaign_id
;
381 if (!empty($row['member_is_test'])) {
382 $row['membership_type'] = $row['membership_type'] . " (test)";
385 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->membership_id
;
387 if (!isset($result->owner_membership_id
)) {
388 // unset renew and followup link for deceased membership
389 $currentMask = $mask;
390 if ($result->membership_status
== 'Deceased') {
391 $currentMask = $currentMask & ~CRM_Core_Action
::RENEW
& ~CRM_Core_Action
::FOLLOWUP
;
394 $isCancelSupported = CRM_Member_BAO_Membership
::isCancelSubscriptionSupported($row['membership_id']);
395 $row['action'] = CRM_Core_Action
::formLink(self
::links('all',
396 $this->_isPaymentProcessor
,
397 $this->_accessContribution
,
404 'id' => $result->membership_id
,
405 'cid' => $result->contact_id
,
406 'cxt' => $this->_context
,
410 'membership.selector.row',
412 $result->membership_id
416 $row['action'] = CRM_Core_Action
::formLink(self
::links('view'), $mask,
418 'id' => $result->membership_id
,
419 'cid' => $result->contact_id
,
420 'cxt' => $this->_context
,
424 'membership.selector.row',
426 $result->membership_id
430 //does membership have auto renew CRM-7137.
432 if (isset($result->membership_recur_id
) && $result->membership_recur_id
&&
433 !CRM_Member_BAO_Membership
::isSubscriptionCancelled($row['membership_id'])
437 $row['auto_renew'] = $autoRenew;
439 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
$result->contact_sub_type
: $result->contact_type
, FALSE, $result->contact_id
451 public function getQILL() {
452 return $this->_query
->qill();
456 * Returns the column headers as an array of tuples:
457 * (name, sortName (key to the sort array))
459 * @param string $action
460 * The action being performed.
461 * @param string $output
462 * What should the result set include (web/email/csv).
465 * the column headers that need to be displayed
467 public function &getColumnHeaders($action = NULL, $output = NULL) {
468 if (!isset(self
::$_columnHeaders)) {
469 self
::$_columnHeaders = array(
471 'name' => ts('Type'),
472 'sort' => 'membership_type',
473 'direction' => CRM_Utils_Sort
::DONTCARE
,
476 'name' => ts('Member Since'),
477 'sort' => 'join_date',
478 'direction' => CRM_Utils_Sort
::DESCENDING
,
481 'name' => ts('Start Date'),
482 'sort' => 'membership_start_date',
483 'direction' => CRM_Utils_Sort
::DONTCARE
,
486 'name' => ts('End Date'),
487 'sort' => 'membership_end_date',
488 'direction' => CRM_Utils_Sort
::DONTCARE
,
491 'name' => ts('Source'),
492 'sort' => 'membership_source',
493 'direction' => CRM_Utils_Sort
::DONTCARE
,
496 'name' => ts('Status'),
497 'sort' => 'membership_status',
498 'direction' => CRM_Utils_Sort
::DONTCARE
,
501 'name' => ts('Auto-renew?'),
503 array('desc' => ts('Actions')),
506 if (!$this->_single
) {
508 array('desc' => ts('Contact Type')),
510 'name' => ts('Name'),
511 'sort' => 'sort_name',
512 'direction' => CRM_Utils_Sort
::DONTCARE
,
515 self
::$_columnHeaders = array_merge($pre, self
::$_columnHeaders);
518 return self
::$_columnHeaders;
524 public function alphabetQuery() {
525 return $this->_query
->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE);
531 public function &getQuery() {
532 return $this->_query
;
536 * Name of export file.
538 * @param string $output
544 public function getExportFileName($output = 'csv') {
545 return ts('CiviCRM Member Search');