First commit

This commit is contained in:
Theodotos Andreou 2018-01-14 13:10:16 +00:00
commit c6e2478c40
13918 changed files with 2303184 additions and 0 deletions

View file

@ -0,0 +1,73 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
* $Id$
*
*/
/**
* This class contains all the function that are called using AJAX (dojo)
*/
class CRM_Member_Page_AJAX {
/**
* SetDefaults according to membership type.
*/
public static function getMemberTypeDefaults() {
if (!$_POST['mtype']) {
$details['name'] = '';
$details['auto_renew'] = '';
$details['total_amount'] = '';
CRM_Utils_JSON::output($details);
}
$memType = CRM_Utils_Type::escape($_POST['mtype'], 'Integer');
$query = "SELECT name, minimum_fee AS total_amount, financial_type_id, auto_renew
FROM civicrm_membership_type
WHERE id = %1";
$dao = CRM_Core_DAO::executeQuery($query, array(1 => array($memType, 'Positive')));
$properties = array('financial_type_id', 'total_amount', 'name', 'auto_renew');
while ($dao->fetch()) {
foreach ($properties as $property) {
$details[$property] = $dao->$property;
}
}
$details['total_amount_numeric'] = $details['total_amount'];
// fix the display of the monetary value, CRM-4038
$details['total_amount'] = CRM_Utils_Money::format($details['total_amount'], NULL, '%a');
$options = CRM_Core_SelectValues::memberAutoRenew();
$details['auto_renew'] = CRM_Utils_Array::value('auto_renew', $options[$details]);
CRM_Utils_JSON::output($details);
}
}

View file

@ -0,0 +1,461 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
* $Id$
*
*/
/**
* Page for displaying list of Payment-Instrument
*/
class CRM_Member_Page_DashBoard extends CRM_Core_Page {
/**
* Heart of the viewing process. The runner gets all the meta data for
* the contact and calls the appropriate type of page to view.
*
* @return void
*/
public function preProcess() {
//CRM-13901 don't show dashboard to contacts with limited view writes & it does not relect
//what they have access to
//@todo implement acls on dashboard querys (preferably via api to enhance that at the same time)
if (!CRM_Core_Permission::check('view all contacts') && !CRM_Core_Permission::check('edit all contacts')) {
$this->showMembershipSummary = FALSE;
$this->assign('membershipSummary', FALSE);
return;
}
$this->assign('membershipSummary', TRUE);
CRM_Utils_System::setTitle(ts('CiviMember'));
$membershipSummary = array();
$preMonth = date("Y-m-d", mktime(0, 0, 0, date("m") - 1, 01, date("Y")));
$preMonthEnd = date("Y-m-t", mktime(0, 0, 0, date("m") - 1, 01, date("Y")));
$preMonthYear = mktime(0, 0, 0, substr($preMonth, 4, 2), 1, substr($preMonth, 0, 4));
$today = getdate();
$date = CRM_Utils_Date::getToday();
$isCurrentMonth = 0;
// You can force the dashboard to display based upon a certain date
$ym = CRM_Utils_Array::value('date', $_GET);
if ($ym) {
if (preg_match('/^\d{6}$/', $ym) == 0 ||
!checkdate(substr($ym, 4, 2), 1, substr($ym, 0, 4)) ||
substr($ym, 0, 1) == 0
) {
CRM_Core_Error::fatal(ts('Invalid date query "%1" in URL (valid syntax is yyyymm).', array(1 => $ym)));
}
$isPreviousMonth = 0;
$isCurrentMonth = substr($ym, 0, 4) == $today['year'] && substr($ym, 4, 2) == $today['mon'];
$ymd = date('Y-m-d', mktime(0, 0, -1, substr($ym, 4, 2) + 1, 1, substr($ym, 0, 4)));
$monthStartTs = mktime(0, 0, 0, substr($ym, 4, 2), 1, substr($ym, 0, 4));
$current = CRM_Utils_Date::customFormat($date, '%Y-%m-%d');
$ym = substr($ym, 0, 4) . '-' . substr($ym, 4, 2);
}
else {
$ym = sprintf("%04d-%02d", $today['year'], $today['mon']);
$ymd = sprintf("%04d-%02d-%02d", $today['year'], $today['mon'], $today['mday']);
$monthStartTs = mktime(0, 0, 0, $today['mon'], 1, $today['year']);
$current = CRM_Utils_Date::customFormat($date, '%Y-%m-%d');
$isCurrentMonth = 1;
$isPreviousMonth = 1;
}
$monthStart = $ym . '-01';
$yearStart = substr($ym, 0, 4) . '-01-01';
$membershipTypes = CRM_Member_BAO_MembershipType::getMembershipTypes(FALSE);
// added
//$membership = new CRM_Member_BAO_Membership;
foreach ($membershipTypes as $key => $value) {
$membershipSummary[$key]['premonth']['new'] = array(
'count' => CRM_Member_BAO_Membership::getMembershipJoins($key, $preMonth, $preMonthEnd),
'name' => $value,
);
$membershipSummary[$key]['premonth']['renew'] = array(
'count' => CRM_Member_BAO_Membership::getMembershipRenewals($key, $preMonth, $preMonthEnd),
'name' => $value,
);
$membershipSummary[$key]['premonth']['total'] = array(
'count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $preMonth, $preMonthEnd),
'name' => $value,
);
$membershipSummary[$key]['month']['new'] = array(
'count' => CRM_Member_BAO_Membership::getMembershipJoins($key, $monthStart, $ymd),
'name' => $value,
);
$membershipSummary[$key]['month']['renew'] = array(
'count' => CRM_Member_BAO_Membership::getMembershipRenewals($key, $monthStart, $ymd),
'name' => $value,
);
$membershipSummary[$key]['month']['total'] = array(
'count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $monthStart, $ymd),
'name' => $value,
);
$membershipSummary[$key]['year']['new'] = array(
'count' => CRM_Member_BAO_Membership::getMembershipJoins($key, $yearStart, $ymd),
'name' => $value,
);
$membershipSummary[$key]['year']['renew'] = array(
'count' => CRM_Member_BAO_Membership::getMembershipRenewals($key, $yearStart, $ymd),
'name' => $value,
);
$membershipSummary[$key]['year']['total'] = array(
'count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $yearStart, $ymd),
'name' => $value,
);
$membershipSummary[$key]['current']['total'] = array(
'count' => CRM_Member_BAO_Membership::getMembershipCount($key, $current),
'name' => $value,
);
$membershipSummary[$key]['total']['total'] = array('count' => CRM_Member_BAO_Membership::getMembershipCount($key, $ymd));
//LCD also get summary stats for membership owners
$membershipSummary[$key]['premonth_owner']['premonth_owner'] = array(
'count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $preMonth, $preMonthEnd, 0, 1),
'name' => $value,
);
$membershipSummary[$key]['month_owner']['month_owner'] = array(
'count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $monthStart, $ymd, 0, 1),
'name' => $value,
);
$membershipSummary[$key]['year_owner']['year_owner'] = array(
'count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $yearStart, $ymd, 0, 1),
'name' => $value,
);
$membershipSummary[$key]['current_owner']['current_owner'] = array(
'count' => CRM_Member_BAO_Membership::getMembershipCount($key, $current, 0, 1),
'name' => $value,
);
$membershipSummary[$key]['total_owner']['total_owner'] = array('count' => CRM_Member_BAO_Membership::getMembershipCount($key, $ymd, 0, 1));
//LCD end
}
$status = CRM_Member_BAO_MembershipStatus::getMembershipStatusCurrent();
$status = implode(',', $status);
/*@codingStandardsIgnoreStart
Disabled for lack of appropriate search
The Membership search isn't able to properly filter by join or renewal events.
Until that works properly, the subtotals shouldn't get links.
foreach ($membershipSummary as $typeID => $details) {
foreach ($details as $key => $value) {
switch ($key) {
case 'premonth':
$membershipSummary[$typeID][$key]['new']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&join=$preMonth&joinEnd=$preMonthEnd&start=$preMonth&end=$preMonthEnd");
$membershipSummary[$typeID][$key]['renew']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&joinEnd=$prePreMonthEnd&start=$preMonth&end=$preMonthEnd");
$membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$preMonth&end=$preMonthEnd");
break;
case 'month':
$membershipSummary[$typeID][$key]['new']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&join=$monthStart&joinEnd=$ymd&start=$monthStart&end=$ymd");
$membershipSummary[$typeID][$key]['renew']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&joinEnd=$preMonthStart&start=$monthStart&end=$ymd");
$membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$monthStart&end=$ymd");
break;
case 'year':
$membershipSummary[$typeID][$key]['new']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&join=$yearStart&joinEnd=$ymd&start=$yearStart&end=$ymd");
$membershipSummary[$typeID][$key]['renew']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&joinEnd=$preYearStart&start=$yearStart&end=$ymd");
$membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$yearStart&end=$ymd");
break;
case 'current':
$membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID");
break;
case 'total':
if (!$isCurrentMonth) {
$membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search',
"reset=1&force=1&start=&end=$ymd&status=$status&type=$typeID"
);
}
else {
$membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search',
"reset=1&force=1&status=$status"
);
}
break;
//LCD add owner urls
case 'premonth_owner':
$membershipSummary[$typeID][$key]['premonth_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$preMonth&end=$preMonthEnd&owner=1");
break;
case 'month_owner':
$membershipSummary[$typeID][$key]['month_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$monthStart&end=$ymd&owner=1");
break;
case 'year_owner':
$membershipSummary[$typeID][$key]['year_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$yearStart&end=$ymd&owner=1");
break;
case 'current_owner':
$membershipSummary[$typeID][$key]['current_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&owner=1");
break;
case 'total_owner':
if (!$isCurrentMonth) {
$membershipSummary[$typeID][$key]['total_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&start=&end=$ymd&status=$status&type=$typeID&owner=1");
}
else {
$membershipSummary[$typeID][$key]['total_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&owner=1");
}
break;
//LCD end
}
}
}
@codingStandardsIgnoreEnd */
// Temporary replacement for current totals column
foreach ($membershipSummary as $typeID => $details) {
if (!$isCurrentMonth) {
$membershipSummary[$typeID]['total']['total']['url'] = CRM_Utils_System::url('civicrm/member/search',
"reset=1&force=1&start=&end=$ymd&status=$status&type=$typeID"
);
$membershipSummary[$typeID]['total_owner']['total_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&start=&end=$ymd&status=$status&type=$typeID&owner=1");
}
else {
$membershipSummary[$typeID]['total']['total']['url'] = CRM_Utils_System::url('civicrm/member/search',
"reset=1&force=1&status=$status"
);
$membershipSummary[$typeID]['total_owner']['total_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&owner=1");
}
$membershipSummary[$typeID]['current']['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID");
$membershipSummary[$typeID]['current_owner']['current_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&owner=1");
}
$totalCount = array();
$newCountPreMonth = $newCountMonth = $newCountYear = 0;
$renewCountPreMonth = $renewCountMonth = $renewCountYear = 0;
$totalCountPreMonth = $totalCountMonth = $totalCountYear = $totalCountCurrent = $totalCountTotal = 0;
$totalCountPreMonth_owner = $totalCountMonth_owner = $totalCountYear_owner = $totalCountCurrent_owner = $totalCountTotal_owner = 0;
foreach ($membershipSummary as $key => $value) {
$newCountPreMonth = $newCountPreMonth + $value['premonth']['new']['count'];
$renewCountPreMonth = $renewCountPreMonth + $value['premonth']['renew']['count'];
$totalCountPreMonth = $totalCountPreMonth + $value['premonth']['total']['count'];
$newCountMonth = $newCountMonth + $value['month']['new']['count'];
$renewCountMonth = $renewCountMonth + $value['month']['renew']['count'];
$totalCountMonth = $totalCountMonth + $value['month']['total']['count'];
$newCountYear = $newCountYear + $value['year']['new']['count'];
$renewCountYear = $renewCountYear + $value['year']['renew']['count'];
$totalCountYear = $totalCountYear + $value['year']['total']['count'];
$totalCountCurrent = $totalCountCurrent + $value['current']['total']['count'];
$totalCountTotal = $totalCountTotal + $value['total']['total']['count'];
//LCD add owner values
$totalCountPreMonth_owner = $totalCountPreMonth_owner + $value['premonth_owner']['premonth_owner']['count'];
$totalCountMonth_owner = $totalCountMonth_owner + $value['month_owner']['month_owner']['count'];
$totalCountYear_owner = $totalCountYear_owner + $value['year_owner']['year_owner']['count'];
$totalCountCurrent_owner = $totalCountCurrent_owner + $value['current_owner']['current_owner']['count'];
$totalCountTotal_owner = $totalCountTotal_owner + $value['total_owner']['total_owner']['count'];
}
$totalCount['premonth']['new'] = array(
'count' => $newCountPreMonth,
//'url' => CRM_Utils_System::url('civicrm/activity/search',
// "reset=1&force=1&signupType=1&dateLow=$preMonth&dateHigh=$preMonthEnd"
//),
);
$totalCount['premonth']['renew'] = array(
'count' => $renewCountPreMonth,
//'url' => CRM_Utils_System::url('civicrm/activity/search',
// "reset=1&force=1&signupType=2&dateLow=$preMonth&dateHigh=$preMonthEnd"
//),
);
$totalCount['premonth']['total'] = array(
'count' => $totalCountPreMonth,
//'url' => CRM_Utils_System::url('civicrm/activity/search',
// "reset=1&force=1&signupType=3&dateLow=$preMonth&dateHigh=$preMonthEnd"
//),
);
$totalCount['month']['new'] = array(
'count' => $newCountMonth,
//'url' => CRM_Utils_System::url('civicrm/activity/search',
// "reset=1&force=1&signupType=1&dateLow=$monthStart&dateHigh=$ymd"
//),
);
$totalCount['month']['renew'] = array(
'count' => $renewCountMonth,
//'url' => CRM_Utils_System::url('civicrm/activity/search',
// "reset=1&force=1&signupType=2&dateLow=$monthStart&dateHigh=$ymd"
//),
);
$totalCount['month']['total'] = array(
'count' => $totalCountMonth,
//'url' => CRM_Utils_System::url('civicrm/activity/search',
// "reset=1&force=1&signupType=3&dateLow=$monthStart&dateHigh=$ymd"
//),
);
$totalCount['year']['new'] = array(
'count' => $newCountYear,
//'url' => CRM_Utils_System::url('civicrm/activity/search',
// "reset=1&force=1&signupType=1&dateLow=$yearStart&dateHigh=$ymd"
//),
);
$totalCount['year']['renew'] = array(
'count' => $renewCountYear,
//'url' => CRM_Utils_System::url('civicrm/activity/search',
// "reset=1&force=1&signupType=2&dateLow=$yearStart&dateHigh=$ymd"
//),
);
$totalCount['year']['total'] = array(
'count' => $totalCountYear,
//'url' => CRM_Utils_System::url('civicrm/activity/search',
// "reset=1&force=1&signupType=3&dateLow=$yearStart&dateHigh=$ymd"
//),
);
$totalCount['current']['total'] = array(
'count' => $totalCountCurrent,
'url' => CRM_Utils_System::url('civicrm/member/search',
"reset=1&force=1&status=$status"
),
);
$totalCount['total']['total'] = array(
'count' => $totalCountTotal,
'url' => CRM_Utils_System::url('civicrm/member/search',
"reset=1&force=1&status=$status"
),
);
if (!$isCurrentMonth) {
$totalCount['total']['total'] = array(
'count' => $totalCountTotal,
'url' => CRM_Utils_System::url('civicrm/member/search',
"reset=1&force=1&status=$status&start=&end=$ymd"
),
);
}
// Activity search also unable to handle owner vs. inherited
//LCD add owner values
$totalCount['premonth_owner']['premonth_owner'] = array(
'count' => $totalCountPreMonth_owner,
// 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&start=$preMonth&end=$preMonthEnd&owner=1"),
);
$totalCount['month_owner']['month_owner'] = array(
'count' => $totalCountMonth_owner,
// 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&start=$monthStart&end=$ymd&owner=1"),
);
$totalCount['year_owner']['year_owner'] = array(
'count' => $totalCountYear_owner,
// 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&start=$yearStart&end=$ymd&owner=1"),
);
$totalCount['current_owner']['current_owner'] = array(
'count' => $totalCountCurrent_owner,
// 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&owner=1"),
);
$totalCount['total_owner']['total_owner'] = array(
'count' => $totalCountTotal_owner,
// 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&owner=1"),
);
if (!$isCurrentMonth) {
$totalCount['total_owner']['total_owner'] = array(
'count' => $totalCountTotal_owner,
// 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&start=&end=$ymd&owner=1"),
);
}
//LCD end
$this->assign('membershipSummary', $membershipSummary);
$this->assign('totalCount', $totalCount);
$this->assign('month', CRM_Utils_Date::customFormat($monthStartTs, '%B'));
$this->assign('year', date('Y', $monthStartTs));
$this->assign('premonth', CRM_Utils_Date::customFormat($preMonth, '%B'));
$this->assign('currentMonth', date('F'));
$this->assign('currentYear', date('Y'));
$this->assign('isCurrent', $isCurrentMonth);
$this->assign('preMonth', $isPreviousMonth);
}
/**
* the main function that is called when the page loads,
* it decides the which action has to be taken for the page.
*
* @return null
*/
public function run() {
$this->preProcess();
$controller = new CRM_Core_Controller_Simple('CRM_Member_Form_Search', ts('Member'), NULL);
$controller->setEmbedded(TRUE);
$controller->reset();
$controller->set('limit', 20);
$controller->set('force', 1);
$controller->set('context', 'dashboard');
$controller->process();
$controller->run();
return parent::run();
}
}

View file

@ -0,0 +1,181 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
* $Id$
*
*/
/**
* Page for displaying list of membership types
*/
class CRM_Member_Page_MembershipStatus extends CRM_Core_Page_Basic {
public $useLivePageJS = TRUE;
/**
* The action links that we need to display for the browse screen.
*
* @var array
*/
static $_links = NULL;
/**
* Get BAO Name.
*
* @return string
* Classname of BAO.
*/
public function getBAOName() {
return 'CRM_Member_BAO_MembershipStatus';
}
/**
* Get action Links.
*
* @return array
* (reference) of action links
*/
public function &links() {
if (!(self::$_links)) {
self::$_links = array(
CRM_Core_Action::UPDATE => array(
'name' => ts('Edit'),
'url' => 'civicrm/admin/member/membershipStatus',
'qs' => 'action=update&id=%%id%%&reset=1',
'title' => ts('Edit Membership Status'),
),
CRM_Core_Action::DISABLE => array(
'name' => ts('Disable'),
'ref' => 'crm-enable-disable',
'title' => ts('Disable Membership Status'),
),
CRM_Core_Action::ENABLE => array(
'name' => ts('Enable'),
'ref' => 'crm-enable-disable',
'title' => ts('Enable Membership Status'),
),
CRM_Core_Action::DELETE => array(
'name' => ts('Delete'),
'url' => 'civicrm/admin/member/membershipStatus',
'qs' => 'action=delete&id=%%id%%',
'title' => ts('Delete Membership Status'),
),
);
}
return self::$_links;
}
/**
* Browse all custom data groups.
*
*
* @return void
*/
public function browse() {
// get all custom groups sorted by weight
$membershipStatus = array();
$dao = new CRM_Member_DAO_MembershipStatus();
$dao->orderBy('weight');
$dao->find();
while ($dao->fetch()) {
$membershipStatus[$dao->id] = array();
CRM_Core_DAO::storeValues($dao, $membershipStatus[$dao->id]);
// form all action links
$action = array_sum(array_keys($this->links()));
// update enable/disable links depending on if it is is_reserved or is_active
if (!$dao->is_reserved) {
if ($dao->is_active) {
$action -= CRM_Core_Action::ENABLE;
}
else {
$action -= CRM_Core_Action::DISABLE;
}
$membershipStatus[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action,
array('id' => $dao->id),
ts('more'),
FALSE,
'membershipStatus.manage.action',
'MembershipStatus',
$dao->id
);
}
if ($startEvent = CRM_Utils_Array::value('start_event', $membershipStatus[$dao->id])) {
$membershipStatus[$dao->id]['start_event'] = ($startEvent == 'join_date') ? 'member since' : str_replace("_", " ", $startEvent);
}
if ($endEvent = CRM_Utils_Array::value('end_event', $membershipStatus[$dao->id])) {
$membershipStatus[$dao->id]['end_event'] = ($endEvent == 'join_date') ? 'member since' : str_replace("_", " ", $endEvent);
}
}
// Add order changing widget to selector
$returnURL = CRM_Utils_System::url('civicrm/admin/member/membershipStatus', "reset=1&action=browse");
CRM_Utils_Weight::addOrder($membershipStatus, 'CRM_Member_DAO_MembershipStatus',
'id', $returnURL
);
$this->assign('rows', $membershipStatus);
}
/**
* Get name of edit form.
*
* @return string
* Classname of edit form.
*/
public function editForm() {
return 'CRM_Member_Form_MembershipStatus';
}
/**
* Get edit form name.
*
* @return string
* name of this page.
*/
public function editName() {
return 'Membership Status';
}
/**
* Get user context.
*
* @param null $mode
*
* @return string
* user context.
*/
public function userContext($mode = NULL) {
return 'civicrm/admin/member/membershipStatus';
}
}

View file

@ -0,0 +1,184 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
* $Id$
*
*/
/**
* Page for displaying list of membership types
*/
class CRM_Member_Page_MembershipType extends CRM_Core_Page {
/**
* The action links that we need to display for the browse screen.
*
* @var array
*/
static $_links = NULL;
public $useLivePageJS = TRUE;
/**
* Get action Links.
*
* @return array
* (reference) of action links
*/
public function &links() {
if (!(self::$_links)) {
self::$_links = array(
CRM_Core_Action::UPDATE => array(
'name' => ts('Edit'),
'url' => 'civicrm/admin/member/membershipType/add',
'qs' => 'action=update&id=%%id%%&reset=1',
'title' => ts('Edit Membership Type'),
),
CRM_Core_Action::DISABLE => array(
'name' => ts('Disable'),
'ref' => 'crm-enable-disable',
'title' => ts('Disable Membership Type'),
),
CRM_Core_Action::ENABLE => array(
'name' => ts('Enable'),
'ref' => 'crm-enable-disable',
'title' => ts('Enable Membership Type'),
),
CRM_Core_Action::DELETE => array(
'name' => ts('Delete'),
'url' => 'civicrm/admin/member/membershipType/add',
'qs' => 'action=delete&id=%%id%%',
'title' => ts('Delete Membership Type'),
),
);
}
return self::$_links;
}
/**
* Run the page.
*
* This method is called after the page is created. It checks for the
* type of action and executes that action.
* Finally it calls the parent's run method.
*
* @return void
*/
public function run() {
$this->browse();
// parent run
return parent::run();
}
/**
* Browse all membership types.
*
*
* @return void
*/
public function browse() {
// get all membership types sorted by weight
$membershipType = array();
$dao = new CRM_Member_DAO_MembershipType();
$dao->orderBy('weight');
$dao->find();
while ($dao->fetch()) {
if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()
&& !CRM_Core_Permission::check('view contributions of type ' . CRM_Contribute_PseudoConstant::financialType($dao->financial_type_id))
) {
continue;
}
$links = self::links();
$membershipType[$dao->id] = array();
CRM_Core_DAO::storeValues($dao, $membershipType[$dao->id]);
$membershipType[$dao->id]['period_type'] = CRM_Utils_Array::value($dao->period_type, CRM_Core_SelectValues::periodType(), '');
$membershipType[$dao->id]['visibility'] = CRM_Utils_Array::value($dao->visibility, CRM_Core_SelectValues::memberVisibility(), '');
//adding column for relationship type label. CRM-4178.
if ($dao->relationship_type_id) {
//If membership associated with 2 or more relationship then display all relationship with comma separated
$relTypeIds = explode(CRM_Core_DAO::VALUE_SEPARATOR, $dao->relationship_type_id);
$relTypeNames = explode(CRM_Core_DAO::VALUE_SEPARATOR, $dao->relationship_direction);
$membershipType[$dao->id]['relationshipTypeName'] = NULL;
foreach ($relTypeIds as $key => $value) {
$relationshipName = 'label_' . $relTypeNames[$key];
if ($membershipType[$dao->id]['relationshipTypeName']) {
$membershipType[$dao->id]['relationshipTypeName'] .= ", ";
}
$membershipType[$dao->id]['relationshipTypeName'] .= CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType',
$value, $relationshipName
);
}
$membershipType[$dao->id]['maxRelated'] = CRM_Utils_Array::value('max_related', $membershipType[$dao->id]);
}
if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && !CRM_Core_Permission::check('edit contributions of type ' . CRM_Contribute_PseudoConstant::financialType($dao->financial_type_id))) {
unset($links[CRM_Core_Action::UPDATE], $links[CRM_Core_Action::ENABLE], $links[CRM_Core_Action::DISABLE]);
}
if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && !CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($dao->financial_type_id))) {
unset($links[CRM_Core_Action::DELETE]);
}
// form all action links
$action = array_sum(array_keys($this->links()));
// update enable/disable links depending on if it is is_reserved or is_active
if (!isset($dao->is_reserved)) {
if ($dao->is_active) {
$action -= CRM_Core_Action::ENABLE;
}
else {
$action -= CRM_Core_Action::DISABLE;
}
$membershipType[$dao->id]['order'] = $membershipType[$dao->id]['weight'];
$membershipType[$dao->id]['action'] = CRM_Core_Action::formLink($links, $action,
array('id' => $dao->id),
ts('more'),
FALSE,
'membershipType.manage.action',
'MembershipType',
$dao->id
);
}
}
$returnURL = CRM_Utils_System::url('civicrm/admin/member/membershipType', "reset=1&action=browse");
CRM_Utils_Weight::addOrder($membershipType, 'CRM_Member_DAO_MembershipType',
'id', $returnURL
);
CRM_Member_BAO_MembershipType::convertDayFormat($membershipType);
$this->assign('rows', $membershipType);
}
}

View file

@ -0,0 +1,653 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
* $Id$
*
*/
class CRM_Member_Page_Tab extends CRM_Core_Page {
/**
* The action links that we need to display for the browse screen.
*
* @var array
*/
static $_links = NULL;
static $_membershipTypesLinks = NULL;
public $_permission = NULL;
public $_contactId = NULL;
/**
* called when action is browse.
*/
public function browse() {
$links = self::links('all', $this->_isPaymentProcessor, $this->_accessContribution);
CRM_Financial_BAO_FinancialType::getAvailableMembershipTypes($membershipTypes);
$addWhere = "membership_type_id IN (0)";
if (!empty($membershipTypes)) {
$addWhere = "membership_type_id IN (" . implode(',', array_keys($membershipTypes)) . ")";
}
$membership = array();
$dao = new CRM_Member_DAO_Membership();
$dao->contact_id = $this->_contactId;
$dao->is_test = 0;
$dao->whereAdd($addWhere);
//$dao->orderBy('name');
$dao->find();
//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);
// get deceased status id
$allStatus = CRM_Member_PseudoConstant::membershipStatus();
$deceasedStatusId = array_search('Deceased', $allStatus);
//get all campaigns.
$allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
//checks membership of contact itself
while ($dao->fetch()) {
$membership[$dao->id] = array();
CRM_Core_DAO::storeValues($dao, $membership[$dao->id]);
//carry campaign.
$membership[$dao->id]['campaign'] = CRM_Utils_Array::value($dao->campaign_id, $allCampaigns);
//get the membership status and type values.
$statusANDType = CRM_Member_BAO_Membership::getStatusANDTypeValues($dao->id);
foreach (array('status', 'membership_type') as $fld) {
$membership[$dao->id][$fld] = CRM_Utils_Array::value($fld, $statusANDType[$dao->id]);
}
if (!empty($statusANDType[$dao->id]['is_current_member'])) {
$membership[$dao->id]['active'] = TRUE;
}
if (empty($dao->owner_membership_id)) {
// unset renew and followup link for deceased membership
$currentMask = $mask;
if ($dao->status_id == $deceasedStatusId) {
$currentMask = $currentMask & ~CRM_Core_Action::RENEW & ~CRM_Core_Action::FOLLOWUP;
}
$isUpdateBilling = FALSE;
// It would be better to determine if there is a recurring contribution &
// is so get the entity for the recurring contribution (& skip if not).
$paymentObject = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity(
$membership[$dao->id]['membership_id'], 'membership', 'obj');
if (!empty($paymentObject)) {
// @todo - get this working with syntax style $paymentObject->supports(array
//('updateSubscriptionBillingInfo'));
$isUpdateBilling = $paymentObject->isSupported('updateSubscriptionBillingInfo');
}
// @todo - get this working with syntax style $paymentObject->supports(array
//('CancelSubscriptionSupported'));
$isCancelSupported = CRM_Member_BAO_Membership::isCancelSubscriptionSupported(
$membership[$dao->id]['membership_id']);
$links = self::links('all',
NULL,
NULL,
$isCancelSupported,
$isUpdateBilling
);
self::getPermissionedLinks($dao->membership_type_id, $links);
$membership[$dao->id]['action'] = CRM_Core_Action::formLink($links,
$currentMask,
array(
'id' => $dao->id,
'cid' => $this->_contactId,
),
ts('Renew') . '...',
FALSE,
'membership.tab.row',
'Membership',
$dao->id
);
}
else {
$links = self::links('view');
self::getPermissionedLinks($dao->membership_type_id, $links);
$membership[$dao->id]['action'] = CRM_Core_Action::formLink($links,
$mask,
array(
'id' => $dao->id,
'cid' => $this->_contactId,
),
ts('more'),
FALSE,
'membership.tab.row',
'Membership',
$dao->id
);
}
//does membership have auto renew CRM-7137.
if (!empty($membership[$dao->id]['contribution_recur_id']) &&
!CRM_Member_BAO_Membership::isSubscriptionCancelled($membership[$dao->id]['membership_id'])
) {
$membership[$dao->id]['auto_renew'] = 1;
}
else {
$membership[$dao->id]['auto_renew'] = 0;
}
// if relevant--membership is active and type allows inheritance--count related memberships
if (CRM_Utils_Array::value('is_current_member', $statusANDType[$dao->id])
&& CRM_Utils_Array::value('relationship_type_id', $statusANDType[$dao->id])
&& empty($dao->owner_membership_id)
) {
// not an related membership
$query = "
SELECT COUNT(m.id)
FROM civicrm_membership m
LEFT JOIN civicrm_membership_status ms ON ms.id = m.status_id
LEFT JOIN civicrm_contact ct ON ct.id = m.contact_id
WHERE m.owner_membership_id = {$dao->id} AND m.is_test = 0 AND ms.is_current_member = 1 AND ct.is_deleted = 0";
$num_related = CRM_Core_DAO::singleValueQuery($query);
$max_related = CRM_Utils_Array::value('max_related', $membership[$dao->id]);
$membership[$dao->id]['related_count'] = ($max_related == '' ? ts('%1 created', array(1 => $num_related)) : ts('%1 out of %2', array(
1 => $num_related,
2 => $max_related,
)));
}
else {
$membership[$dao->id]['related_count'] = ts('N/A');
}
}
//Below code gives list of all Membership Types associated
//with an Organization(CRM-2016)
$membershipTypesResult = civicrm_api3('MembershipType', 'get', array(
'member_of_contact_id' => $this->_contactId,
'options' => array(
'limit' => 0,
),
));
$membershipTypes = CRM_Utils_Array::value('values', $membershipTypesResult, NULL);
foreach ($membershipTypes as $key => $value) {
$membershipTypes[$key]['action'] = CRM_Core_Action::formLink(self::membershipTypeslinks(),
$mask,
array(
'id' => $value['id'],
'cid' => $this->_contactId,
),
ts('more'),
FALSE,
'membershipType.organization.action',
'MembershipType',
$value['id']
);
}
$activeMembers = CRM_Member_BAO_Membership::activeMembers($membership);
$inActiveMembers = CRM_Member_BAO_Membership::activeMembers($membership, 'inactive');
$this->assign('activeMembers', $activeMembers);
$this->assign('inActiveMembers', $inActiveMembers);
$this->assign('membershipTypes', $membershipTypes);
if ($this->_contactId) {
$displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId);
$this->assign('displayName', $displayName);
$this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent('membership', $this->_contactId);
// Refresh other tabs with related data
$this->ajaxResponse['updateTabs'] = array(
'#tab_activity' => CRM_Contact_BAO_Contact::getCountComponent('activity', $this->_contactId),
'#tab_rel' => CRM_Contact_BAO_Contact::getCountComponent('rel', $this->_contactId),
);
if (CRM_Core_Permission::access('CiviContribute')) {
$this->ajaxResponse['updateTabs']['#tab_contribute'] = CRM_Contact_BAO_Contact::getCountComponent('contribution', $this->_contactId);
}
}
}
/**
* called when action is view.
*
* @return null
*/
public function view() {
$controller = new CRM_Core_Controller_Simple(
'CRM_Member_Form_MembershipView',
ts('View Membership'),
$this->_action
);
$controller->setEmbedded(TRUE);
$controller->set('id', $this->_id);
$controller->set('cid', $this->_contactId);
return $controller->run();
}
/**
* called when action is update or new.
*
* @return null
*/
public function edit() {
// set https for offline cc transaction
$mode = CRM_Utils_Request::retrieve('mode', 'String', $this);
if ($mode == 'test' || $mode == 'live') {
CRM_Utils_System::redirectToSSL();
}
// build associated contributions ( note: this is called to show associated contributions in edit mode )
if ($this->_action & CRM_Core_Action::UPDATE) {
$this->assign('accessContribution', FALSE);
if (CRM_Core_Permission::access('CiviContribute')) {
$this->assign('accessContribution', TRUE);
CRM_Member_Page_Tab::associatedContribution($this->_contactId, $this->_id);
//show associated soft credit when contribution payment is paid by different person in edit mode
if ($this->_id && $this->_contactId) {
$filter = " AND cc.id IN (SELECT contribution_id FROM civicrm_membership_payment WHERE membership_id = {$this->_id})";
$softCreditList = CRM_Contribute_BAO_ContributionSoft::getSoftContributionList($this->_contactId, $filter);
if (!empty($softCreditList)) {
$this->assign('softCredit', TRUE);
$this->assign('softCreditRows', $softCreditList);
}
}
}
}
if ($this->_action & CRM_Core_Action::RENEW) {
$path = 'CRM_Member_Form_MembershipRenewal';
$title = ts('Renew Membership');
}
else {
$path = 'CRM_Member_Form_Membership';
$title = ts('Create Membership');
}
$controller = new CRM_Core_Controller_Simple($path, $title, $this->_action);
$controller->setEmbedded(TRUE);
$controller->set('BAOName', $this->getBAOName());
$controller->set('id', $this->_id);
$controller->set('cid', $this->_contactId);
return $controller->run();
}
public function preProcess() {
$context = CRM_Utils_Request::retrieve('context', 'String', $this);
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
if ($context == 'standalone') {
$this->_action = CRM_Core_Action::ADD;
}
else {
$this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
$this->assign('contactId', $this->_contactId);
// check logged in url permission
CRM_Contact_Page_View::checkUserPermission($this);
}
$this->assign('action', $this->_action);
if ($this->_permission == CRM_Core_Permission::EDIT && !CRM_Core_Permission::check('edit memberships')) {
// demote to view since user does not have edit membership rights
$this->_permission = CRM_Core_Permission::VIEW;
$this->assign('permission', 'view');
}
}
/**
* the main function that is called when the page loads, it decides the which action has to be taken for the page.
*
* @return null
*/
public function run() {
$this->preProcess();
// check if we can process credit card membership
$newCredit = CRM_Core_Config::isEnabledBackOfficeCreditCardPayments();
$this->assign('newCredit', $newCredit);
if ($newCredit) {
$this->_isPaymentProcessor = TRUE;
}
else {
$this->_isPaymentProcessor = FALSE;
}
// Only show credit card membership signup if user has CiviContribute permission
if (CRM_Core_Permission::access('CiviContribute')) {
$this->_accessContribution = TRUE;
$this->assign('accessContribution', TRUE);
//show associated soft credit when contribution payment is paid by different person
if ($this->_id && $this->_contactId) {
$filter = " AND cc.id IN (SELECT contribution_id FROM civicrm_membership_payment WHERE membership_id = {$this->_id})";
$softCreditList = CRM_Contribute_BAO_ContributionSoft::getSoftContributionList($this->_contactId, $filter);
if (!empty($softCreditList)) {
$this->assign('softCredit', TRUE);
$this->assign('softCreditRows', $softCreditList);
}
}
}
else {
$this->_accessContribution = FALSE;
$this->assign('accessContribution', FALSE);
$this->assign('softCredit', FALSE);
}
if ($this->_action & CRM_Core_Action::VIEW) {
$this->view();
}
elseif ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE | CRM_Core_Action::RENEW)) {
self::setContext($this);
$this->edit();
}
else {
self::setContext($this);
$this->browse();
}
return parent::run();
}
/**
* @param CRM_Core_Form $form
* @param int $contactId
*/
public static function setContext(&$form, $contactId = NULL) {
$context = CRM_Utils_Request::retrieve('context', 'String', $form, FALSE, 'search');
$qfKey = CRM_Utils_Request::retrieve('key', 'String', $form);
$searchContext = CRM_Utils_Request::retrieve('searchContext', 'String', $form);
//validate the qfKey
if (!CRM_Utils_Rule::qfKey($qfKey)) {
$qfKey = NULL;
}
if (!$contactId) {
$contactId = $form->_contactId;
}
switch ($context) {
case 'dashboard':
$url = CRM_Utils_System::url('civicrm/member', 'reset=1');
break;
case 'membership':
$url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$contactId}&selectedChild=member");
break;
case 'search':
$urlParams = 'force=1';
if ($qfKey) {
$urlParams .= "&qfKey=$qfKey";
}
$form->assign('searchKey', $qfKey);
if ($searchContext) {
$url = CRM_Utils_System::url("civicrm/$searchContext/search", $urlParams);
}
else {
$url = CRM_Utils_System::url('civicrm/member/search', $urlParams);
}
break;
case 'home':
$url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1');
break;
case 'activity':
$url = CRM_Utils_System::url('civicrm/contact/view',
"reset=1&force=1&cid={$contactId}&selectedChild=activity"
);
break;
case 'standalone':
$url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1');
break;
case 'fulltext':
$action = CRM_Utils_Request::retrieve('action', 'String', $form);
$keyName = '&qfKey';
$urlParams = 'force=1';
$urlString = 'civicrm/contact/search/custom';
if ($action == CRM_Core_Action::UPDATE) {
if ($form->_contactId) {
$urlParams .= '&cid=' . $form->_contactId;
}
$keyName = '&key';
$urlParams .= '&context=fulltext&action=view';
$urlString = 'civicrm/contact/view/membership';
}
if ($qfKey) {
$urlParams .= "$keyName=$qfKey";
}
$form->assign('searchKey', $qfKey);
$url = CRM_Utils_System::url($urlString, $urlParams);
break;
default:
$cid = NULL;
if ($contactId) {
$cid = '&cid=' . $contactId;
}
$url = CRM_Utils_System::url('civicrm/member/search', 'force=1' . $cid);
break;
}
$session = CRM_Core_Session::singleton();
$session->pushUserContext($url);
}
/**
* Get action links.
*
* @param string $status
* @param null $isPaymentProcessor
* @param null $accessContribution
* @param bool $isCancelSupported
* @param bool $isUpdateBilling
*
* @return array
* (reference) of action links
*/
public static function &links(
$status = 'all',
$isPaymentProcessor = NULL,
$accessContribution = NULL,
$isCancelSupported = FALSE,
$isUpdateBilling = FALSE
) {
if (!CRM_Utils_Array::value('view', self::$_links)) {
self::$_links['view'] = array(
CRM_Core_Action::VIEW => array(
'name' => ts('View'),
'url' => 'civicrm/contact/view/membership',
'qs' => 'action=view&reset=1&cid=%%cid%%&id=%%id%%&context=membership&selectedChild=member',
'title' => ts('View Membership'),
),
);
}
if (!CRM_Utils_Array::value('all', self::$_links)) {
$extraLinks = array(
CRM_Core_Action::UPDATE => array(
'name' => ts('Edit'),
'url' => 'civicrm/contact/view/membership',
'qs' => 'action=update&reset=1&cid=%%cid%%&id=%%id%%&context=membership&selectedChild=member',
'title' => ts('Edit Membership'),
),
CRM_Core_Action::RENEW => array(
'name' => ts('Renew'),
'url' => 'civicrm/contact/view/membership',
'qs' => 'action=renew&reset=1&cid=%%cid%%&id=%%id%%&context=membership&selectedChild=member',
'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=membership&selectedChild=member&mode=live',
'title' => ts('Renew Membership Using Credit Card'),
),
CRM_Core_Action::DELETE => array(
'name' => ts('Delete'),
'url' => 'civicrm/contact/view/membership',
'qs' => 'action=delete&reset=1&cid=%%cid%%&id=%%id%%&context=membership&selectedChild=member',
'title' => ts('Delete Membership'),
),
);
if (!$isPaymentProcessor || !$accessContribution) {
//unset the renew with credit card when payment
//processor is not available or user is not permitted to create contributions
unset($extraLinks[CRM_Core_Action::FOLLOWUP]);
}
self::$_links['all'] = self::$_links['view'] + $extraLinks;
}
if ($isCancelSupported) {
$cancelMessage = ts('WARNING: If you cancel the recurring contribution associated with this membership, the membership will no longer be renewed automatically. However, the current membership status will not be affected.');
self::$_links['all'][CRM_Core_Action::DISABLE] = array(
'name' => ts('Cancel Auto-renewal'),
'url' => 'civicrm/contribute/unsubscribe',
'qs' => 'reset=1&cid=%%cid%%&mid=%%id%%&context=membership&selectedChild=member',
'title' => ts('Cancel Auto Renew Subscription'),
'extra' => 'onclick = "if (confirm(\'' . $cancelMessage . '\') ) { return true; else return false;}"',
);
}
elseif (isset(self::$_links['all'][CRM_Core_Action::DISABLE])) {
unset(self::$_links['all'][CRM_Core_Action::DISABLE]);
}
if ($isUpdateBilling) {
self::$_links['all'][CRM_Core_Action::MAP] = array(
'name' => ts('Change Billing Details'),
'url' => 'civicrm/contribute/updatebilling',
'qs' => 'reset=1&cid=%%cid%%&mid=%%id%%&context=membership&selectedChild=member',
'title' => ts('Change Billing Details'),
);
}
elseif (isset(self::$_links['all'][CRM_Core_Action::MAP])) {
unset(self::$_links['all'][CRM_Core_Action::MAP]);
}
return self::$_links[$status];
}
/**
* Define action links for membership types of related organization.
*
* @return array
* self::$_membershipTypesLinks array of action links
*/
public static function &membershipTypesLinks() {
if (!self::$_membershipTypesLinks) {
self::$_membershipTypesLinks = array(
CRM_Core_Action::VIEW => array(
'name' => ts('Members'),
'url' => 'civicrm/member/search/',
'qs' => 'reset=1&force=1&type=%%id%%',
'title' => ts('Search'),
),
CRM_Core_Action::UPDATE => array(
'name' => ts('Edit'),
'url' => 'civicrm/admin/member/membershipType',
'qs' => 'action=update&id=%%id%%&reset=1',
'title' => ts('Edit Membership Type'),
),
);
}
return self::$_membershipTypesLinks;
}
/**
* used for the to show the associated.
* contribution for the membership
*
* @param int $contactId
* @param int $membershipId
*/
public static function associatedContribution($contactId = NULL, $membershipId = NULL) {
$controller = new CRM_Core_Controller_Simple(
'CRM_Contribute_Form_Search',
ts('Contributions'),
NULL,
FALSE, FALSE, TRUE
);
$controller->setEmbedded(TRUE);
$controller->reset();
$controller->set('force', 1);
$controller->set('cid', $contactId);
$controller->set('memberId', $membershipId);
$controller->set('context', 'contribution');
$controller->process();
$controller->run();
}
/**
* Get BAO Name.
*
* @return string
* Classname of BAO.
*/
public function getBAOName() {
return 'CRM_Member_BAO_Membership';
}
/**
* Get a list of links based on permissioned FTs.
*
* @param int $memTypeID
* membership type ID
* @param int $links
* (reference ) action links
*/
public static function getPermissionedLinks($memTypeID, &$links) {
if (!CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) {
return FALSE;
}
$finTypeId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $memTypeID, 'financial_type_id');
$finType = CRM_Contribute_PseudoConstant::financialType($finTypeId);
if (!CRM_Core_Permission::check('edit contributions of type ' . $finType)) {
unset($links[CRM_Core_Action::UPDATE]);
unset($links[CRM_Core_Action::RENEW]);
unset($links[CRM_Core_Action::FOLLOWUP]);
}
if (!CRM_Core_Permission::check('delete contributions of type ' . $finType)) {
unset($links[CRM_Core_Action::DELETE]);
}
}
}

View file

@ -0,0 +1,102 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
* $Id$
*
*/
/**
* This class is for building membership block on user dashboard
*/
class CRM_Member_Page_UserDashboard extends CRM_Contact_Page_View_UserDashBoard {
/**
* List memberships for the UF user.
*
*/
public function listMemberships() {
$membership = array();
$dao = new CRM_Member_DAO_Membership();
$dao->contact_id = $this->_contactId;
$dao->is_test = 0;
$dao->find();
while ($dao->fetch()) {
$membership[$dao->id] = array();
CRM_Core_DAO::storeValues($dao, $membership[$dao->id]);
//get the membership status and type values.
$statusANDType = CRM_Member_BAO_Membership::getStatusANDTypeValues($dao->id);
foreach (array(
'status',
'membership_type',
) as $fld) {
$membership[$dao->id][$fld] = CRM_Utils_Array::value($fld, $statusANDType[$dao->id]);
}
if (!empty($statusANDType[$dao->id]['is_current_member'])) {
$membership[$dao->id]['active'] = TRUE;
}
$membership[$dao->id]['renewPageId'] = CRM_Member_BAO_Membership::getContributionPageId($dao->id);
if (!$membership[$dao->id]['renewPageId']) {
// Membership payment was not done via online contribution page or free membership. Check for default membership renewal page from CiviMember Settings
$defaultRenewPageId = Civi::settings()->get('default_renewal_contribution_page');
if ($defaultRenewPageId) {
//CRM-14831 - check if membership type is present in contrib page
$memBlock = CRM_Member_BAO_Membership::getMembershipBlock($defaultRenewPageId);
if (!empty($memBlock['membership_types'])) {
$memTypes = explode(',', $memBlock['membership_types']);
if (in_array($dao->membership_type_id, $memTypes)) {
$membership[$dao->id]['renewPageId'] = $defaultRenewPageId;
}
}
}
}
}
$activeMembers = CRM_Member_BAO_Membership::activeMembers($membership);
$inActiveMembers = CRM_Member_BAO_Membership::activeMembers($membership, 'inactive');
$this->assign('activeMembers', $activeMembers);
$this->assign('inActiveMembers', $inActiveMembers);
}
/**
* the main function that is called when the page
* loads, it decides the which action has to be taken for the page.
*
*/
public function run() {
parent::preProcess();
$this->listMemberships();
}
}