3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
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
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 \const|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 * @param string $context
148 * @return \CRM_Member_Selector_Search
151 function __construct(&$queryParams,
152 $action = CRM_Core_Action
::NONE
,
153 $memberClause = NULL,
158 // submitted form values
159 $this->_queryParams
= &$queryParams;
161 $this->_single
= $single;
162 $this->_limit
= $limit;
163 $this->_context
= $context;
165 $this->_memberClause
= $memberClause;
168 $this->_action
= $action;
170 $this->_query
= new CRM_Contact_BAO_Query($this->_queryParams
,
171 CRM_Member_BAO_Query
::defaultReturnProperties(CRM_Contact_BAO_Query
::MODE_MEMBER
,
175 CRM_Contact_BAO_Query
::MODE_MEMBER
177 $this->_query
->_distinctComponentClause
= " civicrm_membership.id";
178 $this->_query
->_groupByComponentClause
= " GROUP BY civicrm_membership.id ";
183 * This method returns the links that are given for each search row.
184 * currently the links added for each row are
189 * @param string $status
190 * @param null $isPaymentProcessor
191 * @param null $accessContribution
193 * @param null $context
194 * @param bool $isCancelSupported
200 function &links($status = 'all',
201 $isPaymentProcessor = NULL,
202 $accessContribution = NULL,
205 $isCancelSupported = FALSE
208 if ($context == 'search') {
209 $extraParams .= '&compContext=membership';
212 $extraParams .= "&key={$qfKey}";
215 if (!self
::$_links['view']) {
216 self
::$_links['view'] = array(
217 CRM_Core_Action
::VIEW
=> array(
218 'name' => ts('View'),
219 'url' => 'civicrm/contact/view/membership',
220 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=view&context=%%cxt%%&selectedChild=member' . $extraParams,
221 'title' => ts('View Membership'),
225 if (!isset(self
::$_links['all']) ||
!self
::$_links['all']) {
227 CRM_Core_Action
::UPDATE
=> array(
228 'name' => ts('Edit'),
229 'url' => 'civicrm/contact/view/membership',
230 'qs' => 'reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
231 'title' => ts('Edit Membership'),
233 CRM_Core_Action
::DELETE
=> array(
234 'name' => ts('Delete'),
235 'url' => 'civicrm/contact/view/membership',
236 'qs' => 'reset=1&action=delete&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
237 'title' => ts('Delete Membership'),
239 CRM_Core_Action
::RENEW
=> array(
240 'name' => ts('Renew'),
241 'url' => 'civicrm/contact/view/membership',
242 'qs' => 'reset=1&action=renew&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
243 'title' => ts('Renew Membership'),
245 CRM_Core_Action
::FOLLOWUP
=> array(
246 'name' => ts('Renew-Credit Card'),
247 'url' => 'civicrm/contact/view/membership',
248 'qs' => 'action=renew&reset=1&cid=%%cid%%&id=%%id%%&context=%%cxt%%&mode=live' . $extraParams,
249 'title' => ts('Renew Membership Using Credit Card'),
252 if (!$isPaymentProcessor ||
!$accessContribution) {
253 //unset the renew with credit card when payment
254 //processor is not available or user not permitted to make contributions
255 unset($extraLinks[CRM_Core_Action
::FOLLOWUP
]);
258 self
::$_links['all'] = self
::$_links['view'] +
$extraLinks;
261 if ($isCancelSupported) {
262 self
::$_links['all'][CRM_Core_Action
::DISABLE
] = array(
263 'name' => ts('Cancel Auto-renewal'),
264 'url' => 'civicrm/contribute/unsubscribe',
265 'qs' => 'reset=1&mid=%%id%%&context=%%cxt%%' . $extraParams,
266 'title' => 'Cancel Auto Renew Subscription',
269 elseif (isset(self
::$_links['all'][CRM_Core_Action
::DISABLE
])) {
270 unset(self
::$_links['all'][CRM_Core_Action
::DISABLE
]);
273 return self
::$_links[$status];
278 * getter for array of the parameters required for creating pager.
285 function getPagerParams($action, &$params) {
286 $params['status'] = ts('Member') . ' %%StatusMessage%%';
287 $params['csvString'] = NULL;
289 $params['rowCount'] = $this->_limit
;
292 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
295 $params['buttonTop'] = 'PagerTopButton';
296 $params['buttonBottom'] = 'PagerBottomButton';
301 * Returns total number of rows for the query.
305 * @return int Total number of rows
308 function getTotalCount($action) {
309 return $this->_query
->searchQuery(0, 0, NULL,
318 * returns all the rows in the given offset and rowCount
320 * @param enum $action the action being performed
321 * @param int $offset the row number to start from
322 * @param int $rowCount the number of rows to return
323 * @param string $sort the sql string that describes the sort order
324 * @param enum $output what should the result set include (web/email/csv)
326 * @return int the total number of rows for this action
328 function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
329 // check if we can process credit card registration
330 $processors = CRM_Core_PseudoConstant
::paymentProcessor(FALSE, FALSE,
331 "billing_mode IN ( 1, 3 )"
333 if (count($processors) > 0) {
334 $this->_isPaymentProcessor
= TRUE;
337 $this->_isPaymentProcessor
= FALSE;
340 // Only show credit card membership signup and renewal if user has CiviContribute permission
341 if (CRM_Core_Permission
::access('CiviContribute')) {
342 $this->_accessContribution
= TRUE;
345 $this->_accessContribution
= FALSE;
349 $allCampaigns = CRM_Campaign_BAO_Campaign
::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
351 $result = $this->_query
->searchQuery($offset, $rowCount, $sort,
358 // process the result of the query
361 //CRM-4418 check for view, edit, delete
362 $permissions = array(CRM_Core_Permission
::VIEW
);
363 if (CRM_Core_Permission
::check('edit memberships')) {
364 $permissions[] = CRM_Core_Permission
::EDIT
;
366 if (CRM_Core_Permission
::check('delete in CiviMember')) {
367 $permissions[] = CRM_Core_Permission
::DELETE
;
369 $mask = CRM_Core_Action
::mask($permissions);
371 while ($result->fetch()) {
374 // the columns we are interested in
375 foreach (self
::$_properties as $property) {
376 if (property_exists($result, $property)) {
377 $row[$property] = $result->$property;
381 //carry campaign on selectors.
382 $row['campaign'] = CRM_Utils_Array
::value($result->member_campaign_id
, $allCampaigns);
383 $row['campaign_id'] = $result->member_campaign_id
;
385 if (!empty($row['member_is_test'])) {
386 $row['membership_type'] = $row['membership_type'] . " (test)";
389 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->membership_id
;
391 if (!isset($result->owner_membership_id
)) {
392 // unset renew and followup link for deceased membership
393 $currentMask = $mask;
394 if ($result->membership_status
== 'Deceased') {
395 $currentMask = $currentMask & ~CRM_Core_Action
::RENEW
& ~CRM_Core_Action
::FOLLOWUP
;
398 $isCancelSupported = CRM_Member_BAO_Membership
::isCancelSubscriptionSupported($row['membership_id']);
399 $row['action'] = CRM_Core_Action
::formLink(self
::links('all',
400 $this->_isPaymentProcessor
,
401 $this->_accessContribution
,
408 'id' => $result->membership_id
,
409 'cid' => $result->contact_id
,
410 'cxt' => $this->_context
,
414 'membership.selector.row',
416 $result->membership_id
420 $row['action'] = CRM_Core_Action
::formLink(self
::links('view'), $mask,
422 'id' => $result->membership_id
,
423 'cid' => $result->contact_id
,
424 'cxt' => $this->_context
,
428 'membership.selector.row',
430 $result->membership_id
434 //does membership have auto renew CRM-7137.
436 if (isset($result->membership_recur_id
) && $result->membership_recur_id
&&
437 !CRM_Member_BAO_Membership
::isSubscriptionCancelled($row['membership_id'])
441 $row['auto_renew'] = $autoRenew;
443 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
444 $result->contact_sub_type
: $result->contact_type
, FALSE, $result->contact_id
455 * @return array $qill which contains an array of strings
459 // the current internationalisation is bad, but should more or less work
460 // for most of "European" languages
461 public function getQILL() {
462 return $this->_query
->qill();
466 * returns the column headers as an array of tuples:
467 * (name, sortName (key to the sort array))
469 * @param string $action the action being performed
470 * @param enum $output what should the result set include (web/email/csv)
472 * @return array the column headers that need to be displayed
475 public function &getColumnHeaders($action = NULL, $output = NULL) {
476 if (!isset(self
::$_columnHeaders)) {
477 self
::$_columnHeaders = array(
479 'name' => ts('Type'),
480 'sort' => 'membership_type',
481 'direction' => CRM_Utils_Sort
::DONTCARE
,
483 array('name' => ts('Member Since'),
484 'sort' => 'join_date',
485 'direction' => CRM_Utils_Sort
::DESCENDING
,
488 'name' => ts('Start Date'),
489 'sort' => 'membership_start_date',
490 'direction' => CRM_Utils_Sort
::DONTCARE
,
493 'name' => ts('End Date'),
494 'sort' => 'membership_end_date',
495 'direction' => CRM_Utils_Sort
::DONTCARE
,
498 'name' => ts('Source'),
499 'sort' => 'membership_source',
500 'direction' => CRM_Utils_Sort
::DONTCARE
,
503 'name' => ts('Status'),
504 'sort' => 'membership_status',
505 'direction' => CRM_Utils_Sort
::DONTCARE
,
508 'name' => ts('Auto-renew?'),
510 array('desc' => ts('Actions')),
513 if (!$this->_single
) {
515 array('desc' => ts('Contact Type')),
517 'name' => ts('Name'),
518 'sort' => 'sort_name',
519 'direction' => CRM_Utils_Sort
::DONTCARE
,
522 self
::$_columnHeaders = array_merge($pre, self
::$_columnHeaders);
525 return self
::$_columnHeaders;
531 function alphabetQuery() {
532 return $this->_query
->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE);
538 function &getQuery() {
539 return $this->_query
;
543 * name of export file.
545 * @param string $output type of output
547 * @return string name of the file
549 function getExportFileName($output = 'csv') {
550 return ts('CiviCRM Member Search');