diff --git a/CRM/Membershipchurnchart/Page/MembershipChurnChart.php b/CRM/Membershipchurnchart/Page/MembershipChurnChart.php index 5c89272..8ae383e 100644 --- a/CRM/Membershipchurnchart/Page/MembershipChurnChart.php +++ b/CRM/Membershipchurnchart/Page/MembershipChurnChart.php @@ -5,7 +5,6 @@ class CRM_Membershipchurnchart_Page_MembershipChurnChart extends CRM_Core_Page { function run() { - CRM_Core_Session::singleton()->replaceUserContext(CRM_Utils_System::url('civicrm/membership/membershipchurnchart', "reset=1")); $chartData = []; @@ -14,9 +13,8 @@ function run() { $sql = "SELECT * FROM civicrm_membership_churn_monthly_table ORDER BY year, month"; $sqlRes = CRM_Core_DAO::executeQuery($sql); - $totalStats = $years = []; + $years = []; while($sqlRes->fetch()) { - $years[$sqlRes->year] = $sqlRes->year; $data = []; @@ -62,7 +60,7 @@ function run() { $this->assign('endYearRange', $endYearOptions); // Membership types filter - $memTypes = CRM_Membershipchurnchart_Utils::getAllmembershipTypes(); + $memTypes = CRM_Member_PseudoConstant::membershipType(); $this->assign('memTypes', $memTypes); // All status to be displayed as legends diff --git a/CRM/Membershipchurnchart/Utils.php b/CRM/Membershipchurnchart/Utils.php index 074f3d2..7b7ef70 100644 --- a/CRM/Membershipchurnchart/Utils.php +++ b/CRM/Membershipchurnchart/Utils.php @@ -1,68 +1,36 @@ get('membershipchurnchart_startyear'); + if (empty($startYear)) { // Start year not set // So get min and max year from civicrm_membership table $sql = "SELECT YEAR(MIN(join_date)) as min_join_date FROM civicrm_membership"; $sqlRes = CRM_Core_DAO::executeQuery($sql); $sqlRes->fetch(); - $start_year = $sqlRes->min_join_date; + $startYear = $sqlRes->min_join_date; + \Civi::settings()->set('membershipchurnchart_startyear', $startYear); } $end_year = date('Y'); // Current year $end_month = date('n'); // Current month // Get data for one month before the start year, to get the brought forward value - $startMonthYear = "{$start_year}-01"; + $startMonthYear = "{$startYear}-01"; $previous_month = date("m", strtotime($startMonthYear. " -1 months")); $previous_year = date("Y", strtotime($startMonthYear. " -1 months")); self::insertDataIntoChurnTable($previous_year, $previous_month); - for ($i = $start_year; $i <= $end_year; $i++) { + for ($i = $startYear; $i <= $end_year; $i++) { for ($j = 1; $j <= 12; $j++) { self::insertDataIntoChurnTable($i, $j); } @@ -149,13 +117,12 @@ public static function prepareChurnTable() { // to get brought forward value $deleteSql = "DELETE FROM civicrm_membership_churn_monthly_table WHERE year < %1"; $deleteParams = [ - 1 => [$start_year, 'Integer'], + 1 => [$startYear, 'Integer'], ]; CRM_Core_DAO::executeQuery($deleteSql, $deleteParams); } public static function insertDataIntoChurnTable($year, $month) { - if (empty($year) || empty($month)) { return; } @@ -219,8 +186,8 @@ public static function insertDataIntoChurnTable($year, $month) { CRM_Core_DAO::executeQuery($rejoinedSql); } - public static function getAllMemberStatusesForChart(){ - return [/*'Brought Forward',*/'Current', 'Joined', 'Resigned', 'Rejoined']; + public static function getAllMemberStatusesForChart() { + return ['Current', 'Joined', 'Resigned', 'Rejoined']; } public static function getMinChurnValuesForYaxis($row){ @@ -237,7 +204,4 @@ public static function getMinChurnValuesForYaxis($row){ return $allChurns; } - public static function getAllmembershipTypes(){ - return CRM_Member_PseudoConstant::membershipType(); - } } diff --git a/LICENSE.txt b/LICENSE.txt index 00cab73..d4fb3f1 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,5 +1,5 @@ Package: uk.co.vedaconsulting.membershipchurnchart -Copyright (C) 2016, FIXME +Copyright (C) 2020, CiviCRM LLC Licensed under the GNU Affero Public License 3.0 (below). ------------------------------------------------------------------------------- diff --git a/settings/membershipchurnchart.setting.php b/settings/membershipchurnchart.setting.php index e162995..1e36d5f 100644 --- a/settings/membershipchurnchart.setting.php +++ b/settings/membershipchurnchart.setting.php @@ -16,7 +16,7 @@ 'name' => 'membershipchurnchart_startyear', 'type' => 'String', 'html_type' => 'text', - 'default' => '2010', + 'default' => '', 'is_domain' => 1, 'is_contact' => 0, 'title' => E::ts('Start Year'), diff --git a/sql/auto_uninstall.sql b/sql/auto_uninstall.sql index cc97d65..b90acc9 100644 --- a/sql/auto_uninstall.sql +++ b/sql/auto_uninstall.sql @@ -1,6 +1,3 @@ -- Delete churn data tables DROP TABLE IF EXISTS `civicrm_membership_churn_table`; DROP TABLE IF EXISTS `civicrm_membership_churn_monthly_table`; - --- Delete scheduled job -DELETE FROM civicrm_job WHERE api_entity = 'membershipchurnchart' AND api_action = 'preparechurntable';