_queryParams = &$queryParams; $this->_single = $single; $this->_limit = $limit; $this->_context = $context; $this->_memberClause = $memberClause; // type of selector $this->_action = $action; $this->_query = new CRM_Contact_BAO_Query($this->_queryParams, CRM_Member_BAO_Query::defaultReturnProperties(CRM_Contact_BAO_Query::MODE_MEMBER, FALSE ), NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_MEMBER ); $this->_query->_distinctComponentClause = " civicrm_membership.id"; $this->_query->_groupByComponentClause = " GROUP BY civicrm_membership.id "; } /** * This method returns the links that are given for each search row. * currently the links added for each row are * * - View * - Edit * * @param string $status * @param null $isPaymentProcessor * @param null $accessContribution * @param null $qfKey * @param null $context * @param bool $isCancelSupported * * @return array */ public static function &links( $status = 'all', $isPaymentProcessor = NULL, $accessContribution = NULL, $qfKey = NULL, $context = NULL, $isCancelSupported = FALSE ) { $extraParams = NULL; if ($context == 'search') { $extraParams .= '&compContext=membership'; } if ($qfKey) { $extraParams .= "&key={$qfKey}"; } if (!self::$_links['view']) { self::$_links['view'] = array( CRM_Core_Action::VIEW => array( 'name' => ts('View'), 'url' => 'civicrm/contact/view/membership', 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=view&context=%%cxt%%&selectedChild=member' . $extraParams, 'title' => ts('View Membership'), ), ); } if (!isset(self::$_links['all']) || !self::$_links['all']) { $extraLinks = array( CRM_Core_Action::UPDATE => array( 'name' => ts('Edit'), 'url' => 'civicrm/contact/view/membership', 'qs' => 'reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams, 'title' => ts('Edit Membership'), ), CRM_Core_Action::DELETE => array( 'name' => ts('Delete'), 'url' => 'civicrm/contact/view/membership', 'qs' => 'reset=1&action=delete&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams, 'title' => ts('Delete Membership'), ), CRM_Core_Action::RENEW => array( 'name' => ts('Renew'), 'url' => 'civicrm/contact/view/membership', 'qs' => 'reset=1&action=renew&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams, 'title' => ts('Renew Membership'), ), CRM_Core_Action::FOLLOWUP => array( 'name' => ts('Renew-Credit Card'), 'url' => 'civicrm/contact/view/membership', 'qs' => 'action=renew&reset=1&cid=%%cid%%&id=%%id%%&context=%%cxt%%&mode=live' . $extraParams, 'title' => ts('Renew Membership Using Credit Card'), ), ); if (!$isPaymentProcessor || !$accessContribution) { //unset the renew with credit card when payment //processor is not available or user not permitted to make contributions unset($extraLinks[CRM_Core_Action::FOLLOWUP]); } self::$_links['all'] = self::$_links['view'] + $extraLinks; } if ($isCancelSupported) { self::$_links['all'][CRM_Core_Action::DISABLE] = array( 'name' => ts('Cancel Auto-renewal'), 'url' => 'civicrm/contribute/unsubscribe', 'qs' => 'reset=1&mid=%%id%%&context=%%cxt%%' . $extraParams, 'title' => 'Cancel Auto Renew Subscription', ); } elseif (isset(self::$_links['all'][CRM_Core_Action::DISABLE])) { unset(self::$_links['all'][CRM_Core_Action::DISABLE]); } return self::$_links[$status]; } /** * Getter for array of the parameters required for creating pager. * * @param $action * @param array $params */ public function getPagerParams($action, &$params) { $params['status'] = ts('Member') . ' %%StatusMessage%%'; $params['csvString'] = NULL; if ($this->_limit) { $params['rowCount'] = $this->_limit; } else { $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT; } $params['buttonTop'] = 'PagerTopButton'; $params['buttonBottom'] = 'PagerBottomButton'; } /** * Returns total number of rows for the query. * * @param * * @return int * Total number of rows */ public function getTotalCount($action) { return $this->_query->searchQuery(0, 0, NULL, TRUE, FALSE, FALSE, FALSE, FALSE, $this->_memberClause ); } /** * Returns all the rows in the given offset and rowCount * * @param string $action * The action being performed. * @param int $offset * The row number to start from. * @param int $rowCount * The number of rows to return. * @param string $sort * The sql string that describes the sort order. * @param string $output * What should the result set include (web/email/csv). * * @return int * the total number of rows for this action */ public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) { // check if we can process credit card registration $processors = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, "billing_mode IN ( 1, 3 )" ); if (count($processors) > 0) { $this->_isPaymentProcessor = TRUE; } else { $this->_isPaymentProcessor = FALSE; } // Only show credit card membership signup and renewal if user has CiviContribute permission if (CRM_Core_Permission::access('CiviContribute')) { $this->_accessContribution = TRUE; } else { $this->_accessContribution = FALSE; } //get all campaigns. $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE); $result = $this->_query->searchQuery($offset, $rowCount, $sort, FALSE, FALSE, FALSE, FALSE, FALSE, $this->_memberClause ); // process the result of the query $rows = array(); //CRM-4418 check for view, edit, delete $permissions = array(CRM_Core_Permission::VIEW); if (CRM_Core_Permission::check('edit memberships')) { $permissions[] = CRM_Core_Permission::EDIT; } if (CRM_Core_Permission::check('delete in CiviMember')) { $permissions[] = CRM_Core_Permission::DELETE; } $mask = CRM_Core_Action::mask($permissions); while ($result->fetch()) { $row = array(); // the columns we are interested in foreach (self::$_properties as $property) { if (property_exists($result, $property)) { $row[$property] = $result->$property; } } //carry campaign on selectors. $row['campaign'] = CRM_Utils_Array::value($result->member_campaign_id, $allCampaigns); $row['campaign_id'] = $result->member_campaign_id; if (!empty($row['member_is_test'])) { $row['membership_type'] = $row['membership_type'] . " (test)"; } $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->membership_id; if (!isset($result->owner_membership_id)) { // unset renew and followup link for deceased membership $currentMask = $mask; if ($result->membership_status == 'Deceased') { $currentMask = $currentMask & ~CRM_Core_Action::RENEW & ~CRM_Core_Action::FOLLOWUP; } $isCancelSupported = CRM_Member_BAO_Membership::isCancelSubscriptionSupported($row['membership_id']); $row['action'] = CRM_Core_Action::formLink(self::links('all', $this->_isPaymentProcessor, $this->_accessContribution, $this->_key, $this->_context, $isCancelSupported ), $currentMask, array( 'id' => $result->membership_id, 'cid' => $result->contact_id, 'cxt' => $this->_context, ), ts('more'), FALSE, 'membership.selector.row', 'Membership', $result->membership_id ); } else { $row['action'] = CRM_Core_Action::formLink(self::links('view'), $mask, array( 'id' => $result->membership_id, 'cid' => $result->contact_id, 'cxt' => $this->_context, ), ts('more'), FALSE, 'membership.selector.row', 'Membership', $result->membership_id ); } //does membership have auto renew CRM-7137. $autoRenew = FALSE; if (isset($result->membership_recur_id) && $result->membership_recur_id && !CRM_Member_BAO_Membership::isSubscriptionCancelled($row['membership_id']) ) { $autoRenew = TRUE; } $row['auto_renew'] = $autoRenew; $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, FALSE, $result->contact_id ); $rows[] = $row; } return $rows; } /** * @inheritDoc */ public function getQILL() { return $this->_query->qill(); } /** * Returns the column headers as an array of tuples: * (name, sortName (key to the sort array)) * * @param string $action * The action being performed. * @param string $output * What should the result set include (web/email/csv). * * @return array * the column headers that need to be displayed */ public function &getColumnHeaders($action = NULL, $output = NULL) { if (!isset(self::$_columnHeaders)) { self::$_columnHeaders = array( array( 'name' => ts('Type'), 'sort' => 'membership_type', 'direction' => CRM_Utils_Sort::DONTCARE, ), array( 'name' => ts('Member Since'), 'sort' => 'join_date', 'direction' => CRM_Utils_Sort::DESCENDING, ), array( 'name' => ts('Start Date'), 'sort' => 'membership_start_date', 'direction' => CRM_Utils_Sort::DONTCARE, ), array( 'name' => ts('End Date'), 'sort' => 'membership_end_date', 'direction' => CRM_Utils_Sort::DONTCARE, ), array( 'name' => ts('Source'), 'sort' => 'membership_source', 'direction' => CRM_Utils_Sort::DONTCARE, ), array( 'name' => ts('Status'), 'sort' => 'membership_status', 'direction' => CRM_Utils_Sort::DONTCARE, ), array( 'name' => ts('Auto-renew?'), ), array('desc' => ts('Actions')), ); if (!$this->_single) { $pre = array( array('desc' => ts('Contact Type')), array( 'name' => ts('Name'), 'sort' => 'sort_name', 'direction' => CRM_Utils_Sort::DONTCARE, ), ); self::$_columnHeaders = array_merge($pre, self::$_columnHeaders); } } return self::$_columnHeaders; } /** * @return mixed */ public function alphabetQuery() { return $this->_query->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE); } /** * @return string */ public function &getQuery() { return $this->_query; } /** * Name of export file. * * @param string $output * Type of output. * * @return string * name of the file */ public function getExportFileName($output = 'csv') { return ts('CiviCRM Member Search'); } }