5 +--------------------------------------------------------------------+
6 | CiviCRM version 4.3 |
7 +--------------------------------------------------------------------+
8 | Copyright CiviCRM LLC (c) 2004-2013 |
9 +--------------------------------------------------------------------+
10 | This file is a part of CiviCRM. |
12 | CiviCRM is free software; you can copy, modify, and distribute it |
13 | under the terms of the GNU Affero General Public License |
14 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
16 | CiviCRM is distributed in the hope that it will be useful, but |
17 | WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
19 | See the GNU Affero General Public License for more details. |
21 | You should have received a copy of the GNU Affero General Public |
22 | License and the CiviCRM Licensing Exception along |
23 | with this program; if not, contact CiviCRM LLC |
24 | at info[AT]civicrm[DOT]org. If you have questions about the |
25 | GNU Affero General Public License or the licensing of CiviCRM, |
26 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
27 +--------------------------------------------------------------------+
33 * @copyright CiviCRM LLC (c) 2004-2013
37 class CRM_Report_Form_Member_Lapse
extends CRM_Report_Form
{
39 protected $_summary = NULL;
40 protected $_addressField = FALSE;
41 protected $_emailField = FALSE;
42 protected $_phoneField = FALSE;
43 protected $_charts = array('' => 'Tabular');
44 protected $_customGroupExtends = array(
46 public $_drilldownReport = array('member/detail' => 'Link to Detail Report');
48 function __construct() {
49 // UI for selecting columns to appear in the report list
50 // array conatining the columns, group_bys and filters build and provided to Form
51 $this->_columns
= array(
54 'dao' => 'CRM_Contact_DAO_Contact',
58 array('title' => ts('Member Name'),
68 array('title' => ts('First Name'),
77 array('title' => ts('Last Name'),
86 'grouping' => 'contact-fields',
88 'civicrm_membership_type' =>
90 'dao' => 'CRM_Member_DAO_MembershipType',
91 'grouping' => 'member-fields',
97 'title' => ts('Membership Types'),
98 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
99 'options' => CRM_Member_PseudoConstant
::membershipType(),
103 'civicrm_membership' =>
105 'dao' => 'CRM_Member_DAO_Membership',
106 'grouping' => 'member-fields',
109 'membership_type_id' =>
111 'title' => 'Membership Type',
113 'type' => CRM_Utils_Type
::T_STRING
,
115 'membership_start_date' => array('title' => ts('Current Cycle Start Date'),
117 'membership_end_date' => array('title' => ts('Membership Lapse Date'),
123 'membership_end_date' =>
125 'title' => 'Lapsed Memberships',
126 'operatorType' => CRM_Report_Form
::OP_DATE
,
130 'civicrm_membership_status' =>
132 'dao' => 'CRM_Member_DAO_MembershipStatus',
133 'alias' => 'mem_status',
136 'name' => array('title' => ts('Current Status'),
140 'grouping' => 'member-fields',
144 'dao' => 'CRM_Core_DAO_Address',
147 'street_address' => NULL,
149 'postal_code' => NULL,
150 'state_province_id' =>
151 array('title' => ts('State/Province'),
154 array('title' => ts('Country'),
158 'grouping' => 'contact-fields',
162 'dao' => 'CRM_Core_DAO_Phone',
165 array('phone' => NULL),
166 'grouping' => 'contact-fields',
170 'dao' => 'CRM_Core_DAO_Email',
172 array('email' => NULL),
173 'grouping' => 'contact-fields',
177 'dao' => 'CRM_Contact_DAO_GroupContact',
183 'name' => 'group_id',
184 'title' => ts('Group'),
185 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
187 'options' => CRM_Core_PseudoConstant
::group(),
193 $this->_tagFilter
= TRUE;
194 parent
::__construct();
197 function preProcess() {
198 parent
::preProcess();
203 $this->_columnHeaders
= array();
204 foreach ($this->_columns
as $tableName => $table) {
205 if (array_key_exists('fields', $table)) {
206 foreach ($table['fields'] as $fieldName => $field) {
207 if (CRM_Utils_Array
::value('required', $field) ||
208 CRM_Utils_Array
::value($fieldName, $this->_params
['fields'])
210 // to include optional columns address ,email and phone only if checked
211 if ($tableName == 'civicrm_address') {
212 $this->_addressField
= TRUE;
214 elseif ($tableName == 'civicrm_email') {
215 $this->_emailField
= TRUE;
217 elseif ($tableName == 'civicrm_phone') {
218 $this->_phoneField
= TRUE;
220 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
221 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
222 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = $field['title'];
227 $this->_select
= "SELECT " . implode(', ', $select) . " ";
230 static function formRule($fields, $files, $self) {
231 $errors = $grouping = array();
232 //check for searching combination of dispaly columns and
242 FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}
243 INNER JOIN civicrm_membership {$this->_aliases['civicrm_membership']}
244 ON {$this->_aliases['civicrm_contact']}.id =
245 {$this->_aliases['civicrm_membership']}.contact_id AND {$this->_aliases['civicrm_membership']}.is_test = 0
246 LEFT JOIN civicrm_membership_status {$this->_aliases['civicrm_membership_status']}
247 ON {$this->_aliases['civicrm_membership_status']}.id =
248 {$this->_aliases['civicrm_membership']}.status_id
249 LEFT JOIN civicrm_membership_type {$this->_aliases['civicrm_membership_type']}
250 ON {$this->_aliases['civicrm_membership']}.membership_type_id =
251 {$this->_aliases['civicrm_membership_type']}.id";
253 // include address field if address column is to be included
254 if ($this->_addressField
) {
256 LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
257 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND {$this->_aliases['civicrm_address']}.is_primary = 1\n";
260 // include email field if email column is to be included
261 if ($this->_emailField
) {
263 LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
264 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND {$this->_aliases['civicrm_email']}.is_primary = 1\n";
267 // include phone field if phone column is to be included
268 if ($this->_phoneField
) {
270 LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
271 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id
272 AND {$this->_aliases['civicrm_phone']}.is_primary = 1\n";
278 foreach ($this->_columns
as $tableName => $table) {
279 if (array_key_exists('filters', $table)) {
280 foreach ($table['filters'] as $fieldName => $field) {
283 if ($field['operatorType'] & CRM_Utils_Type
::T_DATE
) {
284 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
285 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
286 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
288 if ($relative ||
$from ||
$to) {
289 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
293 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
295 $clause = $this->whereClause($field,
297 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
298 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
299 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
303 if (!empty($clause)) {
304 $clauses[$fieldName] = $clause;
310 if (empty($clauses)) {
311 $this->_where
= "WHERE end_date < '" . date('Y-m-d') . "' AND {$this->_aliases['civicrm_membership_status']}.name = 'Expired'";
314 if (!array_key_exists('end_date', $clauses)) {
315 $this->_where
= "WHERE end_date < '" . date('Y-m-d') . "' AND " . implode(' AND ', $clauses);
318 $this->_where
= "WHERE " . implode(' AND ', $clauses);
322 if ($this->_aclWhere
) {
323 $this->_where
.= " AND {$this->_aclWhere} ";
328 $this->_orderBy
= " ORDER BY {$this->_aliases['civicrm_contact']}.sort_name, {$this->_aliases['civicrm_contact']}.id, {$this->_aliases['civicrm_membership']}.membership_type_id";
331 function postProcess() {
332 $this->beginPostProcess();
334 // get the acl clauses built before we assemble the query
335 $this->buildACLClause($this->_aliases
['civicrm_contact']);
336 $sql = $this->buildQuery(TRUE);
338 $dao = CRM_Core_DAO
::executeQuery($sql);
339 $rows = $graphRows = array();
341 while ($dao->fetch()) {
343 foreach ($this->_columnHeaders
as $key => $value) {
344 $row[$key] = $dao->$key;
349 $this->formatDisplay($rows);
351 // assign variables to templates
352 $this->doTemplateAssignment($rows);
354 $this->endPostProcess($rows);
357 function alterDisplay(&$rows) {
358 // custom code to alter rows
360 $checkList = array();
362 foreach ($rows as $rowNum => $row) {
364 if (!empty($this->_noRepeats
) && $this->_outputMode
!= 'csv') {
365 // not repeat contact display names if it matches with the one
368 $repeatFound = FALSE;
369 foreach ($row as $colName => $colVal) {
370 if (CRM_Utils_Array
::value($colName, $checkList) &&
371 is_array($checkList[$colName]) &&
372 in_array($colVal, $checkList[$colName])
374 $rows[$rowNum][$colName] = "";
377 if (in_array($colName, $this->_noRepeats
)) {
378 $checkList[$colName][] = $colVal;
383 //handle the Membership Type Ids
384 if (array_key_exists('civicrm_membership_membership_type_id', $row)) {
385 if ($value = $row['civicrm_membership_membership_type_id']) {
386 $rows[$rowNum]['civicrm_membership_membership_type_id'] = CRM_Member_PseudoConstant
::membershipType($value, FALSE);
391 // handle state province
392 if (array_key_exists('civicrm_address_state_province_id', $row)) {
393 if ($value = $row['civicrm_address_state_province_id']) {
394 $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant
::stateProvince($value, FALSE);
400 if (array_key_exists('civicrm_address_country_id', $row)) {
401 if ($value = $row['civicrm_address_country_id']) {
402 $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant
::country($value, FALSE);
407 // convert display name to links
408 if (array_key_exists('civicrm_contact_sort_name', $row) &&
409 array_key_exists('civicrm_contact_id', $row)
411 $url = CRM_Report_Utils_Report
::getNextUrl('member/detail',
412 'reset=1&force=1&id_op=eq&id_value=' . $row['civicrm_contact_id'],
413 $this->_absoluteUrl
, $this->_id
, $this->_drilldownReport
415 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
416 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Membership Detail for this Contact.");
419 // skip looking further in rows, if first row itself doesn't
420 // have the column we need