First commit
This commit is contained in:
commit
c6e2478c40
13918 changed files with 2303184 additions and 0 deletions
156
sites/all/modules/civicrm/CRM/Member/ActionMapping.php
Normal file
156
sites/all/modules/civicrm/CRM/Member/ActionMapping.php
Normal file
|
@ -0,0 +1,156 @@
|
|||
<?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 |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
use Civi\ActionSchedule\RecipientBuilder;
|
||||
|
||||
/**
|
||||
* Class CRM_Member_ActionMapping
|
||||
*
|
||||
* This defines the scheduled-reminder functionality for CiviMember
|
||||
* memberships. It allows one to target reminders based on join date
|
||||
* or end date, with additional filtering based on membership-type.
|
||||
*/
|
||||
class CRM_Member_ActionMapping extends \Civi\ActionSchedule\Mapping {
|
||||
|
||||
/**
|
||||
* The value for civicrm_action_schedule.mapping_id which identifies the
|
||||
* "Membership Type" mapping.
|
||||
*
|
||||
* Note: This value is chosen to match legacy DB IDs.
|
||||
*/
|
||||
const MEMBERSHIP_TYPE_MAPPING_ID = 4;
|
||||
|
||||
/**
|
||||
* Register CiviMember-related action mappings.
|
||||
*
|
||||
* @param \Civi\ActionSchedule\Event\MappingRegisterEvent $registrations
|
||||
*/
|
||||
public static function onRegisterActionMappings(\Civi\ActionSchedule\Event\MappingRegisterEvent $registrations) {
|
||||
$registrations->register(CRM_Member_ActionMapping::create(array(
|
||||
'id' => CRM_Member_ActionMapping::MEMBERSHIP_TYPE_MAPPING_ID,
|
||||
'entity' => 'civicrm_membership',
|
||||
'entity_label' => ts('Membership'),
|
||||
'entity_value' => 'civicrm_membership_type',
|
||||
'entity_value_label' => ts('Membership Type'),
|
||||
'entity_status' => 'auto_renew_options',
|
||||
'entity_status_label' => ts('Auto Renew Options'),
|
||||
'entity_date_start' => 'membership_join_date',
|
||||
'entity_date_end' => 'membership_end_date',
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a query to locate recipients who match the given
|
||||
* schedule.
|
||||
*
|
||||
* @param \CRM_Core_DAO_ActionSchedule $schedule
|
||||
* The schedule as configured by the administrator.
|
||||
* @param string $phase
|
||||
* See, e.g., RecipientBuilder::PHASE_RELATION_FIRST.
|
||||
* @param array $defaultParams
|
||||
*
|
||||
* @return \CRM_Utils_SQL_Select
|
||||
* @see RecipientBuilder
|
||||
*/
|
||||
public function createQuery($schedule, $phase, $defaultParams) {
|
||||
$selectedValues = (array) \CRM_Utils_Array::explodePadded($schedule->entity_value);
|
||||
$selectedStatuses = (array) \CRM_Utils_Array::explodePadded($schedule->entity_status);
|
||||
|
||||
$query = \CRM_Utils_SQL_Select::from("{$this->entity} e")->param($defaultParams);
|
||||
$query['casAddlCheckFrom'] = 'civicrm_membership e';
|
||||
$query['casContactIdField'] = 'e.contact_id';
|
||||
$query['casEntityIdField'] = 'e.id';
|
||||
$query['casContactTableAlias'] = NULL;
|
||||
$query['casDateField'] = str_replace('membership_', 'e.', $schedule->start_action_date);
|
||||
|
||||
// FIXME: Numbers should be constants.
|
||||
if (in_array(2, $selectedStatuses)) {
|
||||
//auto-renew memberships
|
||||
$query->where("e.contribution_recur_id IS NOT NULL");
|
||||
}
|
||||
elseif (in_array(1, $selectedStatuses)) {
|
||||
$query->where("e.contribution_recur_id IS NULL");
|
||||
}
|
||||
|
||||
if (!empty($selectedValues)) {
|
||||
$query->where("e.membership_type_id IN (@memberTypeValues)")
|
||||
->param('memberTypeValues', $selectedValues);
|
||||
}
|
||||
else {
|
||||
$query->where("e.membership_type_id IS NULL");
|
||||
}
|
||||
|
||||
$query->where("( e.is_override IS NULL OR e.is_override = 0 )");
|
||||
$query->merge($this->prepareMembershipPermissionsFilter());
|
||||
$query->where("e.status_id IN (#memberStatus)")
|
||||
->param('memberStatus', \CRM_Member_PseudoConstant::membershipStatus(NULL, "(is_current_member = 1 OR name = 'Expired')", 'id'));
|
||||
|
||||
// Why is this only for civicrm_membership?
|
||||
if ($schedule->start_action_date && $schedule->is_repeat == FALSE) {
|
||||
$query['casUseReferenceDate'] = TRUE;
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function prepareMembershipPermissionsFilter() {
|
||||
$query = '
|
||||
SELECT cm.id AS owner_id, cm.contact_id AS owner_contact, m.id AS slave_id, m.contact_id AS slave_contact, cmt.relationship_type_id AS relation_type, rel.contact_id_a, rel.contact_id_b, rel.is_permission_a_b, rel.is_permission_b_a
|
||||
FROM civicrm_membership m
|
||||
LEFT JOIN civicrm_membership cm ON cm.id = m.owner_membership_id
|
||||
LEFT JOIN civicrm_membership_type cmt ON cmt.id = m.membership_type_id
|
||||
LEFT JOIN civicrm_relationship rel ON ( ( rel.contact_id_a = m.contact_id AND rel.contact_id_b = cm.contact_id AND rel.relationship_type_id = cmt.relationship_type_id )
|
||||
OR ( rel.contact_id_a = cm.contact_id AND rel.contact_id_b = m.contact_id AND rel.relationship_type_id = cmt.relationship_type_id ) )
|
||||
WHERE m.owner_membership_id IS NOT NULL AND
|
||||
( rel.is_permission_a_b = 0 OR rel.is_permission_b_a = 0)
|
||||
|
||||
';
|
||||
$excludeIds = array();
|
||||
$dao = \CRM_Core_DAO::executeQuery($query, array());
|
||||
while ($dao->fetch()) {
|
||||
if ($dao->slave_contact == $dao->contact_id_a && $dao->is_permission_a_b == 0) {
|
||||
$excludeIds[] = $dao->slave_contact;
|
||||
}
|
||||
elseif ($dao->slave_contact == $dao->contact_id_b && $dao->is_permission_b_a == 0) {
|
||||
$excludeIds[] = $dao->slave_contact;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($excludeIds)) {
|
||||
return \CRM_Utils_SQL_Select::fragment()
|
||||
->where("!casContactIdField NOT IN (#excludeMemberIds)")
|
||||
->param(array(
|
||||
'#excludeMemberIds' => $excludeIds,
|
||||
));
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
2531
sites/all/modules/civicrm/CRM/Member/BAO/Membership.php
Normal file
2531
sites/all/modules/civicrm/CRM/Member/BAO/Membership.php
Normal file
File diff suppressed because it is too large
Load diff
81
sites/all/modules/civicrm/CRM/Member/BAO/MembershipBlock.php
Normal file
81
sites/all/modules/civicrm/CRM/Member/BAO/MembershipBlock.php
Normal file
|
@ -0,0 +1,81 @@
|
|||
<?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_BAO_MembershipBlock extends CRM_Member_DAO_MembershipBlock {
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the membership Blocks.
|
||||
*
|
||||
* @param array $params
|
||||
* Reference array contains the values submitted by the form.
|
||||
*
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public static function create(&$params) {
|
||||
$hook = empty($params['id']) ? 'create' : 'edit';
|
||||
CRM_Utils_Hook::pre($hook, 'MembershipBlock', CRM_Utils_Array::value('id', $params), $params);
|
||||
$dao = new CRM_Member_DAO_MembershipBlock();
|
||||
$dao->copyValues($params);
|
||||
$dao->id = CRM_Utils_Array::value('id', $params);
|
||||
$dao->save();
|
||||
CRM_Utils_Hook::post($hook, 'MembershipBlock', $dao->id, $dao);
|
||||
return $dao;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete membership Blocks.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function del($id) {
|
||||
$dao = new CRM_Member_DAO_MembershipBlock();
|
||||
$dao->id = $id;
|
||||
$result = FALSE;
|
||||
if ($dao->find(TRUE)) {
|
||||
$dao->delete();
|
||||
$result = TRUE;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
82
sites/all/modules/civicrm/CRM/Member/BAO/MembershipLog.php
Normal file
82
sites/all/modules/civicrm/CRM/Member/BAO/MembershipLog.php
Normal file
|
@ -0,0 +1,82 @@
|
|||
<?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_BAO_MembershipLog extends CRM_Member_DAO_MembershipLog {
|
||||
|
||||
/**
|
||||
* Add the membership log record.
|
||||
*
|
||||
* @param array $params
|
||||
* Properties of the log item.
|
||||
*
|
||||
* @return CRM_Member_DAO_MembershipLog|CRM_Core_Error
|
||||
*/
|
||||
public static function add($params) {
|
||||
$membershipLog = new CRM_Member_DAO_MembershipLog();
|
||||
$membershipLog->copyValues($params);
|
||||
$membershipLog->save();
|
||||
$membershipLog->free();
|
||||
|
||||
return $membershipLog;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete membership log record.
|
||||
*
|
||||
* @param int $membershipID
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function del($membershipID) {
|
||||
$membershipLog = new CRM_Member_DAO_MembershipLog();
|
||||
$membershipLog->membership_id = $membershipID;
|
||||
return $membershipLog->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the modified ID to NULL for log items by the given contact ID.
|
||||
*
|
||||
* @param int $contactID
|
||||
*/
|
||||
public static function resetModifiedID($contactID) {
|
||||
$query = "
|
||||
UPDATE civicrm_membership_log
|
||||
SET modified_id = null
|
||||
WHERE modified_id = %1";
|
||||
|
||||
$params = array(1 => array($contactID, 'Integer'));
|
||||
CRM_Core_DAO::executeQuery($query, $params);
|
||||
}
|
||||
|
||||
}
|
116
sites/all/modules/civicrm/CRM/Member/BAO/MembershipPayment.php
Normal file
116
sites/all/modules/civicrm/CRM/Member/BAO/MembershipPayment.php
Normal file
|
@ -0,0 +1,116 @@
|
|||
<?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_BAO_MembershipPayment extends CRM_Member_DAO_MembershipPayment {
|
||||
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the membership Payments.
|
||||
*
|
||||
* @param array $params
|
||||
* Reference array contains the values submitted by the form.
|
||||
*
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public static function create($params) {
|
||||
$hook = empty($params['id']) ? 'create' : 'edit';
|
||||
CRM_Utils_Hook::pre($hook, 'MembershipPayment', CRM_Utils_Array::value('id', $params), $params);
|
||||
$dao = new CRM_Member_DAO_MembershipPayment();
|
||||
$dao->copyValues($params);
|
||||
// We check for membership_id in case we are being called too early in the process. This is
|
||||
// cludgey but is part of the deprecation process (ie. we are trying to do everything
|
||||
// from LineItem::create with a view to eventually removing this fn & the table.
|
||||
if (!civicrm_api3('Membership', 'getcount', array('id' => $params['membership_id']))) {
|
||||
return $dao;
|
||||
}
|
||||
|
||||
//Fixed for avoiding duplicate entry error when user goes
|
||||
//back and forward during payment mode is notify
|
||||
if (!$dao->find(TRUE)) {
|
||||
$dao->save();
|
||||
}
|
||||
CRM_Utils_Hook::post($hook, 'MembershipPayment', $dao->id, $dao);
|
||||
// CRM-14197 we are in the process on phasing out membershipPayment in favour of storing both contribution_id & entity_id (membership_id) on the line items
|
||||
// table. However, at this stage we have both - there is still quite a bit of refactoring to do to set the line_iten entity_id right the first time
|
||||
// however, we can assume at this stage that any contribution id will have only one line item with that membership type in the line item table
|
||||
// OR the caller will have taken responsibility for updating the line items themselves so we will update using SQL here
|
||||
if (!isset($params['membership_type_id'])) {
|
||||
$membership_type_id = civicrm_api3('membership', 'getvalue', array(
|
||||
'id' => $dao->membership_id,
|
||||
'return' => 'membership_type_id',
|
||||
));
|
||||
}
|
||||
else {
|
||||
$membership_type_id = $params['membership_type_id'];
|
||||
}
|
||||
$sql = "UPDATE civicrm_line_item li
|
||||
LEFT JOIN civicrm_price_field_value pv ON pv.id = li.price_field_value_id
|
||||
SET entity_table = 'civicrm_membership', entity_id = %1
|
||||
WHERE pv.membership_type_id = %2
|
||||
AND contribution_id = %3";
|
||||
CRM_Core_DAO::executeQuery($sql, array(
|
||||
1 => array($dao->membership_id, 'Integer'),
|
||||
2 => array($membership_type_id, 'Integer'),
|
||||
3 => array($dao->contribution_id, 'Integer'),
|
||||
));
|
||||
return $dao;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete membership Payments.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function del($id) {
|
||||
$dao = new CRM_Member_DAO_MembershipPayment();
|
||||
$dao->id = $id;
|
||||
$result = FALSE;
|
||||
if ($dao->find(TRUE)) {
|
||||
$dao->delete();
|
||||
$result = TRUE;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
401
sites/all/modules/civicrm/CRM/Member/BAO/MembershipStatus.php
Normal file
401
sites/all/modules/civicrm/CRM/Member/BAO/MembershipStatus.php
Normal file
|
@ -0,0 +1,401 @@
|
|||
<?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_BAO_MembershipStatus extends CRM_Member_DAO_MembershipStatus {
|
||||
|
||||
/**
|
||||
* Static holder for the default LT.
|
||||
*/
|
||||
static $_defaultMembershipStatus = NULL;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch object based on array of properties.
|
||||
*
|
||||
* @param array $params
|
||||
* (reference ) an assoc array of name/value pairs.
|
||||
* @param array $defaults
|
||||
* (reference ) an assoc array to hold the flattened values.
|
||||
*
|
||||
* @return CRM_Member_BAO_MembershipStatus
|
||||
*/
|
||||
public static function retrieve(&$params, &$defaults) {
|
||||
$membershipStatus = new CRM_Member_DAO_MembershipStatus();
|
||||
$membershipStatus->copyValues($params);
|
||||
if ($membershipStatus->find(TRUE)) {
|
||||
CRM_Core_DAO::storeValues($membershipStatus, $defaults);
|
||||
return $membershipStatus;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the is_active flag in the db.
|
||||
*
|
||||
* @param int $id
|
||||
* Id of the database record.
|
||||
* @param bool $is_active
|
||||
* Value we want to set the is_active field.
|
||||
*
|
||||
* @return Object
|
||||
* DAO object on success, null otherwise
|
||||
*/
|
||||
public static function setIsActive($id, $is_active) {
|
||||
return CRM_Core_DAO::setFieldValue('CRM_Member_DAO_MembershipStatus', $id, 'is_active', $is_active);
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes an associative array and creates a membership Status object.
|
||||
* See http://wiki.civicrm.org/confluence/display/CRM/Database+layer
|
||||
*
|
||||
* @param array $params
|
||||
* (reference ) an assoc array of name/value pairs.
|
||||
*
|
||||
* @throws Exception
|
||||
* @return CRM_Member_BAO_MembershipStatus
|
||||
*/
|
||||
public static function create($params) {
|
||||
$ids = array();
|
||||
if (!empty($params['id'])) {
|
||||
$ids['membershipStatus'] = $params['id'];
|
||||
}
|
||||
else {
|
||||
//don't allow duplicate names - if id not set
|
||||
$status = new CRM_Member_DAO_MembershipStatus();
|
||||
$status->name = $params['name'];
|
||||
if ($status->find(TRUE)) {
|
||||
throw new Exception('A membership status with this name already exists.');
|
||||
}
|
||||
}
|
||||
$membershipStatusBAO = CRM_Member_BAO_MembershipStatus::add($params, $ids);
|
||||
return $membershipStatusBAO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the membership types.
|
||||
*
|
||||
* @param array $params
|
||||
* Reference array contains the values submitted by the form.
|
||||
* @param array $ids
|
||||
* Array contains the id - this param is deprecated.
|
||||
*
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public static function add(&$params, $ids = array()) {
|
||||
$id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('membershipStatus', $ids));
|
||||
if (!$id) {
|
||||
CRM_Core_DAO::setCreateDefaults($params, self::getDefaults());
|
||||
//copy name to label when not passed.
|
||||
if (empty($params['label']) && !empty($params['name'])) {
|
||||
$params['label'] = $params['name'];
|
||||
}
|
||||
|
||||
if (empty($params['name']) && !empty($params['label'])) {
|
||||
$params['name'] = $params['label'];
|
||||
}
|
||||
}
|
||||
|
||||
// set all other defaults to false.
|
||||
if (!empty($params['is_default'])) {
|
||||
$query = "UPDATE civicrm_membership_status SET is_default = 0";
|
||||
CRM_Core_DAO::executeQuery($query,
|
||||
CRM_Core_DAO::$_nullArray
|
||||
);
|
||||
}
|
||||
|
||||
// action is taken depending upon the mode
|
||||
$membershipStatus = new CRM_Member_DAO_MembershipStatus();
|
||||
$membershipStatus->copyValues($params);
|
||||
|
||||
$membershipStatus->id = $id;
|
||||
|
||||
$membershipStatus->save();
|
||||
CRM_Member_PseudoConstant::flush('membershipStatus');
|
||||
return $membershipStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get defaults for new entity.
|
||||
* @return array
|
||||
*/
|
||||
public static function getDefaults() {
|
||||
return array(
|
||||
'is_active' => FALSE,
|
||||
'is_current_member' => FALSE,
|
||||
'is_admin' => FALSE,
|
||||
'is_default' => FALSE,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get membership status.
|
||||
*
|
||||
* @param int $membershipStatusId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getMembershipStatus($membershipStatusId) {
|
||||
$statusDetails = array();
|
||||
$membershipStatus = new CRM_Member_DAO_MembershipStatus();
|
||||
$membershipStatus->id = $membershipStatusId;
|
||||
if ($membershipStatus->find(TRUE)) {
|
||||
CRM_Core_DAO::storeValues($membershipStatus, $statusDetails);
|
||||
}
|
||||
return $statusDetails;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete membership Types.
|
||||
*
|
||||
* @param int $membershipStatusId
|
||||
*
|
||||
* @throws CRM_Core_Exception
|
||||
*/
|
||||
public static function del($membershipStatusId) {
|
||||
//check dependencies
|
||||
//checking if membership status is present in some other table
|
||||
$check = FALSE;
|
||||
|
||||
$dependency = array('Membership', 'MembershipLog');
|
||||
foreach ($dependency as $name) {
|
||||
$baoString = 'CRM_Member_BAO_' . $name;
|
||||
$dao = new $baoString();
|
||||
$dao->status_id = $membershipStatusId;
|
||||
if ($dao->find(TRUE)) {
|
||||
throw new CRM_Core_Exception(ts('This membership status cannot be deleted as memberships exist with this status'));
|
||||
}
|
||||
}
|
||||
CRM_Utils_Weight::delWeight('CRM_Member_DAO_MembershipStatus', $membershipStatusId);
|
||||
//delete from membership Type table
|
||||
$membershipStatus = new CRM_Member_DAO_MembershipStatus();
|
||||
$membershipStatus->id = $membershipStatusId;
|
||||
if (!$membershipStatus->find()) {
|
||||
throw new CRM_Core_Exception(ts('Cannot delete membership status ' . $membershipStatusId));
|
||||
}
|
||||
$membershipStatus->delete();
|
||||
CRM_Member_PseudoConstant::flush('membershipStatus');
|
||||
$membershipStatus->free();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the membership status based on start date, end date, join date & status date.
|
||||
*
|
||||
* @param string $startDate
|
||||
* Start date of the member whose membership status is to be calculated.
|
||||
* @param string $endDate
|
||||
* End date of the member whose membership status is to be calculated.
|
||||
* @param string $joinDate
|
||||
* Join date of the member whose membership status is to be calculated.
|
||||
* @param \date|string $statusDate status date of the member whose membership status is to be calculated.
|
||||
* @param bool $excludeIsAdmin the statuses those having is_admin = 1.
|
||||
* Exclude the statuses those having is_admin = 1.
|
||||
* @param int $membershipTypeID
|
||||
* @param array $membership
|
||||
* Membership params as available to calling function - passed to the hook.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getMembershipStatusByDate(
|
||||
$startDate, $endDate, $joinDate,
|
||||
$statusDate = 'today', $excludeIsAdmin = FALSE, $membershipTypeID, $membership = array()
|
||||
) {
|
||||
$membershipDetails = array();
|
||||
|
||||
if (!$statusDate || $statusDate == 'today') {
|
||||
$statusDate = getdate();
|
||||
$statusDate = date('Ymd',
|
||||
mktime($statusDate['hours'],
|
||||
$statusDate['minutes'],
|
||||
$statusDate['seconds'],
|
||||
$statusDate['mon'],
|
||||
$statusDate['mday'],
|
||||
$statusDate['year']
|
||||
)
|
||||
);
|
||||
}
|
||||
else {
|
||||
$statusDate = CRM_Utils_Date::customFormat($statusDate, '%Y%m%d');
|
||||
}
|
||||
|
||||
$dates = array('start', 'end', 'join');
|
||||
$events = array('start', 'end');
|
||||
|
||||
foreach ($dates as $dat) {
|
||||
if (${$dat . 'Date'} && ${$dat . 'Date'} != "null") {
|
||||
${$dat . 'Date'} = CRM_Utils_Date::customFormat(${$dat . 'Date'}, '%Y%m%d');
|
||||
|
||||
${$dat . 'Year'} = substr(${$dat . 'Date'}, 0, 4);
|
||||
|
||||
${$dat . 'Month'} = substr(${$dat . 'Date'}, 4, 2);
|
||||
|
||||
${$dat . 'Day'} = substr(${$dat . 'Date'}, 6, 2);
|
||||
}
|
||||
else {
|
||||
${$dat . 'Date'} = '';
|
||||
}
|
||||
}
|
||||
|
||||
//fix for CRM-3570, if we have statuses with is_admin=1,
|
||||
//exclude these statuses from calculatation during import.
|
||||
$where = "is_active = 1";
|
||||
if ($excludeIsAdmin) {
|
||||
$where .= " AND is_admin != 1";
|
||||
}
|
||||
|
||||
$query = "
|
||||
SELECT *
|
||||
FROM civicrm_membership_status
|
||||
WHERE {$where}
|
||||
ORDER BY weight ASC";
|
||||
|
||||
$membershipStatus = CRM_Core_DAO::executeQuery($query);
|
||||
$hour = $minute = $second = 0;
|
||||
|
||||
while ($membershipStatus->fetch()) {
|
||||
$startEvent = NULL;
|
||||
$endEvent = NULL;
|
||||
foreach ($events as $eve) {
|
||||
foreach ($dates as $dat) {
|
||||
// calculate start-event/date and end-event/date
|
||||
if (($membershipStatus->{$eve . '_event'} == $dat . '_date') &&
|
||||
${$dat . 'Date'}
|
||||
) {
|
||||
if ($membershipStatus->{$eve . '_event_adjust_unit'} &&
|
||||
$membershipStatus->{$eve . '_event_adjust_interval'}
|
||||
) {
|
||||
// add in months
|
||||
if ($membershipStatus->{$eve . '_event_adjust_unit'} == 'month') {
|
||||
${$eve . 'Event'} = date('Ymd', mktime($hour, $minute, $second,
|
||||
${$dat . 'Month'} + $membershipStatus->{$eve . '_event_adjust_interval'},
|
||||
${$dat . 'Day'},
|
||||
${$dat . 'Year'}
|
||||
));
|
||||
}
|
||||
// add in days
|
||||
if ($membershipStatus->{$eve . '_event_adjust_unit'} == 'day') {
|
||||
${$eve . 'Event'} = date('Ymd', mktime($hour, $minute, $second,
|
||||
${$dat . 'Month'},
|
||||
${$dat . 'Day'} + $membershipStatus->{$eve . '_event_adjust_interval'},
|
||||
${$dat . 'Year'}
|
||||
));
|
||||
}
|
||||
// add in years
|
||||
if ($membershipStatus->{$eve . '_event_adjust_unit'} == 'year') {
|
||||
${$eve . 'Event'} = date('Ymd', mktime($hour, $minute, $second,
|
||||
${$dat . 'Month'},
|
||||
${$dat . 'Day'},
|
||||
${$dat . 'Year'} + $membershipStatus->{$eve . '_event_adjust_interval'}
|
||||
));
|
||||
}
|
||||
// if no interval and unit, present
|
||||
}
|
||||
else {
|
||||
${$eve . 'Event'} = ${$dat . 'Date'};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check if statusDate is in the range of start & end events.
|
||||
if ($startEvent && $endEvent) {
|
||||
if (($statusDate >= $startEvent) && ($statusDate <= $endEvent)) {
|
||||
$membershipDetails['id'] = $membershipStatus->id;
|
||||
$membershipDetails['name'] = $membershipStatus->name;
|
||||
}
|
||||
}
|
||||
elseif ($startEvent) {
|
||||
if ($statusDate >= $startEvent) {
|
||||
$membershipDetails['id'] = $membershipStatus->id;
|
||||
$membershipDetails['name'] = $membershipStatus->name;
|
||||
}
|
||||
}
|
||||
elseif ($endEvent) {
|
||||
if ($statusDate <= $endEvent) {
|
||||
$membershipDetails['id'] = $membershipStatus->id;
|
||||
$membershipDetails['name'] = $membershipStatus->name;
|
||||
}
|
||||
}
|
||||
|
||||
// returns FIRST status record for which status_date is in range.
|
||||
if ($membershipDetails) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
//end fetch
|
||||
|
||||
$membershipStatus->free();
|
||||
|
||||
//we bundle the arguments into an array as we can't pass 8 variables to the hook otherwise
|
||||
// the membership array might contain the pre-altered settings so we don't want to merge this
|
||||
$arguments = array(
|
||||
'start_date' => $startDate,
|
||||
'end_date' => $endDate,
|
||||
'join_date' => $joinDate,
|
||||
'status_date' => $statusDate,
|
||||
'exclude_is_admin' => $endDate,
|
||||
'membership_type_id' => $membershipTypeID,
|
||||
'start_event' => $startEvent,
|
||||
'end_event' => $endEvent,
|
||||
);
|
||||
CRM_Utils_Hook::alterCalculatedMembershipStatus($membershipDetails, $arguments, $membership);
|
||||
return $membershipDetails;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function that return the status ids whose is_current_member is set.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getMembershipStatusCurrent() {
|
||||
$statusIds = array();
|
||||
$membershipStatus = new CRM_Member_DAO_MembershipStatus();
|
||||
$membershipStatus->is_current_member = 1;
|
||||
$membershipStatus->find();
|
||||
$membershipStatus->selectAdd();
|
||||
$membershipStatus->selectAdd('id');
|
||||
while ($membershipStatus->fetch()) {
|
||||
$statusIds[] = $membershipStatus->id;
|
||||
}
|
||||
$membershipStatus->free();
|
||||
return $statusIds;
|
||||
}
|
||||
|
||||
}
|
831
sites/all/modules/civicrm/CRM/Member/BAO/MembershipType.php
Normal file
831
sites/all/modules/civicrm/CRM/Member/BAO/MembershipType.php
Normal file
|
@ -0,0 +1,831 @@
|
|||
<?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_BAO_MembershipType extends CRM_Member_DAO_MembershipType {
|
||||
|
||||
/**
|
||||
* Static holder for the default Membership Type.
|
||||
*/
|
||||
static $_defaultMembershipType = NULL;
|
||||
|
||||
static $_membershipTypeInfo = array();
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch object based on array of properties.
|
||||
*
|
||||
* @param array $params
|
||||
* (reference ) an assoc array of name/value pairs.
|
||||
* @param array $defaults
|
||||
* (reference ) an assoc array to hold the flattened values.
|
||||
*
|
||||
* @return CRM_Member_BAO_MembershipType
|
||||
*/
|
||||
public static function retrieve(&$params, &$defaults) {
|
||||
$membershipType = new CRM_Member_DAO_MembershipType();
|
||||
$membershipType->copyValues($params);
|
||||
if ($membershipType->find(TRUE)) {
|
||||
CRM_Core_DAO::storeValues($membershipType, $defaults);
|
||||
return $membershipType;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the is_active flag in the db.
|
||||
*
|
||||
* @param int $id
|
||||
* Id of the database record.
|
||||
* @param bool $is_active
|
||||
* Value we want to set the is_active field.
|
||||
*
|
||||
* @return Object
|
||||
* DAO object on success, null otherwise
|
||||
*/
|
||||
public static function setIsActive($id, $is_active) {
|
||||
return CRM_Core_DAO::setFieldValue('CRM_Member_DAO_MembershipType', $id, 'is_active', $is_active);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the membership types.
|
||||
*
|
||||
* @param array $params
|
||||
* Reference array contains the values submitted by the form.
|
||||
* @param array $ids
|
||||
* Array contains the id (deprecated).
|
||||
*
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public static function add(&$params, $ids = array()) {
|
||||
$id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('membershipType', $ids));
|
||||
if (!$id) {
|
||||
if (!isset($params['is_active'])) {
|
||||
// do we need this?
|
||||
$params['is_active'] = FALSE;
|
||||
}
|
||||
if (!isset($params['domain_id'])) {
|
||||
$params['domain_id'] = CRM_Core_Config::domainID();
|
||||
}
|
||||
}
|
||||
|
||||
// action is taken depending upon the mode
|
||||
$membershipType = new CRM_Member_DAO_MembershipType();
|
||||
$membershipType->copyValues($params);
|
||||
$membershipType->id = $id;
|
||||
|
||||
// $previousID is the old organization id for membership type i.e 'member_of_contact_id'. This is used when an organization is changed.
|
||||
$previousID = NULL;
|
||||
if ($id) {
|
||||
$previousID = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $id, 'member_of_contact_id');
|
||||
}
|
||||
|
||||
$membershipType->save();
|
||||
if ($id) {
|
||||
// on update we may need to retrieve some details for the price field function - otherwise we get e-notices on attempts to retrieve
|
||||
// name etc - the presence of previous id tells us this is an update
|
||||
$params = array_merge(civicrm_api3('membership_type', 'getsingle', array('id' => $membershipType->id)), $params);
|
||||
}
|
||||
self::createMembershipPriceField($params, $previousID, $membershipType->id);
|
||||
// update all price field value for quick config when membership type is set CRM-11718
|
||||
if ($id) {
|
||||
self::updateAllPriceFieldValue($id, $params);
|
||||
}
|
||||
self::flush();
|
||||
return $membershipType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush anywhere that membership types might be cached.
|
||||
*
|
||||
* @throws \CiviCRM_API3_Exception
|
||||
*/
|
||||
public static function flush() {
|
||||
CRM_Member_PseudoConstant::membershipType(NULL, TRUE);
|
||||
civicrm_api3('membership', 'getfields', array('cache_clear' => 1, 'fieldname' => 'membership_type_id'));
|
||||
civicrm_api3('profile', 'getfields', array('action' => 'submit', 'cache_clear' => 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete membership Types.
|
||||
*
|
||||
* @param int $membershipTypeId
|
||||
*
|
||||
* @throws CRM_Core_Exception
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public static function del($membershipTypeId) {
|
||||
// Check dependencies.
|
||||
$check = FALSE;
|
||||
$status = array();
|
||||
$dependency = array(
|
||||
'Membership' => 'membership_type_id',
|
||||
'MembershipBlock' => 'membership_type_default',
|
||||
);
|
||||
|
||||
foreach ($dependency as $name => $field) {
|
||||
$baoString = 'CRM_Member_BAO_' . $name;
|
||||
$dao = new $baoString();
|
||||
$dao->$field = $membershipTypeId;
|
||||
/** @noinspection PhpUndefinedMethodInspection */
|
||||
if ($dao->find(TRUE)) {
|
||||
$check = TRUE;
|
||||
$status[] = $name;
|
||||
}
|
||||
}
|
||||
if ($check) {
|
||||
$cnt = 1;
|
||||
$message = ts('This membership type cannot be deleted due to following reason(s):');
|
||||
if (in_array('Membership', $status)) {
|
||||
$findMembersURL = CRM_Utils_System::url('civicrm/member/search', 'reset=1');
|
||||
$deleteURL = CRM_Utils_System::url('civicrm/contact/search/advanced', 'reset=1');
|
||||
$message .= '<br/>' . ts('%3. There are some contacts who have this membership type assigned to them. Search for contacts with this membership type from <a href=\'%1\'>Find Members</a>. If you are still getting this message after deleting these memberships, there may be contacts in the Trash (deleted) with this membership type. Try using <a href="%2">Advanced Search</a> and checking "Search in Trash".', array(
|
||||
1 => $findMembersURL,
|
||||
2 => $deleteURL,
|
||||
3 => $cnt,
|
||||
));
|
||||
$cnt++;
|
||||
}
|
||||
|
||||
if (in_array('MembershipBlock', $status)) {
|
||||
$deleteURL = CRM_Utils_System::url('civicrm/admin/contribute', 'reset=1');
|
||||
$message .= ts('%2. This Membership Type is used in an <a href=\'%1\'>Online Contribution page</a>. Uncheck this membership type in the Memberships tab.', array(
|
||||
1 => $deleteURL,
|
||||
2 => $cnt,
|
||||
));
|
||||
throw new CRM_Core_Exception($message);
|
||||
}
|
||||
}
|
||||
CRM_Utils_Weight::delWeight('CRM_Member_DAO_MembershipType', $membershipTypeId);
|
||||
//delete from membership Type table
|
||||
$membershipType = new CRM_Member_DAO_MembershipType();
|
||||
$membershipType->id = $membershipTypeId;
|
||||
|
||||
//fix for membership type delete api
|
||||
$result = FALSE;
|
||||
if ($membershipType->find(TRUE)) {
|
||||
return $membershipType->delete();
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert membership type's 'start day' & 'rollover day' to human readable formats.
|
||||
*
|
||||
* @param array $membershipType
|
||||
* An array of membershipType-details.
|
||||
*/
|
||||
public static function convertDayFormat(&$membershipType) {
|
||||
$periodDays = array(
|
||||
'fixed_period_start_day',
|
||||
'fixed_period_rollover_day',
|
||||
);
|
||||
foreach ($membershipType as $id => $details) {
|
||||
foreach ($periodDays as $pDay) {
|
||||
if (!empty($details[$pDay])) {
|
||||
if ($details[$pDay] > 31) {
|
||||
$month = substr($details[$pDay], 0, strlen($details[$pDay]) - 2);
|
||||
$day = substr($details[$pDay], -2);
|
||||
$monthMap = array(
|
||||
'1' => 'Jan',
|
||||
'2' => 'Feb',
|
||||
'3' => 'Mar',
|
||||
'4' => 'Apr',
|
||||
'5' => 'May',
|
||||
'6' => 'Jun',
|
||||
'7' => 'Jul',
|
||||
'8' => 'Aug',
|
||||
'9' => 'Sep',
|
||||
'10' => 'Oct',
|
||||
'11' => 'Nov',
|
||||
'12' => 'Dec',
|
||||
);
|
||||
$membershipType[$id][$pDay] = $monthMap[$month] . ' ' . $day;
|
||||
}
|
||||
else {
|
||||
$membershipType[$id][$pDay] = $details[$pDay];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get membership Types.
|
||||
*
|
||||
* @param bool $public
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getMembershipTypes($public = TRUE) {
|
||||
$membershipTypes = array();
|
||||
$membershipType = new CRM_Member_DAO_MembershipType();
|
||||
$membershipType->is_active = 1;
|
||||
if ($public) {
|
||||
$membershipType->visibility = 'Public';
|
||||
}
|
||||
$membershipType->orderBy(' weight');
|
||||
$membershipType->find();
|
||||
while ($membershipType->fetch()) {
|
||||
$membershipTypes[$membershipType->id] = $membershipType->name;
|
||||
}
|
||||
$membershipType->free();
|
||||
return $membershipTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get membership Type Details.
|
||||
*
|
||||
* @param int $membershipTypeId
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public static function getMembershipTypeDetails($membershipTypeId) {
|
||||
$membershipTypeDetails = array();
|
||||
|
||||
$membershipType = new CRM_Member_DAO_MembershipType();
|
||||
$membershipType->is_active = 1;
|
||||
$membershipType->id = $membershipTypeId;
|
||||
if ($membershipType->find(TRUE)) {
|
||||
CRM_Core_DAO::storeValues($membershipType, $membershipTypeDetails);
|
||||
$membershipType->free();
|
||||
return $membershipTypeDetails;
|
||||
}
|
||||
else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate start date and end date for new membership.
|
||||
*
|
||||
* @param int $membershipTypeId
|
||||
* Membership type id.
|
||||
* @param string $joinDate
|
||||
* Member since ( in mysql date format ).
|
||||
* @param string $startDate
|
||||
* Start date ( in mysql date format ).
|
||||
* @param null $endDate
|
||||
* @param int $numRenewTerms
|
||||
* How many membership terms are being added to end date (default is 1).
|
||||
*
|
||||
* @return array
|
||||
* associated array with start date, end date and join date for the membership
|
||||
*/
|
||||
public static function getDatesForMembershipType($membershipTypeId, $joinDate = NULL, $startDate = NULL, $endDate = NULL, $numRenewTerms = 1) {
|
||||
$membershipTypeDetails = self::getMembershipTypeDetails($membershipTypeId);
|
||||
|
||||
// Convert all dates to 'Y-m-d' format.
|
||||
foreach (array(
|
||||
'joinDate',
|
||||
'startDate',
|
||||
'endDate',
|
||||
) as $dateParam) {
|
||||
if (!empty($$dateParam)) {
|
||||
$$dateParam = CRM_Utils_Date::processDate($$dateParam, NULL, FALSE, 'Y-m-d');
|
||||
}
|
||||
}
|
||||
if (!$joinDate) {
|
||||
$joinDate = date('Y-m-d');
|
||||
}
|
||||
$actualStartDate = $joinDate;
|
||||
if ($startDate) {
|
||||
$actualStartDate = $startDate;
|
||||
}
|
||||
|
||||
$fixed_period_rollover = FALSE;
|
||||
if (CRM_Utils_Array::value('period_type', $membershipTypeDetails) == 'rolling') {
|
||||
if (!$startDate) {
|
||||
$startDate = $joinDate;
|
||||
}
|
||||
$actualStartDate = $startDate;
|
||||
}
|
||||
elseif (CRM_Utils_Array::value('period_type', $membershipTypeDetails) == 'fixed') {
|
||||
// calculate start date
|
||||
// if !$startDate then use $joinDate
|
||||
$toDay = explode('-', (empty($startDate) ? $joinDate : $startDate));
|
||||
$year = $toDay[0];
|
||||
$month = $toDay[1];
|
||||
$day = $toDay[2];
|
||||
|
||||
if ($membershipTypeDetails['duration_unit'] == 'year') {
|
||||
|
||||
//get start fixed day
|
||||
$startMonth = substr($membershipTypeDetails['fixed_period_start_day'], 0,
|
||||
strlen($membershipTypeDetails['fixed_period_start_day']) - 2
|
||||
);
|
||||
$startDay = substr($membershipTypeDetails['fixed_period_start_day'], -2);
|
||||
|
||||
if (date('Y-m-d', mktime(0, 0, 0, $startMonth, $startDay, $year)) <= date('Y-m-d', mktime(0, 0, 0, $month, $day, $year))) {
|
||||
$actualStartDate = date('Y-m-d', mktime(0, 0, 0, $startMonth, $startDay, $year));
|
||||
}
|
||||
else {
|
||||
$actualStartDate = date('Y-m-d', mktime(0, 0, 0, $startMonth, $startDay, $year - 1));
|
||||
}
|
||||
|
||||
$fixed_period_rollover = self::isDuringFixedAnnualRolloverPeriod($joinDate, $membershipTypeDetails, $year, $actualStartDate);
|
||||
|
||||
if (!$startDate) {
|
||||
$startDate = $actualStartDate;
|
||||
}
|
||||
}
|
||||
elseif ($membershipTypeDetails['duration_unit'] == 'month') {
|
||||
// Check if we are on or after rollover day of the month - CRM-10585
|
||||
// If so, set fixed_period_rollover TRUE so we increment end_date month below.
|
||||
$dateParts = explode('-', $actualStartDate);
|
||||
if ($dateParts[2] >= $membershipTypeDetails['fixed_period_rollover_day']) {
|
||||
$fixed_period_rollover = TRUE;
|
||||
}
|
||||
|
||||
// Start date is always first day of actualStartDate month
|
||||
if (!$startDate) {
|
||||
$actualStartDate = $startDate = $year . '-' . $month . '-01';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate end date if it is not passed by user.
|
||||
if (!$endDate) {
|
||||
//end date calculation
|
||||
$date = explode('-', $actualStartDate);
|
||||
$year = $date[0];
|
||||
$month = $date[1];
|
||||
$day = $date[2];
|
||||
|
||||
switch ($membershipTypeDetails['duration_unit']) {
|
||||
case 'year':
|
||||
$year = $year + ($numRenewTerms * $membershipTypeDetails['duration_interval']);
|
||||
//extend membership date by duration interval.
|
||||
if ($fixed_period_rollover) {
|
||||
$year += 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'month':
|
||||
$month = $month + ($numRenewTerms * $membershipTypeDetails['duration_interval']);
|
||||
//duration interval is month
|
||||
if ($fixed_period_rollover) {
|
||||
//CRM-10585
|
||||
$month += 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'day':
|
||||
$day = $day + ($numRenewTerms * $membershipTypeDetails['duration_interval']);
|
||||
|
||||
if ($fixed_period_rollover) {
|
||||
//Fix Me: Currently we don't allow rollover if
|
||||
//duration interval is day
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if ($membershipTypeDetails['duration_unit'] == 'lifetime') {
|
||||
$endDate = NULL;
|
||||
}
|
||||
else {
|
||||
$endDate = date('Y-m-d', mktime(0, 0, 0, $month, $day - 1, $year));
|
||||
}
|
||||
}
|
||||
|
||||
$membershipDates = array(
|
||||
'start_date' => CRM_Utils_Date::customFormat($startDate, '%Y%m%d'),
|
||||
'end_date' => CRM_Utils_Date::customFormat($endDate, '%Y%m%d'),
|
||||
'join_date' => CRM_Utils_Date::customFormat($joinDate, '%Y%m%d'),
|
||||
);
|
||||
|
||||
return $membershipDates;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this membership start between the rollover date and the start of the next period.
|
||||
* (in which case they will get an extra membership period)
|
||||
* ie if annual memberships run June - May & the rollover is in May memberships between
|
||||
* May and June will return TRUE and between June and May will return FALSE
|
||||
*
|
||||
* @param string $startDate start date of current membership period
|
||||
* @param array $membershipTypeDetails
|
||||
* @param int $year
|
||||
* @param string $actualStartDate
|
||||
* @return bool is this in the window where the membership gets an extra part-period added
|
||||
*/
|
||||
public static function isDuringFixedAnnualRolloverPeriod($startDate, $membershipTypeDetails, $year, $actualStartDate) {
|
||||
|
||||
$rolloverMonth = substr($membershipTypeDetails['fixed_period_rollover_day'], 0,
|
||||
strlen($membershipTypeDetails['fixed_period_rollover_day']) - 2
|
||||
);
|
||||
$rolloverDay = substr($membershipTypeDetails['fixed_period_rollover_day'], -2);
|
||||
|
||||
$calculatedRolloverDate = date('Y-m-d', mktime(0, 0, 0, $rolloverMonth, $rolloverDay, $year));
|
||||
|
||||
//CRM-7825 -membership date rules are :
|
||||
//1. Membership should not be start in future.
|
||||
//2. rollover window should be subset of membership window.
|
||||
|
||||
//get the fixed end date here.
|
||||
$dateParts = explode('-', $actualStartDate);
|
||||
$endDateOfFirstYearMembershipPeriod = date('Y-m-d', mktime(0, 0, 0,
|
||||
$dateParts[1],
|
||||
$dateParts[2] - 1,
|
||||
$dateParts[0] + 1
|
||||
));
|
||||
|
||||
//we know the month and day of the rollover date but not the year (we're just
|
||||
//using the start date year at the moment. So if it's after the end
|
||||
// of the first year of membership then it's the next period & we'll adjust back a year. If it's
|
||||
// before the start_date then it's too early & we'll adjust forward.
|
||||
if ($endDateOfFirstYearMembershipPeriod < $calculatedRolloverDate) {
|
||||
$calculatedRolloverDate = date('Y-m-d', mktime(0, 0, 0, $rolloverMonth, $rolloverDay, $year - 1));
|
||||
}
|
||||
if ($calculatedRolloverDate < $actualStartDate) {
|
||||
$calculatedRolloverDate = date('Y-m-d', mktime(0, 0, 0, $rolloverMonth, $rolloverDay, $year + 1));
|
||||
}
|
||||
|
||||
if ($calculatedRolloverDate <= $startDate) {
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate start date and end date for membership updates.
|
||||
*
|
||||
* Note that this function is called by the api for any membership update although it was
|
||||
* originally written for renewal (which feels a bit fragile but hey....).
|
||||
*
|
||||
* @param int $membershipId
|
||||
* @param $changeToday
|
||||
* @param int $membershipTypeID
|
||||
* If provided, overrides the membership type of the $membershipID membership.
|
||||
* @param int $numRenewTerms
|
||||
* How many membership terms are being added to end date (default is 1).
|
||||
*
|
||||
* CRM-7297 Membership Upsell - Added $membershipTypeID param to facilitate calculations of dates when membership type changes
|
||||
*
|
||||
* @return array
|
||||
* array fo the start date, end date and join date of the membership
|
||||
*/
|
||||
public static function getRenewalDatesForMembershipType($membershipId, $changeToday = NULL, $membershipTypeID = NULL, $numRenewTerms = 1) {
|
||||
$params = array('id' => $membershipId);
|
||||
$membershipDetails = CRM_Member_BAO_Membership::getValues($params, $values);
|
||||
$membershipDetails = $membershipDetails[$membershipId];
|
||||
$statusID = $membershipDetails->status_id;
|
||||
$membershipDates = array();
|
||||
if (!empty($membershipDetails->join_date)) {
|
||||
$membershipDates['join_date'] = CRM_Utils_Date::customFormat($membershipDetails->join_date, '%Y%m%d');
|
||||
}
|
||||
|
||||
$oldPeriodType = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType',
|
||||
CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $membershipId, 'membership_type_id'), 'period_type');
|
||||
|
||||
// CRM-7297 Membership Upsell
|
||||
if (is_null($membershipTypeID)) {
|
||||
$membershipTypeDetails = self::getMembershipTypeDetails($membershipDetails->membership_type_id);
|
||||
}
|
||||
else {
|
||||
$membershipTypeDetails = self::getMembershipTypeDetails($membershipTypeID);
|
||||
}
|
||||
$statusDetails = CRM_Member_BAO_MembershipStatus::getMembershipStatus($statusID);
|
||||
|
||||
if ($statusDetails['is_current_member'] == 1) {
|
||||
$startDate = $membershipDetails->start_date;
|
||||
// CRM=7297 Membership Upsell: we need to handle null end_date in case we are switching
|
||||
// from a lifetime to a different membership type
|
||||
if (is_null($membershipDetails->end_date)) {
|
||||
$date = date('Y-m-d');
|
||||
}
|
||||
else {
|
||||
$date = $membershipDetails->end_date;
|
||||
}
|
||||
$date = explode('-', $date);
|
||||
$logStartDate = date('Y-m-d', mktime(0, 0, 0,
|
||||
(double) $date[1],
|
||||
(double) ($date[2] + 1),
|
||||
(double) $date[0]
|
||||
));
|
||||
|
||||
$date = explode('-', $logStartDate);
|
||||
$year = $date[0];
|
||||
$month = $date[1];
|
||||
$day = $date[2];
|
||||
|
||||
switch ($membershipTypeDetails['duration_unit']) {
|
||||
case 'year':
|
||||
//need to check if the upsell is from rolling to fixed and adjust accordingly
|
||||
if ($membershipTypeDetails['period_type'] == 'fixed' && $oldPeriodType == 'rolling') {
|
||||
$month = substr($membershipTypeDetails['fixed_period_start_day'], 0, strlen($membershipTypeDetails['fixed_period_start_day']) - 2);
|
||||
$day = substr($membershipTypeDetails['fixed_period_start_day'], -2);
|
||||
$year += 1;
|
||||
}
|
||||
else {
|
||||
$year = $year + ($numRenewTerms * $membershipTypeDetails['duration_interval']);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'month':
|
||||
$month = $month + ($numRenewTerms * $membershipTypeDetails['duration_interval']);
|
||||
break;
|
||||
|
||||
case 'day':
|
||||
$day = $day + ($numRenewTerms * $membershipTypeDetails['duration_interval']);
|
||||
break;
|
||||
}
|
||||
if ($membershipTypeDetails['duration_unit'] == 'lifetime') {
|
||||
$endDate = NULL;
|
||||
}
|
||||
else {
|
||||
$endDate = date('Y-m-d', mktime(0, 0, 0,
|
||||
$month,
|
||||
$day - 1,
|
||||
$year
|
||||
));
|
||||
}
|
||||
$today = date('Y-m-d');
|
||||
$membershipDates['today'] = CRM_Utils_Date::customFormat($today, '%Y%m%d');
|
||||
$membershipDates['start_date'] = CRM_Utils_Date::customFormat($startDate, '%Y%m%d');
|
||||
$membershipDates['end_date'] = CRM_Utils_Date::customFormat($endDate, '%Y%m%d');
|
||||
$membershipDates['log_start_date'] = CRM_Utils_Date::customFormat($logStartDate, '%Y%m%d');
|
||||
}
|
||||
else {
|
||||
$today = date('Y-m-d');
|
||||
if ($changeToday) {
|
||||
$today = CRM_Utils_Date::processDate($changeToday, NULL, FALSE, 'Y-m-d');
|
||||
}
|
||||
// Calculate new start/end dates when join date is today
|
||||
$renewalDates = self::getDatesForMembershipType($membershipTypeDetails['id'],
|
||||
$today, NULL, NULL, $numRenewTerms
|
||||
);
|
||||
$membershipDates['today'] = CRM_Utils_Date::customFormat($today, '%Y%m%d');
|
||||
$membershipDates['start_date'] = $renewalDates['start_date'];
|
||||
$membershipDates['end_date'] = $renewalDates['end_date'];
|
||||
$membershipDates['log_start_date'] = $renewalDates['start_date'];
|
||||
// CRM-18503 - set join_date as today in case the membership type is fixed.
|
||||
if ($membershipTypeDetails['period_type'] == 'fixed' && !isset($membershipDates['join_date'])) {
|
||||
$membershipDates['join_date'] = $renewalDates['join_date'];
|
||||
}
|
||||
}
|
||||
if (!isset($membershipDates['join_date'])) {
|
||||
$membershipDates['join_date'] = $membershipDates['start_date'];
|
||||
}
|
||||
|
||||
return $membershipDates;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Please use the Membership API
|
||||
* Retrieve all Membership Types associated with an Organization
|
||||
*
|
||||
* @param int $orgID
|
||||
* Id of Organization.
|
||||
*
|
||||
* @return array
|
||||
* array of the details of membership types
|
||||
*/
|
||||
public static function getMembershipTypesByOrg($orgID) {
|
||||
Civi::log()->warning('Deprecated function getMembershipTypesByOrg, please user membership_type api', array('civi.tag' => 'deprecated'));
|
||||
$memberTypesSameParentOrg = civicrm_api3('MembershipType', 'get', array(
|
||||
'member_of_contact_id' => $orgID,
|
||||
'options' => array(
|
||||
'limit' => 0,
|
||||
),
|
||||
));
|
||||
return CRM_Utils_Array::value('values', $memberTypesSameParentOrg, array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all Membership Types with Member of Contact id.
|
||||
*
|
||||
* @param array $membershipTypes
|
||||
* array of membership type ids
|
||||
* @return array
|
||||
* array of the details of membership types with Member of Contact id
|
||||
*/
|
||||
public static function getMemberOfContactByMemTypes($membershipTypes) {
|
||||
$memTypeOrganizations = array();
|
||||
if (empty($membershipTypes)) {
|
||||
return $memTypeOrganizations;
|
||||
}
|
||||
|
||||
$result = CRM_Core_DAO::executeQuery("SELECT id, member_of_contact_id FROM civicrm_membership_type WHERE id IN (" . implode(',', $membershipTypes) . ")");
|
||||
while ($result->fetch()) {
|
||||
$memTypeOrganizations[$result->id] = $result->member_of_contact_id;
|
||||
}
|
||||
|
||||
return $memTypeOrganizations;
|
||||
}
|
||||
|
||||
/**
|
||||
* The function returns all the Organization for all membershipTypes .
|
||||
*
|
||||
* @param int $membershipTypeId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getMembershipTypeOrganization($membershipTypeId = NULL) {
|
||||
$allMembershipTypes = array();
|
||||
|
||||
$membershipType = new CRM_Member_DAO_MembershipType();
|
||||
|
||||
if (isset($membershipTypeId)) {
|
||||
$membershipType->id = $membershipTypeId;
|
||||
}
|
||||
$membershipType->find();
|
||||
|
||||
while ($membershipType->fetch()) {
|
||||
$allMembershipTypes[$membershipType->id] = $membershipType->member_of_contact_id;
|
||||
}
|
||||
return $allMembershipTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to retrieve organization and associated membership
|
||||
* types
|
||||
*
|
||||
* @return array
|
||||
* arrays of organization and membership types
|
||||
*
|
||||
*/
|
||||
public static function getMembershipTypeInfo() {
|
||||
if (!self::$_membershipTypeInfo) {
|
||||
$orgs = $types = array();
|
||||
|
||||
$query = 'SELECT memType.id, memType.name, memType.member_of_contact_id, c.sort_name
|
||||
FROM civicrm_membership_type memType INNER JOIN civicrm_contact c ON c.id = memType.member_of_contact_id
|
||||
WHERE memType.is_active = 1 ';
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
while ($dao->fetch()) {
|
||||
$orgs[$dao->member_of_contact_id] = $dao->sort_name;
|
||||
$types[$dao->member_of_contact_id][$dao->id] = $dao->name;
|
||||
}
|
||||
|
||||
self::$_membershipTypeInfo = array($orgs, $types);
|
||||
}
|
||||
return self::$_membershipTypeInfo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $params
|
||||
* @param int $previousID
|
||||
* @param int $membershipTypeId
|
||||
*/
|
||||
public static function createMembershipPriceField($params, $previousID, $membershipTypeId) {
|
||||
|
||||
$priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', 'default_membership_type_amount', 'id', 'name');
|
||||
|
||||
if (!empty($params['member_of_contact_id'])) {
|
||||
$fieldName = $params['member_of_contact_id'];
|
||||
}
|
||||
else {
|
||||
$fieldName = $previousID;
|
||||
}
|
||||
$fieldLabel = 'Membership Amount';
|
||||
$optionsIds = NULL;
|
||||
$fieldParams = array(
|
||||
'price_set_id ' => $priceSetId,
|
||||
'name' => $fieldName,
|
||||
);
|
||||
$results = array();
|
||||
CRM_Price_BAO_PriceField::retrieve($fieldParams, $results);
|
||||
if (empty($results)) {
|
||||
$fieldParams = array();
|
||||
$fieldParams['label'] = $fieldLabel;
|
||||
$fieldParams['name'] = $fieldName;
|
||||
$fieldParams['price_set_id'] = $priceSetId;
|
||||
$fieldParams['html_type'] = 'Radio';
|
||||
$fieldParams['is_display_amounts'] = $fieldParams['is_required'] = 0;
|
||||
$fieldParams['weight'] = $fieldParams['option_weight'][1] = 1;
|
||||
$fieldParams['option_label'][1] = $params['name'];
|
||||
$fieldParams['option_description'][1] = CRM_Utils_Array::value('description', $params);
|
||||
|
||||
$fieldParams['membership_type_id'][1] = $membershipTypeId;
|
||||
$fieldParams['option_amount'][1] = empty($params['minimum_fee']) ? 0 : $params['minimum_fee'];
|
||||
$fieldParams['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $params);
|
||||
|
||||
if ($previousID) {
|
||||
CRM_Member_Form_MembershipType::checkPreviousPriceField($previousID, $priceSetId, $membershipTypeId, $optionsIds);
|
||||
$fieldParams['option_id'] = CRM_Utils_Array::value('option_id', $optionsIds);
|
||||
}
|
||||
CRM_Price_BAO_PriceField::create($fieldParams);
|
||||
}
|
||||
else {
|
||||
$fieldID = $results['id'];
|
||||
$fieldValueParams = array(
|
||||
'price_field_id' => $fieldID,
|
||||
'membership_type_id' => $membershipTypeId,
|
||||
);
|
||||
$results = array();
|
||||
CRM_Price_BAO_PriceFieldValue::retrieve($fieldValueParams, $results);
|
||||
if (!empty($results)) {
|
||||
$results['label'] = $results['name'] = $params['name'];
|
||||
$results['amount'] = empty($params['minimum_fee']) ? 0 : $params['minimum_fee'];
|
||||
$optionsIds['id'] = $results['id'];
|
||||
}
|
||||
else {
|
||||
$results = array(
|
||||
'price_field_id' => $fieldID,
|
||||
'name' => $params['name'],
|
||||
'label' => $params['name'],
|
||||
'amount' => empty($params['minimum_fee']) ? 0 : $params['minimum_fee'],
|
||||
'membership_type_id' => $membershipTypeId,
|
||||
'is_active' => 1,
|
||||
);
|
||||
}
|
||||
|
||||
if ($previousID) {
|
||||
CRM_Member_Form_MembershipType::checkPreviousPriceField($previousID, $priceSetId, $membershipTypeId, $optionsIds);
|
||||
if (!empty($optionsIds['option_id'])) {
|
||||
$optionsIds['id'] = current(CRM_Utils_Array::value('option_id', $optionsIds));
|
||||
}
|
||||
}
|
||||
$results['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $params);
|
||||
$results['description'] = CRM_Utils_Array::value('description', $params);
|
||||
CRM_Price_BAO_PriceFieldValue::add($results, $optionsIds);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function updates all price field value for quick config
|
||||
* price set which has membership type
|
||||
*
|
||||
* @param int $membershipTypeId membership type id
|
||||
*
|
||||
* @param array $params
|
||||
*/
|
||||
public static function updateAllPriceFieldValue($membershipTypeId, $params) {
|
||||
$updateFields = array();
|
||||
if (!empty($params['minimum_fee'])) {
|
||||
$amount = $params['minimum_fee'];
|
||||
}
|
||||
else {
|
||||
$amount = 0;
|
||||
}
|
||||
|
||||
$updateValues = array(
|
||||
2 => array('financial_type_id', 'financial_type_id', 'Integer'),
|
||||
3 => array('label', 'name', 'String'),
|
||||
4 => array('amount', 'minimum_fee', 'Float'),
|
||||
5 => array('description', 'description', 'String'),
|
||||
);
|
||||
|
||||
$queryParams = array(1 => array($membershipTypeId, 'Integer'));
|
||||
foreach ($updateValues as $key => $value) {
|
||||
if (array_key_exists($value[1], $params)) {
|
||||
$updateFields[] = "cpfv." . $value[0] . " = %$key";
|
||||
if ($value[1] == 'minimum_fee') {
|
||||
$fieldValue = $amount;
|
||||
}
|
||||
else {
|
||||
$fieldValue = $params[$value[1]];
|
||||
}
|
||||
$queryParams[$key] = array($fieldValue, $value[2]);
|
||||
}
|
||||
}
|
||||
|
||||
$query = "UPDATE `civicrm_price_field_value` cpfv
|
||||
INNER JOIN civicrm_price_field cpf on cpf.id = cpfv.price_field_id
|
||||
INNER JOIN civicrm_price_set cps on cps.id = cpf.price_set_id
|
||||
SET " . implode(' , ', $updateFields) . " WHERE cpfv.membership_type_id = %1
|
||||
AND cps.is_quick_config = 1 AND cps.name != 'default_membership_type_amount'";
|
||||
CRM_Core_DAO::executeQuery($query, $queryParams);
|
||||
}
|
||||
|
||||
}
|
569
sites/all/modules/civicrm/CRM/Member/BAO/Query.php
Normal file
569
sites/all/modules/civicrm/CRM/Member/BAO/Query.php
Normal file
|
@ -0,0 +1,569 @@
|
|||
<?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
|
||||
*/
|
||||
class CRM_Member_BAO_Query extends CRM_Core_BAO_Query {
|
||||
|
||||
/**
|
||||
* Get available fields.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function &getFields() {
|
||||
$fields = CRM_Member_BAO_Membership::exportableFields();
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* If membership are involved, add the specific membership fields.
|
||||
*
|
||||
* @param CRM_Contact_BAO_Query $query
|
||||
*/
|
||||
public static function select(&$query) {
|
||||
// if membership mode add membership id
|
||||
if ($query->_mode & CRM_Contact_BAO_Query::MODE_MEMBER ||
|
||||
CRM_Contact_BAO_Query::componentPresent($query->_returnProperties, 'membership_')
|
||||
) {
|
||||
|
||||
$query->_select['membership_id'] = "civicrm_membership.id as membership_id";
|
||||
$query->_element['membership_id'] = 1;
|
||||
$query->_tables['civicrm_membership'] = 1;
|
||||
$query->_whereTables['civicrm_membership'] = 1;
|
||||
|
||||
//add membership type
|
||||
if (!empty($query->_returnProperties['membership_type'])) {
|
||||
$query->_select['membership_type'] = "civicrm_membership_type.name as membership_type";
|
||||
$query->_element['membership_type'] = 1;
|
||||
$query->_tables['civicrm_membership_type'] = 1;
|
||||
$query->_whereTables['civicrm_membership_type'] = 1;
|
||||
}
|
||||
|
||||
//add join date
|
||||
if (!empty($query->_returnProperties['join_date'])) {
|
||||
$query->_select['join_date'] = "civicrm_membership.join_date as join_date";
|
||||
$query->_element['join_date'] = 1;
|
||||
}
|
||||
|
||||
//add source
|
||||
if (!empty($query->_returnProperties['membership_source'])) {
|
||||
$query->_select['membership_source'] = "civicrm_membership.source as membership_source";
|
||||
$query->_element['membership_source'] = 1;
|
||||
}
|
||||
|
||||
//add status
|
||||
if (!empty($query->_returnProperties['membership_status'])) {
|
||||
$query->_select['membership_status'] = "civicrm_membership_status.label as membership_status";
|
||||
$query->_element['membership_status'] = 1;
|
||||
$query->_tables['civicrm_membership_status'] = 1;
|
||||
$query->_whereTables['civicrm_membership_status'] = 1;
|
||||
}
|
||||
|
||||
if (!empty($query->_returnProperties['membership_is_current_member'])) {
|
||||
$query->_select['is_current_member'] = "civicrm_membership_status.is_current_member as is_current_member";
|
||||
$query->_element['is_current_member'] = 1;
|
||||
$query->_tables['civicrm_membership_status'] = 1;
|
||||
$query->_whereTables['civicrm_membership_status'] = 1;
|
||||
}
|
||||
|
||||
if (!empty($query->_returnProperties['membership_status_id'])) {
|
||||
$query->_select['status_id'] = "civicrm_membership_status.id as status_id";
|
||||
$query->_element['status_id'] = 1;
|
||||
$query->_tables['civicrm_membership_status'] = 1;
|
||||
$query->_whereTables['civicrm_membership_status'] = 1;
|
||||
}
|
||||
|
||||
//add start date / end date
|
||||
if (!empty($query->_returnProperties['membership_start_date'])) {
|
||||
$query->_select['membership_start_date'] = "civicrm_membership.start_date as membership_start_date";
|
||||
$query->_element['membership_start_date'] = 1;
|
||||
}
|
||||
|
||||
if (!empty($query->_returnProperties['membership_end_date'])) {
|
||||
$query->_select['membership_end_date'] = "civicrm_membership.end_date as membership_end_date";
|
||||
$query->_element['membership_end_date'] = 1;
|
||||
}
|
||||
|
||||
//add owner_membership_id
|
||||
if (!empty($query->_returnProperties['owner_membership_id'])) {
|
||||
$query->_select['owner_membership_id'] = "civicrm_membership.owner_membership_id as owner_membership_id";
|
||||
$query->_element['owner_membership_id'] = 1;
|
||||
}
|
||||
//add max_related
|
||||
if (!empty($query->_returnProperties['max_related'])) {
|
||||
$query->_select['max_related'] = "civicrm_membership.max_related as max_related";
|
||||
$query->_element['max_related'] = 1;
|
||||
}
|
||||
//add recur id w/o taking contribution table in join.
|
||||
if (!empty($query->_returnProperties['membership_recur_id'])) {
|
||||
$query->_select['membership_recur_id'] = "civicrm_membership.contribution_recur_id as membership_recur_id";
|
||||
$query->_element['membership_recur_id'] = 1;
|
||||
}
|
||||
|
||||
//add campaign id.
|
||||
if (!empty($query->_returnProperties['member_campaign_id'])) {
|
||||
$query->_select['member_campaign_id'] = 'civicrm_membership.campaign_id as member_campaign_id';
|
||||
$query->_element['member_campaign_id'] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate where clause.
|
||||
*
|
||||
* @param CRM_Contact_BAO_Query $query
|
||||
*/
|
||||
public static function where(&$query) {
|
||||
foreach (array_keys($query->_params) as $id) {
|
||||
if (empty($query->_params[$id][0])) {
|
||||
continue;
|
||||
}
|
||||
if (substr($query->_params[$id][0], 0, 7) == 'member_' || substr($query->_params[$id][0], 0, 11) == 'membership_') {
|
||||
if ($query->_mode == CRM_Contact_BAO_QUERY::MODE_CONTACTS) {
|
||||
$query->_useDistinct = TRUE;
|
||||
}
|
||||
self::whereClauseSingle($query->_params[$id], $query);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate where for a single parameter.
|
||||
*
|
||||
* @param array $values
|
||||
* @param CRM_Contact_BAO_Query $query
|
||||
*/
|
||||
public static function whereClauseSingle(&$values, &$query) {
|
||||
list($name, $op, $value, $grouping) = $values;
|
||||
switch ($name) {
|
||||
case 'member_join_date_low':
|
||||
case 'member_join_date_high':
|
||||
$query->dateQueryBuilder($values,
|
||||
'civicrm_membership', 'member_join_date', 'join_date',
|
||||
'Member Since'
|
||||
);
|
||||
return;
|
||||
|
||||
case 'membership_start_date':
|
||||
case 'member_start_date_low':
|
||||
case 'member_start_date_high':
|
||||
$fldName = str_replace(array('_low', '_high'), '', $name);
|
||||
$query->dateQueryBuilder($values,
|
||||
'civicrm_membership', $fldName, 'start_date',
|
||||
'Start Date'
|
||||
);
|
||||
return;
|
||||
|
||||
case 'membership_end_date':
|
||||
case 'member_end_date_low':
|
||||
case 'member_end_date_high':
|
||||
$fldName = str_replace(array('_low', '_high'), '', $name);
|
||||
$query->dateQueryBuilder($values,
|
||||
'civicrm_membership', $fldName, 'end_date',
|
||||
'End Date'
|
||||
);
|
||||
return;
|
||||
|
||||
case 'member_join_date':
|
||||
$op = '>=';
|
||||
$date = CRM_Utils_Date::format($value);
|
||||
if ($date) {
|
||||
$query->_where[$grouping][] = "civicrm_membership.join_date {$op} {$date}";
|
||||
$format = CRM_Utils_Date::customFormat(CRM_Utils_Date::format(array_reverse($value), '-'));
|
||||
$query->_qill[$grouping][] = ts('Member Since %2 %1', array(1 => $format, 2 => $op));
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
case 'member_source':
|
||||
case 'membership_source':
|
||||
$strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
|
||||
$value = $strtolower(CRM_Core_DAO::escapeString(trim($value)));
|
||||
|
||||
$query->_where[$grouping][] = "civicrm_membership.source $op '{$value}'";
|
||||
$query->_qill[$grouping][] = ts('Source %2 %1', array(1 => $value, 2 => $op));
|
||||
$query->_tables['civicrm_membership'] = $query->_whereTables['civicrm_membership'] = 1;
|
||||
return;
|
||||
|
||||
// CRM-17011 These 2 variants appear in some smart groups saved at some time prior to 4.6.6.
|
||||
case 'member_status_id':
|
||||
case 'member_membership_type_id':
|
||||
if (is_array($value)) {
|
||||
$op = 'IN';
|
||||
$value = array_keys($value);
|
||||
}
|
||||
case 'membership_status':
|
||||
case 'membership_status_id':
|
||||
case 'membership_type':
|
||||
case 'membership_type_id':
|
||||
// CRM-17075 we are specifically handling the possibility we are dealing with the entity reference field
|
||||
// for membership_type_id here (although status would be handled if converted). The unhandled pathway at the moment
|
||||
// is from groupContactCache::load and this is a small fix to get the entity reference field to work.
|
||||
// However, it would seem the larger fix would be to NOT invoke the form formValues for
|
||||
// the load function. The where clause and the whereTables are saved so they should suffice to generate the query
|
||||
// to get a contact list. But, better to deal with in 4.8 now...
|
||||
if (is_string($value) && strpos($value, ',') && $op == '=') {
|
||||
$value = array('IN' => explode(',', $value));
|
||||
}
|
||||
case 'membership_id':
|
||||
case 'member_id': // CRM-18523 Updated to membership_id but kept member_id case for backwards compatibility
|
||||
case 'member_campaign_id':
|
||||
|
||||
if (strpos($name, 'status') !== FALSE) {
|
||||
$name = 'status_id';
|
||||
$qillName = ts('Membership Status');
|
||||
}
|
||||
elseif ($name == 'membership_id' || $name == 'member_id') {
|
||||
$name = 'id';
|
||||
$qillName = ts('Membership ID');
|
||||
}
|
||||
elseif ($name == 'member_campaign_id') {
|
||||
$name = 'campaign_id';
|
||||
$qillName = ts('Campaign');
|
||||
}
|
||||
else {
|
||||
$name = 'membership_type_id';
|
||||
$qillName = ts('Membership Type');
|
||||
}
|
||||
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_membership.$name",
|
||||
$op,
|
||||
$value,
|
||||
"Integer"
|
||||
);
|
||||
list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Member_DAO_Membership', $name, $value, $op);
|
||||
$query->_qill[$grouping][] = $qillName . ' ' . $op . ' ' . $value;
|
||||
$query->_tables['civicrm_membership'] = $query->_whereTables['civicrm_membership'] = 1;
|
||||
return;
|
||||
|
||||
case 'membership_is_current_member':
|
||||
// We don't want to include all tests for sql OR CRM-7827
|
||||
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_membership_status.is_current_member", $op, $value, "Boolean");
|
||||
$query->_qill[$grouping][] = $value ? ts('Is a current member') : ts('Is a non-current member');
|
||||
$query->_tables['civicrm_membership_status'] = $query->_whereTables['civicrm_membership_status'] = 1;
|
||||
return;
|
||||
|
||||
case 'member_test':
|
||||
// We don't want to include all tests for sql OR CRM-7827
|
||||
if (!$value || $query->getOperator() != 'OR') {
|
||||
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_membership.is_test", $op, $value, "Boolean");
|
||||
if ($value) {
|
||||
$query->_qill[$grouping][] = ts('Membership is a Test');
|
||||
}
|
||||
}
|
||||
$query->_tables['civicrm_membership'] = $query->_whereTables['civicrm_membership'] = 1;
|
||||
return;
|
||||
|
||||
case 'member_auto_renew':
|
||||
$op = '=';
|
||||
$where = $qill = array();
|
||||
foreach ($value as $val) {
|
||||
if ($val == 1) {
|
||||
$where[] = ' civicrm_membership.contribution_recur_id IS NULL';
|
||||
$qill[] = ts('Membership is NOT Auto-Renew');
|
||||
}
|
||||
elseif ($val == 2) {
|
||||
$where[] = ' civicrm_membership.contribution_recur_id IS NOT NULL AND ' . CRM_Contact_BAO_Query::buildClause(
|
||||
'ccr.contribution_status_id',
|
||||
$op,
|
||||
array_search(
|
||||
'In Progress',
|
||||
CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name')
|
||||
),
|
||||
'Integer'
|
||||
);
|
||||
$qill[] = ts('Membership is Auto-Renew and In Progress');
|
||||
}
|
||||
elseif ($val == 3) {
|
||||
$where[] = ' civicrm_membership.contribution_recur_id IS NOT NULL AND ' .
|
||||
CRM_Contact_BAO_Query::buildClause(
|
||||
'ccr.contribution_status_id',
|
||||
$op,
|
||||
array_search(
|
||||
'Failed',
|
||||
CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name')
|
||||
),
|
||||
'Integer'
|
||||
);
|
||||
$qill[] = ts('Membership is Auto-Renew and Failed');
|
||||
}
|
||||
elseif ($val == 4) {
|
||||
$where[] = ' civicrm_membership.contribution_recur_id IS NOT NULL AND ' .
|
||||
CRM_Contact_BAO_Query::buildClause(
|
||||
'ccr.contribution_status_id',
|
||||
$op,
|
||||
array_search(
|
||||
'Cancelled',
|
||||
CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name')
|
||||
),
|
||||
'Integer'
|
||||
);
|
||||
$qill[] = ts('Membership is Auto-Renew and Cancelled');
|
||||
}
|
||||
elseif ($val == 5) {
|
||||
$where[] = ' civicrm_membership.contribution_recur_id IS NOT NULL AND ccr.end_date IS NOT NULL AND ccr.end_date < NOW()';
|
||||
$qill[] = ts('Membership is Auto-Renew and Ended');
|
||||
}
|
||||
elseif ($val == 6) {
|
||||
$where[] = ' civicrm_membership.contribution_recur_id IS NOT NULL';
|
||||
$qill[] = ts('Membership is Auto-Renew');
|
||||
}
|
||||
}
|
||||
if (!empty($where)) {
|
||||
$query->_where[$grouping][] = implode(' OR ', $where);
|
||||
$query->_qill[$grouping][] = implode(' OR ', $qill);
|
||||
}
|
||||
|
||||
$query->_tables['civicrm_membership'] = $query->_whereTables['civicrm_membership'] = 1;
|
||||
return;
|
||||
|
||||
case 'member_pay_later':
|
||||
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_membership.is_pay_later",
|
||||
$op,
|
||||
$value,
|
||||
"Integer"
|
||||
);
|
||||
if ($value) {
|
||||
$query->_qill[$grouping][] = ts("Membership is Pay Later");
|
||||
}
|
||||
else {
|
||||
$query->_qill[$grouping][] = ts("Membership is NOT Pay Later");
|
||||
}
|
||||
$query->_tables['civicrm_membership'] = $query->_whereTables['civicrm_membership'] = 1;
|
||||
return;
|
||||
|
||||
case 'member_is_primary':
|
||||
if ($value) {
|
||||
$query->_where[$grouping][] = " civicrm_membership.owner_membership_id IS NULL";
|
||||
$query->_qill[$grouping][] = ts("Primary Members Only");
|
||||
}
|
||||
else {
|
||||
$query->_where[$grouping][] = " civicrm_membership.owner_membership_id IS NOT NULL";
|
||||
$query->_qill[$grouping][] = ts("Related Members Only");
|
||||
}
|
||||
$query->_tables['civicrm_membership'] = $query->_whereTables['civicrm_membership'] = 1;
|
||||
return;
|
||||
|
||||
case 'member_is_override':
|
||||
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_membership.is_override", $op, $value, "Boolean");
|
||||
$query->_qill[$grouping][] = $value ? ts("Membership Status Is Overriden") : ts("Membership Status Is NOT Overriden");
|
||||
$query->_tables['civicrm_membership'] = $query->_whereTables['civicrm_membership'] = 1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate from clause.
|
||||
*
|
||||
* @param string $name
|
||||
* @param int $mode
|
||||
* @param string $side
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function from($name, $mode, $side) {
|
||||
$from = NULL;
|
||||
switch ($name) {
|
||||
case 'civicrm_membership':
|
||||
$from = " $side JOIN civicrm_membership ON civicrm_membership.contact_id = contact_a.id ";
|
||||
$from .= " $side JOIN civicrm_contribution_recur ccr ON ( civicrm_membership.contribution_recur_id = ccr.id )";
|
||||
break;
|
||||
|
||||
case 'civicrm_membership_type':
|
||||
if ($mode & CRM_Contact_BAO_Query::MODE_MEMBER) {
|
||||
$from = " INNER JOIN civicrm_membership_type ON civicrm_membership.membership_type_id = civicrm_membership_type.id ";
|
||||
}
|
||||
else {
|
||||
$from = " $side JOIN civicrm_membership_type ON civicrm_membership.membership_type_id = civicrm_membership_type.id ";
|
||||
}
|
||||
break;
|
||||
|
||||
case 'civicrm_membership_status':
|
||||
if ($mode & CRM_Contact_BAO_Query::MODE_MEMBER) {
|
||||
$from = " INNER JOIN civicrm_membership_status ON civicrm_membership.status_id = civicrm_membership_status.id ";
|
||||
}
|
||||
else {
|
||||
$from = " $side JOIN civicrm_membership_status ON civicrm_membership.status_id = civicrm_membership_status.id ";
|
||||
}
|
||||
break;
|
||||
|
||||
case 'civicrm_membership_payment':
|
||||
$from = " $side JOIN civicrm_membership_payment ON civicrm_membership_payment.membership_id = civicrm_membership.id ";
|
||||
break;
|
||||
}
|
||||
return $from;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default return properties.
|
||||
*
|
||||
* @param string $mode
|
||||
* @param bool $includeCustomFields
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public static function defaultReturnProperties(
|
||||
$mode,
|
||||
$includeCustomFields = TRUE
|
||||
) {
|
||||
$properties = NULL;
|
||||
if ($mode & CRM_Contact_BAO_Query::MODE_MEMBER) {
|
||||
$properties = array(
|
||||
'contact_type' => 1,
|
||||
'contact_sub_type' => 1,
|
||||
'sort_name' => 1,
|
||||
'display_name' => 1,
|
||||
'membership_type' => 1,
|
||||
'member_is_test' => 1,
|
||||
'member_is_pay_later' => 1,
|
||||
'join_date' => 1,
|
||||
'membership_start_date' => 1,
|
||||
'membership_end_date' => 1,
|
||||
'membership_source' => 1,
|
||||
'membership_status' => 1,
|
||||
'membership_id' => 1,
|
||||
'owner_membership_id' => 1,
|
||||
'max_related' => 1,
|
||||
'membership_recur_id' => 1,
|
||||
'member_campaign_id' => 1,
|
||||
'member_is_override' => 1,
|
||||
'member_auto_renew' => 1,
|
||||
);
|
||||
|
||||
if ($includeCustomFields) {
|
||||
// also get all the custom membership properties
|
||||
$fields = CRM_Core_BAO_CustomField::getFieldsForImport('Membership');
|
||||
if (!empty($fields)) {
|
||||
foreach ($fields as $name => $dontCare) {
|
||||
$properties[$name] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the search form.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public static function buildSearchForm(&$form) {
|
||||
$membershipStatus = CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label', FALSE, FALSE);
|
||||
$form->add('select', 'membership_status_id', ts('Membership Status'), $membershipStatus, FALSE, array(
|
||||
'id' => 'membership_status_id',
|
||||
'multiple' => 'multiple',
|
||||
'class' => 'crm-select2',
|
||||
));
|
||||
|
||||
$form->addEntityRef('membership_type_id', ts('Membership Type'), array(
|
||||
'entity' => 'MembershipType',
|
||||
'multiple' => TRUE,
|
||||
'placeholder' => ts('- any -'),
|
||||
'select' => array('minimumInputLength' => 0),
|
||||
));
|
||||
|
||||
$form->addElement('text', 'member_source', ts('Source'));
|
||||
$form->add('number', 'membership_id', ts('Membership ID'), array('class' => 'four', 'min' => 1));
|
||||
|
||||
CRM_Core_Form_Date::buildDateRange($form, 'member_join_date', 1, '_low', '_high', ts('From'), FALSE);
|
||||
$form->addElement('hidden', 'member_join_date_range_error');
|
||||
|
||||
CRM_Core_Form_Date::buildDateRange($form, 'member_start_date', 1, '_low', '_high', ts('From'), FALSE);
|
||||
$form->addElement('hidden', 'member_start_date_range_error');
|
||||
|
||||
CRM_Core_Form_Date::buildDateRange($form, 'member_end_date', 1, '_low', '_high', ts('From'), FALSE);
|
||||
$form->addElement('hidden', 'member_end_date_range_error');
|
||||
|
||||
$form->addFormRule(array('CRM_Member_BAO_Query', 'formRule'), $form);
|
||||
|
||||
$form->addYesNo('membership_is_current_member', ts('Current Member?'), TRUE);
|
||||
$form->addYesNo('member_is_primary', ts('Primary Member?'), TRUE);
|
||||
$form->addYesNo('member_pay_later', ts('Pay Later?'), TRUE);
|
||||
|
||||
$form->add('select', 'member_auto_renew',
|
||||
ts('Auto-Renew Subscription Status?'),
|
||||
array(
|
||||
'1' => ts('- None -'),
|
||||
'2' => ts('In Progress'),
|
||||
'3' => ts('Failed'),
|
||||
'4' => ts('Cancelled'),
|
||||
'5' => ts('Ended'),
|
||||
'6' => ts('Any'),
|
||||
),
|
||||
FALSE, array('class' => 'crm-select2', 'multiple' => 'multiple', 'placeholder' => ts('- any -'))
|
||||
);
|
||||
|
||||
$form->addYesNo('member_test', ts('Membership is a Test?'), TRUE);
|
||||
$form->addYesNo('member_is_override', ts('Membership Status Is Overriden?'), TRUE);
|
||||
|
||||
self::addCustomFormFields($form, array('Membership'));
|
||||
|
||||
CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'member_campaign_id');
|
||||
|
||||
$form->assign('validCiviMember', TRUE);
|
||||
$form->setDefaults(array('member_test' => 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add membership table.
|
||||
*
|
||||
* @param array $tables
|
||||
*/
|
||||
public static function tableNames(&$tables) {
|
||||
if (!empty($tables['civicrm_membership_log']) || !empty($tables['civicrm_membership_status']) || CRM_Utils_Array::value('civicrm_membership_type', $tables)) {
|
||||
$tables = array_merge(array('civicrm_membership' => 1), $tables);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom form rules.
|
||||
*
|
||||
* @param array $fields
|
||||
* @param array $files
|
||||
* @param CRM_Core_Form $form
|
||||
*
|
||||
* @return bool|array
|
||||
*/
|
||||
public static function formRule($fields, $files, $form) {
|
||||
$errors = array();
|
||||
|
||||
if ((empty($fields['member_join_date_low']) || empty($fields['member_join_date_high'])) && (empty($fields['member_start_date_low']) || empty($fields['member_start_date_high'])) && (empty($fields['member_end_date_low']) || empty($fields['member_end_date_high']))) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
CRM_Utils_Rule::validDateRange($fields, 'member_join_date', $errors, ts('Member Since'));
|
||||
CRM_Utils_Rule::validDateRange($fields, 'member_start_date', $errors, ts('Start Date'));
|
||||
CRM_Utils_Rule::validDateRange($fields, 'member_end_date', $errors, ts('End Date'));
|
||||
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
}
|
70
sites/all/modules/civicrm/CRM/Member/Controller/Search.php
Normal file
70
sites/all/modules/civicrm/CRM/Member/Controller/Search.php
Normal file
|
@ -0,0 +1,70 @@
|
|||
<?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 used by the Search functionality.
|
||||
*
|
||||
* - the search controller is used for building/processing multiform
|
||||
* searches.
|
||||
*
|
||||
* Typically the first form will display the search criteria and its results
|
||||
*
|
||||
* The second form is used to process search results with the associated actions
|
||||
*
|
||||
*/
|
||||
class CRM_Member_Controller_Search extends CRM_Core_Controller {
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param string $title
|
||||
* @param bool|int $action
|
||||
* @param bool $modal
|
||||
*/
|
||||
public function __construct($title = NULL, $action = CRM_Core_Action::NONE, $modal = TRUE) {
|
||||
|
||||
parent::__construct($title, $modal);
|
||||
|
||||
$this->_stateMachine = new CRM_Member_StateMachine_Search($this, $action);
|
||||
|
||||
// create and instantiate the pages
|
||||
$this->addPages($this->_stateMachine, $action);
|
||||
|
||||
// add all the actions
|
||||
$config = CRM_Core_Config::singleton();
|
||||
$this->addActions();
|
||||
}
|
||||
|
||||
}
|
522
sites/all/modules/civicrm/CRM/Member/DAO/Membership.php
Normal file
522
sites/all/modules/civicrm/CRM/Member/DAO/Membership.php
Normal file
|
@ -0,0 +1,522 @@
|
|||
<?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
|
||||
*
|
||||
* Generated from xml/schema/CRM/Member/Membership.xml
|
||||
* DO NOT EDIT. Generated by CRM_Core_CodeGen
|
||||
* (GenCodeChecksum:1a9ebe9e0d3ab9247f2a3dda32bab22a)
|
||||
*/
|
||||
require_once 'CRM/Core/DAO.php';
|
||||
require_once 'CRM/Utils/Type.php';
|
||||
/**
|
||||
* CRM_Member_DAO_Membership constructor.
|
||||
*/
|
||||
class CRM_Member_DAO_Membership extends CRM_Core_DAO {
|
||||
/**
|
||||
* Static instance to hold the table name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
static $_tableName = 'civicrm_membership';
|
||||
/**
|
||||
* Should CiviCRM log any modifications to this table in the civicrm_log table.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
static $_log = true;
|
||||
/**
|
||||
* Membership Id
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $id;
|
||||
/**
|
||||
* FK to Contact ID
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $contact_id;
|
||||
/**
|
||||
* FK to Membership Type
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $membership_type_id;
|
||||
/**
|
||||
* Beginning of initial membership period (member since...).
|
||||
*
|
||||
* @var date
|
||||
*/
|
||||
public $join_date;
|
||||
/**
|
||||
* Beginning of current uninterrupted membership period.
|
||||
*
|
||||
* @var date
|
||||
*/
|
||||
public $start_date;
|
||||
/**
|
||||
* Current membership period expire date.
|
||||
*
|
||||
* @var date
|
||||
*/
|
||||
public $end_date;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $source;
|
||||
/**
|
||||
* FK to Membership Status
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $status_id;
|
||||
/**
|
||||
* Admin users may set a manual status which overrides the calculated status. When this flag is true, automated status update scripts should NOT modify status for the record.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_override;
|
||||
/**
|
||||
* Optional FK to Parent Membership.
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $owner_membership_id;
|
||||
/**
|
||||
* Maximum number of related memberships (membership_type override).
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $max_related;
|
||||
/**
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_test;
|
||||
/**
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_pay_later;
|
||||
/**
|
||||
* Conditional foreign key to civicrm_contribution_recur id. Each membership in connection with a recurring contribution carries a foreign key to the recurring contribution record. This assumes we can track these processor initiated events.
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $contribution_recur_id;
|
||||
/**
|
||||
* The campaign for which this membership is attached.
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $campaign_id;
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
function __construct() {
|
||||
$this->__table = 'civicrm_membership';
|
||||
parent::__construct();
|
||||
}
|
||||
/**
|
||||
* Returns foreign keys and entity references.
|
||||
*
|
||||
* @return array
|
||||
* [CRM_Core_Reference_Interface]
|
||||
*/
|
||||
static function getReferenceColumns() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['links'])) {
|
||||
Civi::$statics[__CLASS__]['links'] = static ::createReferenceColumns(__CLASS__);
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'contact_id', 'civicrm_contact', 'id');
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'membership_type_id', 'civicrm_membership_type', 'id');
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'status_id', 'civicrm_membership_status', 'id');
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'owner_membership_id', 'civicrm_membership', 'id');
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'contribution_recur_id', 'civicrm_contribution_recur', 'id');
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'campaign_id', 'civicrm_campaign', 'id');
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['links'];
|
||||
}
|
||||
/**
|
||||
* Returns all the column names of this table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &fields() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fields'])) {
|
||||
Civi::$statics[__CLASS__]['fields'] = array(
|
||||
'membership_id' => array(
|
||||
'name' => 'id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Membership ID') ,
|
||||
'description' => 'Membership Id',
|
||||
'required' => true,
|
||||
'import' => true,
|
||||
'where' => 'civicrm_membership.id',
|
||||
'headerPattern' => '/^(m(embership\s)?id)$/i',
|
||||
'dataPattern' => '',
|
||||
'export' => true,
|
||||
'table_name' => 'civicrm_membership',
|
||||
'entity' => 'Membership',
|
||||
'bao' => 'CRM_Member_BAO_Membership',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'membership_contact_id' => array(
|
||||
'name' => 'contact_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Contact ID') ,
|
||||
'description' => 'FK to Contact ID',
|
||||
'required' => true,
|
||||
'import' => true,
|
||||
'where' => 'civicrm_membership.contact_id',
|
||||
'headerPattern' => '/contact(.?id)?/i',
|
||||
'dataPattern' => '/^\d+$/',
|
||||
'export' => true,
|
||||
'table_name' => 'civicrm_membership',
|
||||
'entity' => 'Membership',
|
||||
'bao' => 'CRM_Member_BAO_Membership',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Contact_DAO_Contact',
|
||||
'html' => array(
|
||||
'type' => 'EntityRef',
|
||||
) ,
|
||||
) ,
|
||||
'membership_type_id' => array(
|
||||
'name' => 'membership_type_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Membership Type Id') ,
|
||||
'description' => 'FK to Membership Type',
|
||||
'required' => true,
|
||||
'import' => true,
|
||||
'where' => 'civicrm_membership.membership_type_id',
|
||||
'headerPattern' => '/^(m(embership\s)?type)$/i',
|
||||
'dataPattern' => '',
|
||||
'export' => false,
|
||||
'table_name' => 'civicrm_membership',
|
||||
'entity' => 'Membership',
|
||||
'bao' => 'CRM_Member_BAO_Membership',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Member_DAO_MembershipType',
|
||||
'html' => array(
|
||||
'type' => 'Select',
|
||||
) ,
|
||||
'pseudoconstant' => array(
|
||||
'table' => 'civicrm_membership_type',
|
||||
'keyColumn' => 'id',
|
||||
'labelColumn' => 'name',
|
||||
)
|
||||
) ,
|
||||
'join_date' => array(
|
||||
'name' => 'join_date',
|
||||
'type' => CRM_Utils_Type::T_DATE,
|
||||
'title' => ts('Member Since') ,
|
||||
'description' => 'Beginning of initial membership period (member since...).',
|
||||
'import' => true,
|
||||
'where' => 'civicrm_membership.join_date',
|
||||
'headerPattern' => '/^join|(j(oin\s)?date)$/i',
|
||||
'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
|
||||
'export' => true,
|
||||
'table_name' => 'civicrm_membership',
|
||||
'entity' => 'Membership',
|
||||
'bao' => 'CRM_Member_BAO_Membership',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Select Date',
|
||||
'formatType' => 'activityDate',
|
||||
) ,
|
||||
) ,
|
||||
'membership_start_date' => array(
|
||||
'name' => 'start_date',
|
||||
'type' => CRM_Utils_Type::T_DATE,
|
||||
'title' => ts('Membership Start Date') ,
|
||||
'description' => 'Beginning of current uninterrupted membership period.',
|
||||
'import' => true,
|
||||
'where' => 'civicrm_membership.start_date',
|
||||
'headerPattern' => '/(member(ship)?.)?start(s)?(.date$)?/i',
|
||||
'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
|
||||
'export' => true,
|
||||
'table_name' => 'civicrm_membership',
|
||||
'entity' => 'Membership',
|
||||
'bao' => 'CRM_Member_BAO_Membership',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Select Date',
|
||||
'formatType' => 'activityDate',
|
||||
) ,
|
||||
) ,
|
||||
'membership_end_date' => array(
|
||||
'name' => 'end_date',
|
||||
'type' => CRM_Utils_Type::T_DATE,
|
||||
'title' => ts('Membership Expiration Date') ,
|
||||
'description' => 'Current membership period expire date.',
|
||||
'import' => true,
|
||||
'where' => 'civicrm_membership.end_date',
|
||||
'headerPattern' => '/(member(ship)?.)?end(s)?(.date$)?/i',
|
||||
'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
|
||||
'export' => true,
|
||||
'table_name' => 'civicrm_membership',
|
||||
'entity' => 'Membership',
|
||||
'bao' => 'CRM_Member_BAO_Membership',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Select Date',
|
||||
'formatType' => 'activityDate',
|
||||
) ,
|
||||
) ,
|
||||
'membership_source' => array(
|
||||
'name' => 'source',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Source') ,
|
||||
'maxlength' => 128,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'import' => true,
|
||||
'where' => 'civicrm_membership.source',
|
||||
'headerPattern' => '/^(member(ship?))?source$/i',
|
||||
'dataPattern' => '',
|
||||
'export' => true,
|
||||
'table_name' => 'civicrm_membership',
|
||||
'entity' => 'Membership',
|
||||
'bao' => 'CRM_Member_BAO_Membership',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Text',
|
||||
) ,
|
||||
) ,
|
||||
'status_id' => array(
|
||||
'name' => 'status_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Membership Status Id') ,
|
||||
'description' => 'FK to Membership Status',
|
||||
'required' => true,
|
||||
'import' => true,
|
||||
'where' => 'civicrm_membership.status_id',
|
||||
'headerPattern' => '/(member(ship|).)?(status)$/i',
|
||||
'dataPattern' => '',
|
||||
'export' => false,
|
||||
'table_name' => 'civicrm_membership',
|
||||
'entity' => 'Membership',
|
||||
'bao' => 'CRM_Member_BAO_Membership',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Member_DAO_MembershipStatus',
|
||||
'html' => array(
|
||||
'type' => 'Select',
|
||||
) ,
|
||||
'pseudoconstant' => array(
|
||||
'table' => 'civicrm_membership_status',
|
||||
'keyColumn' => 'id',
|
||||
'labelColumn' => 'label',
|
||||
)
|
||||
) ,
|
||||
'is_override' => array(
|
||||
'name' => 'is_override',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Status Override') ,
|
||||
'description' => 'Admin users may set a manual status which overrides the calculated status. When this flag is true, automated status update scripts should NOT modify status for the record.',
|
||||
'import' => true,
|
||||
'where' => 'civicrm_membership.is_override',
|
||||
'headerPattern' => '/override$/i',
|
||||
'dataPattern' => '',
|
||||
'export' => true,
|
||||
'table_name' => 'civicrm_membership',
|
||||
'entity' => 'Membership',
|
||||
'bao' => 'CRM_Member_BAO_Membership',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'CheckBox',
|
||||
) ,
|
||||
) ,
|
||||
'owner_membership_id' => array(
|
||||
'name' => 'owner_membership_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Primary Member ID') ,
|
||||
'description' => 'Optional FK to Parent Membership.',
|
||||
'export' => true,
|
||||
'where' => 'civicrm_membership.owner_membership_id',
|
||||
'headerPattern' => '',
|
||||
'dataPattern' => '',
|
||||
'table_name' => 'civicrm_membership',
|
||||
'entity' => 'Membership',
|
||||
'bao' => 'CRM_Member_BAO_Membership',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Member_DAO_Membership',
|
||||
) ,
|
||||
'max_related' => array(
|
||||
'name' => 'max_related',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Max Related') ,
|
||||
'description' => 'Maximum number of related memberships (membership_type override).',
|
||||
'table_name' => 'civicrm_membership',
|
||||
'entity' => 'Membership',
|
||||
'bao' => 'CRM_Member_BAO_Membership',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Text',
|
||||
) ,
|
||||
) ,
|
||||
'member_is_test' => array(
|
||||
'name' => 'is_test',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Test') ,
|
||||
'import' => true,
|
||||
'where' => 'civicrm_membership.is_test',
|
||||
'headerPattern' => '/(is.)?test(.member(ship)?)?/i',
|
||||
'dataPattern' => '',
|
||||
'export' => true,
|
||||
'table_name' => 'civicrm_membership',
|
||||
'entity' => 'Membership',
|
||||
'bao' => 'CRM_Member_BAO_Membership',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'CheckBox',
|
||||
) ,
|
||||
) ,
|
||||
'member_is_pay_later' => array(
|
||||
'name' => 'is_pay_later',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Is Pay Later') ,
|
||||
'import' => true,
|
||||
'where' => 'civicrm_membership.is_pay_later',
|
||||
'headerPattern' => '/(is.)?(pay(.)?later)$/i',
|
||||
'dataPattern' => '',
|
||||
'export' => true,
|
||||
'table_name' => 'civicrm_membership',
|
||||
'entity' => 'Membership',
|
||||
'bao' => 'CRM_Member_BAO_Membership',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'CheckBox',
|
||||
) ,
|
||||
) ,
|
||||
'contribution_recur_id' => array(
|
||||
'name' => 'contribution_recur_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Membership Recurring Contribution') ,
|
||||
'description' => 'Conditional foreign key to civicrm_contribution_recur id. Each membership in connection with a recurring contribution carries a foreign key to the recurring contribution record. This assumes we can track these processor initiated events.',
|
||||
'table_name' => 'civicrm_membership',
|
||||
'entity' => 'Membership',
|
||||
'bao' => 'CRM_Member_BAO_Membership',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Contribute_DAO_ContributionRecur',
|
||||
) ,
|
||||
'member_campaign_id' => array(
|
||||
'name' => 'campaign_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Campaign') ,
|
||||
'description' => 'The campaign for which this membership is attached.',
|
||||
'import' => true,
|
||||
'where' => 'civicrm_membership.campaign_id',
|
||||
'headerPattern' => '',
|
||||
'dataPattern' => '',
|
||||
'export' => true,
|
||||
'table_name' => 'civicrm_membership',
|
||||
'entity' => 'Membership',
|
||||
'bao' => 'CRM_Member_BAO_Membership',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Campaign_DAO_Campaign',
|
||||
'html' => array(
|
||||
'type' => 'Select',
|
||||
) ,
|
||||
'pseudoconstant' => array(
|
||||
'table' => 'civicrm_campaign',
|
||||
'keyColumn' => 'id',
|
||||
'labelColumn' => 'title',
|
||||
)
|
||||
) ,
|
||||
);
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fields'];
|
||||
}
|
||||
/**
|
||||
* Return a mapping from field-name to the corresponding key (as used in fields()).
|
||||
*
|
||||
* @return array
|
||||
* Array(string $name => string $uniqueName).
|
||||
*/
|
||||
static function &fieldKeys() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
|
||||
Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fieldKeys'];
|
||||
}
|
||||
/**
|
||||
* Returns the names of this table
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static function getTableName() {
|
||||
return self::$_tableName;
|
||||
}
|
||||
/**
|
||||
* Returns if this table needs to be logged
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function getLog() {
|
||||
return self::$_log;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be imported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &import($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'membership', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be exported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &export($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'membership', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of indices
|
||||
*/
|
||||
public static function indices($localize = TRUE) {
|
||||
$indices = array(
|
||||
'index_owner_membership_id' => array(
|
||||
'name' => 'index_owner_membership_id',
|
||||
'field' => array(
|
||||
0 => 'owner_membership_id',
|
||||
) ,
|
||||
'localizable' => false,
|
||||
'sig' => 'civicrm_membership::0::owner_membership_id',
|
||||
) ,
|
||||
);
|
||||
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
|
||||
}
|
||||
}
|
368
sites/all/modules/civicrm/CRM/Member/DAO/MembershipBlock.php
Normal file
368
sites/all/modules/civicrm/CRM/Member/DAO/MembershipBlock.php
Normal file
|
@ -0,0 +1,368 @@
|
|||
<?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
|
||||
*
|
||||
* Generated from xml/schema/CRM/Member/MembershipBlock.xml
|
||||
* DO NOT EDIT. Generated by CRM_Core_CodeGen
|
||||
* (GenCodeChecksum:3ee510fab11783acf6ee994f090436f6)
|
||||
*/
|
||||
require_once 'CRM/Core/DAO.php';
|
||||
require_once 'CRM/Utils/Type.php';
|
||||
/**
|
||||
* CRM_Member_DAO_MembershipBlock constructor.
|
||||
*/
|
||||
class CRM_Member_DAO_MembershipBlock extends CRM_Core_DAO {
|
||||
/**
|
||||
* Static instance to hold the table name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
static $_tableName = 'civicrm_membership_block';
|
||||
/**
|
||||
* Should CiviCRM log any modifications to this table in the civicrm_log table.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
static $_log = true;
|
||||
/**
|
||||
* Membership Id
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $id;
|
||||
/**
|
||||
* Name for Membership Status
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $entity_table;
|
||||
/**
|
||||
* FK to civicrm_contribution_page.id
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $entity_id;
|
||||
/**
|
||||
* Membership types to be exposed by this block
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $membership_types;
|
||||
/**
|
||||
* Optional foreign key to membership_type
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $membership_type_default;
|
||||
/**
|
||||
* Display minimum membership fee
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $display_min_fee;
|
||||
/**
|
||||
* Should membership transactions be processed separately
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_separate_payment;
|
||||
/**
|
||||
* Title to display at top of block
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $new_title;
|
||||
/**
|
||||
* Text to display below title
|
||||
*
|
||||
* @var text
|
||||
*/
|
||||
public $new_text;
|
||||
/**
|
||||
* Title for renewal
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $renewal_title;
|
||||
/**
|
||||
* Text to display for member renewal
|
||||
*
|
||||
* @var text
|
||||
*/
|
||||
public $renewal_text;
|
||||
/**
|
||||
* Is membership sign up optional
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_required;
|
||||
/**
|
||||
* Is this membership_block enabled
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_active;
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
function __construct() {
|
||||
$this->__table = 'civicrm_membership_block';
|
||||
parent::__construct();
|
||||
}
|
||||
/**
|
||||
* Returns foreign keys and entity references.
|
||||
*
|
||||
* @return array
|
||||
* [CRM_Core_Reference_Interface]
|
||||
*/
|
||||
static function getReferenceColumns() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['links'])) {
|
||||
Civi::$statics[__CLASS__]['links'] = static ::createReferenceColumns(__CLASS__);
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'entity_id', 'civicrm_contribution_page', 'id');
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'membership_type_default', 'civicrm_membership_type', 'id');
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['links'];
|
||||
}
|
||||
/**
|
||||
* Returns all the column names of this table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &fields() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fields'])) {
|
||||
Civi::$statics[__CLASS__]['fields'] = array(
|
||||
'id' => array(
|
||||
'name' => 'id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Membership Block ID') ,
|
||||
'description' => 'Membership Id',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_membership_block',
|
||||
'entity' => 'MembershipBlock',
|
||||
'bao' => 'CRM_Member_BAO_MembershipBlock',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'entity_table' => array(
|
||||
'name' => 'entity_table',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Membership Block Entity Table') ,
|
||||
'description' => 'Name for Membership Status',
|
||||
'maxlength' => 64,
|
||||
'size' => CRM_Utils_Type::BIG,
|
||||
'table_name' => 'civicrm_membership_block',
|
||||
'entity' => 'MembershipBlock',
|
||||
'bao' => 'CRM_Member_BAO_MembershipBlock',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'entity_id' => array(
|
||||
'name' => 'entity_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Membership Block Entity ID') ,
|
||||
'description' => 'FK to civicrm_contribution_page.id',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_membership_block',
|
||||
'entity' => 'MembershipBlock',
|
||||
'bao' => 'CRM_Member_BAO_MembershipBlock',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Contribute_DAO_ContributionPage',
|
||||
) ,
|
||||
'membership_types' => array(
|
||||
'name' => 'membership_types',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Membership Block Membership Types') ,
|
||||
'description' => 'Membership types to be exposed by this block',
|
||||
'maxlength' => 1024,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_membership_block',
|
||||
'entity' => 'MembershipBlock',
|
||||
'bao' => 'CRM_Member_BAO_MembershipBlock',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'membership_type_default' => array(
|
||||
'name' => 'membership_type_default',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Membership Block Default Type') ,
|
||||
'description' => 'Optional foreign key to membership_type',
|
||||
'table_name' => 'civicrm_membership_block',
|
||||
'entity' => 'MembershipBlock',
|
||||
'bao' => 'CRM_Member_BAO_MembershipBlock',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Member_DAO_MembershipType',
|
||||
) ,
|
||||
'display_min_fee' => array(
|
||||
'name' => 'display_min_fee',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Membership Block Display Minimum Fee') ,
|
||||
'description' => 'Display minimum membership fee',
|
||||
'default' => '1',
|
||||
'table_name' => 'civicrm_membership_block',
|
||||
'entity' => 'MembershipBlock',
|
||||
'bao' => 'CRM_Member_BAO_MembershipBlock',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'is_separate_payment' => array(
|
||||
'name' => 'is_separate_payment',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Membership Block Is Separate Payment') ,
|
||||
'description' => 'Should membership transactions be processed separately',
|
||||
'default' => '1',
|
||||
'table_name' => 'civicrm_membership_block',
|
||||
'entity' => 'MembershipBlock',
|
||||
'bao' => 'CRM_Member_BAO_MembershipBlock',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'new_title' => array(
|
||||
'name' => 'new_title',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Membership Block New Title') ,
|
||||
'description' => 'Title to display at top of block',
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_membership_block',
|
||||
'entity' => 'MembershipBlock',
|
||||
'bao' => 'CRM_Member_BAO_MembershipBlock',
|
||||
'localizable' => 1,
|
||||
) ,
|
||||
'new_text' => array(
|
||||
'name' => 'new_text',
|
||||
'type' => CRM_Utils_Type::T_TEXT,
|
||||
'title' => ts('Membership Block New Text') ,
|
||||
'description' => 'Text to display below title',
|
||||
'table_name' => 'civicrm_membership_block',
|
||||
'entity' => 'MembershipBlock',
|
||||
'bao' => 'CRM_Member_BAO_MembershipBlock',
|
||||
'localizable' => 1,
|
||||
) ,
|
||||
'renewal_title' => array(
|
||||
'name' => 'renewal_title',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Membership Block Renewal Title') ,
|
||||
'description' => 'Title for renewal',
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_membership_block',
|
||||
'entity' => 'MembershipBlock',
|
||||
'bao' => 'CRM_Member_BAO_MembershipBlock',
|
||||
'localizable' => 1,
|
||||
) ,
|
||||
'renewal_text' => array(
|
||||
'name' => 'renewal_text',
|
||||
'type' => CRM_Utils_Type::T_TEXT,
|
||||
'title' => ts('Membership Block Renewal Text') ,
|
||||
'description' => 'Text to display for member renewal',
|
||||
'table_name' => 'civicrm_membership_block',
|
||||
'entity' => 'MembershipBlock',
|
||||
'bao' => 'CRM_Member_BAO_MembershipBlock',
|
||||
'localizable' => 1,
|
||||
) ,
|
||||
'is_required' => array(
|
||||
'name' => 'is_required',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Is Required') ,
|
||||
'description' => 'Is membership sign up optional',
|
||||
'table_name' => 'civicrm_membership_block',
|
||||
'entity' => 'MembershipBlock',
|
||||
'bao' => 'CRM_Member_BAO_MembershipBlock',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'is_active' => array(
|
||||
'name' => 'is_active',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Is Active') ,
|
||||
'description' => 'Is this membership_block enabled',
|
||||
'default' => '1',
|
||||
'table_name' => 'civicrm_membership_block',
|
||||
'entity' => 'MembershipBlock',
|
||||
'bao' => 'CRM_Member_BAO_MembershipBlock',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
);
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fields'];
|
||||
}
|
||||
/**
|
||||
* Return a mapping from field-name to the corresponding key (as used in fields()).
|
||||
*
|
||||
* @return array
|
||||
* Array(string $name => string $uniqueName).
|
||||
*/
|
||||
static function &fieldKeys() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
|
||||
Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fieldKeys'];
|
||||
}
|
||||
/**
|
||||
* Returns the names of this table
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static function getTableName() {
|
||||
return CRM_Core_DAO::getLocaleTableName(self::$_tableName);
|
||||
}
|
||||
/**
|
||||
* Returns if this table needs to be logged
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function getLog() {
|
||||
return self::$_log;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be imported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &import($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'membership_block', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be exported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &export($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'membership_block', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of indices
|
||||
*/
|
||||
public static function indices($localize = TRUE) {
|
||||
$indices = array();
|
||||
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
|
||||
}
|
||||
}
|
296
sites/all/modules/civicrm/CRM/Member/DAO/MembershipLog.php
Normal file
296
sites/all/modules/civicrm/CRM/Member/DAO/MembershipLog.php
Normal file
|
@ -0,0 +1,296 @@
|
|||
<?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
|
||||
*
|
||||
* Generated from xml/schema/CRM/Member/MembershipLog.xml
|
||||
* DO NOT EDIT. Generated by CRM_Core_CodeGen
|
||||
* (GenCodeChecksum:9182bcbeed0a05c3fed5f3027ba89668)
|
||||
*/
|
||||
require_once 'CRM/Core/DAO.php';
|
||||
require_once 'CRM/Utils/Type.php';
|
||||
/**
|
||||
* CRM_Member_DAO_MembershipLog constructor.
|
||||
*/
|
||||
class CRM_Member_DAO_MembershipLog extends CRM_Core_DAO {
|
||||
/**
|
||||
* Static instance to hold the table name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
static $_tableName = 'civicrm_membership_log';
|
||||
/**
|
||||
* Should CiviCRM log any modifications to this table in the civicrm_log table.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
static $_log = true;
|
||||
/**
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $id;
|
||||
/**
|
||||
* FK to Membership table
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $membership_id;
|
||||
/**
|
||||
* New status assigned to membership by this action. FK to Membership Status
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $status_id;
|
||||
/**
|
||||
* New membership period start date
|
||||
*
|
||||
* @var date
|
||||
*/
|
||||
public $start_date;
|
||||
/**
|
||||
* New membership period expiration date.
|
||||
*
|
||||
* @var date
|
||||
*/
|
||||
public $end_date;
|
||||
/**
|
||||
* FK to Contact ID of person under whose credentials this data modification was made.
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $modified_id;
|
||||
/**
|
||||
* Date this membership modification action was logged.
|
||||
*
|
||||
* @var date
|
||||
*/
|
||||
public $modified_date;
|
||||
/**
|
||||
* FK to Membership Type.
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $membership_type_id;
|
||||
/**
|
||||
* Maximum number of related memberships.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $max_related;
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
function __construct() {
|
||||
$this->__table = 'civicrm_membership_log';
|
||||
parent::__construct();
|
||||
}
|
||||
/**
|
||||
* Returns foreign keys and entity references.
|
||||
*
|
||||
* @return array
|
||||
* [CRM_Core_Reference_Interface]
|
||||
*/
|
||||
static function getReferenceColumns() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['links'])) {
|
||||
Civi::$statics[__CLASS__]['links'] = static ::createReferenceColumns(__CLASS__);
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'membership_id', 'civicrm_membership', 'id');
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'status_id', 'civicrm_membership_status', 'id');
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'modified_id', 'civicrm_contact', 'id');
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'membership_type_id', 'civicrm_membership_type', 'id');
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['links'];
|
||||
}
|
||||
/**
|
||||
* Returns all the column names of this table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &fields() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fields'])) {
|
||||
Civi::$statics[__CLASS__]['fields'] = array(
|
||||
'id' => array(
|
||||
'name' => 'id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Membership Log ID') ,
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_membership_log',
|
||||
'entity' => 'MembershipLog',
|
||||
'bao' => 'CRM_Member_BAO_MembershipLog',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'membership_id' => array(
|
||||
'name' => 'membership_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Membership ID') ,
|
||||
'description' => 'FK to Membership table',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_membership_log',
|
||||
'entity' => 'MembershipLog',
|
||||
'bao' => 'CRM_Member_BAO_MembershipLog',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Member_DAO_Membership',
|
||||
) ,
|
||||
'status_id' => array(
|
||||
'name' => 'status_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Membership Status') ,
|
||||
'description' => 'New status assigned to membership by this action. FK to Membership Status',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_membership_log',
|
||||
'entity' => 'MembershipLog',
|
||||
'bao' => 'CRM_Member_BAO_MembershipLog',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Member_DAO_MembershipStatus',
|
||||
) ,
|
||||
'start_date' => array(
|
||||
'name' => 'start_date',
|
||||
'type' => CRM_Utils_Type::T_DATE,
|
||||
'title' => ts('Membership Log Start Date') ,
|
||||
'description' => 'New membership period start date',
|
||||
'table_name' => 'civicrm_membership_log',
|
||||
'entity' => 'MembershipLog',
|
||||
'bao' => 'CRM_Member_BAO_MembershipLog',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'end_date' => array(
|
||||
'name' => 'end_date',
|
||||
'type' => CRM_Utils_Type::T_DATE,
|
||||
'title' => ts('Membership Log End Date') ,
|
||||
'description' => 'New membership period expiration date.',
|
||||
'table_name' => 'civicrm_membership_log',
|
||||
'entity' => 'MembershipLog',
|
||||
'bao' => 'CRM_Member_BAO_MembershipLog',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'modified_id' => array(
|
||||
'name' => 'modified_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Membership Log modified By') ,
|
||||
'description' => 'FK to Contact ID of person under whose credentials this data modification was made.',
|
||||
'table_name' => 'civicrm_membership_log',
|
||||
'entity' => 'MembershipLog',
|
||||
'bao' => 'CRM_Member_BAO_MembershipLog',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Contact_DAO_Contact',
|
||||
) ,
|
||||
'modified_date' => array(
|
||||
'name' => 'modified_date',
|
||||
'type' => CRM_Utils_Type::T_DATE,
|
||||
'title' => ts('Membership Change Date') ,
|
||||
'description' => 'Date this membership modification action was logged.',
|
||||
'table_name' => 'civicrm_membership_log',
|
||||
'entity' => 'MembershipLog',
|
||||
'bao' => 'CRM_Member_BAO_MembershipLog',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'membership_type_id' => array(
|
||||
'name' => 'membership_type_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Membership Type ID') ,
|
||||
'description' => 'FK to Membership Type.',
|
||||
'table_name' => 'civicrm_membership_log',
|
||||
'entity' => 'MembershipLog',
|
||||
'bao' => 'CRM_Member_BAO_MembershipLog',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Member_DAO_MembershipType',
|
||||
) ,
|
||||
'max_related' => array(
|
||||
'name' => 'max_related',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Maximum Related Memberships') ,
|
||||
'description' => 'Maximum number of related memberships.',
|
||||
'table_name' => 'civicrm_membership_log',
|
||||
'entity' => 'MembershipLog',
|
||||
'bao' => 'CRM_Member_BAO_MembershipLog',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
);
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fields'];
|
||||
}
|
||||
/**
|
||||
* Return a mapping from field-name to the corresponding key (as used in fields()).
|
||||
*
|
||||
* @return array
|
||||
* Array(string $name => string $uniqueName).
|
||||
*/
|
||||
static function &fieldKeys() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
|
||||
Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fieldKeys'];
|
||||
}
|
||||
/**
|
||||
* Returns the names of this table
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static function getTableName() {
|
||||
return self::$_tableName;
|
||||
}
|
||||
/**
|
||||
* Returns if this table needs to be logged
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function getLog() {
|
||||
return self::$_log;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be imported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &import($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'membership_log', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be exported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &export($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'membership_log', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of indices
|
||||
*/
|
||||
public static function indices($localize = TRUE) {
|
||||
$indices = array();
|
||||
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
|
||||
}
|
||||
}
|
206
sites/all/modules/civicrm/CRM/Member/DAO/MembershipPayment.php
Normal file
206
sites/all/modules/civicrm/CRM/Member/DAO/MembershipPayment.php
Normal file
|
@ -0,0 +1,206 @@
|
|||
<?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
|
||||
*
|
||||
* Generated from xml/schema/CRM/Member/MembershipPayment.xml
|
||||
* DO NOT EDIT. Generated by CRM_Core_CodeGen
|
||||
* (GenCodeChecksum:f5961822475bf3b83377d72f9ed34b07)
|
||||
*/
|
||||
require_once 'CRM/Core/DAO.php';
|
||||
require_once 'CRM/Utils/Type.php';
|
||||
/**
|
||||
* CRM_Member_DAO_MembershipPayment constructor.
|
||||
*/
|
||||
class CRM_Member_DAO_MembershipPayment extends CRM_Core_DAO {
|
||||
/**
|
||||
* Static instance to hold the table name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
static $_tableName = 'civicrm_membership_payment';
|
||||
/**
|
||||
* Should CiviCRM log any modifications to this table in the civicrm_log table.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
static $_log = true;
|
||||
/**
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $id;
|
||||
/**
|
||||
* FK to Membership table
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $membership_id;
|
||||
/**
|
||||
* FK to contribution table.
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $contribution_id;
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
function __construct() {
|
||||
$this->__table = 'civicrm_membership_payment';
|
||||
parent::__construct();
|
||||
}
|
||||
/**
|
||||
* Returns foreign keys and entity references.
|
||||
*
|
||||
* @return array
|
||||
* [CRM_Core_Reference_Interface]
|
||||
*/
|
||||
static function getReferenceColumns() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['links'])) {
|
||||
Civi::$statics[__CLASS__]['links'] = static ::createReferenceColumns(__CLASS__);
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'membership_id', 'civicrm_membership', 'id');
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'contribution_id', 'civicrm_contribution', 'id');
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['links'];
|
||||
}
|
||||
/**
|
||||
* Returns all the column names of this table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &fields() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fields'])) {
|
||||
Civi::$statics[__CLASS__]['fields'] = array(
|
||||
'id' => array(
|
||||
'name' => 'id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Membership Payment ID') ,
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_membership_payment',
|
||||
'entity' => 'MembershipPayment',
|
||||
'bao' => 'CRM_Member_BAO_MembershipPayment',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'membership_id' => array(
|
||||
'name' => 'membership_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Membership') ,
|
||||
'description' => 'FK to Membership table',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_membership_payment',
|
||||
'entity' => 'MembershipPayment',
|
||||
'bao' => 'CRM_Member_BAO_MembershipPayment',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Member_DAO_Membership',
|
||||
) ,
|
||||
'contribution_id' => array(
|
||||
'name' => 'contribution_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Contribution') ,
|
||||
'description' => 'FK to contribution table.',
|
||||
'table_name' => 'civicrm_membership_payment',
|
||||
'entity' => 'MembershipPayment',
|
||||
'bao' => 'CRM_Member_BAO_MembershipPayment',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Contribute_DAO_Contribution',
|
||||
) ,
|
||||
);
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fields'];
|
||||
}
|
||||
/**
|
||||
* Return a mapping from field-name to the corresponding key (as used in fields()).
|
||||
*
|
||||
* @return array
|
||||
* Array(string $name => string $uniqueName).
|
||||
*/
|
||||
static function &fieldKeys() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
|
||||
Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fieldKeys'];
|
||||
}
|
||||
/**
|
||||
* Returns the names of this table
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static function getTableName() {
|
||||
return self::$_tableName;
|
||||
}
|
||||
/**
|
||||
* Returns if this table needs to be logged
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function getLog() {
|
||||
return self::$_log;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be imported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &import($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'membership_payment', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be exported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &export($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'membership_payment', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of indices
|
||||
*/
|
||||
public static function indices($localize = TRUE) {
|
||||
$indices = array(
|
||||
'UI_contribution_membership' => array(
|
||||
'name' => 'UI_contribution_membership',
|
||||
'field' => array(
|
||||
0 => 'contribution_id',
|
||||
1 => 'membership_id',
|
||||
) ,
|
||||
'localizable' => false,
|
||||
'unique' => true,
|
||||
'sig' => 'civicrm_membership_payment::1::contribution_id::membership_id',
|
||||
) ,
|
||||
);
|
||||
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
|
||||
}
|
||||
}
|
411
sites/all/modules/civicrm/CRM/Member/DAO/MembershipStatus.php
Normal file
411
sites/all/modules/civicrm/CRM/Member/DAO/MembershipStatus.php
Normal file
|
@ -0,0 +1,411 @@
|
|||
<?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
|
||||
*
|
||||
* Generated from xml/schema/CRM/Member/MembershipStatus.xml
|
||||
* DO NOT EDIT. Generated by CRM_Core_CodeGen
|
||||
* (GenCodeChecksum:dfe977e53a6b66703ab4eca3560048e6)
|
||||
*/
|
||||
require_once 'CRM/Core/DAO.php';
|
||||
require_once 'CRM/Utils/Type.php';
|
||||
/**
|
||||
* CRM_Member_DAO_MembershipStatus constructor.
|
||||
*/
|
||||
class CRM_Member_DAO_MembershipStatus extends CRM_Core_DAO {
|
||||
/**
|
||||
* Static instance to hold the table name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
static $_tableName = 'civicrm_membership_status';
|
||||
/**
|
||||
* Should CiviCRM log any modifications to this table in the civicrm_log table.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
static $_log = true;
|
||||
/**
|
||||
* Membership Id
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $id;
|
||||
/**
|
||||
* Name for Membership Status
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
/**
|
||||
* Label for Membership Status
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $label;
|
||||
/**
|
||||
* Event when this status starts.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $start_event;
|
||||
/**
|
||||
* Unit used for adjusting from start_event.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $start_event_adjust_unit;
|
||||
/**
|
||||
* Status range begins this many units from start_event.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $start_event_adjust_interval;
|
||||
/**
|
||||
* Event after which this status ends.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $end_event;
|
||||
/**
|
||||
* Unit used for adjusting from the ending event.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $end_event_adjust_unit;
|
||||
/**
|
||||
* Status range ends this many units from end_event.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $end_event_adjust_interval;
|
||||
/**
|
||||
* Does this status aggregate to current members (e.g. New, Renewed, Grace might all be TRUE... while Unrenewed, Lapsed, Inactive would be FALSE).
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_current_member;
|
||||
/**
|
||||
* Is this status for admin/manual assignment only.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_admin;
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $weight;
|
||||
/**
|
||||
* Assign this status to a membership record if no other status match is found.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_default;
|
||||
/**
|
||||
* Is this membership_status enabled.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_active;
|
||||
/**
|
||||
* Is this membership_status reserved.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_reserved;
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
function __construct() {
|
||||
$this->__table = 'civicrm_membership_status';
|
||||
parent::__construct();
|
||||
}
|
||||
/**
|
||||
* Returns all the column names of this table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &fields() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fields'])) {
|
||||
Civi::$statics[__CLASS__]['fields'] = array(
|
||||
'id' => array(
|
||||
'name' => 'id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Membership Status ID') ,
|
||||
'description' => 'Membership Id',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_membership_status',
|
||||
'entity' => 'MembershipStatus',
|
||||
'bao' => 'CRM_Member_BAO_MembershipStatus',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'membership_status' => array(
|
||||
'name' => 'name',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Membership Status') ,
|
||||
'description' => 'Name for Membership Status',
|
||||
'maxlength' => 128,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'import' => true,
|
||||
'where' => 'civicrm_membership_status.name',
|
||||
'headerPattern' => '',
|
||||
'dataPattern' => '',
|
||||
'export' => true,
|
||||
'table_name' => 'civicrm_membership_status',
|
||||
'entity' => 'MembershipStatus',
|
||||
'bao' => 'CRM_Member_BAO_MembershipStatus',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'label' => array(
|
||||
'name' => 'label',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Label') ,
|
||||
'description' => 'Label for Membership Status',
|
||||
'maxlength' => 128,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_membership_status',
|
||||
'entity' => 'MembershipStatus',
|
||||
'bao' => 'CRM_Member_BAO_MembershipStatus',
|
||||
'localizable' => 1,
|
||||
) ,
|
||||
'start_event' => array(
|
||||
'name' => 'start_event',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Start Event') ,
|
||||
'description' => 'Event when this status starts.',
|
||||
'maxlength' => 12,
|
||||
'size' => CRM_Utils_Type::TWELVE,
|
||||
'table_name' => 'civicrm_membership_status',
|
||||
'entity' => 'MembershipStatus',
|
||||
'bao' => 'CRM_Member_BAO_MembershipStatus',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Select',
|
||||
) ,
|
||||
'pseudoconstant' => array(
|
||||
'callback' => 'CRM_Core_SelectValues::eventDate',
|
||||
)
|
||||
) ,
|
||||
'start_event_adjust_unit' => array(
|
||||
'name' => 'start_event_adjust_unit',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Start Event Adjust Unit') ,
|
||||
'description' => 'Unit used for adjusting from start_event.',
|
||||
'maxlength' => 8,
|
||||
'size' => CRM_Utils_Type::EIGHT,
|
||||
'table_name' => 'civicrm_membership_status',
|
||||
'entity' => 'MembershipStatus',
|
||||
'bao' => 'CRM_Member_BAO_MembershipStatus',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Select',
|
||||
) ,
|
||||
'pseudoconstant' => array(
|
||||
'callback' => 'CRM_Core_SelectValues::unitList',
|
||||
)
|
||||
) ,
|
||||
'start_event_adjust_interval' => array(
|
||||
'name' => 'start_event_adjust_interval',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Start Event Adjust Interval') ,
|
||||
'description' => 'Status range begins this many units from start_event.',
|
||||
'table_name' => 'civicrm_membership_status',
|
||||
'entity' => 'MembershipStatus',
|
||||
'bao' => 'CRM_Member_BAO_MembershipStatus',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'end_event' => array(
|
||||
'name' => 'end_event',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('End Event') ,
|
||||
'description' => 'Event after which this status ends.',
|
||||
'maxlength' => 12,
|
||||
'size' => CRM_Utils_Type::TWELVE,
|
||||
'table_name' => 'civicrm_membership_status',
|
||||
'entity' => 'MembershipStatus',
|
||||
'bao' => 'CRM_Member_BAO_MembershipStatus',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Select',
|
||||
) ,
|
||||
'pseudoconstant' => array(
|
||||
'callback' => 'CRM_Core_SelectValues::eventDate',
|
||||
)
|
||||
) ,
|
||||
'end_event_adjust_unit' => array(
|
||||
'name' => 'end_event_adjust_unit',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('End Event Adjust Unit') ,
|
||||
'description' => 'Unit used for adjusting from the ending event.',
|
||||
'maxlength' => 8,
|
||||
'size' => CRM_Utils_Type::EIGHT,
|
||||
'table_name' => 'civicrm_membership_status',
|
||||
'entity' => 'MembershipStatus',
|
||||
'bao' => 'CRM_Member_BAO_MembershipStatus',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Select',
|
||||
) ,
|
||||
'pseudoconstant' => array(
|
||||
'callback' => 'CRM_Core_SelectValues::unitList',
|
||||
)
|
||||
) ,
|
||||
'end_event_adjust_interval' => array(
|
||||
'name' => 'end_event_adjust_interval',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('End Event Adjust Interval') ,
|
||||
'description' => 'Status range ends this many units from end_event.',
|
||||
'table_name' => 'civicrm_membership_status',
|
||||
'entity' => 'MembershipStatus',
|
||||
'bao' => 'CRM_Member_BAO_MembershipStatus',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'is_current_member' => array(
|
||||
'name' => 'is_current_member',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Current Membership?') ,
|
||||
'description' => 'Does this status aggregate to current members (e.g. New, Renewed, Grace might all be TRUE... while Unrenewed, Lapsed, Inactive would be FALSE).',
|
||||
'table_name' => 'civicrm_membership_status',
|
||||
'entity' => 'MembershipStatus',
|
||||
'bao' => 'CRM_Member_BAO_MembershipStatus',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'is_admin' => array(
|
||||
'name' => 'is_admin',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Admin Assigned Only?') ,
|
||||
'description' => 'Is this status for admin/manual assignment only.',
|
||||
'table_name' => 'civicrm_membership_status',
|
||||
'entity' => 'MembershipStatus',
|
||||
'bao' => 'CRM_Member_BAO_MembershipStatus',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'weight' => array(
|
||||
'name' => 'weight',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Order') ,
|
||||
'table_name' => 'civicrm_membership_status',
|
||||
'entity' => 'MembershipStatus',
|
||||
'bao' => 'CRM_Member_BAO_MembershipStatus',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'is_default' => array(
|
||||
'name' => 'is_default',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Default Status?') ,
|
||||
'description' => 'Assign this status to a membership record if no other status match is found.',
|
||||
'table_name' => 'civicrm_membership_status',
|
||||
'entity' => 'MembershipStatus',
|
||||
'bao' => 'CRM_Member_BAO_MembershipStatus',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'is_active' => array(
|
||||
'name' => 'is_active',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Is Active') ,
|
||||
'description' => 'Is this membership_status enabled.',
|
||||
'default' => '1',
|
||||
'table_name' => 'civicrm_membership_status',
|
||||
'entity' => 'MembershipStatus',
|
||||
'bao' => 'CRM_Member_BAO_MembershipStatus',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'is_reserved' => array(
|
||||
'name' => 'is_reserved',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Is Reserved') ,
|
||||
'description' => 'Is this membership_status reserved.',
|
||||
'table_name' => 'civicrm_membership_status',
|
||||
'entity' => 'MembershipStatus',
|
||||
'bao' => 'CRM_Member_BAO_MembershipStatus',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
);
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fields'];
|
||||
}
|
||||
/**
|
||||
* Return a mapping from field-name to the corresponding key (as used in fields()).
|
||||
*
|
||||
* @return array
|
||||
* Array(string $name => string $uniqueName).
|
||||
*/
|
||||
static function &fieldKeys() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
|
||||
Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fieldKeys'];
|
||||
}
|
||||
/**
|
||||
* Returns the names of this table
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static function getTableName() {
|
||||
return CRM_Core_DAO::getLocaleTableName(self::$_tableName);
|
||||
}
|
||||
/**
|
||||
* Returns if this table needs to be logged
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function getLog() {
|
||||
return self::$_log;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be imported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &import($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'membership_status', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be exported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &export($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'membership_status', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of indices
|
||||
*/
|
||||
public static function indices($localize = TRUE) {
|
||||
$indices = array();
|
||||
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
|
||||
}
|
||||
}
|
557
sites/all/modules/civicrm/CRM/Member/DAO/MembershipType.php
Normal file
557
sites/all/modules/civicrm/CRM/Member/DAO/MembershipType.php
Normal file
|
@ -0,0 +1,557 @@
|
|||
<?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
|
||||
*
|
||||
* Generated from xml/schema/CRM/Member/MembershipType.xml
|
||||
* DO NOT EDIT. Generated by CRM_Core_CodeGen
|
||||
* (GenCodeChecksum:c86019d4817d79e1dd59d69eaa2a3eb6)
|
||||
*/
|
||||
require_once 'CRM/Core/DAO.php';
|
||||
require_once 'CRM/Utils/Type.php';
|
||||
/**
|
||||
* CRM_Member_DAO_MembershipType constructor.
|
||||
*/
|
||||
class CRM_Member_DAO_MembershipType extends CRM_Core_DAO {
|
||||
/**
|
||||
* Static instance to hold the table name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
static $_tableName = 'civicrm_membership_type';
|
||||
/**
|
||||
* Should CiviCRM log any modifications to this table in the civicrm_log table.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
static $_log = true;
|
||||
/**
|
||||
* Membership Id
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $id;
|
||||
/**
|
||||
* Which Domain is this match entry for
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $domain_id;
|
||||
/**
|
||||
* Name of Membership Type
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
/**
|
||||
* Description of Membership Type
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $description;
|
||||
/**
|
||||
* Owner organization for this membership type. FK to Contact ID
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $member_of_contact_id;
|
||||
/**
|
||||
* If membership is paid by a contribution - what financial type should be used. FK to civicrm_financial_type.id
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $financial_type_id;
|
||||
/**
|
||||
* Minimum fee for this membership (0 for free/complimentary memberships).
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
public $minimum_fee;
|
||||
/**
|
||||
* Unit in which membership period is expressed.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $duration_unit;
|
||||
/**
|
||||
* Number of duration units in membership period (e.g. 1 year, 12 months).
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $duration_interval;
|
||||
/**
|
||||
* Rolling membership period starts on signup date. Fixed membership periods start on fixed_period_start_day.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $period_type;
|
||||
/**
|
||||
* For fixed period memberships, month and day (mmdd) on which subscription/membership will start. Period start is back-dated unless after rollover day.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $fixed_period_start_day;
|
||||
/**
|
||||
* For fixed period memberships, signups after this day (mmdd) rollover to next period.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $fixed_period_rollover_day;
|
||||
/**
|
||||
* FK to Relationship Type ID
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $relationship_type_id;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $relationship_direction;
|
||||
/**
|
||||
* Maximum number of related memberships.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $max_related;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $visibility;
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $weight;
|
||||
/**
|
||||
* Receipt Text for membership signup
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $receipt_text_signup;
|
||||
/**
|
||||
* Receipt Text for membership renewal
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $receipt_text_renewal;
|
||||
/**
|
||||
* 0 = No auto-renew option; 1 = Give option, but not required; 2 = Auto-renew required;
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $auto_renew;
|
||||
/**
|
||||
* Is this membership_type enabled
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_active;
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
function __construct() {
|
||||
$this->__table = 'civicrm_membership_type';
|
||||
parent::__construct();
|
||||
}
|
||||
/**
|
||||
* Returns foreign keys and entity references.
|
||||
*
|
||||
* @return array
|
||||
* [CRM_Core_Reference_Interface]
|
||||
*/
|
||||
static function getReferenceColumns() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['links'])) {
|
||||
Civi::$statics[__CLASS__]['links'] = static ::createReferenceColumns(__CLASS__);
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'domain_id', 'civicrm_domain', 'id');
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'member_of_contact_id', 'civicrm_contact', 'id');
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'financial_type_id', 'civicrm_financial_type', 'id');
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['links'];
|
||||
}
|
||||
/**
|
||||
* Returns all the column names of this table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &fields() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fields'])) {
|
||||
Civi::$statics[__CLASS__]['fields'] = array(
|
||||
'id' => array(
|
||||
'name' => 'id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Membership Type ID') ,
|
||||
'description' => 'Membership Id',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_membership_type',
|
||||
'entity' => 'MembershipType',
|
||||
'bao' => 'CRM_Member_BAO_MembershipType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'domain_id' => array(
|
||||
'name' => 'domain_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Membership Type Domain') ,
|
||||
'description' => 'Which Domain is this match entry for',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_membership_type',
|
||||
'entity' => 'MembershipType',
|
||||
'bao' => 'CRM_Member_BAO_MembershipType',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Core_DAO_Domain',
|
||||
'pseudoconstant' => array(
|
||||
'table' => 'civicrm_domain',
|
||||
'keyColumn' => 'id',
|
||||
'labelColumn' => 'name',
|
||||
)
|
||||
) ,
|
||||
'membership_type' => array(
|
||||
'name' => 'name',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Membership Type') ,
|
||||
'description' => 'Name of Membership Type',
|
||||
'maxlength' => 128,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'import' => true,
|
||||
'where' => 'civicrm_membership_type.name',
|
||||
'headerPattern' => '',
|
||||
'dataPattern' => '',
|
||||
'export' => true,
|
||||
'table_name' => 'civicrm_membership_type',
|
||||
'entity' => 'MembershipType',
|
||||
'bao' => 'CRM_Member_BAO_MembershipType',
|
||||
'localizable' => 1,
|
||||
) ,
|
||||
'description' => array(
|
||||
'name' => 'description',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Membership Type Description') ,
|
||||
'description' => 'Description of Membership Type',
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_membership_type',
|
||||
'entity' => 'MembershipType',
|
||||
'bao' => 'CRM_Member_BAO_MembershipType',
|
||||
'localizable' => 1,
|
||||
'html' => array(
|
||||
'type' => 'TextArea',
|
||||
) ,
|
||||
) ,
|
||||
'member_of_contact_id' => array(
|
||||
'name' => 'member_of_contact_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Membership Type Organization') ,
|
||||
'description' => 'Owner organization for this membership type. FK to Contact ID',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_membership_type',
|
||||
'entity' => 'MembershipType',
|
||||
'bao' => 'CRM_Member_BAO_MembershipType',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Contact_DAO_Contact',
|
||||
) ,
|
||||
'financial_type_id' => array(
|
||||
'name' => 'financial_type_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Membership Financial Type') ,
|
||||
'description' => 'If membership is paid by a contribution - what financial type should be used. FK to civicrm_financial_type.id',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_membership_type',
|
||||
'entity' => 'MembershipType',
|
||||
'bao' => 'CRM_Member_BAO_MembershipType',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Financial_DAO_FinancialType',
|
||||
'pseudoconstant' => array(
|
||||
'table' => 'civicrm_financial_type',
|
||||
'keyColumn' => 'id',
|
||||
'labelColumn' => 'name',
|
||||
)
|
||||
) ,
|
||||
'minimum_fee' => array(
|
||||
'name' => 'minimum_fee',
|
||||
'type' => CRM_Utils_Type::T_MONEY,
|
||||
'title' => ts('membership Type Minimum Fee') ,
|
||||
'description' => 'Minimum fee for this membership (0 for free/complimentary memberships).',
|
||||
'precision' => array(
|
||||
18,
|
||||
9
|
||||
) ,
|
||||
'table_name' => 'civicrm_membership_type',
|
||||
'entity' => 'MembershipType',
|
||||
'bao' => 'CRM_Member_BAO_MembershipType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'duration_unit' => array(
|
||||
'name' => 'duration_unit',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Membership Type Duration Unit') ,
|
||||
'description' => 'Unit in which membership period is expressed.',
|
||||
'maxlength' => 8,
|
||||
'size' => CRM_Utils_Type::EIGHT,
|
||||
'table_name' => 'civicrm_membership_type',
|
||||
'entity' => 'MembershipType',
|
||||
'bao' => 'CRM_Member_BAO_MembershipType',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Select',
|
||||
) ,
|
||||
'pseudoconstant' => array(
|
||||
'callback' => 'CRM_Core_SelectValues::membershipTypeUnitList',
|
||||
)
|
||||
) ,
|
||||
'duration_interval' => array(
|
||||
'name' => 'duration_interval',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Membership Type Duration Interval') ,
|
||||
'description' => 'Number of duration units in membership period (e.g. 1 year, 12 months).',
|
||||
'table_name' => 'civicrm_membership_type',
|
||||
'entity' => 'MembershipType',
|
||||
'bao' => 'CRM_Member_BAO_MembershipType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'period_type' => array(
|
||||
'name' => 'period_type',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Membership Type Plan') ,
|
||||
'description' => 'Rolling membership period starts on signup date. Fixed membership periods start on fixed_period_start_day.',
|
||||
'maxlength' => 8,
|
||||
'size' => CRM_Utils_Type::EIGHT,
|
||||
'table_name' => 'civicrm_membership_type',
|
||||
'entity' => 'MembershipType',
|
||||
'bao' => 'CRM_Member_BAO_MembershipType',
|
||||
'localizable' => 0,
|
||||
'pseudoconstant' => array(
|
||||
'callback' => 'CRM_Core_SelectValues::periodType',
|
||||
)
|
||||
) ,
|
||||
'fixed_period_start_day' => array(
|
||||
'name' => 'fixed_period_start_day',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Fixed Period Start Day') ,
|
||||
'description' => 'For fixed period memberships, month and day (mmdd) on which subscription/membership will start. Period start is back-dated unless after rollover day.',
|
||||
'table_name' => 'civicrm_membership_type',
|
||||
'entity' => 'MembershipType',
|
||||
'bao' => 'CRM_Member_BAO_MembershipType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'fixed_period_rollover_day' => array(
|
||||
'name' => 'fixed_period_rollover_day',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Fixed Period Rollover Day') ,
|
||||
'description' => 'For fixed period memberships, signups after this day (mmdd) rollover to next period.',
|
||||
'table_name' => 'civicrm_membership_type',
|
||||
'entity' => 'MembershipType',
|
||||
'bao' => 'CRM_Member_BAO_MembershipType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'relationship_type_id' => array(
|
||||
'name' => 'relationship_type_id',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Membership Type Relationship') ,
|
||||
'description' => 'FK to Relationship Type ID',
|
||||
'maxlength' => 64,
|
||||
'size' => CRM_Utils_Type::BIG,
|
||||
'table_name' => 'civicrm_membership_type',
|
||||
'entity' => 'MembershipType',
|
||||
'bao' => 'CRM_Member_BAO_MembershipType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'relationship_direction' => array(
|
||||
'name' => 'relationship_direction',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Relationship Direction') ,
|
||||
'maxlength' => 128,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_membership_type',
|
||||
'entity' => 'MembershipType',
|
||||
'bao' => 'CRM_Member_BAO_MembershipType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'max_related' => array(
|
||||
'name' => 'max_related',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Max Related Members for Type') ,
|
||||
'description' => 'Maximum number of related memberships.',
|
||||
'table_name' => 'civicrm_membership_type',
|
||||
'entity' => 'MembershipType',
|
||||
'bao' => 'CRM_Member_BAO_MembershipType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'visibility' => array(
|
||||
'name' => 'visibility',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Visible') ,
|
||||
'maxlength' => 64,
|
||||
'size' => CRM_Utils_Type::BIG,
|
||||
'table_name' => 'civicrm_membership_type',
|
||||
'entity' => 'MembershipType',
|
||||
'bao' => 'CRM_Member_BAO_MembershipType',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Select',
|
||||
) ,
|
||||
'pseudoconstant' => array(
|
||||
'callback' => 'CRM_Core_SelectValues::memberVisibility',
|
||||
)
|
||||
) ,
|
||||
'weight' => array(
|
||||
'name' => 'weight',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Order') ,
|
||||
'table_name' => 'civicrm_membership_type',
|
||||
'entity' => 'MembershipType',
|
||||
'bao' => 'CRM_Member_BAO_MembershipType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'receipt_text_signup' => array(
|
||||
'name' => 'receipt_text_signup',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Membership Type Receipt Text') ,
|
||||
'description' => 'Receipt Text for membership signup',
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_membership_type',
|
||||
'entity' => 'MembershipType',
|
||||
'bao' => 'CRM_Member_BAO_MembershipType',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'TextArea',
|
||||
) ,
|
||||
) ,
|
||||
'receipt_text_renewal' => array(
|
||||
'name' => 'receipt_text_renewal',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Membership Type Renewal Text') ,
|
||||
'description' => 'Receipt Text for membership renewal',
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_membership_type',
|
||||
'entity' => 'MembershipType',
|
||||
'bao' => 'CRM_Member_BAO_MembershipType',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'TextArea',
|
||||
) ,
|
||||
) ,
|
||||
'auto_renew' => array(
|
||||
'name' => 'auto_renew',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Auto Renew') ,
|
||||
'description' => '0 = No auto-renew option; 1 = Give option, but not required; 2 = Auto-renew required;',
|
||||
'table_name' => 'civicrm_membership_type',
|
||||
'entity' => 'MembershipType',
|
||||
'bao' => 'CRM_Member_BAO_MembershipType',
|
||||
'localizable' => 0,
|
||||
'pseudoconstant' => array(
|
||||
'callback' => 'CRM_Core_SelectValues::memberAutoRenew',
|
||||
)
|
||||
) ,
|
||||
'is_active' => array(
|
||||
'name' => 'is_active',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Is Active') ,
|
||||
'description' => 'Is this membership_type enabled',
|
||||
'default' => '1',
|
||||
'table_name' => 'civicrm_membership_type',
|
||||
'entity' => 'MembershipType',
|
||||
'bao' => 'CRM_Member_BAO_MembershipType',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
);
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fields'];
|
||||
}
|
||||
/**
|
||||
* Return a mapping from field-name to the corresponding key (as used in fields()).
|
||||
*
|
||||
* @return array
|
||||
* Array(string $name => string $uniqueName).
|
||||
*/
|
||||
static function &fieldKeys() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
|
||||
Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fieldKeys'];
|
||||
}
|
||||
/**
|
||||
* Returns the names of this table
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static function getTableName() {
|
||||
return CRM_Core_DAO::getLocaleTableName(self::$_tableName);
|
||||
}
|
||||
/**
|
||||
* Returns if this table needs to be logged
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function getLog() {
|
||||
return self::$_log;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be imported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &import($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'membership_type', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be exported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &export($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'membership_type', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of indices
|
||||
*/
|
||||
public static function indices($localize = TRUE) {
|
||||
$indices = array(
|
||||
'index_relationship_type_id' => array(
|
||||
'name' => 'index_relationship_type_id',
|
||||
'field' => array(
|
||||
0 => 'relationship_type_id',
|
||||
) ,
|
||||
'localizable' => false,
|
||||
'sig' => 'civicrm_membership_type::0::relationship_type_id',
|
||||
) ,
|
||||
);
|
||||
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
|
||||
}
|
||||
}
|
454
sites/all/modules/civicrm/CRM/Member/Form.php
Normal file
454
sites/all/modules/civicrm/CRM/Member/Form.php
Normal file
|
@ -0,0 +1,454 @@
|
|||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for offline membership / membership type / membership renewal and membership status forms
|
||||
*
|
||||
*/
|
||||
class CRM_Member_Form extends CRM_Contribute_Form_AbstractEditPayment {
|
||||
|
||||
/**
|
||||
* The id of the object being edited / created
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $_id;
|
||||
|
||||
/**
|
||||
* Membership Type ID
|
||||
* @var
|
||||
*/
|
||||
protected $_memType;
|
||||
|
||||
/**
|
||||
* Array of from email ids
|
||||
* @var array
|
||||
*/
|
||||
protected $_fromEmails = array();
|
||||
|
||||
/**
|
||||
* Details of all enabled membership types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $allMembershipTypeDetails = array();
|
||||
|
||||
/**
|
||||
* Array of membership type IDs and whether they permit autorenewal.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $membershipTypeRenewalStatus = array();
|
||||
|
||||
/**
|
||||
* Price set ID configured for the form.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $_priceSetId;
|
||||
|
||||
/**
|
||||
* Price set details as an array.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $_priceSet;
|
||||
|
||||
/**
|
||||
* Values submitted to the form, processed along the way.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_params = array();
|
||||
|
||||
public function preProcess() {
|
||||
// Check for edit permission.
|
||||
if (!CRM_Core_Permission::checkActionPermission('CiviMember', $this->_action)) {
|
||||
CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
|
||||
}
|
||||
if (!CRM_Member_BAO_Membership::statusAvailabilty()) {
|
||||
// all possible statuses are disabled - redirect back to contact form
|
||||
CRM_Core_Error::statusBounce(ts('There are no configured membership statuses. You cannot add this membership until your membership statuses are correctly configured'));
|
||||
}
|
||||
|
||||
parent::preProcess();
|
||||
$params = array();
|
||||
$params['context'] = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'membership');
|
||||
$params['id'] = CRM_Utils_Request::retrieve('id', 'Positive', $this);
|
||||
$params['mode'] = CRM_Utils_Request::retrieve('mode', 'String', $this);
|
||||
|
||||
$this->setContextVariables($params);
|
||||
|
||||
$this->assign('context', $this->_context);
|
||||
$this->assign('membershipMode', $this->_mode);
|
||||
$this->allMembershipTypeDetails = CRM_Member_BAO_Membership::buildMembershipTypeValues($this, array(), TRUE);
|
||||
foreach ($this->allMembershipTypeDetails as $index => $membershipType) {
|
||||
if ($membershipType['auto_renew']) {
|
||||
$this->_recurMembershipTypes[$index] = $membershipType;
|
||||
$this->membershipTypeRenewalStatus[$index] = $membershipType['auto_renew'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form. MobileProvider that in edit/view mode
|
||||
* the default values are retrieved from the database
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
* defaults
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
if (isset($this->_id)) {
|
||||
$params = array('id' => $this->_id);
|
||||
CRM_Member_BAO_Membership::retrieve($params, $defaults);
|
||||
if (isset($defaults['minimum_fee'])) {
|
||||
$defaults['minimum_fee'] = CRM_Utils_Money::format($defaults['minimum_fee'], NULL, '%a');
|
||||
}
|
||||
|
||||
if (isset($defaults['status'])) {
|
||||
$this->assign('membershipStatus', $defaults['status']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_action & CRM_Core_Action::ADD) {
|
||||
$defaults['is_active'] = 1;
|
||||
}
|
||||
|
||||
if (isset($defaults['member_of_contact_id']) &&
|
||||
$defaults['member_of_contact_id']
|
||||
) {
|
||||
$defaults['member_org'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
|
||||
$defaults['member_of_contact_id'], 'display_name'
|
||||
);
|
||||
}
|
||||
if (!empty($defaults['membership_type_id'])) {
|
||||
$this->_memType = $defaults['membership_type_id'];
|
||||
}
|
||||
if (is_numeric($this->_memType)) {
|
||||
$defaults['membership_type_id'] = array();
|
||||
$defaults['membership_type_id'][0] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType',
|
||||
$this->_memType,
|
||||
'member_of_contact_id',
|
||||
'id'
|
||||
);
|
||||
$defaults['membership_type_id'][1] = $this->_memType;
|
||||
}
|
||||
else {
|
||||
$defaults['membership_type_id'] = $this->_memType;
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
|
||||
$this->addPaymentProcessorSelect(TRUE, FALSE, TRUE);
|
||||
CRM_Core_Payment_Form::buildPaymentForm($this, $this->_paymentProcessor, FALSE, TRUE, $this->getDefaultPaymentInstrumentId());
|
||||
// Build the form for auto renew. This is displayed when in credit card mode or update mode.
|
||||
// The reason for showing it in update mode is not that clear.
|
||||
if ($this->_mode || ($this->_action & CRM_Core_Action::UPDATE)) {
|
||||
if (!empty($this->_recurPaymentProcessors)) {
|
||||
$this->assign('allowAutoRenew', TRUE);
|
||||
}
|
||||
|
||||
$autoRenewElement = $this->addElement('checkbox', 'auto_renew', ts('Membership renewed automatically'),
|
||||
NULL, array('onclick' => "showHideByValue('auto_renew','','send-receipt','table-row','radio',true); showHideNotice( );")
|
||||
);
|
||||
if ($this->_action & CRM_Core_Action::UPDATE) {
|
||||
$autoRenewElement->freeze();
|
||||
}
|
||||
|
||||
$this->assign('recurProcessor', json_encode($this->_recurPaymentProcessors));
|
||||
$this->addElement('checkbox',
|
||||
'auto_renew',
|
||||
ts('Membership renewed automatically')
|
||||
);
|
||||
|
||||
}
|
||||
$this->assign('autoRenewOptions', json_encode($this->membershipTypeRenewalStatus));
|
||||
|
||||
if ($this->_action & CRM_Core_Action::RENEW) {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'upload',
|
||||
'name' => ts('Renew'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
));
|
||||
}
|
||||
elseif ($this->_action & CRM_Core_Action::DELETE) {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Delete'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
));
|
||||
}
|
||||
else {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'upload',
|
||||
'name' => ts('Save'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'upload',
|
||||
'name' => ts('Save and New'),
|
||||
'subName' => 'new',
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract values from the contact create boxes on the form and assign appropriately to
|
||||
*
|
||||
* - $this->_contributorEmail,
|
||||
* - $this->_memberEmail &
|
||||
* - $this->_contributionName
|
||||
* - $this->_memberName
|
||||
* - $this->_contactID (effectively memberContactId but changing might have spin-off effects)
|
||||
* - $this->_contributorContactId - id of the contributor
|
||||
* - $this->_receiptContactId
|
||||
*
|
||||
* If the member & contributor are the same then the values will be the same. But if different people paid
|
||||
* then they weill differ
|
||||
*
|
||||
* @param array $formValues
|
||||
* values from form. The important values we are looking for are.
|
||||
* - contact_id
|
||||
* - soft_credit_contact_id
|
||||
*/
|
||||
public function storeContactFields($formValues) {
|
||||
// in a 'standalone form' (contact id not in the url) the contact will be in the form values
|
||||
if (!empty($formValues['contact_id'])) {
|
||||
$this->_contactID = $formValues['contact_id'];
|
||||
}
|
||||
|
||||
list($this->_memberDisplayName,
|
||||
$this->_memberEmail
|
||||
) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID);
|
||||
|
||||
//CRM-10375 Where the payer differs to the member the payer should get the email.
|
||||
// here we store details in order to do that
|
||||
if (!empty($formValues['soft_credit_contact_id'])) {
|
||||
$this->_receiptContactId = $this->_contributorContactID = $formValues['soft_credit_contact_id'];
|
||||
list($this->_contributorDisplayName,
|
||||
$this->_contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contributorContactID);
|
||||
}
|
||||
else {
|
||||
$this->_receiptContactId = $this->_contributorContactID = $this->_contactID;
|
||||
$this->_contributorDisplayName = $this->_memberDisplayName;
|
||||
$this->_contributorEmail = $this->_memberEmail;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set variables in a way that can be accessed from different places.
|
||||
*
|
||||
* This is part of refactoring for unit testability on the submit function.
|
||||
*
|
||||
* @param array $params
|
||||
*/
|
||||
protected function setContextVariables($params) {
|
||||
$variables = array(
|
||||
'action' => '_action',
|
||||
'context' => '_context',
|
||||
'id' => '_id',
|
||||
'cid' => '_contactID',
|
||||
'mode' => '_mode',
|
||||
);
|
||||
foreach ($variables as $paramKey => $classVar) {
|
||||
if (isset($params[$paramKey]) && !isset($this->$classVar)) {
|
||||
$this->$classVar = $params[$paramKey];
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_id) {
|
||||
$this->_memType = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'membership_type_id');
|
||||
$this->_membershipIDs[] = $this->_id;
|
||||
}
|
||||
$this->_fromEmails = CRM_Core_BAO_Email::getFromEmail();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a recurring contribution record.
|
||||
*
|
||||
* Recurring contribution parameters are set explicitly rather than merging paymentParams because it's hard
|
||||
* to know the downstream impacts if we keep passing around the same array.
|
||||
*
|
||||
* @param $paymentParams
|
||||
*
|
||||
* @return array
|
||||
* @throws \CiviCRM_API3_Exception
|
||||
*/
|
||||
protected function processRecurringContribution($paymentParams) {
|
||||
$membershipID = $paymentParams['membership_type_id'][1];
|
||||
$contributionRecurParams = array(
|
||||
'contact_id' => $paymentParams['contactID'],
|
||||
'amount' => $paymentParams['total_amount'],
|
||||
'contribution_status_id' => 'Pending',
|
||||
'payment_processor_id' => $paymentParams['payment_processor_id'],
|
||||
'campaign_id' => $paymentParams['campaign_id'],
|
||||
'financial_type_id' => $paymentParams['financial_type_id'],
|
||||
'is_email_receipt' => $paymentParams['is_email_receipt'],
|
||||
'payment_instrument_id' => $paymentParams['payment_instrument_id'],
|
||||
'invoice_id' => $paymentParams['invoice_id'],
|
||||
);
|
||||
|
||||
$mapping = array(
|
||||
'frequency_interval' => 'duration_interval',
|
||||
'frequency_unit' => 'duration_unit',
|
||||
);
|
||||
$membershipType = civicrm_api3('MembershipType', 'getsingle', array(
|
||||
'id' => $membershipID,
|
||||
'return' => $mapping,
|
||||
));
|
||||
|
||||
$returnParams = array('is_recur' => TRUE);
|
||||
foreach ($mapping as $recurringFieldName => $membershipTypeFieldName) {
|
||||
$contributionRecurParams[$recurringFieldName] = $membershipType[$membershipTypeFieldName];
|
||||
$returnParams[$recurringFieldName] = $membershipType[$membershipTypeFieldName];
|
||||
}
|
||||
|
||||
$contributionRecur = civicrm_api3('ContributionRecur', 'create', $contributionRecurParams);
|
||||
$returnParams['contributionRecurID'] = $contributionRecur['id'];
|
||||
return $returnParams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure price parameters are set.
|
||||
*
|
||||
* If they are not set it means a quick config option has been chosen so we
|
||||
* fill them in here to make the two flows the same. They look like 'price_2' => 2 etc.
|
||||
*
|
||||
* @param array $formValues
|
||||
*/
|
||||
protected function ensurePriceParamsAreSet(&$formValues) {
|
||||
foreach ($formValues as $key => $value) {
|
||||
if ((substr($key, 0, 6) == 'price_') && is_numeric(substr($key, 6))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
$priceFields = CRM_Member_BAO_Membership::setQuickConfigMembershipParameters(
|
||||
$formValues['membership_type_id'][0],
|
||||
$formValues['membership_type_id'][1],
|
||||
CRM_Utils_Array::value('total_amount', $formValues),
|
||||
$this->_priceSetId
|
||||
);
|
||||
$formValues = array_merge($formValues, $priceFields['price_fields']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the details for the selected price set.
|
||||
*
|
||||
* @param array $params
|
||||
* Parameters submitted to the form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function getPriceSetDetails($params) {
|
||||
$priceSetID = CRM_Utils_Array::value('price_set_id', $params);
|
||||
if ($priceSetID) {
|
||||
return CRM_Price_BAO_PriceSet::getSetDetail($priceSetID);
|
||||
}
|
||||
else {
|
||||
$priceSet = CRM_Price_BAO_PriceSet::getDefaultPriceSet('membership');
|
||||
$priceSet = reset($priceSet);
|
||||
return CRM_Price_BAO_PriceSet::getSetDetail($priceSet['setID']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the selected price set id.
|
||||
*
|
||||
* @param array $params
|
||||
* Parameters submitted to the form.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected static function getPriceSetID($params) {
|
||||
$priceSetID = CRM_Utils_Array::value('price_set_id', $params);
|
||||
if (!$priceSetID) {
|
||||
$priceSetDetails = self::getPriceSetDetails($params);
|
||||
return key($priceSetDetails);
|
||||
}
|
||||
return $priceSetID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store parameters relating to price sets.
|
||||
*
|
||||
* @param array $formValues
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function setPriceSetParameters($formValues) {
|
||||
$this->_priceSetId = self::getPriceSetID($formValues);
|
||||
$priceSetDetails = self::getPriceSetDetails($formValues);
|
||||
$this->_priceSet = $priceSetDetails[$this->_priceSetId];
|
||||
// process price set and get total amount and line items.
|
||||
$this->ensurePriceParamsAreSet($formValues);
|
||||
return $formValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper function for unit tests.
|
||||
*
|
||||
* @param array $formValues
|
||||
*/
|
||||
public function testSubmit($formValues) {
|
||||
$this->setContextVariables($formValues);
|
||||
$this->_memType = $formValues['membership_type_id'][1];
|
||||
$this->_params = $formValues;
|
||||
$this->submit();
|
||||
}
|
||||
|
||||
}
|
1909
sites/all/modules/civicrm/CRM/Member/Form/Membership.php
Normal file
1909
sites/all/modules/civicrm/CRM/Member/Form/Membership.php
Normal file
File diff suppressed because it is too large
Load diff
505
sites/all/modules/civicrm/CRM/Member/Form/MembershipBlock.php
Normal file
505
sites/all/modules/civicrm/CRM/Member/Form/MembershipBlock.php
Normal file
|
@ -0,0 +1,505 @@
|
|||
<?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$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* form to process actions on Membership
|
||||
*/
|
||||
class CRM_Member_Form_MembershipBlock extends CRM_Contribute_Form_ContributionPage {
|
||||
|
||||
/**
|
||||
* Store membership price set id
|
||||
*/
|
||||
protected $_memPriceSetId = NULL;
|
||||
|
||||
/**
|
||||
* Set default values for the form. Note that in edit/view mode
|
||||
* the default values are retrieved from the database
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
//parent::setDefaultValues();
|
||||
$defaults = array();
|
||||
if (isset($this->_id)) {
|
||||
$defaults = CRM_Member_BAO_Membership::getMembershipBlock($this->_id);
|
||||
}
|
||||
$defaults['member_is_active'] = $defaults['is_active'];
|
||||
|
||||
// Set Display Minimum Fee default to true if we are adding a new membership block
|
||||
if (!isset($defaults['id'])) {
|
||||
$defaults['display_min_fee'] = 1;
|
||||
}
|
||||
else {
|
||||
$this->assign('membershipBlockId', $defaults['id']);
|
||||
}
|
||||
if ($this->_id &&
|
||||
($priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id, 3, 1))
|
||||
) {
|
||||
$defaults['member_price_set_id'] = $priceSetId;
|
||||
$this->_memPriceSetId = $priceSetId;
|
||||
}
|
||||
else {
|
||||
// for membership_types
|
||||
// if ( isset( $defaults['membership_types'] ) ) {
|
||||
$priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id, 3);
|
||||
$this->assign('isQuick', 1);
|
||||
$this->_memPriceSetId = $priceSetId;
|
||||
$pFIDs = array();
|
||||
if ($priceSetId) {
|
||||
CRM_Core_DAO::commonRetrieveAll('CRM_Price_DAO_PriceField', 'price_set_id', $priceSetId, $pFIDs, $return = array(
|
||||
'html_type',
|
||||
'name',
|
||||
'label',
|
||||
));
|
||||
foreach ($pFIDs as $pid => $pValue) {
|
||||
if ($pValue['html_type'] == 'Radio' && $pValue['name'] == 'membership_amount') {
|
||||
$defaults['mem_price_field_id'] = $pValue['id'];
|
||||
$defaults['membership_type_label'] = $pValue['label'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($defaults['mem_price_field_id'])) {
|
||||
$options = array();
|
||||
$priceFieldOptions = CRM_Price_BAO_PriceFieldValue::getValues($defaults['mem_price_field_id'], $options, 'id', 1);
|
||||
foreach ($options as $k => $v) {
|
||||
$newMembershipType[$v['membership_type_id']] = 1;
|
||||
if (!empty($defaults['auto_renew'])) {
|
||||
$defaults["auto_renew_" . $v['membership_type_id']] = $defaults['auto_renew'][$v['membership_type_id']];
|
||||
}
|
||||
}
|
||||
$defaults['membership_type'] = $newMembershipType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$membershipTypes = CRM_Member_BAO_MembershipType::getMembershipTypes();
|
||||
|
||||
if (!empty($membershipTypes)) {
|
||||
$this->addElement('checkbox', 'member_is_active', ts('Membership Section Enabled?'));
|
||||
|
||||
$this->addElement('text', 'new_title', ts('Title - New Membership'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipBlock', 'new_title'));
|
||||
|
||||
$this->add('wysiwyg', 'new_text', ts('Introductory Message - New Memberships'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipBlock', 'new_text'));
|
||||
|
||||
$this->addElement('text', 'renewal_title', ts('Title - Renewals'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipBlock', 'renewal_title'));
|
||||
|
||||
$this->add('wysiwyg', 'renewal_text', ts('Introductory Message - Renewals'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipBlock', 'renewal_text'));
|
||||
|
||||
$this->addElement('checkbox', 'is_required', ts('Require Membership Signup'));
|
||||
$this->addElement('checkbox', 'display_min_fee', ts('Display Membership Fee'));
|
||||
$this->addElement('checkbox', 'is_separate_payment', ts('Separate Membership Payment'));
|
||||
$this->addElement('text', 'membership_type_label', ts('Membership Types Label'), array('placeholder' => ts('Membership')));
|
||||
|
||||
$paymentProcessor = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, 'is_recur = 1');
|
||||
$paymentProcessorIds = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage',
|
||||
$this->_id, 'payment_processor'
|
||||
);
|
||||
$paymentProcessorId = explode(CRM_Core_DAO::VALUE_SEPARATOR, $paymentProcessorIds);
|
||||
$isRecur = TRUE;
|
||||
foreach ($paymentProcessorId as $dontCare => $id) {
|
||||
if (!array_key_exists($id, $paymentProcessor)) {
|
||||
$isRecur = FALSE;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$membership = $membershipDefault = $params = array();
|
||||
foreach ($membershipTypes as $k => $v) {
|
||||
$membership[] = $this->createElement('advcheckbox', $k, NULL, $v);
|
||||
$membershipDefault[] = $this->createElement('radio', NULL, NULL, NULL, $k);
|
||||
$membershipRequired[$k] = NULL;
|
||||
if ($isRecur) {
|
||||
$autoRenew = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $k, 'auto_renew');
|
||||
$membershipRequired[$k] = $autoRenew;
|
||||
$autoRenewOptions = array();
|
||||
if ($autoRenew) {
|
||||
$autoRenewOptions = array(ts('Not offered'), ts('Give option'), ts('Required'));
|
||||
$this->addElement('select', "auto_renew_$k", ts('Auto-renew'), $autoRenewOptions);
|
||||
//CRM-15573
|
||||
if ($autoRenew == 2) {
|
||||
$this->freeze("auto_renew_$k");
|
||||
$params['id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipBlock', $this->_id, 'id', 'entity_id');
|
||||
}
|
||||
$this->_renewOption[$k] = $autoRenew;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//CRM-15573
|
||||
if (!empty($params['id'])) {
|
||||
$params['membership_types'] = serialize($membershipRequired);
|
||||
CRM_Member_BAO_MembershipBlock::create($params);
|
||||
}
|
||||
$this->add('hidden', "mem_price_field_id", '', array('id' => "mem_price_field_id"));
|
||||
$this->assign('is_recur', $isRecur);
|
||||
if (isset($this->_renewOption)) {
|
||||
$this->assign('auto_renew', $this->_renewOption);
|
||||
}
|
||||
$this->addGroup($membership, 'membership_type', ts('Membership Types'));
|
||||
$this->addGroup($membershipDefault, 'membership_type_default', ts('Membership Types Default'))
|
||||
->setAttribute('allowClear', TRUE);
|
||||
|
||||
$this->addFormRule(array('CRM_Member_Form_MembershipBlock', 'formRule'), $this->_id);
|
||||
}
|
||||
$price = CRM_Price_BAO_PriceSet::getAssoc(FALSE, 'CiviMember');
|
||||
if (CRM_Utils_System::isNull($price)) {
|
||||
$this->assign('price', FALSE);
|
||||
}
|
||||
else {
|
||||
$this->assign('price', TRUE);
|
||||
}
|
||||
$this->add('select', 'member_price_set_id', ts('Membership Price Set'), (array('' => ts('- none -')) + $price));
|
||||
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$single = $session->get('singleForm');
|
||||
if ($single) {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Save'),
|
||||
'spacing' => ' ',
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
));
|
||||
}
|
||||
else {
|
||||
parent::buildQuickForm();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validation.
|
||||
*
|
||||
* @param array $params
|
||||
* (ref.) an assoc array of name/value pairs.
|
||||
*
|
||||
* @param $files
|
||||
* @param int $contributionPageId
|
||||
*
|
||||
* @return bool|array
|
||||
* mixed true or array of errors
|
||||
*/
|
||||
public static function formRule($params, $files, $contributionPageId = NULL) {
|
||||
$errors = array();
|
||||
|
||||
if (!empty($params['member_price_set_id'])) {
|
||||
//check if this price set has membership type both auto-renew and non-auto-renew memberships.
|
||||
$bothTypes = CRM_Price_BAO_PriceSet::isMembershipPriceSetContainsMixOfRenewNonRenew($params['member_price_set_id']);
|
||||
|
||||
//check for supporting payment processors
|
||||
//if both auto-renew and non-auto-renew memberships
|
||||
if ($bothTypes) {
|
||||
$paymentProcessorIds = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage',
|
||||
$contributionPageId, 'payment_processor'
|
||||
);
|
||||
|
||||
$paymentProcessorId = explode(CRM_Core_DAO::VALUE_SEPARATOR, $paymentProcessorIds);
|
||||
|
||||
if (!empty($paymentProcessorId)) {
|
||||
foreach ($paymentProcessorId as $pid) {
|
||||
if ($pid) {
|
||||
$processor = Civi\Payment\System::singleton()->getById($pid);
|
||||
if (!$processor->supports('MultipleConcurrentPayments')) {
|
||||
$errors['member_price_set_id'] = ts('The membership price set associated with this online contribution allows a user to select BOTH an auto-renew AND a non-auto-renew membership. This requires submitting multiple processor transactions, and is not supported for one or more of the payment processors enabled under the Amounts tab.');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($params['member_is_active'])) {
|
||||
|
||||
// don't allow price set w/ membership signup, CRM-5095
|
||||
if ($contributionPageId && ($setID = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $contributionPageId, NULL, 1))) {
|
||||
|
||||
$extends = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $setID, 'extends');
|
||||
if ($extends != CRM_Core_Component::getComponentID('CiviMember')) {
|
||||
$errors['member_is_active'] = ts('You cannot enable both Membership Signup and a Contribution Price Set on the same online contribution page.');
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($params['member_price_set_id'])) {
|
||||
return $errors;
|
||||
}
|
||||
|
||||
if (!isset($params['membership_type']) ||
|
||||
(!is_array($params['membership_type']))
|
||||
) {
|
||||
$errors['membership_type'] = ts('Please select at least one Membership Type to include in the Membership section of this page.');
|
||||
}
|
||||
else {
|
||||
$membershipType = array_values($params['membership_type']);
|
||||
$isRecur = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $contributionPageId, 'is_recur');
|
||||
if (array_sum($membershipType) == 0) {
|
||||
$errors['membership_type'] = ts('Please select at least one Membership Type to include in the Membership section of this page.');
|
||||
}
|
||||
elseif (array_sum($membershipType) > CRM_Price_Form_Field::NUM_OPTION) {
|
||||
// for CRM-13079
|
||||
$errors['membership_type'] = ts('You cannot select more than %1 choices. For more complex functionality, please use a Price Set.', array(1 => CRM_Price_Form_Field::NUM_OPTION));
|
||||
}
|
||||
elseif ($isRecur) {
|
||||
if (empty($params['is_separate_payment']) && array_sum($membershipType) != 0) {
|
||||
$errors['is_separate_payment'] = ts('You need to enable Separate Membership Payment when online contribution page is configured for both Membership and Recurring Contribution');
|
||||
}
|
||||
elseif (!empty($params['is_separate_payment'])) {
|
||||
foreach ($params['membership_type'] as $mt => $dontCare) {
|
||||
if (!empty($params["auto_renew_$mt"])) {
|
||||
$errors["auto_renew_$mt"] = ts('You cannot enable both Recurring Contributions and Auto-renew memberships on the same online contribution page');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//for CRM-1302
|
||||
//if Membership status is not present, then display an error message
|
||||
$dao = new CRM_Member_BAO_MembershipStatus();
|
||||
if (!$dao->find()) {
|
||||
$errors['_qf_default'] = ts('Add status rules, before configuring membership');
|
||||
}
|
||||
|
||||
//give error if default is selected for an unchecked membership type
|
||||
if (!empty($params['membership_type_default']) && !$params['membership_type'][$params['membership_type_default']]) {
|
||||
$errors['membership_type_default'] = ts('Can\'t set default option for an unchecked membership type.');
|
||||
}
|
||||
|
||||
if ($contributionPageId) {
|
||||
$amountBlock = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $contributionPageId, 'amount_block_is_active');
|
||||
|
||||
if (!$amountBlock && !empty($params['is_separate_payment'])) {
|
||||
$errors['is_separate_payment'] = ts('Please enable the contribution amount section to use this option.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
// get the submitted form values.
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
$deletePriceSet = 0;
|
||||
if ($params['membership_type']) {
|
||||
// we do this in case the user has hit the forward/back button
|
||||
$dao = new CRM_Member_DAO_MembershipBlock();
|
||||
$dao->entity_table = 'civicrm_contribution_page';
|
||||
$dao->entity_id = $this->_id;
|
||||
$dao->find(TRUE);
|
||||
$membershipID = $dao->id;
|
||||
if ($membershipID) {
|
||||
$params['id'] = $membershipID;
|
||||
}
|
||||
|
||||
$membershipTypes = array();
|
||||
if (is_array($params['membership_type'])) {
|
||||
foreach ($params['membership_type'] as $k => $v) {
|
||||
if ($v) {
|
||||
$membershipTypes[$k] = CRM_Utils_Array::value("auto_renew_$k", $params);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_id && !empty($params['member_price_set_id'])) {
|
||||
CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'amount_block_is_active', 0);
|
||||
}
|
||||
|
||||
// check for price set.
|
||||
$priceSetID = CRM_Utils_Array::value('member_price_set_id', $params);
|
||||
if (!empty($params['member_is_active']) && is_array($membershipTypes) && !$priceSetID) {
|
||||
$usedPriceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id, 2);
|
||||
if (empty($params['mem_price_field_id']) && !$usedPriceSetId) {
|
||||
$pageTitle = strtolower(CRM_Utils_String::munge($this->_values['title'], '_', 245));
|
||||
$setParams['title'] = $this->_values['title'];
|
||||
if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $pageTitle, 'id', 'name')) {
|
||||
$setParams['name'] = $pageTitle;
|
||||
}
|
||||
elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $pageTitle . '_' . $this->_id, 'id', 'name')) {
|
||||
$setParams['name'] = $pageTitle . '_' . $this->_id;
|
||||
}
|
||||
else {
|
||||
$timeSec = explode(".", microtime(TRUE));
|
||||
$setParams['name'] = $pageTitle . '_' . date('is', $timeSec[0]) . $timeSec[1];
|
||||
}
|
||||
$setParams['is_quick_config'] = 1;
|
||||
$setParams['extends'] = CRM_Core_Component::getComponentID('CiviMember');
|
||||
$setParams['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $this->_values);
|
||||
$priceSet = CRM_Price_BAO_PriceSet::create($setParams);
|
||||
$priceSetID = $priceSet->id;
|
||||
$fieldParams['price_set_id'] = $priceSet->id;
|
||||
}
|
||||
elseif ($usedPriceSetId) {
|
||||
$setParams['extends'] = CRM_Core_Component::getComponentID('CiviMember');
|
||||
$setParams['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $this->_values);
|
||||
$setParams['id'] = $usedPriceSetId;
|
||||
$priceSet = CRM_Price_BAO_PriceSet::create($setParams);
|
||||
$priceSetID = $priceSet->id;
|
||||
$fieldParams['price_set_id'] = $priceSet->id;
|
||||
}
|
||||
else {
|
||||
$fieldParams['id'] = CRM_Utils_Array::value('mem_price_field_id', $params);
|
||||
$priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', CRM_Utils_Array::value('mem_price_field_id', $params), 'price_set_id');
|
||||
}
|
||||
$editedFieldParams = array(
|
||||
'price_set_id' => $priceSetID,
|
||||
'name' => 'membership_amount',
|
||||
);
|
||||
$editedResults = array();
|
||||
CRM_Price_BAO_PriceField::retrieve($editedFieldParams, $editedResults);
|
||||
if (empty($editedResults['id'])) {
|
||||
$fieldParams['name'] = strtolower(CRM_Utils_String::munge('Membership Amount', '_', 245));
|
||||
if (empty($params['mem_price_field_id'])) {
|
||||
CRM_Utils_Weight::updateOtherWeights('CRM_Price_DAO_PriceField', 0, 1, array('price_set_id' => $priceSetID));
|
||||
}
|
||||
$fieldParams['weight'] = 1;
|
||||
}
|
||||
else {
|
||||
$fieldParams['id'] = CRM_Utils_Array::value('id', $editedResults);
|
||||
}
|
||||
|
||||
$fieldParams['label'] = !empty($params['membership_type_label']) ? $params['membership_type_label'] : ts('Membership');
|
||||
$fieldParams['is_active'] = 1;
|
||||
$fieldParams['html_type'] = 'Radio';
|
||||
$fieldParams['is_required'] = !empty($params['is_required']) ? 1 : 0;
|
||||
$fieldParams['is_display_amounts'] = !empty($params['display_min_fee']) ? 1 : 0;
|
||||
$rowCount = 1;
|
||||
$options = array();
|
||||
if (!empty($fieldParams['id'])) {
|
||||
CRM_Core_PseudoConstant::populate($options, 'CRM_Price_DAO_PriceFieldValue', TRUE, 'membership_type_id', NULL, " price_field_id = {$fieldParams['id']} ");
|
||||
}
|
||||
|
||||
foreach ($membershipTypes as $memType => $memAutoRenew) {
|
||||
if ($priceFieldID = CRM_Utils_Array::key($memType, $options)) {
|
||||
$fieldParams['option_id'][$rowCount] = $priceFieldID;
|
||||
unset($options[$priceFieldID]);
|
||||
}
|
||||
$membetype = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($memType);
|
||||
$fieldParams['option_label'][$rowCount] = CRM_Utils_Array::value('name', $membetype);
|
||||
$fieldParams['option_amount'][$rowCount] = CRM_Utils_Array::value('minimum_fee', $membetype, 0);
|
||||
$fieldParams['option_weight'][$rowCount] = CRM_Utils_Array::value('weight', $membetype);
|
||||
$fieldParams['option_description'][$rowCount] = CRM_Utils_Array::value('description', $membetype);
|
||||
$fieldParams['default_option'] = CRM_Utils_Array::value('membership_type_default', $params);
|
||||
$fieldParams['option_financial_type_id'][$rowCount] = CRM_Utils_Array::value('financial_type_id', $membetype);
|
||||
|
||||
$fieldParams['membership_type_id'][$rowCount] = $memType;
|
||||
// [$rowCount] = $membetype[''];
|
||||
$rowCount++;
|
||||
}
|
||||
foreach ($options as $priceFieldID => $memType) {
|
||||
CRM_Price_BAO_PriceFieldValue::setIsActive($priceFieldID, '0');
|
||||
}
|
||||
$priceField = CRM_Price_BAO_PriceField::create($fieldParams);
|
||||
}
|
||||
elseif (!$priceSetID) {
|
||||
$deletePriceSet = 1;
|
||||
}
|
||||
|
||||
$params['is_required'] = CRM_Utils_Array::value('is_required', $params, FALSE);
|
||||
$params['is_active'] = CRM_Utils_Array::value('member_is_active', $params, FALSE);
|
||||
|
||||
if ($priceSetID) {
|
||||
$params['membership_types'] = 'null';
|
||||
$params['membership_type_default'] = CRM_Utils_Array::value('membership_type_default', $params, 'null');
|
||||
$params['membership_types'] = serialize($membershipTypes);
|
||||
$params['display_min_fee'] = CRM_Utils_Array::value('display_min_fee', $params, FALSE);
|
||||
$params['is_separate_payment'] = CRM_Utils_Array::value('is_separate_payment', $params, FALSE);
|
||||
}
|
||||
$params['entity_table'] = 'civicrm_contribution_page';
|
||||
$params['entity_id'] = $this->_id;
|
||||
|
||||
$dao = new CRM_Member_DAO_MembershipBlock();
|
||||
$dao->copyValues($params);
|
||||
$dao->save();
|
||||
|
||||
if ($priceSetID && $params['is_active']) {
|
||||
CRM_Price_BAO_PriceSet::addTo('civicrm_contribution_page', $this->_id, $priceSetID);
|
||||
}
|
||||
|
||||
if ($deletePriceSet || !CRM_Utils_Array::value('member_is_active', $params, FALSE)) {
|
||||
|
||||
if ($this->_memPriceSetId) {
|
||||
$pFIDs = array();
|
||||
$conditionParams = array(
|
||||
'price_set_id' => $this->_memPriceSetId,
|
||||
'html_type' => 'radio',
|
||||
'name' => 'contribution_amount',
|
||||
);
|
||||
|
||||
CRM_Core_DAO::commonRetrieve('CRM_Price_DAO_PriceField', $conditionParams, $pFIDs);
|
||||
if (empty($pFIDs['id'])) {
|
||||
CRM_Price_BAO_PriceSet::removeFrom('civicrm_contribution_page', $this->_id);
|
||||
CRM_Price_BAO_PriceSet::setIsQuickConfig($this->_memPriceSetId, '0');
|
||||
}
|
||||
else {
|
||||
|
||||
CRM_Price_BAO_PriceField::setIsActive($params['mem_price_field_id'], '0');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
parent::endPostProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a descriptive name for the page, used in wizard header
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle() {
|
||||
return ts('Memberships');
|
||||
}
|
||||
|
||||
}
|
159
sites/all/modules/civicrm/CRM/Member/Form/MembershipConfig.php
Normal file
159
sites/all/modules/civicrm/CRM/Member/Form/MembershipConfig.php
Normal file
|
@ -0,0 +1,159 @@
|
|||
<?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$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for offline membership / membership type / membership renewal and membership status forms
|
||||
*
|
||||
*/
|
||||
class CRM_Member_Form_MembershipConfig extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* The id of the object being edited / created
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $_id;
|
||||
|
||||
/**
|
||||
* The name of the BAO object for this form.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_BAOName;
|
||||
|
||||
/**
|
||||
* Explicitly declare the entity api name.
|
||||
*/
|
||||
public function getDefaultEntity() {
|
||||
return 'MembershipType';
|
||||
}
|
||||
|
||||
public function preProcess() {
|
||||
$this->_id = $this->get('id');
|
||||
$this->_BAOName = $this->get('BAOName');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form. MobileProvider that in edit/view mode
|
||||
* the default values are retrieved from the database
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
* defaults
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
|
||||
if (isset($this->_id)) {
|
||||
$params = array('id' => $this->_id);
|
||||
$baoName = $this->_BAOName;
|
||||
$baoName::retrieve($params, $defaults);
|
||||
}
|
||||
|
||||
if (isset($defaults['minimum_fee'])) {
|
||||
$defaults['minimum_fee'] = CRM_Utils_Money::format($defaults['minimum_fee'], NULL, '%a');
|
||||
}
|
||||
|
||||
if (isset($defaults['status'])) {
|
||||
$this->assign('membershipStatus', $defaults['status']);
|
||||
}
|
||||
|
||||
if ($this->_action & CRM_Core_Action::ADD) {
|
||||
$defaults['is_active'] = 1;
|
||||
}
|
||||
|
||||
if (isset($defaults['member_of_contact_id']) &&
|
||||
$defaults['member_of_contact_id']
|
||||
) {
|
||||
$defaults['member_org'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
|
||||
$defaults['member_of_contact_id'], 'display_name'
|
||||
);
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
if ($this->_action & CRM_Core_Action::RENEW) {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'upload',
|
||||
'name' => ts('Renew'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
));
|
||||
}
|
||||
elseif ($this->_action & CRM_Core_Action::DELETE) {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Delete'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
));
|
||||
}
|
||||
else {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'upload',
|
||||
'name' => ts('Save'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'upload',
|
||||
'name' => ts('Save and New'),
|
||||
'subName' => 'new',
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
716
sites/all/modules/civicrm/CRM/Member/Form/MembershipRenewal.php
Normal file
716
sites/all/modules/civicrm/CRM/Member/Form/MembershipRenewal.php
Normal file
|
@ -0,0 +1,716 @@
|
|||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for Membership Renewal
|
||||
*/
|
||||
class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form {
|
||||
|
||||
/**
|
||||
* Display name of the member.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_memberDisplayName = NULL;
|
||||
|
||||
/**
|
||||
* email of the person paying for the membership (used for receipts)
|
||||
*/
|
||||
protected $_memberEmail = NULL;
|
||||
|
||||
/**
|
||||
* Contact ID of the member.
|
||||
*
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $_contactID = NULL;
|
||||
|
||||
/**
|
||||
* Display name of the person paying for the membership (used for receipts)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_contributorDisplayName = NULL;
|
||||
|
||||
/**
|
||||
* email of the person paying for the membership (used for receipts)
|
||||
*/
|
||||
protected $_contributorEmail = NULL;
|
||||
|
||||
/**
|
||||
* email of the person paying for the membership (used for receipts)
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_contributorContactID = NULL;
|
||||
|
||||
/**
|
||||
* ID of the person the receipt is to go to
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_receiptContactId = NULL;
|
||||
|
||||
/**
|
||||
* context would be set to standalone if the contact is use is being selected from
|
||||
* the form rather than in the URL
|
||||
*/
|
||||
public $_context;
|
||||
|
||||
/**
|
||||
* End date of renewed membership.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $endDate = NULL;
|
||||
|
||||
/**
|
||||
* Has an email been sent.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $isMailSent = FALSE;
|
||||
|
||||
/**
|
||||
* The name of the renewed membership type.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $membershipTypeName = '';
|
||||
|
||||
/**
|
||||
* An array to hold a list of datefields on the form
|
||||
* so that they can be converted to ISO in a consistent manner
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_dateFields = array(
|
||||
'receive_date' => array('default' => 'now'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Pre-process form.
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function preProcess() {
|
||||
|
||||
// This string makes up part of the class names, differentiating them (not sure why) from the membership fields.
|
||||
$this->assign('formClass', 'membershiprenew');
|
||||
parent::preProcess();
|
||||
|
||||
$this->assign('endDate', CRM_Utils_Date::customFormat(CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership',
|
||||
$this->_id, 'end_date'
|
||||
)
|
||||
));
|
||||
$this->assign('membershipStatus',
|
||||
CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus',
|
||||
CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership',
|
||||
$this->_id, 'status_id'
|
||||
),
|
||||
'name'
|
||||
)
|
||||
);
|
||||
|
||||
if ($this->_mode) {
|
||||
$membershipFee = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'minimum_fee');
|
||||
if (!$membershipFee) {
|
||||
$statusMsg = ts('Membership Renewal using a credit card requires a Membership fee. Since there is no fee associated with the selected membership type, you can use the normal renewal mode.');
|
||||
CRM_Core_Session::setStatus($statusMsg, '', 'info');
|
||||
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view/membership',
|
||||
"reset=1&action=renew&cid={$this->_contactID}&id={$this->_id}&context=membership"
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// when custom data is included in this page
|
||||
if (!empty($_POST['hidden_custom'])) {
|
||||
CRM_Custom_Form_CustomData::preProcess($this, NULL, $this->_memType, 1, 'Membership', $this->_id);
|
||||
CRM_Custom_Form_CustomData::buildQuickForm($this);
|
||||
CRM_Custom_Form_CustomData::setDefaultValues($this);
|
||||
}
|
||||
|
||||
CRM_Utils_System::setTitle(ts('Renew Membership'));
|
||||
|
||||
parent::preProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
* the default values are retrieved from the database
|
||||
*
|
||||
* @return array
|
||||
* Default values.
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
|
||||
$defaults = parent::setDefaultValues();
|
||||
|
||||
// set renewal_date and receive_date to today in correct input format (setDateDefaults uses today if no value passed)
|
||||
list($now, $currentTime) = CRM_Utils_Date::setDateDefaults();
|
||||
$defaults['renewal_date'] = $now;
|
||||
$defaults['receive_date'] = $now;
|
||||
$defaults['receive_date_time'] = $currentTime;
|
||||
|
||||
if ($defaults['id']) {
|
||||
$defaults['record_contribution'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipPayment',
|
||||
$defaults['id'],
|
||||
'contribution_id',
|
||||
'membership_id'
|
||||
);
|
||||
}
|
||||
|
||||
$defaults['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'financial_type_id');
|
||||
|
||||
//CRM-13420
|
||||
if (empty($defaults['payment_instrument_id'])) {
|
||||
$defaults['payment_instrument_id'] = key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1'));
|
||||
}
|
||||
|
||||
$defaults['total_amount'] = CRM_Utils_Money::format(CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType',
|
||||
$this->_memType,
|
||||
'minimum_fee'
|
||||
), NULL, '%a');
|
||||
|
||||
$defaults['record_contribution'] = 0;
|
||||
$defaults['num_terms'] = 1;
|
||||
$defaults['send_receipt'] = 0;
|
||||
|
||||
//set Soft Credit Type to Gift by default
|
||||
$scTypes = CRM_Core_OptionGroup::values("soft_credit_type");
|
||||
$defaults['soft_credit_type_id'] = CRM_Utils_Array::value(ts('Gift'), array_flip($scTypes));
|
||||
|
||||
$renewalDate = CRM_Utils_Date::processDate(CRM_Utils_Array::value('renewal_date', $defaults),
|
||||
NULL, NULL, 'Y-m-d'
|
||||
);
|
||||
$this->assign('renewalDate', $renewalDate);
|
||||
$this->assign('member_is_test', CRM_Utils_Array::value('member_is_test', $defaults));
|
||||
|
||||
if ($this->_mode) {
|
||||
$defaults = $this->getBillingDefaults($defaults);
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
|
||||
parent::buildQuickForm();
|
||||
|
||||
$defaults = parent::setDefaultValues();
|
||||
$this->assign('customDataType', 'Membership');
|
||||
$this->assign('customDataSubType', $this->_memType);
|
||||
$this->assign('entityID', $this->_id);
|
||||
$selOrgMemType[0][0] = $selMemTypeOrg[0] = ts('- select -');
|
||||
|
||||
$allMembershipInfo = array();
|
||||
|
||||
//CRM-16950
|
||||
$taxRates = CRM_Core_PseudoConstant::getTaxRates();
|
||||
$taxRate = CRM_Utils_Array::value($this->allMembershipTypeDetails[$defaults['membership_type_id']]['financial_type_id'], $taxRates);
|
||||
|
||||
$invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
|
||||
|
||||
// auto renew options if enabled for the membership
|
||||
$options = CRM_Core_SelectValues::memberAutoRenew();
|
||||
|
||||
foreach ($this->allMembershipTypeDetails as $key => $values) {
|
||||
if (!empty($values['is_active'])) {
|
||||
if ($this->_mode && empty($values['minimum_fee'])) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
$memberOfContactId = CRM_Utils_Array::value('member_of_contact_id', $values);
|
||||
if (empty($selMemTypeOrg[$memberOfContactId])) {
|
||||
$selMemTypeOrg[$memberOfContactId] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
|
||||
$memberOfContactId,
|
||||
'display_name',
|
||||
'id'
|
||||
);
|
||||
|
||||
$selOrgMemType[$memberOfContactId][0] = ts('- select -');
|
||||
}
|
||||
if (empty($selOrgMemType[$memberOfContactId][$key])) {
|
||||
$selOrgMemType[$memberOfContactId][$key] = CRM_Utils_Array::value('name', $values);
|
||||
}
|
||||
}
|
||||
|
||||
//CRM-16950
|
||||
$taxAmount = NULL;
|
||||
$totalAmount = CRM_Utils_Array::value('minimum_fee', $values);
|
||||
if (CRM_Utils_Array::value($values['financial_type_id'], $taxRates)) {
|
||||
$taxAmount = ($taxRate / 100) * CRM_Utils_Array::value('minimum_fee', $values);
|
||||
$totalAmount = $totalAmount + $taxAmount;
|
||||
}
|
||||
|
||||
// build membership info array, which is used to set the payment information block when
|
||||
// membership type is selected.
|
||||
$allMembershipInfo[$key] = array(
|
||||
'financial_type_id' => CRM_Utils_Array::value('financial_type_id', $values),
|
||||
'total_amount' => CRM_Utils_Money::format($totalAmount, NULL, '%a'),
|
||||
'total_amount_numeric' => $totalAmount,
|
||||
'tax_message' => $taxAmount ? ts("Includes %1 amount of %2", array(1 => CRM_Utils_Array::value('tax_term', $invoiceSettings), 2 => CRM_Utils_Money::format($taxAmount))) : $taxAmount,
|
||||
);
|
||||
|
||||
if (!empty($values['auto_renew'])) {
|
||||
$allMembershipInfo[$key]['auto_renew'] = $options[$values['auto_renew']];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->assign('allMembershipInfo', json_encode($allMembershipInfo));
|
||||
|
||||
if ($this->_memType) {
|
||||
$this->assign('orgName', $selMemTypeOrg[$this->allMembershipTypeDetails[$this->_memType]['member_of_contact_id']]);
|
||||
$this->assign('memType', $this->allMembershipTypeDetails[$this->_memType]['name']);
|
||||
}
|
||||
|
||||
// force select of organization by default, if only one organization in
|
||||
// the list
|
||||
if (count($selMemTypeOrg) == 2) {
|
||||
unset($selMemTypeOrg[0], $selOrgMemType[0][0]);
|
||||
}
|
||||
//sort membership organization and type, CRM-6099
|
||||
natcasesort($selMemTypeOrg);
|
||||
foreach ($selOrgMemType as $index => $orgMembershipType) {
|
||||
natcasesort($orgMembershipType);
|
||||
$selOrgMemType[$index] = $orgMembershipType;
|
||||
}
|
||||
|
||||
$js = array('onChange' => "setPaymentBlock(); CRM.buildCustomData('Membership', this.value);");
|
||||
$sel = &$this->addElement('hierselect',
|
||||
'membership_type_id',
|
||||
ts('Renewal Membership Organization and Type'), $js
|
||||
);
|
||||
|
||||
$sel->setOptions(array($selMemTypeOrg, $selOrgMemType));
|
||||
$elements = array();
|
||||
if ($sel) {
|
||||
$elements[] = $sel;
|
||||
}
|
||||
|
||||
$this->applyFilter('__ALL__', 'trim');
|
||||
|
||||
$this->addDate('renewal_date', ts('Date Renewal Entered'), FALSE, array('formatType' => 'activityDate'));
|
||||
|
||||
$this->add('select', 'financial_type_id', ts('Financial Type'),
|
||||
array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::financialType()
|
||||
);
|
||||
|
||||
$this->add('text', 'num_terms', ts('Extend Membership by'), array('onchange' => "setPaymentBlock();"), TRUE);
|
||||
$this->addRule('num_terms', ts('Please enter a whole number for how many periods to renew.'), 'integer');
|
||||
|
||||
if (CRM_Core_Permission::access('CiviContribute') && !$this->_mode) {
|
||||
$this->addElement('checkbox', 'record_contribution', ts('Record Renewal Payment?'), NULL, array('onclick' => "checkPayment();"));
|
||||
|
||||
$this->add('text', 'total_amount', ts('Amount'));
|
||||
$this->addRule('total_amount', ts('Please enter a valid amount.'), 'money');
|
||||
|
||||
$this->addDate('receive_date', ts('Received'), FALSE, array('formatType' => 'activityDateTime'));
|
||||
|
||||
$this->add('select', 'payment_instrument_id', ts('Payment Method'),
|
||||
array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(),
|
||||
FALSE, array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);")
|
||||
);
|
||||
|
||||
$this->add('text', 'trxn_id', ts('Transaction ID'));
|
||||
$this->addRule('trxn_id', ts('Transaction ID already exists in Database.'),
|
||||
'objectExists', array('CRM_Contribute_DAO_Contribution', $this->_id, 'trxn_id')
|
||||
);
|
||||
|
||||
$this->add('select', 'contribution_status_id', ts('Payment Status'),
|
||||
CRM_Contribute_BAO_Contribution_Utils::getContributionStatuses('membership')
|
||||
);
|
||||
|
||||
$this->add('text', 'check_number', ts('Check Number'),
|
||||
CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'check_number')
|
||||
);
|
||||
}
|
||||
else {
|
||||
$this->add('text', 'total_amount', ts('Amount'));
|
||||
$this->addRule('total_amount', ts('Please enter a valid amount.'), 'money');
|
||||
}
|
||||
$this->addElement('checkbox', 'send_receipt', ts('Send Confirmation and Receipt?'), NULL,
|
||||
array('onclick' => "showHideByValue( 'send_receipt', '', 'notice', 'table-row', 'radio', false ); showHideByValue( 'send_receipt', '', 'fromEmail', 'table-row', 'radio',false);")
|
||||
);
|
||||
|
||||
$this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails);
|
||||
|
||||
$this->add('textarea', 'receipt_text_renewal', ts('Renewal Message'));
|
||||
|
||||
// Retrieve the name and email of the contact - this will be the TO for receipt email
|
||||
list($this->_contributorDisplayName,
|
||||
$this->_contributorEmail
|
||||
) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID);
|
||||
$this->assign('email', $this->_contributorEmail);
|
||||
// The member form uses emailExists. Assigning both while we transition / synchronise.
|
||||
$this->assign('emailExists', $this->_contributorEmail);
|
||||
|
||||
$mailingInfo = Civi::settings()->get('mailing_backend');
|
||||
$this->assign('outBound_option', $mailingInfo['outBound_option']);
|
||||
|
||||
if (CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'contribution_recur_id')) {
|
||||
if (CRM_Member_BAO_Membership::isCancelSubscriptionSupported($this->_id)) {
|
||||
$this->assign('cancelAutoRenew',
|
||||
CRM_Utils_System::url('civicrm/contribute/unsubscribe', "reset=1&mid={$this->_id}")
|
||||
);
|
||||
}
|
||||
}
|
||||
$this->addFormRule(array('CRM_Member_Form_MembershipRenewal', 'formRule'), $this);
|
||||
$this->addElement('checkbox', 'is_different_contribution_contact', ts('Record Payment from a Different Contact?'));
|
||||
$this->addSelect('soft_credit_type_id', array('entity' => 'contribution_soft'));
|
||||
$this->addEntityRef('soft_credit_contact_id', ts('Payment From'), array('create' => TRUE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Validation.
|
||||
*
|
||||
* @param array $params
|
||||
* (ref.) an assoc array of name/value pairs.
|
||||
*
|
||||
* @return bool|array
|
||||
* mixed true or array of errors
|
||||
*/
|
||||
public static function formRule($params, $files, $self) {
|
||||
$errors = array();
|
||||
if ($params['membership_type_id'][0] == 0) {
|
||||
$errors['membership_type_id'] = ts('Oops. It looks like you are trying to change the membership type while renewing the membership. Please click the "change membership type" link, and select a Membership Organization.');
|
||||
}
|
||||
if ($params['membership_type_id'][1] == 0) {
|
||||
$errors['membership_type_id'] = ts('Oops. It looks like you are trying to change the membership type while renewing the membership. Please click the "change membership type" link and select a Membership Type from the list.');
|
||||
}
|
||||
|
||||
// CRM-20571
|
||||
// Get the Join Date from Membership info as it is not available in the Renewal form
|
||||
$joinDate = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $self->_id, 'join_date');
|
||||
|
||||
// CRM-20571: Check if the renewal date is not before Join Date, if it is then add to 'errors' array
|
||||
// The fields in Renewal form come into this routine in $params array. 'renewal_date' is in the form
|
||||
// We process both the dates before comparison using CRM utils so that they are in same date format
|
||||
if (isset($params['renewal_date'])) {
|
||||
if (CRM_Utils_Date::processDate($params['renewal_date']) < CRM_Utils_Date::processDate($joinDate)) {
|
||||
$errors['renewal_date'] = ts('Renewal date must be the same or later than Member since (Join Date).');
|
||||
}
|
||||
}
|
||||
|
||||
//total amount condition arise when membership type having no
|
||||
//minimum fee
|
||||
if (isset($params['record_contribution'])) {
|
||||
if (!$params['financial_type_id']) {
|
||||
$errors['financial_type_id'] = ts('Please select a Financial Type.');
|
||||
}
|
||||
if (!$params['total_amount']) {
|
||||
$errors['total_amount'] = ts('Please enter a Contribution Amount.');
|
||||
}
|
||||
if (empty($params['payment_instrument_id'])) {
|
||||
$errors['payment_instrument_id'] = ts('Payment Method is a required field.');
|
||||
}
|
||||
}
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the renewal form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
// get the submitted form values.
|
||||
$this->_params = $this->controller->exportValues($this->_name);
|
||||
$this->assignBillingName();
|
||||
|
||||
try {
|
||||
$this->submit();
|
||||
$statusMsg = ts('%1 membership for %2 has been renewed.', array(1 => $this->membershipTypeName, 2 => $this->_memberDisplayName));
|
||||
|
||||
if ($this->endDate) {
|
||||
$statusMsg .= ' ' . ts('The new membership End Date is %1.', array(
|
||||
1 => CRM_Utils_Date::customFormat(substr($this->endDate, 0, 8)),
|
||||
));
|
||||
}
|
||||
|
||||
if ($this->isMailSent) {
|
||||
$statusMsg .= ' ' . ts('A renewal confirmation and receipt has been sent to %1.', array(
|
||||
1 => $this->_contributorEmail,
|
||||
));
|
||||
return $statusMsg;
|
||||
}
|
||||
return $statusMsg;
|
||||
}
|
||||
catch (\Civi\Payment\Exception\PaymentProcessorException $e) {
|
||||
CRM_Core_Error::displaySessionError($e->getMessage());
|
||||
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view/membership',
|
||||
"reset=1&action=renew&cid={$this->_contactID}&id={$this->_id}&context=membership&mode={$this->_mode}"
|
||||
));
|
||||
}
|
||||
|
||||
CRM_Core_Session::setStatus($statusMsg, ts('Complete'), 'success');
|
||||
}
|
||||
|
||||
/**
|
||||
* Process form submission.
|
||||
*
|
||||
* This function is also accessed by a unit test.
|
||||
*/
|
||||
protected function submit() {
|
||||
$this->storeContactFields($this->_params);
|
||||
$this->beginPostProcess();
|
||||
$now = CRM_Utils_Date::getToday(NULL, 'YmdHis');
|
||||
$this->convertDateFieldsToMySQL($this->_params);
|
||||
$this->assign('receive_date', $this->_params['receive_date']);
|
||||
$this->processBillingAddress();
|
||||
list($userName) = CRM_Contact_BAO_Contact_Location::getEmailDetails(CRM_Core_Session::singleton()->get('userID'));
|
||||
$this->_params['total_amount'] = CRM_Utils_Array::value('total_amount', $this->_params,
|
||||
CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'minimum_fee')
|
||||
);
|
||||
$this->_membershipId = $this->_id;
|
||||
$customFieldsFormatted = CRM_Core_BAO_CustomField::postProcess($this->_params,
|
||||
$this->_id,
|
||||
'Membership'
|
||||
);
|
||||
if (empty($this->_params['financial_type_id'])) {
|
||||
$this->_params['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'financial_type_id');
|
||||
}
|
||||
$contributionRecurID = NULL;
|
||||
$this->assign('membershipID', $this->_id);
|
||||
$this->assign('contactID', $this->_contactID);
|
||||
$this->assign('module', 'Membership');
|
||||
$this->assign('receiptType', 'membership renewal');
|
||||
$this->_params['currencyID'] = CRM_Core_Config::singleton()->defaultCurrency;
|
||||
$this->_params['invoice_id'] = $this->_params['invoiceID'] = md5(uniqid(rand(), TRUE));
|
||||
|
||||
if (!empty($this->_params['send_receipt'])) {
|
||||
$this->_params['receipt_date'] = $now;
|
||||
$this->assign('receipt_date', CRM_Utils_Date::mysqlToIso($this->_params['receipt_date']));
|
||||
}
|
||||
else {
|
||||
$this->_params['receipt_date'] = NULL;
|
||||
}
|
||||
|
||||
if ($this->_mode) {
|
||||
$this->_params['register_date'] = $now;
|
||||
$this->_params['description'] = ts("Contribution submitted by a staff person using member's credit card for renewal");
|
||||
$this->_params['amount'] = $this->_params['total_amount'];
|
||||
$this->_params['payment_instrument_id'] = $this->_paymentProcessor['payment_instrument_id'];
|
||||
|
||||
// at this point we've created a contact and stored its address etc
|
||||
// all the payment processors expect the name and address to be in the passed params
|
||||
// so we copy stuff over to first_name etc.
|
||||
$paymentParams = $this->_params;
|
||||
if (!empty($this->_params['send_receipt'])) {
|
||||
$paymentParams['email'] = $this->_contributorEmail;
|
||||
}
|
||||
$paymentParams['is_email_receipt'] = !empty($this->_params['send_receipt']);
|
||||
|
||||
$paymentParams['contactID'] = $this->_contributorContactID;
|
||||
|
||||
CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $paymentParams, TRUE);
|
||||
|
||||
$payment = $this->_paymentProcessor['object'];
|
||||
|
||||
if (!empty($this->_params['auto_renew'])) {
|
||||
$contributionRecurParams = $this->processRecurringContribution($paymentParams);
|
||||
$contributionRecurID = $contributionRecurParams['contributionRecurID'];
|
||||
$paymentParams = array_merge($paymentParams, $contributionRecurParams);
|
||||
}
|
||||
|
||||
$result = $payment->doPayment($paymentParams);
|
||||
$this->_params = array_merge($this->_params, $result);
|
||||
|
||||
$this->_params['contribution_status_id'] = $result['payment_status_id'];
|
||||
$this->_params['trxn_id'] = $result['trxn_id'];
|
||||
$this->_params['is_test'] = ($this->_mode == 'live') ? 0 : 1;
|
||||
$this->set('params', $this->_params);
|
||||
$this->assign('trxn_id', $result['trxn_id']);
|
||||
}
|
||||
|
||||
$renewalDate = !empty($this->_params['renewal_date']) ? $renewalDate = CRM_Utils_Date::processDate($this->_params['renewal_date']) : NULL;
|
||||
|
||||
// check for test membership.
|
||||
$isTestMembership = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_membershipId, 'is_test');
|
||||
|
||||
// chk for renewal for multiple terms CRM-8750
|
||||
$numRenewTerms = 1;
|
||||
if (is_numeric(CRM_Utils_Array::value('num_terms', $this->_params))) {
|
||||
$numRenewTerms = $this->_params['num_terms'];
|
||||
}
|
||||
|
||||
//if contribution status is pending then set pay later
|
||||
$this->_params['is_pay_later'] = FALSE;
|
||||
if ($this->_params['contribution_status_id'] == array_search('Pending', CRM_Contribute_PseudoConstant::contributionStatus())) {
|
||||
$this->_params['is_pay_later'] = 1;
|
||||
}
|
||||
|
||||
// These variable sets prior to renewMembership may not be required for this form. They were in
|
||||
// a function this form shared with other forms.
|
||||
$membershipSource = NULL;
|
||||
if (!empty($this->_params['membership_source'])) {
|
||||
$membershipSource = $this->_params['membership_source'];
|
||||
}
|
||||
|
||||
$isPending = ($this->_params['contribution_status_id'] == 2) ? TRUE : FALSE;
|
||||
|
||||
list($renewMembership) = CRM_Member_BAO_Membership::processMembership(
|
||||
$this->_contactID, $this->_params['membership_type_id'][1], $isTestMembership,
|
||||
$renewalDate, NULL, $customFieldsFormatted, $numRenewTerms, $this->_membershipId,
|
||||
$isPending,
|
||||
$contributionRecurID, $membershipSource, $this->_params['is_pay_later'], CRM_Utils_Array::value('campaign_id',
|
||||
$this->_params)
|
||||
);
|
||||
|
||||
$this->endDate = CRM_Utils_Date::processDate($renewMembership->end_date);
|
||||
|
||||
$this->membershipTypeName = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $renewMembership->membership_type_id,
|
||||
'name');
|
||||
|
||||
if (!empty($this->_params['record_contribution']) || $this->_mode) {
|
||||
// set the source
|
||||
$this->_params['contribution_source'] = "{$this->membershipTypeName} Membership: Offline membership renewal (by {$userName})";
|
||||
|
||||
//create line items
|
||||
$lineItem = array();
|
||||
$this->_params = $this->setPriceSetParameters($this->_params);
|
||||
CRM_Price_BAO_PriceSet::processAmount($this->_priceSet['fields'],
|
||||
$this->_params, $lineItem[$this->_priceSetId], NULL, $this->_priceSetId
|
||||
);
|
||||
//CRM-11529 for quick config backoffice transactions
|
||||
//when financial_type_id is passed in form, update the
|
||||
//line items with the financial type selected in form
|
||||
if ($submittedFinancialType = CRM_Utils_Array::value('financial_type_id', $this->_params)) {
|
||||
foreach ($lineItem[$this->_priceSetId] as &$li) {
|
||||
$li['financial_type_id'] = $submittedFinancialType;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($lineItem)) {
|
||||
$this->_params['lineItems'] = $lineItem;
|
||||
$this->_params['processPriceSet'] = TRUE;
|
||||
}
|
||||
|
||||
//assign contribution contact id to the field expected by recordMembershipContribution
|
||||
if ($this->_contributorContactID != $this->_contactID) {
|
||||
$this->_params['contribution_contact_id'] = $this->_contributorContactID;
|
||||
if (!empty($this->_params['soft_credit_type_id'])) {
|
||||
$this->_params['soft_credit'] = array(
|
||||
'soft_credit_type_id' => $this->_params['soft_credit_type_id'],
|
||||
'contact_id' => $this->_contactID,
|
||||
);
|
||||
}
|
||||
}
|
||||
$this->_params['contact_id'] = $this->_contactID;
|
||||
//recordMembershipContribution receives params as a reference & adds one variable. This is
|
||||
// not a great pattern & ideally it would not receive as a reference. We assign our params as a
|
||||
// temporary variable to avoid e-notice & to make it clear to future refactorer that
|
||||
// this function is NOT reliant on that var being set
|
||||
$temporaryParams = array_merge($this->_params, array(
|
||||
'membership_id' => $renewMembership->id,
|
||||
'contribution_recur_id' => $contributionRecurID,
|
||||
));
|
||||
//Remove `tax_amount` if it is not calculated.
|
||||
if (CRM_Utils_Array::value('tax_amount', $temporaryParams) === 0) {
|
||||
unset($temporaryParams['tax_amount']);
|
||||
}
|
||||
CRM_Member_BAO_Membership::recordMembershipContribution($temporaryParams);
|
||||
}
|
||||
|
||||
if (!empty($this->_params['send_receipt'])) {
|
||||
|
||||
$receiptFrom = $this->_params['from_email_address'];
|
||||
|
||||
if (!empty($this->_params['payment_instrument_id'])) {
|
||||
$paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument();
|
||||
$this->_params['paidBy'] = $paymentInstrument[$this->_params['payment_instrument_id']];
|
||||
}
|
||||
//get the group Tree
|
||||
$this->_groupTree = CRM_Core_BAO_CustomGroup::getTree('Membership', NULL, $this->_id, FALSE, $this->_memType);
|
||||
|
||||
// retrieve custom data
|
||||
$customFields = $customValues = $fo = array();
|
||||
foreach ($this->_groupTree as $groupID => $group) {
|
||||
if ($groupID == 'info') {
|
||||
continue;
|
||||
}
|
||||
foreach ($group['fields'] as $k => $field) {
|
||||
$field['title'] = $field['label'];
|
||||
$customFields["custom_{$k}"] = $field;
|
||||
}
|
||||
}
|
||||
$members = array(array('member_id', '=', $this->_membershipId, 0, 0));
|
||||
// check whether its a test drive
|
||||
if ($this->_mode == 'test') {
|
||||
$members[] = array('member_test', '=', 1, 0, 0);
|
||||
}
|
||||
CRM_Core_BAO_UFGroup::getValues($this->_contactID, $customFields, $customValues, FALSE, $members);
|
||||
|
||||
$this->assign_by_ref('formValues', $this->_params);
|
||||
if (!empty($this->_params['contribution_id'])) {
|
||||
$this->assign('contributionID', $this->_params['contribution_id']);
|
||||
}
|
||||
|
||||
$this->assign('membership_name', CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType',
|
||||
$renewMembership->membership_type_id
|
||||
));
|
||||
$this->assign('customValues', $customValues);
|
||||
$this->assign('mem_start_date', CRM_Utils_Date::customFormat($renewMembership->start_date));
|
||||
$this->assign('mem_end_date', CRM_Utils_Date::customFormat($renewMembership->end_date));
|
||||
if ($this->_mode) {
|
||||
$this->assign('address', CRM_Utils_Address::getFormattedBillingAddressFieldsFromParameters(
|
||||
$this->_params,
|
||||
$this->_bltID
|
||||
));
|
||||
$this->assign('contributeMode', 'direct');
|
||||
$this->assign('isAmountzero', 0);
|
||||
$this->assign('is_pay_later', 0);
|
||||
$this->assign('isPrimary', 1);
|
||||
$this->assign('receipt_text_renewal', $this->_params['receipt_text']);
|
||||
if ($this->_mode == 'test') {
|
||||
$this->assign('action', '1024');
|
||||
}
|
||||
}
|
||||
|
||||
list($this->isMailSent) = CRM_Core_BAO_MessageTemplate::sendTemplate(
|
||||
array(
|
||||
'groupName' => 'msg_tpl_workflow_membership',
|
||||
'valueName' => 'membership_offline_receipt',
|
||||
'contactId' => $this->_receiptContactId,
|
||||
'from' => $receiptFrom,
|
||||
'toName' => $this->_contributorDisplayName,
|
||||
'toEmail' => $this->_contributorEmail,
|
||||
'isTest' => $this->_mode == 'test',
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
153
sites/all/modules/civicrm/CRM/Member/Form/MembershipStatus.php
Normal file
153
sites/all/modules/civicrm/CRM/Member/Form/MembershipStatus.php
Normal file
|
@ -0,0 +1,153 @@
|
|||
<?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 generates form components for Membership Type
|
||||
*
|
||||
*/
|
||||
class CRM_Member_Form_MembershipStatus extends CRM_Member_Form_MembershipConfig {
|
||||
|
||||
/**
|
||||
* Set default values for the form. MobileProvider that in edit/view mode
|
||||
* the default values are retrieved from the database
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = parent::setDefaultValues();
|
||||
|
||||
//finding default weight to be put
|
||||
if (empty($defaults['weight'])) {
|
||||
$defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Member_DAO_MembershipStatus');
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
|
||||
if ($this->_action & CRM_Core_Action::DELETE) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->applyFilter('__ALL__', 'trim');
|
||||
|
||||
if ($this->_id) {
|
||||
$name = $this->add('text', 'name', ts('Name'),
|
||||
CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipStatus', 'name')
|
||||
);
|
||||
$name->freeze();
|
||||
$this->assign('id', $this->_id);
|
||||
}
|
||||
$this->add('text', 'label', ts('Label'),
|
||||
CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipStatus', 'label'), TRUE
|
||||
);
|
||||
$this->addRule('label', ts('A membership status with this label already exists. Please select another label.'),
|
||||
'objectExists', array('CRM_Member_DAO_MembershipStatus', $this->_id, 'name')
|
||||
);
|
||||
|
||||
$this->add('select', 'start_event', ts('Start Event'), CRM_Core_SelectValues::eventDate(), TRUE);
|
||||
$this->add('select', 'start_event_adjust_unit', ts('Start Event Adjustment'), array('' => ts('- select -')) + CRM_Core_SelectValues::unitList());
|
||||
$this->add('text', 'start_event_adjust_interval', ts('Start Event Adjust Interval'),
|
||||
CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipStatus', 'start_event_adjust_interval')
|
||||
);
|
||||
$this->add('select', 'end_event', ts('End Event'), array('' => ts('- select -')) + CRM_Core_SelectValues::eventDate());
|
||||
$this->add('select', 'end_event_adjust_unit', ts('End Event Adjustment'), array('' => ts('- select -')) + CRM_Core_SelectValues::unitList());
|
||||
$this->add('text', 'end_event_adjust_interval', ts('End Event Adjust Interval'),
|
||||
CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipStatus', 'end_event_adjust_interval')
|
||||
);
|
||||
$this->add('checkbox', 'is_current_member', ts('Current Membership?'));
|
||||
$this->add('checkbox', 'is_admin', ts('Administrator Only?'));
|
||||
|
||||
$this->add('text', 'weight', ts('Order'),
|
||||
CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipStatus', 'weight')
|
||||
);
|
||||
$this->add('checkbox', 'is_default', ts('Default?'));
|
||||
$this->add('checkbox', 'is_active', ts('Enabled?'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
if ($this->_action & CRM_Core_Action::DELETE) {
|
||||
try {
|
||||
CRM_Member_BAO_MembershipStatus::del($this->_id);
|
||||
}
|
||||
catch (CRM_Core_Exception $e) {
|
||||
CRM_Core_Error::statusBounce($e->getMessage(), NULL, ts('Delete Failed'));
|
||||
}
|
||||
CRM_Core_Session::setStatus(ts('Selected membership status has been deleted.'), ts('Record Deleted'), 'success');
|
||||
}
|
||||
else {
|
||||
$params = $ids = array();
|
||||
// store the submitted values in an array
|
||||
$params = $this->exportValues();
|
||||
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
|
||||
$params['is_current_member'] = CRM_Utils_Array::value('is_current_member', $params, FALSE);
|
||||
$params['is_admin'] = CRM_Utils_Array::value('is_admin', $params, FALSE);
|
||||
$params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE);
|
||||
|
||||
if ($this->_action & CRM_Core_Action::UPDATE) {
|
||||
$ids['membershipStatus'] = $this->_id;
|
||||
}
|
||||
$oldWeight = NULL;
|
||||
if ($this->_id) {
|
||||
$oldWeight = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus', $this->_id, 'weight', 'id');
|
||||
}
|
||||
$params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Member_DAO_MembershipStatus', $oldWeight, $params['weight']);
|
||||
|
||||
// only for add mode, set label to name.
|
||||
if ($this->_action & CRM_Core_Action::ADD) {
|
||||
$params['name'] = $params['label'];
|
||||
}
|
||||
|
||||
$membershipStatus = CRM_Member_BAO_MembershipStatus::add($params, $ids);
|
||||
CRM_Core_Session::setStatus(ts('The membership status \'%1\' has been saved.',
|
||||
array(1 => $membershipStatus->label)
|
||||
), ts('Saved'), 'success');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
443
sites/all/modules/civicrm/CRM/Member/Form/MembershipType.php
Normal file
443
sites/all/modules/civicrm/CRM/Member/Form/MembershipType.php
Normal file
|
@ -0,0 +1,443 @@
|
|||
<?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 generates form components for Membership Type
|
||||
*
|
||||
*/
|
||||
class CRM_Member_Form_MembershipType extends CRM_Member_Form_MembershipConfig {
|
||||
|
||||
/**
|
||||
* Max number of contacts we will display for membership-organisation
|
||||
*/
|
||||
const MAX_CONTACTS = 50;
|
||||
|
||||
public function preProcess() {
|
||||
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0);
|
||||
$this->_BAOName = 'CRM_Member_BAO_MembershipType';
|
||||
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add');
|
||||
$this->assign('action', $this->_action);
|
||||
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$url = CRM_Utils_System::url('civicrm/admin/member/membershipType', 'reset=1');
|
||||
$session->pushUserContext($url);
|
||||
|
||||
$this->setPageTitle(ts('Membership Type'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form. MobileProvider that in edit/view mode
|
||||
* the default values are retrieved from the database
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = parent::setDefaultValues();
|
||||
|
||||
//finding default weight to be put
|
||||
if (!isset($defaults['weight']) || (!$defaults['weight'])) {
|
||||
$defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Member_DAO_MembershipType');
|
||||
}
|
||||
//setting default relationshipType
|
||||
if (isset($defaults['relationship_type_id'])) {
|
||||
//$defaults['relationship_type_id'] = $defaults['relationship_type_id'].'_a_b';
|
||||
// Set values for relation type select box
|
||||
$relTypeIds = explode(CRM_Core_DAO::VALUE_SEPARATOR, $defaults['relationship_type_id']);
|
||||
$relDirections = explode(CRM_Core_DAO::VALUE_SEPARATOR, $defaults['relationship_direction']);
|
||||
$defaults['relationship_type_id'] = array();
|
||||
foreach ($relTypeIds as $key => $value) {
|
||||
$defaults['relationship_type_id'][] = $value . '_' . $relDirections[$key];
|
||||
}
|
||||
}
|
||||
|
||||
//setting default fixed_period_start_day & fixed_period_rollover_day
|
||||
$periods = array('fixed_period_start_day', 'fixed_period_rollover_day');
|
||||
foreach ($periods as $per) {
|
||||
if (isset($defaults[$per])) {
|
||||
$date = $defaults[$per];
|
||||
|
||||
$defaults[$per] = array();
|
||||
if ($date > 31) {
|
||||
$date = ($date < 999) ? '0' . $date : $date;
|
||||
$defaults[$per]['M'] = substr($date, 0, 2);
|
||||
$defaults[$per]['d'] = substr($date, 2, 3);
|
||||
}
|
||||
else {
|
||||
//special case when only day is rollover and duration is month
|
||||
$defaults['month_fixed_period_rollover_day']['d'] = $date;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
|
||||
if ($this->_action & CRM_Core_Action::DELETE) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->applyFilter('__ALL__', 'trim');
|
||||
$this->add('text', 'name', ts('Name'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'name'), TRUE);
|
||||
|
||||
$this->addRule('name', ts('A membership type with this name already exists. Please select another name.'),
|
||||
'objectExists', array('CRM_Member_DAO_MembershipType', $this->_id)
|
||||
);
|
||||
$this->add('text', 'description', ts('Description'),
|
||||
CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'description')
|
||||
);
|
||||
$this->add('text', 'minimum_fee', ts('Minimum Fee'),
|
||||
CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'minimum_fee')
|
||||
);
|
||||
$this->addRule('minimum_fee', ts('Please enter a monetary value for the Minimum Fee.'), 'money');
|
||||
|
||||
$this->addSelect('duration_unit', array(), TRUE);
|
||||
|
||||
//period type
|
||||
$this->addSelect('period_type', array(), TRUE);
|
||||
|
||||
$this->add('text', 'duration_interval', ts('Duration Interval'),
|
||||
CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'duration_interval')
|
||||
);
|
||||
|
||||
$props = array('api' => array('params' => array('contact_type' => 'Organization')));
|
||||
$this->addEntityRef('member_of_contact_id', ts('Membership Organization'), $props, TRUE);
|
||||
|
||||
//start day
|
||||
$this->add('date', 'fixed_period_start_day', ts('Fixed Period Start Day'),
|
||||
CRM_Core_SelectValues::date(NULL, 'M d'), FALSE
|
||||
);
|
||||
|
||||
//Auto-renew Option
|
||||
$paymentProcessor = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, 'is_recur = 1');
|
||||
$isAuthorize = FALSE;
|
||||
$options = array();
|
||||
if (is_array($paymentProcessor) && !empty($paymentProcessor)) {
|
||||
$isAuthorize = TRUE;
|
||||
$options = CRM_Core_SelectValues::memberAutoRenew();
|
||||
}
|
||||
|
||||
$this->addRadio('auto_renew', ts('Auto-renew Option'), $options);
|
||||
$this->assign('authorize', $isAuthorize);
|
||||
|
||||
//rollover day
|
||||
$this->add('date', 'fixed_period_rollover_day', ts('Fixed Period Rollover Day'),
|
||||
CRM_Core_SelectValues::date(NULL, 'M d'), FALSE
|
||||
);
|
||||
$this->add('date', 'month_fixed_period_rollover_day', ts('Fixed Period Rollover Day'),
|
||||
CRM_Core_SelectValues::date(NULL, 'd'), FALSE
|
||||
);
|
||||
$this->add('select', 'financial_type_id', ts('Financial Type'),
|
||||
array('' => ts('- select -')) + CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, $this->_action), TRUE, array('class' => 'crm-select2')
|
||||
);
|
||||
|
||||
$relTypeInd = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, NULL, TRUE);
|
||||
if (is_array($relTypeInd)) {
|
||||
asort($relTypeInd);
|
||||
}
|
||||
$memberRel = $this->add('select', 'relationship_type_id', ts('Relationship Type'),
|
||||
$relTypeInd, FALSE, array('class' => 'crm-select2 huge', 'multiple' => 1));
|
||||
|
||||
$this->addSelect('visibility', array('placeholder' => NULL, 'option_url' => NULL));
|
||||
|
||||
$this->add('text', 'weight', ts('Order'),
|
||||
CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'weight')
|
||||
);
|
||||
$this->add('checkbox', 'is_active', ts('Enabled?'));
|
||||
|
||||
$membershipRecords = FALSE;
|
||||
if ($this->_action & CRM_Core_Action::UPDATE) {
|
||||
$result = civicrm_api3("Membership", "get", array("membership_type_id" => $this->_id, "options" => array("limit" => 1)));
|
||||
$membershipRecords = ($result["count"] > 0);
|
||||
if ($membershipRecords) {
|
||||
$memberRel->freeze();
|
||||
}
|
||||
}
|
||||
|
||||
$this->assign('membershipRecordsExists', $membershipRecords);
|
||||
|
||||
$this->add('text', 'max_related', ts('Max related'),
|
||||
CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'max_related')
|
||||
);
|
||||
|
||||
$this->addFormRule(array('CRM_Member_Form_MembershipType', 'formRule'));
|
||||
|
||||
$this->assign('membershipTypeId', $this->_id);
|
||||
|
||||
if (CRM_Contribute_BAO_Contribution::checkContributeSettings('deferred_revenue_enabled')) {
|
||||
$deferredFinancialType = CRM_Financial_BAO_FinancialAccount::getDeferredFinancialType();
|
||||
$this->assign('deferredFinancialType', array_keys($deferredFinancialType));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validation.
|
||||
*
|
||||
* @param array $params
|
||||
* (ref.) an assoc array of name/value pairs.
|
||||
*
|
||||
* @return bool|array
|
||||
* mixed true or array of errors
|
||||
*/
|
||||
public static function formRule($params) {
|
||||
$errors = array();
|
||||
|
||||
if (!$params['name']) {
|
||||
$errors['name'] = ts('Please enter a membership type name.');
|
||||
}
|
||||
|
||||
if (($params['minimum_fee'] > 0) && !$params['financial_type_id']) {
|
||||
$errors['financial_type_id'] = ts('Please enter the financial Type.');
|
||||
}
|
||||
|
||||
if (empty($params['duration_interval']) and $params['duration_unit'] != 'lifetime') {
|
||||
$errors['duration_interval'] = ts('Please enter a duration interval.');
|
||||
}
|
||||
|
||||
if (in_array(CRM_Utils_Array::value('auto_renew', $params), array(
|
||||
1,
|
||||
2,
|
||||
))) {
|
||||
if (($params['duration_interval'] > 1 && $params['duration_unit'] == 'year') ||
|
||||
($params['duration_interval'] > 12 && $params['duration_unit'] == 'month')
|
||||
) {
|
||||
$errors['duration_unit'] = ts('Automatic renewals are not supported by the currently available payment processors when the membership duration is greater than 1 year / 12 months.');
|
||||
}
|
||||
}
|
||||
|
||||
if ($params['period_type'] == 'fixed' &&
|
||||
$params['duration_unit'] == 'day'
|
||||
) {
|
||||
$errors['period_type'] = ts('Period type should be Rolling when duration unit is Day');
|
||||
}
|
||||
|
||||
if (($params['period_type'] == 'fixed') &&
|
||||
($params['duration_unit'] == 'year')
|
||||
) {
|
||||
$periods = array('fixed_period_start_day', 'fixed_period_rollover_day');
|
||||
foreach ($periods as $period) {
|
||||
$month = $params[$period]['M'];
|
||||
$date = $params[$period]['d'];
|
||||
if (!$month || !$date) {
|
||||
switch ($period) {
|
||||
case 'fixed_period_start_day':
|
||||
$errors[$period] = ts('Please enter a valid fixed period start day');
|
||||
break;
|
||||
|
||||
case 'fixed_period_rollover_day':
|
||||
$errors[$period] = ts('Please enter a valid fixed period rollover day');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($params['fixed_period_start_day'] && !empty($params['fixed_period_start_day'])) {
|
||||
$params['fixed_period_start_day']['Y'] = date('Y');
|
||||
if (!CRM_Utils_Rule::qfDate($params['fixed_period_start_day'])) {
|
||||
$errors['fixed_period_start_day'] = ts('Please enter valid Fixed Period Start Day');
|
||||
}
|
||||
}
|
||||
|
||||
if ($params['fixed_period_rollover_day'] && !empty($params['fixed_period_rollover_day'])) {
|
||||
$params['fixed_period_rollover_day']['Y'] = date('Y');
|
||||
if (!CRM_Utils_Rule::qfDate($params['fixed_period_rollover_day'])) {
|
||||
$errors['fixed_period_rollover_day'] = ts('Please enter valid Fixed Period Rollover Day');
|
||||
}
|
||||
}
|
||||
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
if ($this->_action & CRM_Core_Action::DELETE) {
|
||||
try {
|
||||
CRM_Member_BAO_MembershipType::del($this->_id);
|
||||
}
|
||||
catch (CRM_Core_Exception $e) {
|
||||
CRM_Core_Error::statusBounce($e->getMessage(), NULL, ts('Membership Type Not Deleted'));
|
||||
}
|
||||
CRM_Core_Session::setStatus(ts('Selected membership type has been deleted.'), ts('Record Deleted'), 'success');
|
||||
}
|
||||
else {
|
||||
$buttonName = $this->controller->getButtonName();
|
||||
$submitted = $this->controller->exportValues($this->_name);
|
||||
|
||||
$fields = array(
|
||||
'name',
|
||||
'weight',
|
||||
'is_active',
|
||||
'member_of_contact_id',
|
||||
'visibility',
|
||||
'period_type',
|
||||
'minimum_fee',
|
||||
'description',
|
||||
'auto_renew',
|
||||
'duration_unit',
|
||||
'duration_interval',
|
||||
'financial_type_id',
|
||||
'fixed_period_start_day',
|
||||
'fixed_period_rollover_day',
|
||||
'month_fixed_period_rollover_day',
|
||||
'max_related',
|
||||
);
|
||||
|
||||
$params = $ids = array();
|
||||
foreach ($fields as $fld) {
|
||||
$params[$fld] = CRM_Utils_Array::value($fld, $submitted, 'NULL');
|
||||
}
|
||||
|
||||
//clean money.
|
||||
if ($params['minimum_fee']) {
|
||||
$params['minimum_fee'] = CRM_Utils_Rule::cleanMoney($params['minimum_fee']);
|
||||
}
|
||||
|
||||
$hasRelTypeVal = FALSE;
|
||||
if (!CRM_Utils_System::isNull($submitted['relationship_type_id'])) {
|
||||
// To insert relation ids and directions with value separator
|
||||
$relTypeDirs = $submitted['relationship_type_id'];
|
||||
$relIds = $relDirection = array();
|
||||
foreach ($relTypeDirs as $key => $value) {
|
||||
$relationId = explode('_', $value);
|
||||
if (count($relationId) == 3 &&
|
||||
is_numeric($relationId[0])
|
||||
) {
|
||||
$relIds[] = $relationId[0];
|
||||
$relDirection[] = $relationId[1] . '_' . $relationId[2];
|
||||
}
|
||||
}
|
||||
if (!empty($relIds)) {
|
||||
$hasRelTypeVal = TRUE;
|
||||
$params['relationship_type_id'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $relIds);
|
||||
$params['relationship_direction'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $relDirection);
|
||||
}
|
||||
}
|
||||
if (!$hasRelTypeVal) {
|
||||
$params['relationship_type_id'] = $params['relationship_direction'] = $params['max_related'] = 'NULL';
|
||||
}
|
||||
|
||||
if ($params['duration_unit'] == 'lifetime' &&
|
||||
empty($params['duration_interval'])
|
||||
) {
|
||||
$params['duration_interval'] = 1;
|
||||
}
|
||||
|
||||
$periods = array('fixed_period_start_day', 'fixed_period_rollover_day');
|
||||
foreach ($periods as $per) {
|
||||
if (!empty($params[$per]['M']) && !empty($params[$per]['d'])) {
|
||||
$mon = $params[$per]['M'];
|
||||
$dat = $params[$per]['d'];
|
||||
$mon = ($mon < 10) ? '0' . $mon : $mon;
|
||||
$dat = ($dat < 10) ? '0' . $dat : $dat;
|
||||
$params[$per] = $mon . $dat;
|
||||
}
|
||||
elseif ($per == 'fixed_period_rollover_day' && !empty($params['month_fixed_period_rollover_day'])) {
|
||||
$params['fixed_period_rollover_day'] = $params['month_fixed_period_rollover_day']['d'];
|
||||
unset($params['month_fixed_period_rollover_day']);
|
||||
}
|
||||
else {
|
||||
$params[$per] = 'NULL';
|
||||
}
|
||||
}
|
||||
$oldWeight = NULL;
|
||||
|
||||
if ($this->_id) {
|
||||
$oldWeight = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType',
|
||||
$this->_id, 'weight', 'id'
|
||||
);
|
||||
}
|
||||
$params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Member_DAO_MembershipType',
|
||||
$oldWeight, $params['weight']
|
||||
);
|
||||
|
||||
if ($this->_action & CRM_Core_Action::UPDATE) {
|
||||
$ids['membershipType'] = $this->_id;
|
||||
}
|
||||
|
||||
$membershipType = CRM_Member_BAO_MembershipType::add($params, $ids);
|
||||
|
||||
CRM_Core_Session::setStatus(ts('The membership type \'%1\' has been saved.',
|
||||
array(1 => $membershipType->name)
|
||||
), ts('Saved'), 'success');
|
||||
$session = CRM_Core_Session::singleton();
|
||||
if ($buttonName == $this->getButtonName('upload', 'new')) {
|
||||
$session->replaceUserContext(
|
||||
CRM_Utils_System::url('civicrm/admin/member/membershipType/add', 'action=add&reset=1')
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $previousID
|
||||
* @param int $priceSetId
|
||||
* @param int $membershipTypeId
|
||||
* @param $optionsIds
|
||||
*/
|
||||
public static function checkPreviousPriceField($previousID, $priceSetId, $membershipTypeId, &$optionsIds) {
|
||||
if ($previousID) {
|
||||
$editedFieldParams = array(
|
||||
'price_set_id ' => $priceSetId,
|
||||
'name' => $previousID,
|
||||
);
|
||||
$editedResults = array();
|
||||
CRM_Price_BAO_PriceField::retrieve($editedFieldParams, $editedResults);
|
||||
if (!empty($editedResults)) {
|
||||
$editedFieldParams = array(
|
||||
'price_field_id' => $editedResults['id'],
|
||||
'membership_type_id' => $membershipTypeId,
|
||||
);
|
||||
$editedResults = array();
|
||||
CRM_Price_BAO_PriceFieldValue::retrieve($editedFieldParams, $editedResults);
|
||||
$optionsIds['option_id'][1] = CRM_Utils_Array::value('id', $editedResults);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
420
sites/all/modules/civicrm/CRM/Member/Form/MembershipView.php
Normal file
420
sites/all/modules/civicrm/CRM/Member/Form/MembershipView.php
Normal file
|
@ -0,0 +1,420 @@
|
|||
<?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 generates form components for Payment-Instrument
|
||||
*
|
||||
*/
|
||||
class CRM_Member_Form_MembershipView extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* The action links that we need to display for the browse screen.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $_links = NULL;
|
||||
|
||||
/**
|
||||
* Add context information at the end of a link.
|
||||
*
|
||||
* @return string
|
||||
* extra query parameters
|
||||
*/
|
||||
public function addContext() {
|
||||
$extra = '';
|
||||
foreach (array('context', 'selectedChild') as $arg) {
|
||||
if ($value = CRM_Utils_Request::retrieve($arg, 'String', $this)) {
|
||||
$extra .= "&{$arg}={$value}";
|
||||
}
|
||||
}
|
||||
return $extra;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get action Links.
|
||||
*
|
||||
* @return array
|
||||
* (reference) of action links
|
||||
*/
|
||||
public function &links() {
|
||||
if (!(self::$_links)) {
|
||||
self::$_links = array(
|
||||
CRM_Core_Action::DELETE => array(
|
||||
'name' => ts('Delete'),
|
||||
'url' => 'civicrm/contact/view/membership',
|
||||
'qs' => 'action=view&id=%%id%%&cid=%%cid%%&relAction=delete&mid=%%mid%%&reset=1' . $this->addContext(),
|
||||
'title' => ts('Cancel Related Membership'),
|
||||
),
|
||||
CRM_Core_Action::ADD => array(
|
||||
'name' => ts('Create'),
|
||||
'url' => 'civicrm/contact/view/membership',
|
||||
'qs' => 'action=view&id=%%id%%&cid=%%cid%%&relAction=create&rid=%%rid%%&reset=1' . $this->addContext(),
|
||||
'title' => ts('Create Related Membership'),
|
||||
),
|
||||
);
|
||||
}
|
||||
return self::$_links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform create or delete action on related memberships.
|
||||
*
|
||||
* @param string $action
|
||||
* Create or delete.
|
||||
* @param array $owner
|
||||
* Primary membership info (membership_id, contact_id, membership_type ...).
|
||||
*/
|
||||
public function relAction($action, $owner) {
|
||||
switch ($action) {
|
||||
case 'delete':
|
||||
$id = CRM_Utils_Request::retrieve('mid', 'Positive', $this);
|
||||
$relatedContactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
|
||||
$relatedDisplayName = CRM_Contact_BAO_Contact::displayName($relatedContactId);
|
||||
CRM_Member_BAO_Membership::del($id);
|
||||
CRM_Core_Session::setStatus(ts('Related membership for %1 has been deleted.', array(1 => $relatedDisplayName)),
|
||||
ts('Membership Deleted'), 'success');
|
||||
break;
|
||||
|
||||
case 'create':
|
||||
$ids = array();
|
||||
$params = array(
|
||||
'contact_id' => CRM_Utils_Request::retrieve('rid', 'Positive', $this),
|
||||
'membership_type_id' => $owner['membership_type_id'],
|
||||
'owner_membership_id' => $owner['id'],
|
||||
'join_date' => CRM_Utils_Date::processDate($owner['join_date'], NULL, TRUE, 'Ymd'),
|
||||
'start_date' => CRM_Utils_Date::processDate($owner['start_date'], NULL, TRUE, 'Ymd'),
|
||||
'end_date' => CRM_Utils_Date::processDate($owner['end_date'], NULL, TRUE, 'Ymd'),
|
||||
'source' => ts('Manual Assignment of Related Membership'),
|
||||
'is_test' => $owner['is_test'],
|
||||
'campaign_id' => CRM_Utils_Array::value('campaign_id', $owner),
|
||||
'status_id' => $owner['status_id'],
|
||||
'skipStatusCal' => TRUE,
|
||||
'createActivity' => TRUE,
|
||||
);
|
||||
CRM_Member_BAO_Membership::create($params, $ids);
|
||||
$relatedDisplayName = CRM_Contact_BAO_Contact::displayName($params['contact_id']);
|
||||
CRM_Core_Session::setStatus(ts('Related membership for %1 has been created.', array(1 => $relatedDisplayName)),
|
||||
ts('Membership Added'), 'success');
|
||||
break;
|
||||
|
||||
default:
|
||||
CRM_Core_Error::fatal(ts("Invalid action specified in URL"));
|
||||
}
|
||||
|
||||
// Redirect back to membership view page for the owner, without the relAction parameters
|
||||
CRM_Utils_System::redirect(
|
||||
CRM_Utils_System::url(
|
||||
'civicrm/contact/view/membership',
|
||||
"action=view&reset=1&id={$owner['membership_id']}&cid={$owner['contact_id']}" . $this->addContext()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set variables up before form is built.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
|
||||
$values = array();
|
||||
$id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
|
||||
|
||||
// Make sure context is assigned to template for condition where we come here view civicrm/membership/view
|
||||
$context = CRM_Utils_Request::retrieve('context', 'String', $this);
|
||||
$this->assign('context', $context);
|
||||
|
||||
if ($id) {
|
||||
$params = array('id' => $id);
|
||||
CRM_Member_BAO_Membership::retrieve($params, $values);
|
||||
if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) {
|
||||
$finTypeId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $values['membership_type_id'], 'financial_type_id');
|
||||
$finType = CRM_Contribute_PseudoConstant::financialType($finTypeId);
|
||||
if (!CRM_Core_Permission::check('view contributions of type ' . $finType)) {
|
||||
CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
|
||||
}
|
||||
}
|
||||
else {
|
||||
$this->assign('noACL', TRUE);
|
||||
}
|
||||
$membershipType = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($values['membership_type_id']);
|
||||
|
||||
// Do the action on related Membership if needed
|
||||
$relAction = CRM_Utils_Request::retrieve('relAction', 'String', $this);
|
||||
if ($relAction) {
|
||||
$this->relAction($relAction, $values);
|
||||
}
|
||||
|
||||
// build associated contributions
|
||||
$this->assign('accessContribution', FALSE);
|
||||
if (CRM_Core_Permission::access('CiviContribute')) {
|
||||
$this->assign('accessContribution', TRUE);
|
||||
CRM_Member_Page_Tab::associatedContribution($values['contact_id'], $id);
|
||||
}
|
||||
|
||||
//Provide information about membership source when it is the result of a relationship (CRM-1901)
|
||||
$values['owner_membership_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership',
|
||||
$id,
|
||||
'owner_membership_id'
|
||||
);
|
||||
|
||||
if (isset($values['owner_membership_id'])) {
|
||||
$values['owner_contact_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership',
|
||||
$values['owner_membership_id'],
|
||||
'contact_id',
|
||||
'id'
|
||||
);
|
||||
|
||||
$values['owner_display_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
|
||||
$values['owner_contact_id'],
|
||||
'display_name',
|
||||
'id'
|
||||
);
|
||||
|
||||
$direction = strrev($membershipType['relationship_direction']);
|
||||
// To display relationship type in view membership page
|
||||
$relTypeIds = str_replace(CRM_Core_DAO::VALUE_SEPARATOR, ",", $membershipType['relationship_type_id']);
|
||||
$sql = "
|
||||
SELECT relationship_type_id,
|
||||
CASE
|
||||
WHEN contact_id_a = {$values['owner_contact_id']} AND contact_id_b = {$values['contact_id']} THEN 'b_a'
|
||||
WHEN contact_id_b = {$values['owner_contact_id']} AND contact_id_a = {$values['contact_id']} THEN 'a_b'
|
||||
END AS 'relType'
|
||||
FROM civicrm_relationship
|
||||
WHERE relationship_type_id IN ($relTypeIds)";
|
||||
$dao = CRM_Core_DAO::executeQuery($sql);
|
||||
$values['relationship'] = NULL;
|
||||
while ($dao->fetch()) {
|
||||
$typeId = $dao->relationship_type_id;
|
||||
$direction = $dao->relType;
|
||||
if ($direction && $typeId) {
|
||||
if ($values['relationship']) {
|
||||
$values['relationship'] .= ',';
|
||||
}
|
||||
$values['relationship'] .= CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType',
|
||||
$typeId,
|
||||
"name_$direction",
|
||||
'id'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->assign('has_related', FALSE);
|
||||
// if membership can be granted, and we are the owner of the membership
|
||||
if (!empty($membershipType['relationship_type_id']) && empty($values['owner_membership_id'])) {
|
||||
// display related contacts/membership block
|
||||
$this->assign('has_related', TRUE);
|
||||
$this->assign('max_related', CRM_Utils_Array::value('max_related', $values, ts('Unlimited')));
|
||||
// split the relations in 2 arrays based on direction
|
||||
$relTypeId = explode(CRM_Core_DAO::VALUE_SEPARATOR, $membershipType['relationship_type_id']);
|
||||
$relDirection = explode(CRM_Core_DAO::VALUE_SEPARATOR, $membershipType['relationship_direction']);
|
||||
foreach ($relTypeId as $rid) {
|
||||
$dir = each($relDirection);
|
||||
$relTypeDir[substr($dir['value'], 0, 1)][] = $rid;
|
||||
}
|
||||
// build query in 2 parts with a UNION if necessary
|
||||
// _x and _y are replaced with _a and _b first, then vice-versa
|
||||
// comment is a qualifier for the relationship - now just job_title
|
||||
$select = "
|
||||
SELECT r.id, c.id as cid, c.display_name as name, c.job_title as comment,
|
||||
rt.name_x_y as relation, r.start_date, r.end_date,
|
||||
m.id as mid, ms.is_current_member, ms.label as status
|
||||
FROM civicrm_relationship r
|
||||
LEFT JOIN civicrm_relationship_type rt ON rt.id = r.relationship_type_id
|
||||
LEFT JOIN civicrm_contact c ON c.id = r.contact_id_x
|
||||
LEFT JOIN civicrm_membership m ON (m.owner_membership_id = {$values['id']}
|
||||
AND m.contact_id = r.contact_id_x AND m.is_test = 0)
|
||||
LEFT JOIN civicrm_membership_status ms ON ms.id = m.status_id
|
||||
WHERE r.contact_id_y = {$values['contact_id']} AND r.is_active = 1 AND c.is_deleted = 0";
|
||||
$query = '';
|
||||
foreach (array('a', 'b') as $dir) {
|
||||
if (isset($relTypeDir[$dir])) {
|
||||
$query .= ($query ? ' UNION ' : '')
|
||||
. str_replace('_y', '_' . $dir, str_replace('_x', '_' . ($dir == 'a' ? 'b' : 'a'), $select))
|
||||
. ' AND r.relationship_type_id IN (' . implode(',', $relTypeDir[$dir]) . ')';
|
||||
}
|
||||
}
|
||||
$query .= " ORDER BY is_current_member DESC";
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
$related = array();
|
||||
$relatedRemaining = CRM_Utils_Array::value('max_related', $values, PHP_INT_MAX);
|
||||
$rowElememts = array(
|
||||
'id',
|
||||
'cid',
|
||||
'name',
|
||||
'comment',
|
||||
'relation',
|
||||
'mid',
|
||||
'start_date',
|
||||
'end_date',
|
||||
'is_current_member',
|
||||
'status',
|
||||
);
|
||||
|
||||
while ($dao->fetch()) {
|
||||
$row = array();
|
||||
foreach ($rowElememts as $field) {
|
||||
$row[$field] = $dao->$field;
|
||||
}
|
||||
if ($row['mid'] && ($row['is_current_member'] == 1)) {
|
||||
$relatedRemaining--;
|
||||
$row['action'] = CRM_Core_Action::formLink(self::links(), CRM_Core_Action::DELETE,
|
||||
array(
|
||||
'id' => CRM_Utils_Request::retrieve('id', 'Positive', $this),
|
||||
'cid' => $row['cid'],
|
||||
'mid' => $row['mid'],
|
||||
),
|
||||
ts('more'),
|
||||
FALSE,
|
||||
'membership.relationship.action',
|
||||
'Relationship',
|
||||
CRM_Utils_Request::retrieve('id', 'Positive', $this)
|
||||
);
|
||||
}
|
||||
else {
|
||||
if ($relatedRemaining > 0) {
|
||||
$row['action'] = CRM_Core_Action::formLink(self::links(), CRM_Core_Action::ADD,
|
||||
array(
|
||||
'id' => CRM_Utils_Request::retrieve('id', 'Positive', $this),
|
||||
'cid' => $row['cid'],
|
||||
'rid' => $row['cid'],
|
||||
),
|
||||
ts('more'),
|
||||
FALSE,
|
||||
'membership.relationship.action',
|
||||
'Relationship',
|
||||
CRM_Utils_Request::retrieve('id', 'Positive', $this)
|
||||
);
|
||||
}
|
||||
}
|
||||
$related[] = $row;
|
||||
}
|
||||
$this->assign('related', $related);
|
||||
if ($relatedRemaining <= 0) {
|
||||
$this->assign('related_text', ts('None available'));
|
||||
}
|
||||
else {
|
||||
if ($relatedRemaining < 100000) {
|
||||
$this->assign('related_text', ts('%1 available', array(1 => $relatedRemaining)));
|
||||
}
|
||||
else {
|
||||
$this->assign('related_text', ts('Unlimited', array(1 => $relatedRemaining)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$displayName = CRM_Contact_BAO_Contact::displayName($values['contact_id']);
|
||||
$this->assign('displayName', $displayName);
|
||||
|
||||
// Check if this is default domain contact CRM-10482
|
||||
if (CRM_Contact_BAO_Contact::checkDomainContact($values['contact_id'])) {
|
||||
$displayName .= ' (' . ts('default organization') . ')';
|
||||
}
|
||||
|
||||
// omitting contactImage from title for now since the summary overlay css doesn't work outside crm-container
|
||||
CRM_Utils_System::setTitle(ts('View Membership for') . ' ' . $displayName);
|
||||
|
||||
// add viewed membership to recent items list
|
||||
$recentTitle = $displayName . ' - ' . ts('Membership Type:') . ' ' . $values['membership_type'];
|
||||
$url = CRM_Utils_System::url('civicrm/contact/view/membership',
|
||||
"action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"
|
||||
);
|
||||
|
||||
$recentOther = array();
|
||||
if (CRM_Core_Permission::checkActionPermission('CiviMember', CRM_Core_Action::UPDATE)) {
|
||||
$recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/membership',
|
||||
"action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"
|
||||
);
|
||||
}
|
||||
if (CRM_Core_Permission::checkActionPermission('CiviMember', CRM_Core_Action::DELETE)) {
|
||||
$recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/membership',
|
||||
"action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"
|
||||
);
|
||||
}
|
||||
CRM_Utils_Recent::add($recentTitle,
|
||||
$url,
|
||||
$values['id'],
|
||||
'Membership',
|
||||
$values['contact_id'],
|
||||
NULL,
|
||||
$recentOther
|
||||
);
|
||||
|
||||
CRM_Member_Page_Tab::setContext($this, $values['contact_id']);
|
||||
|
||||
$memType = CRM_Core_DAO::getFieldValue("CRM_Member_DAO_Membership", $id, "membership_type_id");
|
||||
|
||||
$groupTree = CRM_Core_BAO_CustomGroup::getTree('Membership', NULL, $id, 0, $memType);
|
||||
CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $id);
|
||||
|
||||
$isRecur = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $id, 'contribution_recur_id');
|
||||
|
||||
$autoRenew = $isRecur ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
if (!empty($values['is_test'])) {
|
||||
$values['membership_type'] .= ' (test) ';
|
||||
}
|
||||
|
||||
$subscriptionCancelled = CRM_Member_BAO_Membership::isSubscriptionCancelled($id);
|
||||
$values['auto_renew'] = ($autoRenew && !$subscriptionCancelled) ? 'Yes' : 'No';
|
||||
|
||||
//do check for campaigns
|
||||
if ($campaignId = CRM_Utils_Array::value('campaign_id', $values)) {
|
||||
$campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId);
|
||||
$values['campaign'] = $campaigns[$campaignId];
|
||||
}
|
||||
|
||||
$this->assign($values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Done'),
|
||||
'spacing' => ' ',
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
}
|
370
sites/all/modules/civicrm/CRM/Member/Form/Search.php
Normal file
370
sites/all/modules/civicrm/CRM/Member/Form/Search.php
Normal file
|
@ -0,0 +1,370 @@
|
|||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Membership search.
|
||||
*
|
||||
* Class is a pane in advanced search and the membership search page.
|
||||
*/
|
||||
class CRM_Member_Form_Search extends CRM_Core_Form_Search {
|
||||
|
||||
/**
|
||||
* The params that are sent to the query.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_queryParams;
|
||||
|
||||
/**
|
||||
* Are we restricting ourselves to a single contact.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_single = FALSE;
|
||||
|
||||
/**
|
||||
* Are we restricting ourselves to a single contact.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_limit = NULL;
|
||||
|
||||
/**
|
||||
* Prefix for the controller.
|
||||
*/
|
||||
protected $_prefix = "member_";
|
||||
|
||||
/**
|
||||
* Declare entity reference fields as they will need to be converted to using 'IN'.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $entityReferenceFields = array('membership_type_id');
|
||||
|
||||
/**
|
||||
* Processing needed for buildForm and later.
|
||||
*/
|
||||
public function preProcess() {
|
||||
$this->set('searchFormName', 'Search');
|
||||
|
||||
$this->_searchButtonName = $this->getButtonName('refresh');
|
||||
$this->_actionButtonName = $this->getButtonName('next', 'action');
|
||||
|
||||
$this->_done = FALSE;
|
||||
|
||||
$this->defaults = array();
|
||||
|
||||
/*
|
||||
* we allow the controller to set force/reset externally, useful when we are being
|
||||
* driven by the wizard framework
|
||||
*/
|
||||
|
||||
$this->_reset = CRM_Utils_Request::retrieve('reset', 'Boolean');
|
||||
$this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $this, FALSE);
|
||||
$this->_limit = CRM_Utils_Request::retrieve('limit', 'Positive', $this);
|
||||
$this->_context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'search');
|
||||
|
||||
$this->assign("context", $this->_context);
|
||||
|
||||
// get user submitted values
|
||||
// get it from controller only if form has been submitted, else preProcess has set this
|
||||
if (!empty($_POST)) {
|
||||
$this->_formValues = $this->controller->exportValues($this->_name);
|
||||
}
|
||||
else {
|
||||
$this->_formValues = $this->get('formValues');
|
||||
}
|
||||
|
||||
if ($this->_force) {
|
||||
$this->postProcess();
|
||||
$this->set('force', 0);
|
||||
}
|
||||
|
||||
$sortID = NULL;
|
||||
if ($this->get(CRM_Utils_Sort::SORT_ID)) {
|
||||
$sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
|
||||
$this->get(CRM_Utils_Sort::SORT_DIRECTION)
|
||||
);
|
||||
}
|
||||
|
||||
$this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues, 0, FALSE, NULL, $this->entityReferenceFields);
|
||||
$selector = new CRM_Member_Selector_Search($this->_queryParams,
|
||||
$this->_action,
|
||||
NULL,
|
||||
$this->_single,
|
||||
$this->_limit,
|
||||
$this->_context
|
||||
);
|
||||
$prefix = NULL;
|
||||
if ($this->_context == 'basic') {
|
||||
$prefix = $this->_prefix;
|
||||
}
|
||||
|
||||
$this->assign("{$prefix}limit", $this->_limit);
|
||||
$this->assign("{$prefix}single", $this->_single);
|
||||
|
||||
$controller = new CRM_Core_Selector_Controller($selector,
|
||||
$this->get(CRM_Utils_Pager::PAGE_ID),
|
||||
$sortID,
|
||||
CRM_Core_Action::VIEW,
|
||||
$this,
|
||||
CRM_Core_Selector_Controller::TRANSFER,
|
||||
$prefix
|
||||
);
|
||||
|
||||
$controller->setEmbedded(TRUE);
|
||||
$controller->moveFromSessionToTemplate();
|
||||
|
||||
$this->assign('summary', $this->get('summary'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
$this->addSortNameField();
|
||||
|
||||
CRM_Member_BAO_Query::buildSearchForm($this);
|
||||
|
||||
$rows = $this->get('rows');
|
||||
if (is_array($rows)) {
|
||||
if (!$this->_single) {
|
||||
$this->addRowSelectors($rows);
|
||||
}
|
||||
|
||||
$permission = CRM_Core_Permission::getPermission();
|
||||
|
||||
$this->addTaskMenu(CRM_Member_Task::permissionedTaskTitles($permission));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the label for the sortName field if email searching is on.
|
||||
*
|
||||
* (email searching is a setting under search preferences).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getSortNameLabelWithEmail() {
|
||||
return ts('Member Name or Email');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the label for the sortName field if email searching is off.
|
||||
*
|
||||
* (email searching is a setting under search preferences).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getSortNameLabelWithOutEmail() {
|
||||
return ts('Member Name');
|
||||
}
|
||||
|
||||
/**
|
||||
* The post processing of the form gets done here.
|
||||
*
|
||||
* Key things done during post processing are
|
||||
* - check for reset or next request. if present, skip post procesing.
|
||||
* - now check if user requested running a saved search, if so, then
|
||||
* the form values associated with the saved search are used for searching.
|
||||
* - if user has done a submit with new values the regular post submissing is
|
||||
* done.
|
||||
* The processing consists of using a Selector / Controller framework for getting the
|
||||
* search results.
|
||||
*/
|
||||
public function postProcess() {
|
||||
if ($this->_done) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->_done = TRUE;
|
||||
|
||||
$this->_formValues = $this->controller->exportValues($this->_name);
|
||||
|
||||
$this->fixFormValues();
|
||||
|
||||
// We don't show test records in summaries or dashboards
|
||||
if (empty($this->_formValues['member_test']) && $this->_force) {
|
||||
$this->_formValues["member_test"] = 0;
|
||||
}
|
||||
|
||||
CRM_Core_BAO_CustomValue::fixCustomFieldValue($this->_formValues);
|
||||
|
||||
$this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues, 0, FALSE, NULL, $this->entityReferenceFields);
|
||||
|
||||
$this->set('formValues', $this->_formValues);
|
||||
$this->set('queryParams', $this->_queryParams);
|
||||
|
||||
$buttonName = $this->controller->getButtonName();
|
||||
if ($buttonName == $this->_actionButtonName) {
|
||||
// check actionName and if next, then do not repeat a search, since we are going to the next page
|
||||
|
||||
// hack, make sure we reset the task values
|
||||
$stateMachine = $this->controller->getStateMachine();
|
||||
$formName = $stateMachine->getTaskFormName();
|
||||
$this->controller->resetPage($formName);
|
||||
return;
|
||||
}
|
||||
|
||||
$sortID = NULL;
|
||||
if ($this->get(CRM_Utils_Sort::SORT_ID)) {
|
||||
$sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
|
||||
$this->get(CRM_Utils_Sort::SORT_DIRECTION)
|
||||
);
|
||||
}
|
||||
|
||||
$this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues, 0, FALSE, NULL, $this->entityReferenceFields);
|
||||
|
||||
$selector = new CRM_Member_Selector_Search($this->_queryParams,
|
||||
$this->_action,
|
||||
NULL,
|
||||
$this->_single,
|
||||
$this->_limit,
|
||||
$this->_context
|
||||
);
|
||||
$selector->setKey($this->controller->_key);
|
||||
|
||||
$prefix = NULL;
|
||||
if ($this->_context == 'basic') {
|
||||
$prefix = $this->_prefix;
|
||||
}
|
||||
|
||||
$controller = new CRM_Core_Selector_Controller($selector,
|
||||
$this->get(CRM_Utils_Pager::PAGE_ID),
|
||||
$sortID,
|
||||
CRM_Core_Action::VIEW,
|
||||
$this,
|
||||
CRM_Core_Selector_Controller::SESSION,
|
||||
$prefix
|
||||
);
|
||||
$controller->setEmbedded(TRUE);
|
||||
|
||||
$query = &$selector->getQuery();
|
||||
$controller->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values.
|
||||
*
|
||||
* @todo - can this function override be removed?
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
return $this->_defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* If this search has been forced then see if there are any get values, and if so over-ride the post values.
|
||||
*
|
||||
* Note that this means that GET over-rides POST :) & that force with no parameters can be very destructive.
|
||||
*/
|
||||
public function fixFormValues() {
|
||||
if (!$this->_force) {
|
||||
return;
|
||||
}
|
||||
|
||||
$status = CRM_Utils_Request::retrieve('status', 'String');
|
||||
if ($status) {
|
||||
$status = explode(',', $status);
|
||||
$this->_formValues['membership_status_id'] = $this->_defaults['membership_status_id'] = (array) $status;
|
||||
}
|
||||
|
||||
$membershipType = CRM_Utils_Request::retrieve('type', 'String');
|
||||
|
||||
if ($membershipType) {
|
||||
$this->_formValues['membership_type_id'] = array($membershipType);
|
||||
$this->_defaults['membership_type_id'] = array($membershipType);
|
||||
}
|
||||
|
||||
$cid = CRM_Utils_Request::retrieve('cid', 'Positive');
|
||||
|
||||
if ($cid) {
|
||||
$cid = CRM_Utils_Type::escape($cid, 'Integer');
|
||||
if ($cid > 0) {
|
||||
$this->_formValues['contact_id'] = $cid;
|
||||
list($display, $image) = CRM_Contact_BAO_Contact::getDisplayAndImage($cid);
|
||||
$this->_defaults['sort_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $cid,
|
||||
'sort_name'
|
||||
);
|
||||
// also assign individual mode to the template
|
||||
$this->_single = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
$fromDate = CRM_Utils_Request::retrieve('start', 'Date');
|
||||
if ($fromDate) {
|
||||
list($date) = CRM_Utils_Date::setDateDefaults($fromDate);
|
||||
$this->_formValues['member_start_date_low'] = $this->_defaults['member_start_date_low'] = $date;
|
||||
}
|
||||
|
||||
$toDate = CRM_Utils_Request::retrieve('end', 'Date');
|
||||
if ($toDate) {
|
||||
list($date) = CRM_Utils_Date::setDateDefaults($toDate);
|
||||
$this->_formValues['member_start_date_high'] = $this->_defaults['member_start_date_high'] = $date;
|
||||
}
|
||||
$joinDate = CRM_Utils_Request::retrieve('join', 'Date');
|
||||
if ($joinDate) {
|
||||
list($date) = CRM_Utils_Date::setDateDefaults($joinDate);
|
||||
$this->_formValues['member_join_date_low'] = $this->_defaults['member_join_date_low'] = $date;
|
||||
}
|
||||
|
||||
$joinEndDate = CRM_Utils_Request::retrieve('joinEnd', 'Date');
|
||||
if ($joinEndDate) {
|
||||
list($date) = CRM_Utils_Date::setDateDefaults($joinEndDate);
|
||||
$this->_formValues['member_join_date_high'] = $this->_defaults['member_join_date_high'] = $date;
|
||||
}
|
||||
|
||||
$this->_limit = CRM_Utils_Request::retrieve('limit', 'Positive',
|
||||
$this
|
||||
);
|
||||
|
||||
//LCD also allow restrictions to membership owner via GET
|
||||
$owner = CRM_Utils_Request::retrieve('owner', 'String');
|
||||
if (in_array($owner, array('0', '1'))) {
|
||||
$this->_formValues['member_is_primary'] = $this->_defaults['member_is_primary'] = $owner;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a descriptive name for the page, used in wizard header.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle() {
|
||||
return ts('Find Memberships');
|
||||
}
|
||||
|
||||
}
|
190
sites/all/modules/civicrm/CRM/Member/Form/Task.php
Normal file
190
sites/all/modules/civicrm/CRM/Member/Form/Task.php
Normal file
|
@ -0,0 +1,190 @@
|
|||
<?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 for civimember task actions
|
||||
*
|
||||
*/
|
||||
class CRM_Member_Form_Task extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* The task being performed.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_task;
|
||||
|
||||
/**
|
||||
* The additional clause that we restrict the search with.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_componentClause = NULL;
|
||||
|
||||
/**
|
||||
* The array that holds all the component ids.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_componentIds;
|
||||
|
||||
/**
|
||||
* The array that holds all the contact ids.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $_contactIds;
|
||||
|
||||
/**
|
||||
* The array that holds all the member ids.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_memberIds;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*
|
||||
* @param
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
self::preProcessCommon($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
* @param bool $useTable
|
||||
*/
|
||||
public static function preProcessCommon(&$form, $useTable = FALSE) {
|
||||
$form->_memberIds = array();
|
||||
|
||||
$values = $form->controller->exportValues($form->get('searchFormName'));
|
||||
|
||||
$form->_task = $values['task'];
|
||||
$memberTasks = CRM_Member_Task::tasks();
|
||||
$form->assign('taskName', $memberTasks[$form->_task]);
|
||||
|
||||
$ids = array();
|
||||
if ($values['radio_ts'] == 'ts_sel') {
|
||||
foreach ($values as $name => $value) {
|
||||
if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) {
|
||||
$ids[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$queryParams = $form->get('queryParams');
|
||||
$sortOrder = NULL;
|
||||
if ($form->get(CRM_Utils_Sort::SORT_ORDER)) {
|
||||
$sortOrder = $form->get(CRM_Utils_Sort::SORT_ORDER);
|
||||
}
|
||||
$query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE,
|
||||
CRM_Contact_BAO_Query::MODE_MEMBER
|
||||
);
|
||||
$query->_distinctComponentClause = ' civicrm_membership.id';
|
||||
$query->_groupByComponentClause = ' GROUP BY civicrm_membership.id ';
|
||||
$result = $query->searchQuery(0, 0, $sortOrder);
|
||||
|
||||
while ($result->fetch()) {
|
||||
$ids[] = $result->membership_id;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($ids)) {
|
||||
$form->_componentClause = ' civicrm_membership.id IN ( ' . implode(',', $ids) . ' ) ';
|
||||
$form->assign('totalSelectedMembers', count($ids));
|
||||
}
|
||||
|
||||
$form->_memberIds = $form->_componentIds = $ids;
|
||||
|
||||
//set the context for redirection for any task actions
|
||||
$session = CRM_Core_Session::singleton();
|
||||
|
||||
$qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $form);
|
||||
$urlParams = 'force=1';
|
||||
if (CRM_Utils_Rule::qfKey($qfKey)) {
|
||||
$urlParams .= "&qfKey=$qfKey";
|
||||
}
|
||||
|
||||
$searchFormName = strtolower($form->get('searchFormName'));
|
||||
if ($searchFormName == 'search') {
|
||||
$session->replaceUserContext(CRM_Utils_System::url('civicrm/member/search', $urlParams));
|
||||
}
|
||||
else {
|
||||
$session->replaceUserContext(CRM_Utils_System::url("civicrm/contact/search/$searchFormName",
|
||||
$urlParams
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given the membership id, compute the contact id
|
||||
* since its used for things like send email
|
||||
*/
|
||||
public function setContactIDs() {
|
||||
$this->_contactIds = &CRM_Core_DAO::getContactIDsFromComponent($this->_memberIds,
|
||||
'civicrm_membership'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple shell that derived classes can call to add buttons to.
|
||||
* the form with a customized title for the main Submit
|
||||
*
|
||||
* @param string $title
|
||||
* Title of the main button.
|
||||
* @param string $nextType
|
||||
* @param string $backType
|
||||
* @param bool $submitOnce
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addDefaultButtons($title, $nextType = 'next', $backType = 'back', $submitOnce = FALSE) {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => $nextType,
|
||||
'name' => $title,
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => $backType,
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
}
|
277
sites/all/modules/civicrm/CRM/Member/Form/Task/Batch.php
Normal file
277
sites/all/modules/civicrm/CRM/Member/Form/Task/Batch.php
Normal file
|
@ -0,0 +1,277 @@
|
|||
<?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 provides the functionality for batch profile update for members
|
||||
*/
|
||||
class CRM_Member_Form_Task_Batch extends CRM_Member_Form_Task {
|
||||
|
||||
/**
|
||||
* The title of the group.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_title;
|
||||
|
||||
/**
|
||||
* Maximum profile fields that will be displayed.
|
||||
*/
|
||||
protected $_maxFields = 9;
|
||||
|
||||
/**
|
||||
* Variable to store redirect path.
|
||||
*/
|
||||
protected $_userContext;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
// initialize the task and row fields
|
||||
parent::preProcess();
|
||||
|
||||
//get the contact read only fields to display.
|
||||
$readOnlyFields = array_merge(array('sort_name' => ts('Name')),
|
||||
CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
|
||||
'contact_autocomplete_options',
|
||||
TRUE, NULL, FALSE, 'name', TRUE
|
||||
)
|
||||
);
|
||||
//get the read only field data.
|
||||
$returnProperties = array_fill_keys(array_keys($readOnlyFields), 1);
|
||||
$contactDetails = CRM_Contact_BAO_Contact_Utils::contactDetails($this->_memberIds,
|
||||
'CiviMember', $returnProperties
|
||||
);
|
||||
$this->assign('contactDetails', $contactDetails);
|
||||
$this->assign('readOnlyFields', $readOnlyFields);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$ufGroupId = $this->get('ufGroupId');
|
||||
|
||||
if (!$ufGroupId) {
|
||||
CRM_Core_Error::fatal('ufGroupId is missing');
|
||||
}
|
||||
$this->_title = ts('Update multiple memberships') . ' - ' . CRM_Core_BAO_UFGroup::getTitle($ufGroupId);
|
||||
CRM_Utils_System::setTitle($this->_title);
|
||||
|
||||
$this->addDefaultButtons(ts('Save'));
|
||||
$this->_fields = array();
|
||||
$this->_fields = CRM_Core_BAO_UFGroup::getFields($ufGroupId, FALSE, CRM_Core_Action::VIEW);
|
||||
|
||||
// remove file type field and then limit fields
|
||||
$suppressFields = FALSE;
|
||||
$removehtmlTypes = array('File', 'Autocomplete-Select');
|
||||
foreach ($this->_fields as $name => $field) {
|
||||
if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name) &&
|
||||
in_array($this->_fields[$name]['html_type'], $removehtmlTypes)
|
||||
) {
|
||||
$suppressFields = TRUE;
|
||||
unset($this->_fields[$name]);
|
||||
}
|
||||
|
||||
//fix to reduce size as we are using this field in grid
|
||||
if (is_array($field['attributes']) && !empty($this->_fields[$name]['attributes']['size']) && $this->_fields[$name]['attributes']['size'] > 19) {
|
||||
//shrink class to "form-text-medium"
|
||||
$this->_fields[$name]['attributes']['size'] = 19;
|
||||
}
|
||||
}
|
||||
|
||||
$this->_fields = array_slice($this->_fields, 0, $this->_maxFields);
|
||||
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'submit',
|
||||
'name' => ts('Update Members(s)'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
));
|
||||
|
||||
$this->assign('profileTitle', $this->_title);
|
||||
$this->assign('componentIds', $this->_memberIds);
|
||||
|
||||
//load all campaigns.
|
||||
if (array_key_exists('member_campaign_id', $this->_fields)) {
|
||||
$this->_componentCampaigns = array();
|
||||
CRM_Core_PseudoConstant::populate($this->_componentCampaigns,
|
||||
'CRM_Member_DAO_Membership',
|
||||
TRUE, 'campaign_id', 'id',
|
||||
' id IN (' . implode(' , ', array_values($this->_memberIds)) . ' ) '
|
||||
);
|
||||
}
|
||||
|
||||
$customFields = CRM_Core_BAO_CustomField::getFields('Membership');
|
||||
foreach ($this->_memberIds as $memberId) {
|
||||
$typeId = CRM_Core_DAO::getFieldValue("CRM_Member_DAO_Membership", $memberId, 'membership_type_id');
|
||||
foreach ($this->_fields as $name => $field) {
|
||||
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
|
||||
$customValue = CRM_Utils_Array::value($customFieldID, $customFields);
|
||||
$entityColumnValue = array();
|
||||
if (!empty($customValue['extends_entity_column_value'])) {
|
||||
$entityColumnValue = explode(CRM_Core_DAO::VALUE_SEPARATOR,
|
||||
$customValue['extends_entity_column_value']
|
||||
);
|
||||
}
|
||||
if ((CRM_Utils_Array::value($typeId, $entityColumnValue)) ||
|
||||
CRM_Utils_System::isNull($entityColumnValue[$typeId])
|
||||
) {
|
||||
CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $memberId);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// handle non custom fields
|
||||
CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $memberId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->assign('fields', $this->_fields);
|
||||
|
||||
// don't set the status message when form is submitted.
|
||||
$buttonName = $this->controller->getButtonName('submit');
|
||||
|
||||
if ($suppressFields && $buttonName != '_qf_Batch_next') {
|
||||
CRM_Core_Session::setStatus(ts("File or Autocomplete-Select type field(s) in the selected profile are not supported for Update multiple memberships."), ts('Unsupported Field Type'), 'error');
|
||||
}
|
||||
|
||||
$this->addDefaultButtons(ts('Update Memberships'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
if (empty($this->_fields)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$defaults = array();
|
||||
foreach ($this->_memberIds as $memberId) {
|
||||
CRM_Core_BAO_UFGroup::setProfileDefaults(NULL, $this->_fields, $defaults, FALSE, $memberId, 'Membership');
|
||||
}
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->exportValues();
|
||||
$dates = array(
|
||||
'join_date',
|
||||
'membership_start_date',
|
||||
'membership_end_date',
|
||||
);
|
||||
if (isset($params['field'])) {
|
||||
$customFields = array();
|
||||
foreach ($params['field'] as $key => $value) {
|
||||
$ids['membership'] = $key;
|
||||
if (!empty($value['membership_source'])) {
|
||||
$value['source'] = $value['membership_source'];
|
||||
}
|
||||
|
||||
if (!empty($value['membership_type'])) {
|
||||
$membershipTypeId = $value['membership_type_id'] = $value['membership_type'][1];
|
||||
}
|
||||
|
||||
unset($value['membership_source']);
|
||||
unset($value['membership_type']);
|
||||
|
||||
//Get the membership status
|
||||
$value['status_id'] = (CRM_Utils_Array::value('membership_status', $value)) ? $value['membership_status'] : CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $key, 'status_id');
|
||||
unset($value['membership_status']);
|
||||
foreach ($dates as $val) {
|
||||
if (isset($value[$val])) {
|
||||
$value[$val] = CRM_Utils_Date::processDate($value[$val]);
|
||||
}
|
||||
}
|
||||
if (empty($customFields)) {
|
||||
if (empty($value['membership_type_id'])) {
|
||||
$membershipTypeId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $key, 'membership_type_id');
|
||||
}
|
||||
|
||||
// membership type custom data
|
||||
$customFields = CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, $membershipTypeId);
|
||||
|
||||
$customFields = CRM_Utils_Array::crmArrayMerge($customFields,
|
||||
CRM_Core_BAO_CustomField::getFields('Membership',
|
||||
FALSE, FALSE, NULL, NULL, TRUE
|
||||
)
|
||||
);
|
||||
}
|
||||
//check for custom data
|
||||
$value['custom'] = CRM_Core_BAO_CustomField::postProcess($params['field'][$key],
|
||||
$key,
|
||||
'Membership',
|
||||
$membershipTypeId
|
||||
);
|
||||
|
||||
$membership = CRM_Member_BAO_Membership::add($value, $ids);
|
||||
|
||||
// add custom field values
|
||||
if (!empty($value['custom']) &&
|
||||
is_array($value['custom'])
|
||||
) {
|
||||
CRM_Core_BAO_CustomValueTable::store($value['custom'], 'civicrm_membership', $membership->id);
|
||||
}
|
||||
}
|
||||
|
||||
CRM_Core_Session::setStatus(ts("Your updates have been saved."), ts('Saved'), 'success');
|
||||
}
|
||||
else {
|
||||
CRM_Core_Session::setStatus(ts("No updates have been saved."), ts('Not Saved'), 'alert');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
101
sites/all/modules/civicrm/CRM/Member/Form/Task/Delete.php
Normal file
101
sites/all/modules/civicrm/CRM/Member/Form/Task/Delete.php
Normal file
|
@ -0,0 +1,101 @@
|
|||
<?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 provides the functionality to delete a group of
|
||||
* members. This class provides functionality for the actual
|
||||
* deletion.
|
||||
*/
|
||||
class CRM_Member_Form_Task_Delete extends CRM_Member_Form_Task {
|
||||
|
||||
/**
|
||||
* Are we operating in "single mode", i.e. deleting one
|
||||
* specific membership?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_single = FALSE;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
//check for delete
|
||||
if (!CRM_Core_Permission::checkActionPermission('CiviMember', CRM_Core_Action::DELETE)) {
|
||||
CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
|
||||
}
|
||||
parent::preProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->addDefaultButtons(ts('Delete Memberships'), 'done');
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
$deleted = $failed = 0;
|
||||
foreach ($this->_memberIds as $memberId) {
|
||||
if (CRM_Member_BAO_Membership::del($memberId)) {
|
||||
$deleted++;
|
||||
}
|
||||
else {
|
||||
$failed++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($deleted) {
|
||||
$msg = ts('%count membership deleted.', array('plural' => '%count memberships deleted.', 'count' => $deleted));
|
||||
CRM_Core_Session::setStatus($msg, ts('Removed'), 'success');
|
||||
}
|
||||
|
||||
if ($failed) {
|
||||
CRM_Core_Session::setStatus(ts('1 could not be deleted.', array('plural' => '%count could not be deleted.', 'count' => $failed)), ts('Error'), 'error');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
113
sites/all/modules/civicrm/CRM/Member/Form/Task/Email.php
Normal file
113
sites/all/modules/civicrm/CRM/Member/Form/Task/Email.php
Normal file
|
@ -0,0 +1,113 @@
|
|||
<?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: Email.php 45499 2013-02-08 12:31:05Z kurund $
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to email a group of
|
||||
* contacts.
|
||||
*/
|
||||
class CRM_Member_Form_Task_Email extends CRM_Member_Form_Task {
|
||||
|
||||
/**
|
||||
* Are we operating in "single mode", i.e. sending email to one
|
||||
* specific contact?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $_single = FALSE;
|
||||
|
||||
/**
|
||||
* Are we operating in "single mode", i.e. sending email to one
|
||||
* specific contact?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $_noEmails = FALSE;
|
||||
|
||||
/**
|
||||
* All the existing templates in the system.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $_templates = NULL;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
CRM_Contact_Form_Task_EmailCommon::preProcessFromAddress($this);
|
||||
parent::preProcess();
|
||||
|
||||
// we have all the membership ids, so now we get the contact ids
|
||||
parent::setContactIDs();
|
||||
|
||||
$this->assign('single', $this->_single);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
//enable form element
|
||||
$this->assign('emailTask', TRUE);
|
||||
|
||||
CRM_Contact_Form_Task_EmailCommon::buildQuickForm($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
CRM_Contact_Form_Task_EmailCommon::postProcess($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* List available tokens for this form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function listTokens() {
|
||||
$tokens = CRM_Core_SelectValues::contactTokens();
|
||||
return $tokens;
|
||||
}
|
||||
|
||||
}
|
148
sites/all/modules/civicrm/CRM/Member/Form/Task/Label.php
Normal file
148
sites/all/modules/civicrm/CRM/Member/Form/Task/Label.php
Normal file
|
@ -0,0 +1,148 @@
|
|||
<?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 helps to print the labels for contacts
|
||||
*
|
||||
*/
|
||||
class CRM_Member_Form_Task_Label extends CRM_Member_Form_Task {
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
$this->setContactIDs();
|
||||
CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'templates/CRM/Member/Form/Task/Label.js');
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
CRM_Contact_Form_Task_Label::buildLabelForm($this);
|
||||
$this->addElement('checkbox', 'per_membership', ts('Print one label per Membership (rather than per contact)'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*
|
||||
* @return array
|
||||
* array of default values
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
$format = CRM_Core_BAO_LabelFormat::getDefaultValues();
|
||||
$defaults['label_name'] = CRM_Utils_Array::value('name', $format);
|
||||
$defaults['merge_same_address'] = 0;
|
||||
$defaults['merge_same_household'] = 0;
|
||||
$defaults['do_not_mail'] = 1;
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
$formValues = $this->controller->exportValues($this->_name);
|
||||
$locationTypeID = $formValues['location_type_id'];
|
||||
$respectDoNotMail = CRM_Utils_Array::value('do_not_mail', $formValues);
|
||||
$labelName = $formValues['label_name'];
|
||||
$mergeSameAddress = CRM_Utils_Array::value('merge_same_address', $formValues);
|
||||
$mergeSameHousehold = CRM_Utils_Array::value('merge_same_household', $formValues);
|
||||
$isPerMembership = CRM_Utils_Array::value('per_membership', $formValues);
|
||||
if ($isPerMembership && ($mergeSameAddress || $mergeSameHousehold)) {
|
||||
// this shouldn't happen - perhaps is could if JS is disabled
|
||||
CRM_Core_Session::setStatus(ts('As you are printing one label per membership your merge settings are being ignored'));
|
||||
$mergeSameAddress = $mergeSameHousehold = FALSE;
|
||||
}
|
||||
// so no-one is tempted to refer to this again after relevant values are extracted
|
||||
unset($formValues);
|
||||
|
||||
list($rows, $tokenFields) = CRM_Contact_Form_Task_LabelCommon::getRows($this->_contactIds, $locationTypeID, $respectDoNotMail, $mergeSameAddress, $mergeSameHousehold);
|
||||
|
||||
$individualFormat = FALSE;
|
||||
if ($mergeSameAddress) {
|
||||
CRM_Core_BAO_Address::mergeSameAddress($rows);
|
||||
$individualFormat = TRUE;
|
||||
}
|
||||
if ($mergeSameHousehold) {
|
||||
$rows = CRM_Contact_Form_Task_LabelCommon::mergeSameHousehold($rows);
|
||||
$individualFormat = TRUE;
|
||||
}
|
||||
// format the addresses according to CIVICRM_ADDRESS_FORMAT (CRM-1327)
|
||||
foreach ((array) $rows as $id => $row) {
|
||||
if ($commMethods = CRM_Utils_Array::value('preferred_communication_method', $row)) {
|
||||
$val = array_filter(explode(CRM_Core_DAO::VALUE_SEPARATOR, $commMethods));
|
||||
$comm = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method');
|
||||
$temp = array();
|
||||
foreach ($val as $vals) {
|
||||
$temp[] = $comm[$vals];
|
||||
}
|
||||
$row['preferred_communication_method'] = implode(', ', $temp);
|
||||
}
|
||||
$row['id'] = $id;
|
||||
$formatted = CRM_Utils_Address::format($row, 'mailing_format', FALSE, TRUE, $individualFormat, $tokenFields);
|
||||
$rows[$id] = array($formatted);
|
||||
}
|
||||
if ($isPerMembership) {
|
||||
$labelRows = array();
|
||||
$memberships = civicrm_api3('membership', 'get', array(
|
||||
'id' => array('IN' => $this->_memberIds),
|
||||
'return' => 'contact_id',
|
||||
));
|
||||
foreach ($memberships['values'] as $id => $membership) {
|
||||
if (isset($rows[$membership['contact_id']])) {
|
||||
$labelRows[$id] = $rows[$membership['contact_id']];
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$labelRows = $rows;
|
||||
}
|
||||
//call function to create labels
|
||||
CRM_Contact_Form_Task_LabelCommon::createLabel($labelRows, $labelName);
|
||||
CRM_Utils_System::civiExit(1);
|
||||
}
|
||||
|
||||
}
|
113
sites/all/modules/civicrm/CRM/Member/Form/Task/PDFLetter.php
Normal file
113
sites/all/modules/civicrm/CRM/Member/Form/Task/PDFLetter.php
Normal file
|
@ -0,0 +1,113 @@
|
|||
<?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 provides the functionality to create PDF letter for a group of
|
||||
* contacts or a single contact.
|
||||
*/
|
||||
class CRM_Member_Form_Task_PDFLetter extends CRM_Member_Form_Task {
|
||||
|
||||
/**
|
||||
* All the existing templates in the system.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $_templates = NULL;
|
||||
|
||||
public $_single = NULL;
|
||||
|
||||
public $_cid = NULL;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
$this->skipOnHold = $this->skipDeceased = FALSE;
|
||||
parent::preProcess();
|
||||
$this->setContactIDs();
|
||||
CRM_Contact_Form_Task_PDFLetterCommon::preProcess($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set defaults.
|
||||
* (non-PHPdoc)
|
||||
* @see CRM_Core_Form::setDefaultValues()
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
return CRM_Contact_Form_Task_PDFLetterCommon::setDefaultValues();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
//enable form element
|
||||
$this->assign('suppressForm', FALSE);
|
||||
CRM_Contact_Form_Task_PDFLetterCommon::buildQuickForm($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
// TODO: rewrite using contribution token and one letter by contribution
|
||||
$this->setContactIDs();
|
||||
$skipOnHold = isset($this->skipOnHold) ? $this->skipOnHold : FALSE;
|
||||
$skipDeceased = isset($this->skipDeceased) ? $this->skipDeceased : TRUE;
|
||||
CRM_Member_Form_Task_PDFLetterCommon::postProcessMembers(
|
||||
$this, $this->_memberIds, $skipOnHold, $skipDeceased, $this->_contactIds
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* List available tokens for this form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function listTokens() {
|
||||
$tokens = CRM_Core_SelectValues::contactTokens();
|
||||
$tokens = array_merge(CRM_Core_SelectValues::membershipTokens(), $tokens);
|
||||
return $tokens;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This class provides the common functionality for creating PDF letter for
|
||||
* members
|
||||
*/
|
||||
class CRM_Member_Form_Task_PDFLetterCommon extends CRM_Contact_Form_Task_PDFLetterCommon {
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
* @todo this is horrible copy & paste code because there is so much risk of breakage
|
||||
* in fixing the existing pdfLetter classes to be suitably generic
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* @param $membershipIDs
|
||||
* @param $skipOnHold
|
||||
* @param $skipDeceased
|
||||
* @param $contactIDs
|
||||
*/
|
||||
public static function postProcessMembers(&$form, $membershipIDs, $skipOnHold, $skipDeceased, $contactIDs) {
|
||||
$formValues = $form->controller->exportValues($form->getName());
|
||||
list($formValues, $categories, $html_message, $messageToken, $returnProperties) = self::processMessageTemplate($formValues);
|
||||
|
||||
$html
|
||||
= self::generateHTML(
|
||||
$membershipIDs,
|
||||
$returnProperties,
|
||||
$skipOnHold,
|
||||
$skipDeceased,
|
||||
$messageToken,
|
||||
$html_message,
|
||||
$categories
|
||||
);
|
||||
// This seems silly, but the old behavior was to first check `_cid`
|
||||
// and then use the provided `$contactIds`. Probably not even necessary,
|
||||
// but difficult to audit.
|
||||
$contactIDs = $form->_cid ? array($form->_cid) : $contactIDs;
|
||||
self::createActivities($form, $html_message, $contactIDs, $formValues['subject'], CRM_Utils_Array::value('campaign_id', $formValues));
|
||||
|
||||
CRM_Utils_PDF_Utils::html2pdf($html, "CiviLetter.pdf", FALSE, $formValues);
|
||||
|
||||
$form->postProcessHook();
|
||||
|
||||
CRM_Utils_System::civiExit(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate htmlfor pdf letters.
|
||||
*
|
||||
* @param array $membershipIDs
|
||||
* @param array $returnProperties
|
||||
* @param bool $skipOnHold
|
||||
* @param bool $skipDeceased
|
||||
* @param array $messageToken
|
||||
* @param $html_message
|
||||
* @param $categories
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function generateHTML($membershipIDs, $returnProperties, $skipOnHold, $skipDeceased, $messageToken, $html_message, $categories) {
|
||||
$memberships = CRM_Utils_Token::getMembershipTokenDetails($membershipIDs);
|
||||
$html = array();
|
||||
|
||||
foreach ($membershipIDs as $membershipID) {
|
||||
$membership = $memberships[$membershipID];
|
||||
// get contact information
|
||||
$contactId = $membership['contact_id'];
|
||||
$params = array('contact_id' => $contactId);
|
||||
//getTokenDetails is much like calling the api contact.get function - but - with some minor
|
||||
// special handlings. It precedes the existence of the api
|
||||
list($contacts) = CRM_Utils_Token::getTokenDetails(
|
||||
$params,
|
||||
$returnProperties,
|
||||
$skipOnHold,
|
||||
$skipDeceased,
|
||||
NULL,
|
||||
$messageToken,
|
||||
'CRM_Contribution_Form_Task_PDFLetterCommon'
|
||||
);
|
||||
|
||||
$tokenHtml = CRM_Utils_Token::replaceContactTokens($html_message, $contacts[$contactId], TRUE, $messageToken);
|
||||
$tokenHtml = CRM_Utils_Token::replaceEntityTokens('membership', $membership, $tokenHtml, $messageToken);
|
||||
$tokenHtml = CRM_Utils_Token::replaceHookTokens($tokenHtml, $contacts[$contactId], $categories, TRUE);
|
||||
$tokenHtml = CRM_Utils_Token::parseThroughSmarty($tokenHtml, $contacts[$contactId]);
|
||||
|
||||
$html[] = $tokenHtml;
|
||||
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
}
|
148
sites/all/modules/civicrm/CRM/Member/Form/Task/PickProfile.php
Normal file
148
sites/all/modules/civicrm/CRM/Member/Form/Task/PickProfile.php
Normal file
|
@ -0,0 +1,148 @@
|
|||
<?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 provides the functionality for batch profile update for membership
|
||||
*/
|
||||
class CRM_Member_Form_Task_PickProfile extends CRM_Member_Form_Task {
|
||||
|
||||
/**
|
||||
* The title of the group
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_title;
|
||||
|
||||
/**
|
||||
* Maximum members that should be allowed to update
|
||||
*/
|
||||
protected $_maxMembers = 100;
|
||||
|
||||
/**
|
||||
* Variable to store redirect path
|
||||
*/
|
||||
protected $_userContext;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
// initialize the task and row fields
|
||||
parent::preProcess();
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$this->_userContext = $session->readUserContext();
|
||||
|
||||
CRM_Utils_System::setTitle(ts('Update multiple memberships'));
|
||||
|
||||
$validate = FALSE;
|
||||
//validations
|
||||
if (count($this->_memberIds) > $this->_maxMembers) {
|
||||
CRM_Core_Session::setStatus(ts("The maximum number of members you can select for Update multiple memberships is %1. You have selected %2. Please select fewer members from your search results and try again.", array(
|
||||
1 => $this->_maxMembers,
|
||||
2 => count($this->_memberIds),
|
||||
)), ts('Update multiple records error'), 'error');
|
||||
$validate = TRUE;
|
||||
}
|
||||
|
||||
// than redirect
|
||||
if ($validate) {
|
||||
CRM_Utils_System::redirect($this->_userContext);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$types = array('Membership');
|
||||
$profiles = CRM_Core_BAO_UFGroup::getProfiles($types, TRUE);
|
||||
|
||||
if (empty($profiles)) {
|
||||
CRM_Core_Session::setStatus(ts("You will need to create a Profile containing the %1 fields you want to edit before you can use Update multiple memberships. Navigate to Administer CiviCRM >> CiviCRM Profile to configure a Profile. Consult the online Administrator documentation for more information.", array(1 => $types[0])), ts('Update multiple records error'), 'error');
|
||||
CRM_Utils_System::redirect($this->_userContext);
|
||||
}
|
||||
|
||||
$ufGroupElement = $this->add('select', 'uf_group_id', ts('Select Profile'),
|
||||
array(
|
||||
'' => ts('- select profile -'),
|
||||
) + $profiles, TRUE
|
||||
);
|
||||
$this->addDefaultButtons(ts('Continue'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add local and global form rules.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addRules() {
|
||||
$this->addFormRule(array('CRM_Member_Form_Task_PickProfile', 'formRule'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param array $fields
|
||||
* Posted values of the form.
|
||||
*
|
||||
* @return array
|
||||
* list of errors to be posted back to the form
|
||||
*/
|
||||
public static function formRule($fields) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->exportValues();
|
||||
|
||||
$this->set('ufGroupId', $params['uf_group_id']);
|
||||
|
||||
// also reset the batch page so it gets new values from the db
|
||||
$this->controller->resetPage('Batch');
|
||||
}
|
||||
|
||||
}
|
104
sites/all/modules/civicrm/CRM/Member/Form/Task/Print.php
Normal file
104
sites/all/modules/civicrm/CRM/Member/Form/Task/Print.php
Normal file
|
@ -0,0 +1,104 @@
|
|||
<?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 provides the functionality to print members
|
||||
*/
|
||||
class CRM_Member_Form_Task_Print extends CRM_Member_Form_Task {
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preprocess();
|
||||
|
||||
// set print view, so that print templates are called
|
||||
$this->controller->setPrint(1);
|
||||
|
||||
// get the formatted params
|
||||
$queryParams = $this->get('queryParams');
|
||||
|
||||
$sortID = NULL;
|
||||
if ($this->get(CRM_Utils_Sort::SORT_ID)) {
|
||||
$sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
|
||||
$this->get(CRM_Utils_Sort::SORT_DIRECTION)
|
||||
);
|
||||
}
|
||||
|
||||
$selector = new CRM_Member_Selector_Search($queryParams, $this->_action, $this->_componentClause);
|
||||
$controller = new CRM_Core_Selector_Controller($selector, NULL, $sortID, CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::SCREEN);
|
||||
$controller->setEmbedded(TRUE);
|
||||
$controller->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object - it consists of
|
||||
* - displaying the QILL (query in local language)
|
||||
* - displaying elements for saving the search
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
//
|
||||
// just need to add a javacript to popup the window for printing
|
||||
//
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Print Members'),
|
||||
'js' => array('onclick' => 'window.print()'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'back',
|
||||
'name' => ts('Done'),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
// redirect to the main search page after printing is over
|
||||
}
|
||||
|
||||
}
|
66
sites/all/modules/civicrm/CRM/Member/Form/Task/Result.php
Normal file
66
sites/all/modules/civicrm/CRM/Member/Form/Task/Result.php
Normal file
|
@ -0,0 +1,66 @@
|
|||
<?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$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Used for displaying results
|
||||
*
|
||||
*
|
||||
*/
|
||||
class CRM_Member_Form_Task_Result extends CRM_Member_Form_Task {
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'done',
|
||||
'name' => ts('Done'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
<?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 provides the functionality to save a search
|
||||
* Saved Searches are used for saving frequently used queries
|
||||
*/
|
||||
class CRM_Member_Form_Task_SearchTaskHookSample extends CRM_Member_Form_Task {
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
$rows = array();
|
||||
// display name and membership details of all selected contacts
|
||||
$memberIDs = implode(',', $this->_memberIds);
|
||||
|
||||
$query = "
|
||||
SELECT mem.start_date as start_date,
|
||||
mem.end_date as end_date,
|
||||
mem.source as source,
|
||||
ct.display_name as display_name
|
||||
FROM civicrm_membership mem
|
||||
INNER JOIN civicrm_contact ct ON ( mem.contact_id = ct.id )
|
||||
WHERE mem.id IN ( $memberIDs )";
|
||||
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
while ($dao->fetch()) {
|
||||
$rows[] = array(
|
||||
'display_name' => $dao->display_name,
|
||||
'start_date' => CRM_Utils_Date::customFormat($dao->start_date),
|
||||
'end_date' => CRM_Utils_Date::customFormat($dao->end_date),
|
||||
'source' => $dao->source,
|
||||
);
|
||||
}
|
||||
$this->assign('rows', $rows);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'done',
|
||||
'name' => ts('Done'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
}
|
62
sites/all/modules/civicrm/CRM/Member/Import/Controller.php
Normal file
62
sites/all/modules/civicrm/CRM/Member/Import/Controller.php
Normal file
|
@ -0,0 +1,62 @@
|
|||
<?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_Import_Controller extends CRM_Core_Controller {
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param string $title
|
||||
* @param bool|int $action
|
||||
* @param bool $modal
|
||||
*/
|
||||
public function __construct($title = NULL, $action = CRM_Core_Action::NONE, $modal = TRUE) {
|
||||
parent::__construct($title, $modal);
|
||||
|
||||
// lets get around the time limit issue if possible, CRM-2113
|
||||
if (!ini_get('safe_mode')) {
|
||||
set_time_limit(0);
|
||||
}
|
||||
|
||||
$this->_stateMachine = new CRM_Import_StateMachine($this, $action);
|
||||
|
||||
// create and instantiate the pages
|
||||
$this->addPages($this->_stateMachine, $action);
|
||||
|
||||
// add all the actions
|
||||
$config = CRM_Core_Config::singleton();
|
||||
$this->addActions($config->uploadDir, array('uploadFile'));
|
||||
}
|
||||
|
||||
}
|
209
sites/all/modules/civicrm/CRM/Member/Import/Field.php
Normal file
209
sites/all/modules/civicrm/CRM/Member/Import/Field.php
Normal file
|
@ -0,0 +1,209 @@
|
|||
<?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_Import_Field {
|
||||
|
||||
/**#@+
|
||||
* @var string
|
||||
*/
|
||||
|
||||
/**
|
||||
* Name of the field
|
||||
*/
|
||||
public $_name;
|
||||
|
||||
/**
|
||||
* Title of the field to be used in display
|
||||
*/
|
||||
public $_title;
|
||||
|
||||
/**
|
||||
* Type of field
|
||||
* @var enum
|
||||
*/
|
||||
public $_type;
|
||||
|
||||
/**
|
||||
* Is this field required
|
||||
* @var boolean
|
||||
*/
|
||||
public $_required;
|
||||
|
||||
/**
|
||||
* Data to be carried for use by a derived class
|
||||
* @var object
|
||||
*/
|
||||
public $_payload;
|
||||
|
||||
/**
|
||||
* Regexp to match the CSV header of this column/field
|
||||
* @var string
|
||||
*/
|
||||
public $_headerPattern;
|
||||
|
||||
/**
|
||||
* Regexp to match the pattern of data from various column/fields
|
||||
* @var string
|
||||
*/
|
||||
public $_dataPattern;
|
||||
|
||||
/**
|
||||
* Value of this field
|
||||
* @var object
|
||||
*/
|
||||
public $_value;
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param $title
|
||||
* @param int $type
|
||||
* @param string $headerPattern
|
||||
* @param string $dataPattern
|
||||
*/
|
||||
public function __construct($name, $title, $type = CRM_Utils_Type::T_INT, $headerPattern = '//', $dataPattern = '//') {
|
||||
$this->_name = $name;
|
||||
$this->_title = $title;
|
||||
$this->_type = $type;
|
||||
$this->_headerPattern = $headerPattern;
|
||||
$this->_dataPattern = $dataPattern;
|
||||
|
||||
$this->_value = NULL;
|
||||
}
|
||||
|
||||
public function resetValue() {
|
||||
$this->_value = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* The value is in string format. convert the value to the type of this field
|
||||
* and set the field value with the appropriate type
|
||||
*
|
||||
* @param $value
|
||||
*/
|
||||
public function setValue($value) {
|
||||
$this->_value = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function validate() {
|
||||
|
||||
if (CRM_Utils_System::isNull($this->_value)) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
switch ($this->_name) {
|
||||
case 'contact_id':
|
||||
// note: we validate extistence of the contact in API, upon
|
||||
// insert (it would be too costlty to do a db call here)
|
||||
return CRM_Utils_Rule::integer($this->_value);
|
||||
|
||||
case 'receive_date':
|
||||
case 'cancel_date':
|
||||
case 'receipt_date':
|
||||
case 'thankyou_date':
|
||||
return CRM_Utils_Rule::date($this->_value);
|
||||
|
||||
case 'non_deductible_amount':
|
||||
case 'total_amount':
|
||||
case 'fee_amount':
|
||||
case 'net_amount':
|
||||
return CRM_Utils_Rule::money($this->_value);
|
||||
|
||||
case 'trxn_id':
|
||||
static $seenTrxnIds = array();
|
||||
if (in_array($this->_value, $seenTrxnIds)) {
|
||||
return FALSE;
|
||||
}
|
||||
elseif ($this->_value) {
|
||||
$seenTrxnIds[] = $this->_value;
|
||||
return TRUE;
|
||||
}
|
||||
else {
|
||||
$this->_value = NULL;
|
||||
return TRUE;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'currency':
|
||||
return CRM_Utils_Rule::currencyCode($this->_value);
|
||||
|
||||
case 'membership_type':
|
||||
static $membershipTypes = NULL;
|
||||
if (!$membershipTypes) {
|
||||
$membershipTypes = CRM_Member_PseudoConstant::membershipType();
|
||||
}
|
||||
if (in_array($this->_value, $membershipTypes)) {
|
||||
return TRUE;
|
||||
}
|
||||
else {
|
||||
return FALSE;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'payment_instrument':
|
||||
static $paymentInstruments = NULL;
|
||||
if (!$paymentInstruments) {
|
||||
$paymentInstruments = CRM_Member_PseudoConstant::paymentInstrument();
|
||||
}
|
||||
if (in_array($this->_value, $paymentInstruments)) {
|
||||
return TRUE;
|
||||
}
|
||||
else {
|
||||
return FALSE;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// check whether that's a valid custom field id
|
||||
// and if so, check the contents' validity
|
||||
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($this->_name)) {
|
||||
static $customFields = NULL;
|
||||
if (!$customFields) {
|
||||
$customFields = CRM_Core_BAO_CustomField::getFields('Membership');
|
||||
}
|
||||
if (!array_key_exists($customFieldID, $customFields)) {
|
||||
return FALSE;
|
||||
}
|
||||
return CRM_Core_BAO_CustomValue::typecheck($customFields[$customFieldID]['data_type'], $this->_value);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
<?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 gets the name of the file to upload
|
||||
*/
|
||||
class CRM_Member_Import_Form_DataSource extends CRM_Import_Form_DataSource {
|
||||
|
||||
const PATH = 'civicrm/member/import';
|
||||
|
||||
const IMPORT_ENTITY = 'Membership';
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
|
||||
$duplicateOptions = array();
|
||||
$duplicateOptions[] = $this->createElement('radio',
|
||||
NULL, NULL, ts('Insert new Membership'), CRM_Import_Parser::DUPLICATE_SKIP
|
||||
);
|
||||
$duplicateOptions[] = $this->createElement('radio',
|
||||
NULL, NULL, ts('Update existing Membership'), CRM_Import_Parser::DUPLICATE_UPDATE
|
||||
);
|
||||
|
||||
$this->addGroup($duplicateOptions, 'onDuplicate',
|
||||
ts('Import mode')
|
||||
);
|
||||
$this->setDefaults(array(
|
||||
'onDuplicate' => CRM_Import_Parser::DUPLICATE_SKIP,
|
||||
));
|
||||
|
||||
$this->addContactTypeSelector();
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the uploaded file.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
$this->storeFormValues(array(
|
||||
'onDuplicate',
|
||||
'contactType',
|
||||
'dateFormats',
|
||||
'savedMapping',
|
||||
));
|
||||
|
||||
$this->submitFileForMapping('CRM_Member_Import_Parser_Membership');
|
||||
}
|
||||
|
||||
}
|
521
sites/all/modules/civicrm/CRM/Member/Import/Form/MapField.php
Normal file
521
sites/all/modules/civicrm/CRM/Member/Import/Form/MapField.php
Normal file
|
@ -0,0 +1,521 @@
|
|||
<?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 gets the name of the file to upload
|
||||
*/
|
||||
class CRM_Member_Import_Form_MapField extends CRM_Import_Form_MapField {
|
||||
|
||||
|
||||
/**
|
||||
* store contactType.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
static $_contactType = NULL;
|
||||
|
||||
|
||||
/**
|
||||
* Set variables up before form is built.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
$this->_mapperFields = $this->get('fields');
|
||||
asort($this->_mapperFields);
|
||||
|
||||
$this->_columnCount = $this->get('columnCount');
|
||||
$this->assign('columnCount', $this->_columnCount);
|
||||
$this->_dataValues = $this->get('dataValues');
|
||||
$this->assign('dataValues', $this->_dataValues);
|
||||
|
||||
$skipColumnHeader = $this->controller->exportValue('DataSource', 'skipColumnHeader');
|
||||
$this->_onDuplicate = $this->get('onDuplicate', isset($onDuplicate) ? $onDuplicate : "");
|
||||
|
||||
$highlightedFields = array();
|
||||
if ($skipColumnHeader) {
|
||||
$this->assign('skipColumnHeader', $skipColumnHeader);
|
||||
$this->assign('rowDisplayCount', 3);
|
||||
/* if we had a column header to skip, stash it for later */
|
||||
|
||||
$this->_columnHeaders = $this->_dataValues[0];
|
||||
}
|
||||
else {
|
||||
$this->assign('rowDisplayCount', 2);
|
||||
}
|
||||
|
||||
//CRM-2219 removing other required fields since for updation only
|
||||
//membership id is required.
|
||||
if ($this->_onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE) {
|
||||
$remove = array('membership_contact_id', 'email', 'first_name', 'last_name', 'external_identifier');
|
||||
foreach ($remove as $value) {
|
||||
unset($this->_mapperFields[$value]);
|
||||
}
|
||||
$highlightedFieldsArray = array('membership_id', 'membership_start_date', 'membership_type_id');
|
||||
foreach ($highlightedFieldsArray as $name) {
|
||||
$highlightedFields[] = $name;
|
||||
}
|
||||
}
|
||||
elseif ($this->_onDuplicate == CRM_Import_Parser::DUPLICATE_SKIP) {
|
||||
unset($this->_mapperFields['membership_id']);
|
||||
$highlightedFieldsArray = array(
|
||||
'membership_contact_id',
|
||||
'email',
|
||||
'external_identifier',
|
||||
'membership_start_date',
|
||||
'membership_type_id',
|
||||
);
|
||||
foreach ($highlightedFieldsArray as $name) {
|
||||
$highlightedFields[] = $name;
|
||||
}
|
||||
}
|
||||
|
||||
// modify field title
|
||||
$this->_mapperFields['status_id'] = ts('Membership Status');
|
||||
$this->_mapperFields['membership_type_id'] = ts('Membership Type');
|
||||
|
||||
self::$_contactType = $this->get('contactType');
|
||||
$this->assign('highlightedFields', $highlightedFields);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
//to save the current mappings
|
||||
if (!$this->get('savedMapping')) {
|
||||
$saveDetailsName = ts('Save this field mapping');
|
||||
$this->applyFilter('saveMappingName', 'trim');
|
||||
$this->add('text', 'saveMappingName', ts('Name'));
|
||||
$this->add('text', 'saveMappingDesc', ts('Description'));
|
||||
}
|
||||
else {
|
||||
$savedMapping = $this->get('savedMapping');
|
||||
|
||||
list($mappingName, $mappingContactType, $mappingLocation, $mappingPhoneType, $mappingRelation) = CRM_Core_BAO_Mapping::getMappingFields($savedMapping);
|
||||
|
||||
$mappingName = $mappingName[1];
|
||||
$mappingContactType = $mappingContactType[1];
|
||||
$mappingLocation = CRM_Utils_Array::value('1', $mappingLocation);
|
||||
$mappingPhoneType = CRM_Utils_Array::value('1', $mappingPhoneType);
|
||||
$mappingRelation = CRM_Utils_Array::value('1', $mappingRelation);
|
||||
|
||||
//mapping is to be loaded from database
|
||||
|
||||
$params = array('id' => $savedMapping);
|
||||
$temp = array();
|
||||
$mappingDetails = CRM_Core_BAO_Mapping::retrieve($params, $temp);
|
||||
|
||||
$this->assign('loadedMapping', $mappingDetails->name);
|
||||
$this->set('loadedMapping', $savedMapping);
|
||||
|
||||
$getMappingName = new CRM_Core_DAO_Mapping();
|
||||
$getMappingName->id = $savedMapping;
|
||||
$getMappingName->mapping_type = 'Import Memberships';
|
||||
$getMappingName->find();
|
||||
while ($getMappingName->fetch()) {
|
||||
$mapperName = $getMappingName->name;
|
||||
}
|
||||
|
||||
$this->assign('savedName', $mapperName);
|
||||
|
||||
$this->add('hidden', 'mappingId', $savedMapping);
|
||||
|
||||
$this->addElement('checkbox', 'updateMapping', ts('Update this field mapping'), NULL);
|
||||
$saveDetailsName = ts('Save as a new field mapping');
|
||||
$this->add('text', 'saveMappingName', ts('Name'));
|
||||
$this->add('text', 'saveMappingDesc', ts('Description'));
|
||||
}
|
||||
|
||||
$this->addElement('checkbox', 'saveMapping', $saveDetailsName, NULL, array('onclick' => "showSaveDetails(this)"));
|
||||
|
||||
$this->addFormRule(array('CRM_Member_Import_Form_MapField', 'formRule'), $this);
|
||||
|
||||
//-------- end of saved mapping stuff ---------
|
||||
|
||||
$defaults = array();
|
||||
$mapperKeys = array_keys($this->_mapperFields);
|
||||
$hasHeaders = !empty($this->_columnHeaders);
|
||||
$headerPatterns = $this->get('headerPatterns');
|
||||
$dataPatterns = $this->get('dataPatterns');
|
||||
$hasLocationTypes = $this->get('fieldTypes');
|
||||
|
||||
/* Initialize all field usages to false */
|
||||
|
||||
foreach ($mapperKeys as $key) {
|
||||
$this->_fieldUsed[$key] = FALSE;
|
||||
}
|
||||
$this->_location_types = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
|
||||
$sel1 = $this->_mapperFields;
|
||||
if (!$this->get('onDuplicate')) {
|
||||
unset($sel1['id']);
|
||||
unset($sel1['membership_id']);
|
||||
}
|
||||
|
||||
$sel2[''] = NULL;
|
||||
|
||||
$js = "<script type='text/javascript'>\n";
|
||||
$formName = 'document.forms.' . $this->_name;
|
||||
|
||||
//used to warn for mismatch column count or mismatch mapping
|
||||
$warning = 0;
|
||||
|
||||
for ($i = 0; $i < $this->_columnCount; $i++) {
|
||||
$sel = &$this->addElement('hierselect', "mapper[$i]", ts('Mapper for Field %1', array(1 => $i)), NULL);
|
||||
$jsSet = FALSE;
|
||||
if ($this->get('savedMapping')) {
|
||||
if (isset($mappingName[$i])) {
|
||||
if ($mappingName[$i] != ts('- do not import -')) {
|
||||
|
||||
$mappingHeader = array_keys($this->_mapperFields, $mappingName[$i]);
|
||||
|
||||
//When locationType is not set
|
||||
$js .= "{$formName}['mapper[$i][1]'].style.display = 'none';\n";
|
||||
|
||||
//When phoneType is not set
|
||||
$js .= "{$formName}['mapper[$i][2]'].style.display = 'none';\n";
|
||||
|
||||
$js .= "{$formName}['mapper[$i][3]'].style.display = 'none';\n";
|
||||
|
||||
$defaults["mapper[$i]"] = array($mappingHeader[0]);
|
||||
$jsSet = TRUE;
|
||||
}
|
||||
else {
|
||||
$defaults["mapper[$i]"] = array();
|
||||
}
|
||||
if (!$jsSet) {
|
||||
for ($k = 1; $k < 4; $k++) {
|
||||
$js .= "{$formName}['mapper[$i][$k]'].style.display = 'none';\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// this load section to help mapping if we ran out of saved columns when doing Load Mapping
|
||||
$js .= "swapOptions($formName, 'mapper[$i]', 0, 3, 'hs_mapper_" . $i . "_');\n";
|
||||
|
||||
if ($hasHeaders) {
|
||||
$defaults["mapper[$i]"] = array($this->defaultFromHeader($this->_columnHeaders[$i], $headerPatterns));
|
||||
}
|
||||
else {
|
||||
$defaults["mapper[$i]"] = array($this->defaultFromData($dataPatterns, $i));
|
||||
}
|
||||
}
|
||||
//end of load mapping
|
||||
}
|
||||
else {
|
||||
$js .= "swapOptions($formName, 'mapper[$i]', 0, 3, 'hs_mapper_" . $i . "_');\n";
|
||||
if ($hasHeaders) {
|
||||
// Infer the default from the skipped headers if we have them
|
||||
$defaults["mapper[$i]"] = array(
|
||||
$this->defaultFromHeader($this->_columnHeaders[$i],
|
||||
$headerPatterns
|
||||
),
|
||||
// $defaultLocationType->id
|
||||
0,
|
||||
);
|
||||
}
|
||||
else {
|
||||
// Otherwise guess the default from the form of the data
|
||||
$defaults["mapper[$i]"] = array(
|
||||
$this->defaultFromData($dataPatterns, $i),
|
||||
// $defaultLocationType->id
|
||||
0,
|
||||
);
|
||||
}
|
||||
}
|
||||
$sel->setOptions(array($sel1, $sel2, (isset($sel3)) ? $sel3 : "", (isset($sel4)) ? $sel4 : ""));
|
||||
}
|
||||
$js .= "</script>\n";
|
||||
$this->assign('initHideBoxes', $js);
|
||||
|
||||
//set warning if mismatch in more than
|
||||
if (isset($mappingName)) {
|
||||
if (($this->_columnCount != count($mappingName))) {
|
||||
$warning++;
|
||||
}
|
||||
}
|
||||
if ($warning != 0 && $this->get('savedMapping')) {
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$session->setStatus(ts('The data columns in this import file appear to be different from the saved mapping. Please verify that you have selected the correct saved mapping before continuing.'));
|
||||
}
|
||||
else {
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$session->setStatus(NULL);
|
||||
}
|
||||
|
||||
$this->setDefaults($defaults);
|
||||
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'back',
|
||||
'name' => ts('Previous'),
|
||||
),
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Continue'),
|
||||
'spacing' => ' ',
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param array $fields
|
||||
* Posted values of the form.
|
||||
*
|
||||
* @param $files
|
||||
* @param $self
|
||||
*
|
||||
* @return array
|
||||
* list of errors to be posted back to the form
|
||||
*/
|
||||
public static function formRule($fields, $files, $self) {
|
||||
$errors = array();
|
||||
|
||||
if (!array_key_exists('savedMapping', $fields)) {
|
||||
$importKeys = array();
|
||||
foreach ($fields['mapper'] as $mapperPart) {
|
||||
$importKeys[] = $mapperPart[0];
|
||||
}
|
||||
// FIXME: should use the schema titles, not redeclare them
|
||||
$requiredFields = array(
|
||||
'membership_contact_id' => ts('Contact ID'),
|
||||
'membership_type_id' => ts('Membership Type'),
|
||||
'membership_start_date' => ts('Membership Start Date'),
|
||||
);
|
||||
|
||||
$contactTypeId = $self->get('contactType');
|
||||
$contactTypes = array(
|
||||
CRM_Import_Parser::CONTACT_INDIVIDUAL => 'Individual',
|
||||
CRM_Import_Parser::CONTACT_HOUSEHOLD => 'Household',
|
||||
CRM_Import_Parser::CONTACT_ORGANIZATION => 'Organization',
|
||||
);
|
||||
$params = array(
|
||||
'used' => 'Unsupervised',
|
||||
'contact_type' => $contactTypes[$contactTypeId],
|
||||
);
|
||||
list($ruleFields, $threshold) = CRM_Dedupe_BAO_RuleGroup::dedupeRuleFieldsWeight($params);
|
||||
$weightSum = 0;
|
||||
foreach ($importKeys as $key => $val) {
|
||||
if (array_key_exists($val, $ruleFields)) {
|
||||
$weightSum += $ruleFields[$val];
|
||||
}
|
||||
}
|
||||
$fieldMessage = '';
|
||||
foreach ($ruleFields as $field => $weight) {
|
||||
$fieldMessage .= ' ' . $field . '(weight ' . $weight . ')';
|
||||
}
|
||||
|
||||
foreach ($requiredFields as $field => $title) {
|
||||
if (!in_array($field, $importKeys)) {
|
||||
if ($field == 'membership_contact_id') {
|
||||
if ((($weightSum >= $threshold || in_array('external_identifier', $importKeys)) &&
|
||||
$self->_onDuplicate != CRM_Import_Parser::DUPLICATE_UPDATE
|
||||
) ||
|
||||
in_array('membership_id', $importKeys)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
if (!isset($errors['_qf_default'])) {
|
||||
$errors['_qf_default'] = '';
|
||||
}
|
||||
$errors['_qf_default'] .= ts('Missing required contact matching fields.') . " $fieldMessage " . ts('(Sum of all weights should be greater than or equal to threshold: %1).', array(
|
||||
1 => $threshold,
|
||||
)) . ' ' . ts('(OR Membership ID if update mode.)') . '<br />';
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!isset($errors['_qf_default'])) {
|
||||
$errors['_qf_default'] = '';
|
||||
}
|
||||
$errors['_qf_default'] .= ts('Missing required field: %1', array(
|
||||
1 => $title,
|
||||
)) . '<br />';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($fields['saveMapping'])) {
|
||||
$nameField = CRM_Utils_Array::value('saveMappingName', $fields);
|
||||
if (empty($nameField)) {
|
||||
$errors['saveMappingName'] = ts('Name is required to save Import Mapping');
|
||||
}
|
||||
else {
|
||||
$mappingTypeId = CRM_Core_OptionGroup::getValue('mapping_type', 'Import Membership', 'name');
|
||||
|
||||
if (CRM_Core_BAO_Mapping::checkMapping($nameField, $mappingTypeId)) {
|
||||
$errors['saveMappingName'] = ts('Duplicate Import Membership Mapping Name');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($errors)) {
|
||||
if (!empty($errors['saveMappingName'])) {
|
||||
$_flag = 1;
|
||||
$assignError = new CRM_Core_Page();
|
||||
$assignError->assign('mappingDetailsError', $_flag);
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the mapped fields and map it into the uploaded file
|
||||
* preview the file and extract some summary statistics
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->controller->exportValues('MapField');
|
||||
//reload the mapfield if load mapping is pressed
|
||||
if (!empty($params['savedMapping'])) {
|
||||
$this->set('savedMapping', $params['savedMapping']);
|
||||
$this->controller->resetPage($this->_name);
|
||||
return;
|
||||
}
|
||||
|
||||
$fileName = $this->controller->exportValue('DataSource', 'uploadFile');
|
||||
$seperator = $this->controller->exportValue('DataSource', 'fieldSeparator');
|
||||
$skipColumnHeader = $this->controller->exportValue('DataSource', 'skipColumnHeader');
|
||||
|
||||
$mapperKeys = array();
|
||||
$mapper = array();
|
||||
$mapperKeys = $this->controller->exportValue($this->_name, 'mapper');
|
||||
$mapperKeysMain = array();
|
||||
$mapperLocType = array();
|
||||
$mapperPhoneType = array();
|
||||
|
||||
for ($i = 0; $i < $this->_columnCount; $i++) {
|
||||
$mapper[$i] = $this->_mapperFields[$mapperKeys[$i][0]];
|
||||
$mapperKeysMain[$i] = $mapperKeys[$i][0];
|
||||
|
||||
if (!empty($mapperKeys[$i][1]) && is_numeric($mapperKeys[$i][1])) {
|
||||
$mapperLocType[$i] = $mapperKeys[$i][1];
|
||||
}
|
||||
else {
|
||||
$mapperLocType[$i] = NULL;
|
||||
}
|
||||
|
||||
if (!empty($mapperKeys[$i][2]) && (!is_numeric($mapperKeys[$i][2]))) {
|
||||
$mapperPhoneType[$i] = $mapperKeys[$i][2];
|
||||
}
|
||||
else {
|
||||
$mapperPhoneType[$i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
$this->set('mapper', $mapper);
|
||||
|
||||
// store mapping Id to display it in the preview page
|
||||
if (!empty($params['mappingId'])) {
|
||||
$this->set('loadMappingId', $params['mappingId']);
|
||||
}
|
||||
//Updating Mapping Records
|
||||
if (!empty($params['updateMapping'])) {
|
||||
$mappingFields = new CRM_Core_DAO_MappingField();
|
||||
$mappingFields->mapping_id = $params['mappingId'];
|
||||
$mappingFields->find();
|
||||
|
||||
$mappingFieldsId = array();
|
||||
while ($mappingFields->fetch()) {
|
||||
if ($mappingFields->id) {
|
||||
$mappingFieldsId[$mappingFields->column_number] = $mappingFields->id;
|
||||
}
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $this->_columnCount; $i++) {
|
||||
$updateMappingFields = new CRM_Core_DAO_MappingField();
|
||||
$updateMappingFields->id = $mappingFieldsId[$i];
|
||||
$updateMappingFields->mapping_id = $params['mappingId'];
|
||||
$updateMappingFields->column_number = $i;
|
||||
|
||||
$mapperKeyParts = explode('_', $mapperKeys[$i][0], 3);
|
||||
$id = isset($mapperKeyParts[0]) ? $mapperKeyParts[0] : NULL;
|
||||
$first = isset($mapperKeyParts[1]) ? $mapperKeyParts[1] : NULL;
|
||||
$second = isset($mapperKeyParts[2]) ? $mapperKeyParts[2] : NULL;
|
||||
$updateMappingFields->name = $mapper[$i];
|
||||
$updateMappingFields->save();
|
||||
}
|
||||
}
|
||||
|
||||
//Saving Mapping Details and Records
|
||||
if (!empty($params['saveMapping'])) {
|
||||
$mappingParams = array(
|
||||
'name' => $params['saveMappingName'],
|
||||
'description' => $params['saveMappingDesc'],
|
||||
'mapping_type_id' => CRM_Core_OptionGroup::getValue('mapping_type',
|
||||
'Import Membership',
|
||||
'name'
|
||||
),
|
||||
);
|
||||
$saveMapping = CRM_Core_BAO_Mapping::add($mappingParams);
|
||||
|
||||
for ($i = 0; $i < $this->_columnCount; $i++) {
|
||||
|
||||
$saveMappingFields = new CRM_Core_DAO_MappingField();
|
||||
$saveMappingFields->mapping_id = $saveMapping->id;
|
||||
$saveMappingFields->column_number = $i;
|
||||
|
||||
$mapperKeyParts = explode('_', $mapperKeys[$i][0], 3);
|
||||
$id = isset($mapperKeyParts[0]) ? $mapperKeyParts[0] : NULL;
|
||||
$first = isset($mapperKeyParts[1]) ? $mapperKeyParts[1] : NULL;
|
||||
$second = isset($mapperKeyParts[2]) ? $mapperKeyParts[2] : NULL;
|
||||
$saveMappingFields->name = $mapper[$i];
|
||||
$saveMappingFields->save();
|
||||
}
|
||||
$this->set('savedMapping', $saveMappingFields->mapping_id);
|
||||
}
|
||||
|
||||
$parser = new CRM_Member_Import_Parser_Membership($mapperKeysMain, $mapperLocType, $mapperPhoneType);
|
||||
$parser->run($fileName, $seperator, $mapper, $skipColumnHeader,
|
||||
CRM_Import_Parser::MODE_PREVIEW, $this->get('contactType')
|
||||
);
|
||||
// add all the necessary variables to the form
|
||||
$parser->set($this);
|
||||
}
|
||||
|
||||
}
|
198
sites/all/modules/civicrm/CRM/Member/Import/Form/Preview.php
Normal file
198
sites/all/modules/civicrm/CRM/Member/Import/Form/Preview.php
Normal file
|
@ -0,0 +1,198 @@
|
|||
<?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 previews the uploaded file and returns summary
|
||||
* statistics
|
||||
*/
|
||||
class CRM_Member_Import_Form_Preview extends CRM_Import_Form_Preview {
|
||||
|
||||
/**
|
||||
* Set variables up before form is built.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
$skipColumnHeader = $this->controller->exportValue('DataSource', 'skipColumnHeader');
|
||||
|
||||
//get the data from the session
|
||||
$dataValues = $this->get('dataValues');
|
||||
$mapper = $this->get('mapper');
|
||||
$invalidRowCount = $this->get('invalidRowCount');
|
||||
$conflictRowCount = $this->get('conflictRowCount');
|
||||
$mismatchCount = $this->get('unMatchCount');
|
||||
|
||||
//get the mapping name displayed if the mappingId is set
|
||||
$mappingId = $this->get('loadMappingId');
|
||||
if ($mappingId) {
|
||||
$mapDAO = new CRM_Core_DAO_Mapping();
|
||||
$mapDAO->id = $mappingId;
|
||||
$mapDAO->find(TRUE);
|
||||
$this->assign('loadedMapping', $mappingId);
|
||||
$this->assign('savedName', $mapDAO->name);
|
||||
}
|
||||
|
||||
if ($skipColumnHeader) {
|
||||
$this->assign('skipColumnHeader', $skipColumnHeader);
|
||||
$this->assign('rowDisplayCount', 3);
|
||||
}
|
||||
else {
|
||||
$this->assign('rowDisplayCount', 2);
|
||||
}
|
||||
|
||||
if ($invalidRowCount) {
|
||||
$urlParams = 'type=' . CRM_Import_Parser::ERROR . '&parser=CRM_Member_Import_Parser';
|
||||
$this->set('downloadErrorRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams));
|
||||
}
|
||||
|
||||
if ($conflictRowCount) {
|
||||
$urlParams = 'type=' . CRM_Import_Parser::CONFLICT . '&parser=CRM_Member_Import_Parser';
|
||||
$this->set('downloadConflictRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams));
|
||||
}
|
||||
|
||||
if ($mismatchCount) {
|
||||
$urlParams = 'type=' . CRM_Import_Parser::NO_MATCH . '&parser=CRM_Member_Import_Parser';
|
||||
$this->set('downloadMismatchRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams));
|
||||
}
|
||||
|
||||
$properties = array(
|
||||
'mapper',
|
||||
'dataValues',
|
||||
'columnCount',
|
||||
'totalRowCount',
|
||||
'validRowCount',
|
||||
'invalidRowCount',
|
||||
'conflictRowCount',
|
||||
'downloadErrorRecordsUrl',
|
||||
'downloadConflictRecordsUrl',
|
||||
'downloadMismatchRecordsUrl',
|
||||
);
|
||||
|
||||
foreach ($properties as $property) {
|
||||
$this->assign($property, $this->get($property));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the mapped fields and map it into the uploaded file
|
||||
* preview the file and extract some summary statistics
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
$fileName = $this->controller->exportValue('DataSource', 'uploadFile');
|
||||
$seperator = $this->controller->exportValue('DataSource', 'fieldSeparator');
|
||||
$skipColumnHeader = $this->controller->exportValue('DataSource', 'skipColumnHeader');
|
||||
$invalidRowCount = $this->get('invalidRowCount');
|
||||
$conflictRowCount = $this->get('conflictRowCount');
|
||||
$onDuplicate = $this->get('onDuplicate');
|
||||
|
||||
$mapper = $this->controller->exportValue('MapField', 'mapper');
|
||||
$mapperKeys = array();
|
||||
$mapperLocType = array();
|
||||
$mapperPhoneType = array();
|
||||
// Note: we keep the multi-dimension array (even thought it's not
|
||||
// needed in the case of memberships import) so that we can merge
|
||||
// the common code with contacts import later and subclass contact
|
||||
// and membership imports from there
|
||||
foreach ($mapper as $key => $value) {
|
||||
$mapperKeys[$key] = $mapper[$key][0];
|
||||
|
||||
if (!empty($mapper[$key][1]) && is_numeric($mapper[$key][1])) {
|
||||
$mapperLocType[$key] = $mapper[$key][1];
|
||||
}
|
||||
else {
|
||||
$mapperLocType[$key] = NULL;
|
||||
}
|
||||
|
||||
if (!empty($mapper[$key][2]) && (!is_numeric($mapper[$key][2]))) {
|
||||
$mapperPhoneType[$key] = $mapper[$key][2];
|
||||
}
|
||||
else {
|
||||
$mapperPhoneType[$key] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
$parser = new CRM_Member_Import_Parser_Membership($mapperKeys, $mapperLocType, $mapperPhoneType);
|
||||
|
||||
$mapFields = $this->get('fields');
|
||||
|
||||
foreach ($mapper as $key => $value) {
|
||||
$header = array();
|
||||
if (isset($mapFields[$mapper[$key][0]])) {
|
||||
$header[] = $mapFields[$mapper[$key][0]];
|
||||
}
|
||||
$mapperFields[] = implode(' - ', $header);
|
||||
}
|
||||
$parser->run($fileName, $seperator,
|
||||
$mapperFields,
|
||||
$skipColumnHeader,
|
||||
CRM_Import_Parser::MODE_IMPORT,
|
||||
$this->get('contactType'),
|
||||
$onDuplicate
|
||||
);
|
||||
|
||||
// add all the necessary variables to the form
|
||||
$parser->set($this, CRM_Import_Parser::MODE_IMPORT);
|
||||
|
||||
// check if there is any error occurred
|
||||
|
||||
$errorStack = CRM_Core_Error::singleton();
|
||||
$errors = $errorStack->getErrors();
|
||||
$errorMessage = array();
|
||||
|
||||
if (is_array($errors)) {
|
||||
foreach ($errors as $key => $value) {
|
||||
$errorMessage[] = $value['message'];
|
||||
}
|
||||
|
||||
$errorFile = $fileName['name'] . '.error.log';
|
||||
|
||||
if ($fd = fopen($errorFile, 'w')) {
|
||||
fwrite($fd, implode('\n', $errorMessage));
|
||||
}
|
||||
fclose($fd);
|
||||
|
||||
$this->set('errorFile', $errorFile);
|
||||
$urlParams = 'type=' . CRM_Import_Parser::ERROR . '&parser=CRM_Member_Import_Parser';
|
||||
$this->set('downloadErrorRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams));
|
||||
$urlParams = 'type=' . CRM_Import_Parser::CONFLICT . '&parser=CRM_Member_Import_Parser';
|
||||
$this->set('downloadConflictRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams));
|
||||
$urlParams = 'type=' . CRM_Import_Parser::NO_MATCH . '&parser=CRM_Member_Import_Parser';
|
||||
$this->set('downloadMismatchRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
114
sites/all/modules/civicrm/CRM/Member/Import/Form/Summary.php
Normal file
114
sites/all/modules/civicrm/CRM/Member/Import/Form/Summary.php
Normal file
|
@ -0,0 +1,114 @@
|
|||
<?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 summarizes the import results
|
||||
*/
|
||||
class CRM_Member_Import_Form_Summary extends CRM_Import_Form_Summary {
|
||||
|
||||
/**
|
||||
* Set variables up before form is built.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
// set the error message path to display
|
||||
$this->assign('errorFile', $this->get('errorFile'));
|
||||
|
||||
$totalRowCount = $this->get('totalRowCount');
|
||||
$relatedCount = $this->get('relatedCount');
|
||||
$totalRowCount += $relatedCount;
|
||||
$this->set('totalRowCount', $totalRowCount);
|
||||
|
||||
$invalidRowCount = $this->get('invalidRowCount');
|
||||
$conflictRowCount = $this->get('conflictRowCount');
|
||||
$duplicateRowCount = $this->get('duplicateRowCount');
|
||||
$onDuplicate = $this->get('onDuplicate');
|
||||
$mismatchCount = $this->get('unMatchCount');
|
||||
if ($duplicateRowCount > 0) {
|
||||
$urlParams = 'type=' . CRM_Import_Parser::DUPLICATE . '&parser=CRM_Member_Import_Parser';
|
||||
$this->set('downloadDuplicateRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams));
|
||||
}
|
||||
elseif ($mismatchCount) {
|
||||
$urlParams = 'type=' . CRM_Import_Parser::NO_MATCH . '&parser=CRM_Member_Import_Parser';
|
||||
$this->set('downloadMismatchRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams));
|
||||
}
|
||||
else {
|
||||
$duplicateRowCount = 0;
|
||||
$this->set('duplicateRowCount', $duplicateRowCount);
|
||||
}
|
||||
|
||||
$this->assign('dupeError', FALSE);
|
||||
|
||||
if ($onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE) {
|
||||
$dupeActionString = ts('These records have been updated with the imported data.');
|
||||
}
|
||||
elseif ($onDuplicate == CRM_Import_Parser::DUPLICATE_FILL) {
|
||||
$dupeActionString = ts('These records have been filled in with the imported data.');
|
||||
}
|
||||
else {
|
||||
/* Skip by default */
|
||||
|
||||
$dupeActionString = ts('These records have not been imported.');
|
||||
|
||||
$this->assign('dupeError', TRUE);
|
||||
|
||||
/* only subtract dupes from successful import if we're skipping */
|
||||
|
||||
$this->set('validRowCount', $totalRowCount - $invalidRowCount -
|
||||
$conflictRowCount - $duplicateRowCount - $mismatchCount
|
||||
);
|
||||
}
|
||||
$this->assign('dupeActionString', $dupeActionString);
|
||||
|
||||
$properties = array(
|
||||
'totalRowCount',
|
||||
'validRowCount',
|
||||
'invalidRowCount',
|
||||
'conflictRowCount',
|
||||
'downloadConflictRecordsUrl',
|
||||
'downloadErrorRecordsUrl',
|
||||
'duplicateRowCount',
|
||||
'downloadDuplicateRecordsUrl',
|
||||
'downloadMismatchRecordsUrl',
|
||||
'groupAdditions',
|
||||
'unMatchCount',
|
||||
);
|
||||
foreach ($properties as $property) {
|
||||
$this->assign($property, $this->get($property));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
437
sites/all/modules/civicrm/CRM/Member/Import/Parser.php
Normal file
437
sites/all/modules/civicrm/CRM/Member/Import/Parser.php
Normal file
|
@ -0,0 +1,437 @@
|
|||
<?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$
|
||||
*
|
||||
*/
|
||||
abstract class CRM_Member_Import_Parser extends CRM_Import_Parser {
|
||||
|
||||
protected $_fileName;
|
||||
|
||||
/**#@+
|
||||
* @var integer
|
||||
*/
|
||||
|
||||
/**
|
||||
* Imported file size
|
||||
*/
|
||||
protected $_fileSize;
|
||||
|
||||
/**
|
||||
* Seperator being used
|
||||
*/
|
||||
protected $_seperator;
|
||||
|
||||
/**
|
||||
* Total number of lines in file
|
||||
*/
|
||||
protected $_lineCount;
|
||||
|
||||
/**
|
||||
* Whether the file has a column header or not
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_haveColumnHeader;
|
||||
|
||||
/**
|
||||
* @param string $fileName
|
||||
* @param string $seperator
|
||||
* @param $mapper
|
||||
* @param bool $skipColumnHeader
|
||||
* @param int $mode
|
||||
* @param int $contactType
|
||||
* @param int $onDuplicate
|
||||
*
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function run(
|
||||
$fileName,
|
||||
$seperator = ',',
|
||||
&$mapper,
|
||||
$skipColumnHeader = FALSE,
|
||||
$mode = self::MODE_PREVIEW,
|
||||
$contactType = self::CONTACT_INDIVIDUAL,
|
||||
$onDuplicate = self::DUPLICATE_SKIP
|
||||
) {
|
||||
if (!is_array($fileName)) {
|
||||
CRM_Core_Error::fatal();
|
||||
}
|
||||
$fileName = $fileName['name'];
|
||||
|
||||
switch ($contactType) {
|
||||
case self::CONTACT_INDIVIDUAL:
|
||||
$this->_contactType = 'Individual';
|
||||
break;
|
||||
|
||||
case self::CONTACT_HOUSEHOLD:
|
||||
$this->_contactType = 'Household';
|
||||
break;
|
||||
|
||||
case self::CONTACT_ORGANIZATION:
|
||||
$this->_contactType = 'Organization';
|
||||
}
|
||||
|
||||
$this->init();
|
||||
|
||||
$this->_haveColumnHeader = $skipColumnHeader;
|
||||
|
||||
$this->_seperator = $seperator;
|
||||
|
||||
$fd = fopen($fileName, "r");
|
||||
if (!$fd) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$this->_lineCount = $this->_warningCount = 0;
|
||||
$this->_invalidRowCount = $this->_validCount = 0;
|
||||
$this->_totalCount = $this->_conflictCount = 0;
|
||||
|
||||
$this->_errors = array();
|
||||
$this->_warnings = array();
|
||||
$this->_conflicts = array();
|
||||
|
||||
$this->_fileSize = number_format(filesize($fileName) / 1024.0, 2);
|
||||
|
||||
if ($mode == self::MODE_MAPFIELD) {
|
||||
$this->_rows = array();
|
||||
}
|
||||
else {
|
||||
$this->_activeFieldCount = count($this->_activeFields);
|
||||
}
|
||||
|
||||
while (!feof($fd)) {
|
||||
$this->_lineCount++;
|
||||
|
||||
$values = fgetcsv($fd, 8192, $seperator);
|
||||
if (!$values) {
|
||||
continue;
|
||||
}
|
||||
|
||||
self::encloseScrub($values);
|
||||
|
||||
// skip column header if we're not in mapfield mode
|
||||
if ($mode != self::MODE_MAPFIELD && $skipColumnHeader) {
|
||||
$skipColumnHeader = FALSE;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* trim whitespace around the values */
|
||||
|
||||
$empty = TRUE;
|
||||
foreach ($values as $k => $v) {
|
||||
$values[$k] = trim($v, " \t\r\n");
|
||||
}
|
||||
if (CRM_Utils_System::isNull($values)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->_totalCount++;
|
||||
|
||||
if ($mode == self::MODE_MAPFIELD) {
|
||||
$returnCode = $this->mapField($values);
|
||||
}
|
||||
elseif ($mode == self::MODE_PREVIEW) {
|
||||
$returnCode = $this->preview($values);
|
||||
}
|
||||
elseif ($mode == self::MODE_SUMMARY) {
|
||||
$returnCode = $this->summary($values);
|
||||
}
|
||||
elseif ($mode == self::MODE_IMPORT) {
|
||||
$returnCode = $this->import($onDuplicate, $values);
|
||||
}
|
||||
else {
|
||||
$returnCode = self::ERROR;
|
||||
}
|
||||
|
||||
// note that a line could be valid but still produce a warning
|
||||
if ($returnCode & self::VALID) {
|
||||
$this->_validCount++;
|
||||
if ($mode == self::MODE_MAPFIELD) {
|
||||
$this->_rows[] = $values;
|
||||
$this->_activeFieldCount = max($this->_activeFieldCount, count($values));
|
||||
}
|
||||
}
|
||||
|
||||
if ($returnCode & self::WARNING) {
|
||||
$this->_warningCount++;
|
||||
if ($this->_warningCount < $this->_maxWarningCount) {
|
||||
$this->_warningCount[] = $line;
|
||||
}
|
||||
}
|
||||
|
||||
if ($returnCode & self::ERROR) {
|
||||
$this->_invalidRowCount++;
|
||||
if ($this->_invalidRowCount < $this->_maxErrorCount) {
|
||||
$recordNumber = $this->_lineCount;
|
||||
array_unshift($values, $recordNumber);
|
||||
$this->_errors[] = $values;
|
||||
}
|
||||
}
|
||||
|
||||
if ($returnCode & self::CONFLICT) {
|
||||
$this->_conflictCount++;
|
||||
$recordNumber = $this->_lineCount;
|
||||
array_unshift($values, $recordNumber);
|
||||
$this->_conflicts[] = $values;
|
||||
}
|
||||
|
||||
if ($returnCode & self::DUPLICATE) {
|
||||
if ($returnCode & self::MULTIPLE_DUPE) {
|
||||
/* TODO: multi-dupes should be counted apart from singles
|
||||
* on non-skip action */
|
||||
}
|
||||
$this->_duplicateCount++;
|
||||
$recordNumber = $this->_lineCount;
|
||||
array_unshift($values, $recordNumber);
|
||||
$this->_duplicates[] = $values;
|
||||
if ($onDuplicate != self::DUPLICATE_SKIP) {
|
||||
$this->_validCount++;
|
||||
}
|
||||
}
|
||||
|
||||
// we give the derived class a way of aborting the process
|
||||
// note that the return code could be multiple code or'ed together
|
||||
if ($returnCode & self::STOP) {
|
||||
break;
|
||||
}
|
||||
|
||||
// if we are done processing the maxNumber of lines, break
|
||||
if ($this->_maxLinesToProcess > 0 && $this->_validCount >= $this->_maxLinesToProcess) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fclose($fd);
|
||||
|
||||
if ($mode == self::MODE_PREVIEW || $mode == self::MODE_IMPORT) {
|
||||
$customHeaders = $mapper;
|
||||
|
||||
$customfields = CRM_Core_BAO_CustomField::getFields('Membership');
|
||||
foreach ($customHeaders as $key => $value) {
|
||||
if ($id = CRM_Core_BAO_CustomField::getKeyID($value)) {
|
||||
$customHeaders[$key] = $customfields[$id][0];
|
||||
}
|
||||
}
|
||||
if ($this->_invalidRowCount) {
|
||||
// removed view url for invlaid contacts
|
||||
$headers = array_merge(array(
|
||||
ts('Line Number'),
|
||||
ts('Reason'),
|
||||
), $customHeaders);
|
||||
$this->_errorFileName = self::errorFileName(self::ERROR);
|
||||
|
||||
self::exportCSV($this->_errorFileName, $headers, $this->_errors);
|
||||
}
|
||||
if ($this->_conflictCount) {
|
||||
$headers = array_merge(array(
|
||||
ts('Line Number'),
|
||||
ts('Reason'),
|
||||
), $customHeaders);
|
||||
$this->_conflictFileName = self::errorFileName(self::CONFLICT);
|
||||
self::exportCSV($this->_conflictFileName, $headers, $this->_conflicts);
|
||||
}
|
||||
if ($this->_duplicateCount) {
|
||||
$headers = array_merge(array(
|
||||
ts('Line Number'),
|
||||
ts('View Membership URL'),
|
||||
), $customHeaders);
|
||||
|
||||
$this->_duplicateFileName = self::errorFileName(self::DUPLICATE);
|
||||
self::exportCSV($this->_duplicateFileName, $headers, $this->_duplicates);
|
||||
}
|
||||
}
|
||||
return $this->fini();
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a list of the importable field keys that the user has selected
|
||||
* set the active fields array to this list
|
||||
*
|
||||
* @param array $fieldKeys mapped array of values
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setActiveFields($fieldKeys) {
|
||||
$this->_activeFieldCount = count($fieldKeys);
|
||||
foreach ($fieldKeys as $key) {
|
||||
if (empty($this->_fields[$key])) {
|
||||
$this->_activeFields[] = new CRM_Member_Import_Field('', ts('- do not import -'));
|
||||
}
|
||||
else {
|
||||
$this->_activeFields[] = clone($this->_fields[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the field values for input to the api.
|
||||
*
|
||||
* @return array
|
||||
* (reference ) associative array of name/value pairs
|
||||
*/
|
||||
public function &getActiveFieldParams() {
|
||||
$params = array();
|
||||
for ($i = 0; $i < $this->_activeFieldCount; $i++) {
|
||||
if (isset($this->_activeFields[$i]->_value)
|
||||
&& !isset($params[$this->_activeFields[$i]->_name])
|
||||
&& !isset($this->_activeFields[$i]->_related)
|
||||
) {
|
||||
|
||||
$params[$this->_activeFields[$i]->_name] = $this->_activeFields[$i]->_value;
|
||||
}
|
||||
}
|
||||
return $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param $title
|
||||
* @param int $type
|
||||
* @param string $headerPattern
|
||||
* @param string $dataPattern
|
||||
*/
|
||||
public function addField($name, $title, $type = CRM_Utils_Type::T_INT, $headerPattern = '//', $dataPattern = '//') {
|
||||
if (empty($name)) {
|
||||
$this->_fields['doNotImport'] = new CRM_Member_Import_Field($name, $title, $type, $headerPattern, $dataPattern);
|
||||
}
|
||||
else {
|
||||
|
||||
//$tempField = CRM_Contact_BAO_Contact::importableFields('Individual', null );
|
||||
$tempField = CRM_Contact_BAO_Contact::importableFields('All', NULL);
|
||||
if (!array_key_exists($name, $tempField)) {
|
||||
$this->_fields[$name] = new CRM_Member_Import_Field($name, $title, $type, $headerPattern, $dataPattern);
|
||||
}
|
||||
else {
|
||||
$this->_fields[$name] = new CRM_Contact_Import_Field($name, $title, $type, $headerPattern, $dataPattern,
|
||||
CRM_Utils_Array::value('hasLocationType', $tempField[$name])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store parser values.
|
||||
*
|
||||
* @param CRM_Core_Session $store
|
||||
*
|
||||
* @param int $mode
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function set($store, $mode = self::MODE_SUMMARY) {
|
||||
$store->set('fileSize', $this->_fileSize);
|
||||
$store->set('lineCount', $this->_lineCount);
|
||||
$store->set('seperator', $this->_seperator);
|
||||
$store->set('fields', $this->getSelectValues());
|
||||
$store->set('fieldTypes', $this->getSelectTypes());
|
||||
|
||||
$store->set('headerPatterns', $this->getHeaderPatterns());
|
||||
$store->set('dataPatterns', $this->getDataPatterns());
|
||||
$store->set('columnCount', $this->_activeFieldCount);
|
||||
|
||||
$store->set('totalRowCount', $this->_totalCount);
|
||||
$store->set('validRowCount', $this->_validCount);
|
||||
$store->set('invalidRowCount', $this->_invalidRowCount);
|
||||
$store->set('conflictRowCount', $this->_conflictCount);
|
||||
|
||||
switch ($this->_contactType) {
|
||||
case 'Individual':
|
||||
$store->set('contactType', CRM_Import_Parser::CONTACT_INDIVIDUAL);
|
||||
break;
|
||||
|
||||
case 'Household':
|
||||
$store->set('contactType', CRM_Import_Parser::CONTACT_HOUSEHOLD);
|
||||
break;
|
||||
|
||||
case 'Organization':
|
||||
$store->set('contactType', CRM_Import_Parser::CONTACT_ORGANIZATION);
|
||||
}
|
||||
|
||||
if ($this->_invalidRowCount) {
|
||||
$store->set('errorsFileName', $this->_errorFileName);
|
||||
}
|
||||
if ($this->_conflictCount) {
|
||||
$store->set('conflictsFileName', $this->_conflictFileName);
|
||||
}
|
||||
if (isset($this->_rows) && !empty($this->_rows)) {
|
||||
$store->set('dataValues', $this->_rows);
|
||||
}
|
||||
|
||||
if ($mode == self::MODE_IMPORT) {
|
||||
$store->set('duplicateRowCount', $this->_duplicateCount);
|
||||
if ($this->_duplicateCount) {
|
||||
$store->set('duplicatesFileName', $this->_duplicateFileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Export data to a CSV file.
|
||||
*
|
||||
* @param string $fileName
|
||||
* @param array $header
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function exportCSV($fileName, $header, $data) {
|
||||
$output = array();
|
||||
$fd = fopen($fileName, 'w');
|
||||
|
||||
foreach ($header as $key => $value) {
|
||||
$header[$key] = "\"$value\"";
|
||||
}
|
||||
$config = CRM_Core_Config::singleton();
|
||||
$output[] = implode($config->fieldSeparator, $header);
|
||||
|
||||
foreach ($data as $datum) {
|
||||
foreach ($datum as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
foreach ($value[0] as $k1 => $v1) {
|
||||
if ($k1 == 'location_type_id') {
|
||||
continue;
|
||||
}
|
||||
$datum[$k1] = $v1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$datum[$key] = "\"$value\"";
|
||||
}
|
||||
}
|
||||
$output[] = implode($config->fieldSeparator, $datum);
|
||||
}
|
||||
fwrite($fd, implode("\n", $output));
|
||||
fclose($fd);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,766 @@
|
|||
<?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$
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
require_once 'api/api.php';
|
||||
|
||||
/**
|
||||
* class to parse membership csv files
|
||||
*/
|
||||
class CRM_Member_Import_Parser_Membership extends CRM_Member_Import_Parser {
|
||||
|
||||
protected $_mapperKeys;
|
||||
|
||||
private $_contactIdIndex;
|
||||
private $_totalAmountIndex;
|
||||
private $_membershipTypeIndex;
|
||||
private $_membershipStatusIndex;
|
||||
|
||||
/**
|
||||
* Array of successfully imported membership id's
|
||||
*
|
||||
* @array
|
||||
*/
|
||||
protected $_newMemberships;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param $mapperKeys
|
||||
* @param null $mapperLocType
|
||||
* @param null $mapperPhoneType
|
||||
*/
|
||||
public function __construct(&$mapperKeys, $mapperLocType = NULL, $mapperPhoneType = NULL) {
|
||||
parent::__construct();
|
||||
$this->_mapperKeys = &$mapperKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
* The initializer code, called before the processing
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init() {
|
||||
$fields = CRM_Member_BAO_Membership::importableFields($this->_contactType, FALSE);
|
||||
|
||||
foreach ($fields as $name => $field) {
|
||||
$field['type'] = CRM_Utils_Array::value('type', $field, CRM_Utils_Type::T_INT);
|
||||
$field['dataPattern'] = CRM_Utils_Array::value('dataPattern', $field, '//');
|
||||
$field['headerPattern'] = CRM_Utils_Array::value('headerPattern', $field, '//');
|
||||
$this->addField($name, $field['title'], $field['type'], $field['headerPattern'], $field['dataPattern']);
|
||||
}
|
||||
|
||||
$this->_newMemberships = array();
|
||||
|
||||
$this->setActiveFields($this->_mapperKeys);
|
||||
|
||||
// FIXME: we should do this in one place together with Form/MapField.php
|
||||
$this->_contactIdIndex = -1;
|
||||
$this->_membershipTypeIndex = -1;
|
||||
$this->_membershipStatusIndex = -1;
|
||||
|
||||
$index = 0;
|
||||
foreach ($this->_mapperKeys as $key) {
|
||||
switch ($key) {
|
||||
case 'membership_contact_id':
|
||||
$this->_contactIdIndex = $index;
|
||||
break;
|
||||
|
||||
case 'membership_type_id':
|
||||
$this->_membershipTypeIndex = $index;
|
||||
break;
|
||||
|
||||
case 'status_id':
|
||||
$this->_membershipStatusIndex = $index;
|
||||
break;
|
||||
}
|
||||
$index++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the values in mapField mode.
|
||||
*
|
||||
* @param array $values
|
||||
* The array of values belonging to this line.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function mapField(&$values) {
|
||||
return CRM_Import_Parser::VALID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the values in preview mode.
|
||||
*
|
||||
* @param array $values
|
||||
* The array of values belonging to this line.
|
||||
*
|
||||
* @return bool
|
||||
* the result of this processing
|
||||
*/
|
||||
public function preview(&$values) {
|
||||
return $this->summary($values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the values in summary mode.
|
||||
*
|
||||
* @param array $values
|
||||
* The array of values belonging to this line.
|
||||
*
|
||||
* @return bool
|
||||
* the result of this processing
|
||||
*/
|
||||
public function summary(&$values) {
|
||||
$erroneousField = NULL;
|
||||
$response = $this->setActiveFieldValues($values, $erroneousField);
|
||||
|
||||
$errorRequired = FALSE;
|
||||
|
||||
if ($this->_membershipTypeIndex < 0) {
|
||||
$errorRequired = TRUE;
|
||||
}
|
||||
else {
|
||||
$errorRequired = !CRM_Utils_Array::value($this->_membershipTypeIndex, $values);
|
||||
}
|
||||
|
||||
if ($errorRequired) {
|
||||
array_unshift($values, ts('Missing required fields'));
|
||||
return CRM_Import_Parser::ERROR;
|
||||
}
|
||||
|
||||
$params = $this->getActiveFieldParams();
|
||||
$errorMessage = NULL;
|
||||
|
||||
//To check whether start date or join date is provided
|
||||
if (empty($params['membership_start_date']) && empty($params['join_date'])) {
|
||||
$errorMessage = 'Membership Start Date is required to create a memberships.';
|
||||
CRM_Contact_Import_Parser_Contact::addToErrorMsg('Start Date', $errorMessage);
|
||||
}
|
||||
|
||||
//for date-Formats
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$dateType = $session->get('dateTypes');
|
||||
foreach ($params as $key => $val) {
|
||||
|
||||
if ($val) {
|
||||
switch ($key) {
|
||||
case 'join_date':
|
||||
if (CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key)) {
|
||||
if (!CRM_Utils_Rule::date($params[$key])) {
|
||||
CRM_Contact_Import_Parser_Contact::addToErrorMsg('Member Since', $errorMessage);
|
||||
}
|
||||
}
|
||||
else {
|
||||
CRM_Contact_Import_Parser_Contact::addToErrorMsg('Member Since', $errorMessage);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'membership_start_date':
|
||||
if (CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key)) {
|
||||
if (!CRM_Utils_Rule::date($params[$key])) {
|
||||
CRM_Contact_Import_Parser_Contact::addToErrorMsg('Start Date', $errorMessage);
|
||||
}
|
||||
}
|
||||
else {
|
||||
CRM_Contact_Import_Parser_Contact::addToErrorMsg('Start Date', $errorMessage);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'membership_end_date':
|
||||
if (CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key)) {
|
||||
if (!CRM_Utils_Rule::date($params[$key])) {
|
||||
CRM_Contact_Import_Parser_Contact::addToErrorMsg('End date', $errorMessage);
|
||||
}
|
||||
}
|
||||
else {
|
||||
CRM_Contact_Import_Parser_Contact::addToErrorMsg('End date', $errorMessage);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'membership_type_id':
|
||||
$membershipTypes = CRM_Member_PseudoConstant::membershipType();
|
||||
if (!CRM_Utils_Array::crmInArray($val, $membershipTypes) &&
|
||||
!array_key_exists($val, $membershipTypes)
|
||||
) {
|
||||
CRM_Contact_Import_Parser_Contact::addToErrorMsg('Membership Type', $errorMessage);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'status_id':
|
||||
if (!CRM_Utils_Array::crmInArray($val, CRM_Member_PseudoConstant::membershipStatus())) {
|
||||
CRM_Contact_Import_Parser_Contact::addToErrorMsg('Membership Status', $errorMessage);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'email':
|
||||
if (!CRM_Utils_Rule::email($val)) {
|
||||
CRM_Contact_Import_Parser_Contact::addToErrorMsg('Email Address', $errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//date-Format part ends
|
||||
|
||||
$params['contact_type'] = 'Membership';
|
||||
|
||||
//checking error in custom data
|
||||
CRM_Contact_Import_Parser_Contact::isErrorInCustomData($params, $errorMessage);
|
||||
|
||||
if ($errorMessage) {
|
||||
$tempMsg = "Invalid value for field(s) : $errorMessage";
|
||||
array_unshift($values, $tempMsg);
|
||||
$errorMessage = NULL;
|
||||
return CRM_Import_Parser::ERROR;
|
||||
}
|
||||
|
||||
return CRM_Import_Parser::VALID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the values in import mode.
|
||||
*
|
||||
* @param int $onDuplicate
|
||||
* The code for what action to take on duplicates.
|
||||
* @param array $values
|
||||
* The array of values belonging to this line.
|
||||
*
|
||||
* @return bool
|
||||
* the result of this processing
|
||||
*/
|
||||
public function import($onDuplicate, &$values) {
|
||||
try {
|
||||
// first make sure this is a valid line
|
||||
$response = $this->summary($values);
|
||||
if ($response != CRM_Import_Parser::VALID) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$params = $this->getActiveFieldParams();
|
||||
|
||||
//assign join date equal to start date if join date is not provided
|
||||
if (empty($params['join_date']) && !empty($params['membership_start_date'])) {
|
||||
$params['join_date'] = $params['membership_start_date'];
|
||||
}
|
||||
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$dateType = $session->get('dateTypes');
|
||||
$formatted = array();
|
||||
$customDataType = !empty($params['contact_type']) ? $params['contact_type'] : 'Membership';
|
||||
$customFields = CRM_Core_BAO_CustomField::getFields($customDataType);
|
||||
|
||||
// don't add to recent items, CRM-4399
|
||||
$formatted['skipRecentView'] = TRUE;
|
||||
$dateLabels = array(
|
||||
'join_date' => ts('Member Since'),
|
||||
'membership_start_date' => ts('Start Date'),
|
||||
'membership_end_date' => ts('End Date'),
|
||||
);
|
||||
foreach ($params as $key => $val) {
|
||||
if ($val) {
|
||||
switch ($key) {
|
||||
case 'join_date':
|
||||
case 'membership_start_date':
|
||||
case 'membership_end_date':
|
||||
if (CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key)) {
|
||||
if (!CRM_Utils_Rule::date($params[$key])) {
|
||||
CRM_Contact_Import_Parser_Contact::addToErrorMsg($dateLabels[$key], $errorMessage);
|
||||
}
|
||||
}
|
||||
else {
|
||||
CRM_Contact_Import_Parser_Contact::addToErrorMsg($dateLabels[$key], $errorMessage);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'membership_type_id':
|
||||
if (!is_numeric($val)) {
|
||||
unset($params['membership_type_id']);
|
||||
$params['membership_type'] = $val;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'status_id':
|
||||
if (!is_numeric($val)) {
|
||||
unset($params['status_id']);
|
||||
$params['membership_status'] = $val;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'is_override':
|
||||
$params[$key] = CRM_Utils_String::strtobool($val);
|
||||
break;
|
||||
}
|
||||
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
|
||||
if ($customFields[$customFieldID]['data_type'] == 'Date') {
|
||||
CRM_Contact_Import_Parser_Contact::formatCustomDate($params, $formatted, $dateType, $key);
|
||||
unset($params[$key]);
|
||||
}
|
||||
elseif ($customFields[$customFieldID]['data_type'] == 'Boolean') {
|
||||
$params[$key] = CRM_Utils_String::strtoboolstr($val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//date-Format part ends
|
||||
|
||||
static $indieFields = NULL;
|
||||
if ($indieFields == NULL) {
|
||||
$tempIndieFields = CRM_Member_DAO_Membership::import();
|
||||
$indieFields = $tempIndieFields;
|
||||
}
|
||||
|
||||
$formatValues = array();
|
||||
foreach ($params as $key => $field) {
|
||||
if ($field == NULL || $field === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$formatValues[$key] = $field;
|
||||
}
|
||||
|
||||
//format params to meet api v2 requirements.
|
||||
//@todo find a way to test removing this formatting
|
||||
$formatError = $this->membership_format_params($formatValues, $formatted, TRUE);
|
||||
|
||||
if ($onDuplicate != CRM_Import_Parser::DUPLICATE_UPDATE) {
|
||||
$formatted['custom'] = CRM_Core_BAO_CustomField::postProcess($formatted,
|
||||
NULL,
|
||||
'Membership'
|
||||
);
|
||||
}
|
||||
else {
|
||||
//fix for CRM-2219 Update Membership
|
||||
// onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE
|
||||
if (!empty($formatted['is_override']) && empty($formatted['status_id'])) {
|
||||
array_unshift($values, 'Required parameter missing: Status');
|
||||
return CRM_Import_Parser::ERROR;
|
||||
}
|
||||
|
||||
if (!empty($formatValues['membership_id'])) {
|
||||
$dao = new CRM_Member_BAO_Membership();
|
||||
$dao->id = $formatValues['membership_id'];
|
||||
$dates = array('join_date', 'start_date', 'end_date');
|
||||
foreach ($dates as $v) {
|
||||
if (empty($formatted[$v])) {
|
||||
$formatted[$v] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $formatValues['membership_id'], $v);
|
||||
}
|
||||
}
|
||||
|
||||
$formatted['custom'] = CRM_Core_BAO_CustomField::postProcess($formatted,
|
||||
$formatValues['membership_id'],
|
||||
'Membership'
|
||||
);
|
||||
if ($dao->find(TRUE)) {
|
||||
$ids = array(
|
||||
'membership' => $formatValues['membership_id'],
|
||||
'userId' => $session->get('userID'),
|
||||
);
|
||||
|
||||
if (empty($params['line_item']) && !empty($formatted['membership_type_id'])) {
|
||||
CRM_Price_BAO_LineItem::getLineItemArray($formatted, NULL, 'membership', $formatted['membership_type_id']);
|
||||
}
|
||||
|
||||
$newMembership = CRM_Member_BAO_Membership::create($formatted, $ids, TRUE);
|
||||
if (civicrm_error($newMembership)) {
|
||||
array_unshift($values, $newMembership['is_error'] . ' for Membership ID ' . $formatValues['membership_id'] . '. Row was skipped.');
|
||||
return CRM_Import_Parser::ERROR;
|
||||
}
|
||||
else {
|
||||
$this->_newMemberships[] = $newMembership->id;
|
||||
return CRM_Import_Parser::VALID;
|
||||
}
|
||||
}
|
||||
else {
|
||||
array_unshift($values, 'Matching Membership record not found for Membership ID ' . $formatValues['membership_id'] . '. Row was skipped.');
|
||||
return CRM_Import_Parser::ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Format dates
|
||||
$startDate = CRM_Utils_Date::customFormat(CRM_Utils_Array::value('start_date', $formatted), '%Y-%m-%d');
|
||||
$endDate = CRM_Utils_Date::customFormat(CRM_Utils_Array::value('end_date', $formatted), '%Y-%m-%d');
|
||||
$joinDate = CRM_Utils_Date::customFormat(CRM_Utils_Array::value('join_date', $formatted), '%Y-%m-%d');
|
||||
|
||||
if ($this->_contactIdIndex < 0) {
|
||||
$error = $this->checkContactDuplicate($formatValues);
|
||||
|
||||
if (CRM_Core_Error::isAPIError($error, CRM_Core_ERROR::DUPLICATE_CONTACT)) {
|
||||
$matchedIDs = explode(',', $error['error_message']['params'][0]);
|
||||
if (count($matchedIDs) > 1) {
|
||||
array_unshift($values, 'Multiple matching contact records detected for this row. The membership was not imported');
|
||||
return CRM_Import_Parser::ERROR;
|
||||
}
|
||||
else {
|
||||
$cid = $matchedIDs[0];
|
||||
$formatted['contact_id'] = $cid;
|
||||
|
||||
//fix for CRM-1924
|
||||
$calcDates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($formatted['membership_type_id'],
|
||||
$joinDate,
|
||||
$startDate,
|
||||
$endDate
|
||||
);
|
||||
self::formattedDates($calcDates, $formatted);
|
||||
|
||||
//fix for CRM-3570, exclude the statuses those having is_admin = 1
|
||||
//now user can import is_admin if is override is true.
|
||||
$excludeIsAdmin = FALSE;
|
||||
if (empty($formatted['is_override'])) {
|
||||
$formatted['exclude_is_admin'] = $excludeIsAdmin = TRUE;
|
||||
}
|
||||
$calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($startDate,
|
||||
$endDate,
|
||||
$joinDate,
|
||||
'today',
|
||||
$excludeIsAdmin,
|
||||
$formatted['membership_type_id'],
|
||||
$formatted
|
||||
);
|
||||
|
||||
if (empty($formatted['status_id'])) {
|
||||
$formatted['status_id'] = $calcStatus['id'];
|
||||
}
|
||||
elseif (empty($formatted['is_override'])) {
|
||||
if (empty($calcStatus)) {
|
||||
array_unshift($values, 'Status in import row (' . $formatValues['status_id'] . ') does not match calculated status based on your configured Membership Status Rules. Record was not imported.');
|
||||
return CRM_Import_Parser::ERROR;
|
||||
}
|
||||
elseif ($formatted['status_id'] != $calcStatus['id']) {
|
||||
//Status Hold" is either NOT mapped or is FALSE
|
||||
array_unshift($values, 'Status in import row (' . $formatValues['status_id'] . ') does not match calculated status based on your configured Membership Status Rules (' . $calcStatus['name'] . '). Record was not imported.');
|
||||
return CRM_Import_Parser::ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
$newMembership = civicrm_api3('membership', 'create', $formatted);
|
||||
|
||||
$this->_newMemberships[] = $newMembership['id'];
|
||||
return CRM_Import_Parser::VALID;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Using new Dedupe rule.
|
||||
$ruleParams = array(
|
||||
'contact_type' => $this->_contactType,
|
||||
'used' => 'Unsupervised',
|
||||
);
|
||||
$fieldsArray = CRM_Dedupe_BAO_Rule::dedupeRuleFields($ruleParams);
|
||||
$disp = '';
|
||||
|
||||
foreach ($fieldsArray as $value) {
|
||||
if (array_key_exists(trim($value), $params)) {
|
||||
$paramValue = $params[trim($value)];
|
||||
if (is_array($paramValue)) {
|
||||
$disp .= $params[trim($value)][0][trim($value)] . " ";
|
||||
}
|
||||
else {
|
||||
$disp .= $params[trim($value)] . " ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($params['external_identifier'])) {
|
||||
if ($disp) {
|
||||
$disp .= "AND {$params['external_identifier']}";
|
||||
}
|
||||
else {
|
||||
$disp = $params['external_identifier'];
|
||||
}
|
||||
}
|
||||
|
||||
array_unshift($values, 'No matching Contact found for (' . $disp . ')');
|
||||
return CRM_Import_Parser::ERROR;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!empty($formatValues['external_identifier'])) {
|
||||
$checkCid = new CRM_Contact_DAO_Contact();
|
||||
$checkCid->external_identifier = $formatValues['external_identifier'];
|
||||
$checkCid->find(TRUE);
|
||||
if ($checkCid->id != $formatted['contact_id']) {
|
||||
array_unshift($values, 'Mismatch of External ID:' . $formatValues['external_identifier'] . ' and Contact Id:' . $formatted['contact_id']);
|
||||
return CRM_Import_Parser::ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
//to calculate dates
|
||||
$calcDates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($formatted['membership_type_id'],
|
||||
$joinDate,
|
||||
$startDate,
|
||||
$endDate
|
||||
);
|
||||
self::formattedDates($calcDates, $formatted);
|
||||
//end of date calculation part
|
||||
|
||||
//fix for CRM-3570, exclude the statuses those having is_admin = 1
|
||||
//now user can import is_admin if is override is true.
|
||||
$excludeIsAdmin = FALSE;
|
||||
if (empty($formatted['is_override'])) {
|
||||
$formatted['exclude_is_admin'] = $excludeIsAdmin = TRUE;
|
||||
}
|
||||
$calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($startDate,
|
||||
$endDate,
|
||||
$joinDate,
|
||||
'today',
|
||||
$excludeIsAdmin,
|
||||
$formatted['membership_type_id'],
|
||||
$formatted
|
||||
);
|
||||
if (empty($formatted['status_id'])) {
|
||||
$formatted['status_id'] = CRM_Utils_Array::value('id', $calcStatus);
|
||||
}
|
||||
elseif (empty($formatted['is_override'])) {
|
||||
if (empty($calcStatus)) {
|
||||
array_unshift($values, 'Status in import row (' . CRM_Utils_Array::value('status_id', $formatValues) . ') does not match calculated status based on your configured Membership Status Rules. Record was not imported.');
|
||||
return CRM_Import_Parser::ERROR;
|
||||
}
|
||||
elseif ($formatted['status_id'] != $calcStatus['id']) {
|
||||
//Status Hold" is either NOT mapped or is FALSE
|
||||
array_unshift($values, 'Status in import row (' . CRM_Utils_Array::value('status_id', $formatValues) . ') does not match calculated status based on your configured Membership Status Rules (' . $calcStatus['name'] . '). Record was not imported.');
|
||||
return CRM_Import_Parser::ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
$newMembership = civicrm_api3('membership', 'create', $formatted);
|
||||
|
||||
$this->_newMemberships[] = $newMembership['id'];
|
||||
return CRM_Import_Parser::VALID;
|
||||
}
|
||||
}
|
||||
catch (Exception $e) {
|
||||
array_unshift($values, $e->getMessage());
|
||||
return CRM_Import_Parser::ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array of successfully imported membership id's
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function &getImportedMemberships() {
|
||||
return $this->_newMemberships;
|
||||
}
|
||||
|
||||
/**
|
||||
* The initializer code, called before the processing
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function fini() {
|
||||
}
|
||||
|
||||
/**
|
||||
* to calculate join, start and end dates
|
||||
*
|
||||
* @param array $calcDates
|
||||
* Array of dates returned by getDatesForMembershipType().
|
||||
*
|
||||
* @param $formatted
|
||||
*
|
||||
*/
|
||||
public function formattedDates($calcDates, &$formatted) {
|
||||
$dates = array(
|
||||
'join_date',
|
||||
'start_date',
|
||||
'end_date',
|
||||
);
|
||||
|
||||
foreach ($dates as $d) {
|
||||
if (isset($formatted[$d]) &&
|
||||
!CRM_Utils_System::isNull($formatted[$d])
|
||||
) {
|
||||
$formatted[$d] = CRM_Utils_Date::isoToMysql($formatted[$d]);
|
||||
}
|
||||
elseif (isset($calcDates[$d])) {
|
||||
$formatted[$d] = CRM_Utils_Date::isoToMysql($calcDates[$d]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated - this function formats params according to v2 standards but
|
||||
* need to be sure about the impact of not calling it so retaining on the import class
|
||||
* take the input parameter list as specified in the data model and
|
||||
* convert it into the same format that we use in QF and BAO object
|
||||
*
|
||||
* @param array $params
|
||||
* Associative array of property name/value.
|
||||
* pairs to insert in new contact.
|
||||
* @param array $values
|
||||
* The reformatted properties that we can use internally.
|
||||
*
|
||||
* @param array|bool $create Is the formatted Values array going to
|
||||
* be used for CRM_Member_BAO_Membership:create()
|
||||
*
|
||||
* @throws Exception
|
||||
* @return array|error
|
||||
*/
|
||||
public function membership_format_params($params, &$values, $create = FALSE) {
|
||||
require_once 'api/v3/utils.php';
|
||||
$fields = CRM_Member_DAO_Membership::fields();
|
||||
_civicrm_api3_store_values($fields, $params, $values);
|
||||
|
||||
$customFields = CRM_Core_BAO_CustomField::getFields('Membership');
|
||||
|
||||
foreach ($params as $key => $value) {
|
||||
// ignore empty values or empty arrays etc
|
||||
if (CRM_Utils_System::isNull($value)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//Handling Custom Data
|
||||
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
|
||||
$values[$key] = $value;
|
||||
$type = $customFields[$customFieldID]['html_type'];
|
||||
if ($type == 'CheckBox' || $type == 'Multi-Select' || $type == 'AdvMulti-Select') {
|
||||
$mulValues = explode(',', $value);
|
||||
$customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE);
|
||||
$values[$key] = array();
|
||||
foreach ($mulValues as $v1) {
|
||||
foreach ($customOption as $customValueID => $customLabel) {
|
||||
$customValue = $customLabel['value'];
|
||||
if ((strtolower($customLabel['label']) == strtolower(trim($v1))) ||
|
||||
(strtolower($customValue) == strtolower(trim($v1)))
|
||||
) {
|
||||
if ($type == 'CheckBox') {
|
||||
$values[$key][$customValue] = 1;
|
||||
}
|
||||
else {
|
||||
$values[$key][] = $customValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch ($key) {
|
||||
case 'membership_contact_id':
|
||||
if (!CRM_Utils_Rule::integer($value)) {
|
||||
throw new Exception("contact_id not valid: $value");
|
||||
}
|
||||
$dao = new CRM_Core_DAO();
|
||||
$qParams = array();
|
||||
$svq = $dao->singleValueQuery("SELECT id FROM civicrm_contact WHERE id = $value",
|
||||
$qParams
|
||||
);
|
||||
if (!$svq) {
|
||||
throw new Exception("Invalid Contact ID: There is no contact record with contact_id = $value.");
|
||||
}
|
||||
$values['contact_id'] = $values['membership_contact_id'];
|
||||
unset($values['membership_contact_id']);
|
||||
break;
|
||||
|
||||
case 'membership_type_id':
|
||||
if (!CRM_Utils_Array::value($value, CRM_Member_PseudoConstant::membershipType())) {
|
||||
throw new Exception('Invalid Membership Type Id');
|
||||
}
|
||||
$values[$key] = $value;
|
||||
break;
|
||||
|
||||
case 'membership_type':
|
||||
$membershipTypeId = CRM_Utils_Array::key(ucfirst($value),
|
||||
CRM_Member_PseudoConstant::membershipType()
|
||||
);
|
||||
if ($membershipTypeId) {
|
||||
if (!empty($values['membership_type_id']) &&
|
||||
$membershipTypeId != $values['membership_type_id']
|
||||
) {
|
||||
throw new Exception('Mismatched membership Type and Membership Type Id');
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new Exception('Invalid Membership Type');
|
||||
}
|
||||
$values['membership_type_id'] = $membershipTypeId;
|
||||
break;
|
||||
|
||||
case 'status_id':
|
||||
if (!CRM_Utils_Array::value($value, CRM_Member_PseudoConstant::membershipStatus())) {
|
||||
throw new Exception('Invalid Membership Status Id');
|
||||
}
|
||||
$values[$key] = $value;
|
||||
break;
|
||||
|
||||
case 'membership_status':
|
||||
$membershipStatusId = CRM_Utils_Array::key(ucfirst($value),
|
||||
CRM_Member_PseudoConstant::membershipStatus()
|
||||
);
|
||||
if ($membershipStatusId) {
|
||||
if (!empty($values['status_id']) &&
|
||||
$membershipStatusId != $values['status_id']
|
||||
) {
|
||||
throw new Exception('Mismatched membership Status and Membership Status Id');
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new Exception('Invalid Membership Status');
|
||||
}
|
||||
$values['status_id'] = $membershipStatusId;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
_civicrm_api3_custom_format_params($params, $values, 'Membership');
|
||||
|
||||
if ($create) {
|
||||
// CRM_Member_BAO_Membership::create() handles membership_start_date,
|
||||
// membership_end_date and membership_source. So, if $values contains
|
||||
// membership_start_date, membership_end_date or membership_source,
|
||||
// convert it to start_date, end_date or source
|
||||
$changes = array(
|
||||
'membership_start_date' => 'start_date',
|
||||
'membership_end_date' => 'end_date',
|
||||
'membership_source' => 'source',
|
||||
);
|
||||
|
||||
foreach ($changes as $orgVal => $changeVal) {
|
||||
if (isset($values[$orgVal])) {
|
||||
$values[$changeVal] = $values[$orgVal];
|
||||
unset($values[$orgVal]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
217
sites/all/modules/civicrm/CRM/Member/Info.php
Normal file
217
sites/all/modules/civicrm/CRM/Member/Info.php
Normal file
|
@ -0,0 +1,217 @@
|
|||
<?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 |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class introduces component to the system and provides all the
|
||||
* information about it. It needs to extend CRM_Core_Component_Info
|
||||
* abstract class.
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
class CRM_Member_Info extends CRM_Core_Component_Info {
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected $keyword = 'member';
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* Provides base information about the component.
|
||||
* Needs to be implemented in component's information
|
||||
* class.
|
||||
*
|
||||
* @return array
|
||||
* collection of required component settings
|
||||
*/
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getInfo() {
|
||||
return array(
|
||||
'name' => 'CiviMember',
|
||||
'translatedName' => ts('CiviMember'),
|
||||
'title' => ts('CiviCRM Membership Engine'),
|
||||
'search' => 1,
|
||||
'showActivitiesInCore' => 1,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* Provides permissions that are used by component.
|
||||
* Needs to be implemented in component's information
|
||||
* class.
|
||||
*
|
||||
* NOTE: if using conditionally permission return,
|
||||
* implementation of $getAllUnconditionally is required.
|
||||
*
|
||||
* @param bool $getAllUnconditionally
|
||||
* @param bool $descriptions
|
||||
* Whether to return permission descriptions
|
||||
*
|
||||
* @return array|null
|
||||
* collection of permissions, null if none
|
||||
*/
|
||||
public function getPermissions($getAllUnconditionally = FALSE, $descriptions = FALSE) {
|
||||
$permissions = array(
|
||||
'access CiviMember' => array(
|
||||
ts('access CiviMember'),
|
||||
ts('View memberships'),
|
||||
),
|
||||
'edit memberships' => array(
|
||||
ts('edit memberships'),
|
||||
ts('Create and update memberships'),
|
||||
),
|
||||
'delete in CiviMember' => array(
|
||||
ts('delete in CiviMember'),
|
||||
ts('Delete memberships'),
|
||||
),
|
||||
);
|
||||
|
||||
if (!$descriptions) {
|
||||
foreach ($permissions as $name => $attr) {
|
||||
$permissions[$name] = array_shift($attr);
|
||||
}
|
||||
}
|
||||
|
||||
return $permissions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* Provides information about user dashboard element
|
||||
* offered by this component.
|
||||
*
|
||||
* @return array|null
|
||||
* collection of required dashboard settings,
|
||||
* null if no element offered
|
||||
*/
|
||||
/**
|
||||
* @return array|null
|
||||
*/
|
||||
public function getUserDashboardElement() {
|
||||
return array(
|
||||
'name' => ts('Memberships'),
|
||||
'title' => ts('Your Membership(s)'),
|
||||
// this is CiviContribute specific permission, since
|
||||
// there is no permission that could be checked for
|
||||
// CiviMember
|
||||
'perm' => array('make online contributions'),
|
||||
'weight' => 30,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* Provides information about user dashboard element
|
||||
* offered by this component.
|
||||
*
|
||||
* @return array|null
|
||||
* collection of required dashboard settings,
|
||||
* null if no element offered
|
||||
*/
|
||||
/**
|
||||
* @return array|null
|
||||
*/
|
||||
public function registerTab() {
|
||||
return array(
|
||||
'title' => ts('Memberships'),
|
||||
'url' => 'membership',
|
||||
'weight' => 30,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* Provides information about advanced search pane
|
||||
* offered by this component.
|
||||
*
|
||||
* @return array|null
|
||||
* collection of required pane settings,
|
||||
* null if no element offered
|
||||
*/
|
||||
/**
|
||||
* @return array|null
|
||||
*/
|
||||
public function registerAdvancedSearchPane() {
|
||||
return array(
|
||||
'title' => ts('Memberships'),
|
||||
'weight' => 30,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* Provides potential activity types that this
|
||||
* component might want to register in activity history.
|
||||
* Needs to be implemented in component's information
|
||||
* class.
|
||||
*
|
||||
* @return array|null
|
||||
* collection of activity types
|
||||
*/
|
||||
/**
|
||||
* @return array|null
|
||||
*/
|
||||
public function getActivityTypes() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* add shortcut to Create New.
|
||||
* @param $shortCuts
|
||||
* @param $newCredit
|
||||
*/
|
||||
public function creatNewShortcut(&$shortCuts, $newCredit) {
|
||||
if (CRM_Core_Permission::check('access CiviMember') &&
|
||||
CRM_Core_Permission::check('edit memberships')
|
||||
) {
|
||||
$shortCut[] = array(
|
||||
'path' => 'civicrm/member/add',
|
||||
'query' => "reset=1&action=add&context=standalone",
|
||||
'ref' => 'new-membership',
|
||||
'title' => ts('Membership'),
|
||||
);
|
||||
if ($newCredit) {
|
||||
$title = ts('Membership') . '<br /> (' . ts('credit card') . ')';
|
||||
$shortCut[0]['shortCuts'][] = array(
|
||||
'path' => 'civicrm/member/add',
|
||||
'query' => "reset=1&action=add&context=standalone&mode=live",
|
||||
'ref' => 'new-membership-cc',
|
||||
'title' => $title,
|
||||
);
|
||||
}
|
||||
$shortCuts = array_merge($shortCuts, $shortCut);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
73
sites/all/modules/civicrm/CRM/Member/Page/AJAX.php
Normal file
73
sites/all/modules/civicrm/CRM/Member/Page/AJAX.php
Normal 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);
|
||||
}
|
||||
|
||||
}
|
461
sites/all/modules/civicrm/CRM/Member/Page/DashBoard.php
Normal file
461
sites/all/modules/civicrm/CRM/Member/Page/DashBoard.php
Normal 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();
|
||||
}
|
||||
|
||||
}
|
181
sites/all/modules/civicrm/CRM/Member/Page/MembershipStatus.php
Normal file
181
sites/all/modules/civicrm/CRM/Member/Page/MembershipStatus.php
Normal 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';
|
||||
}
|
||||
|
||||
}
|
184
sites/all/modules/civicrm/CRM/Member/Page/MembershipType.php
Normal file
184
sites/all/modules/civicrm/CRM/Member/Page/MembershipType.php
Normal 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);
|
||||
}
|
||||
|
||||
}
|
653
sites/all/modules/civicrm/CRM/Member/Page/Tab.php
Normal file
653
sites/all/modules/civicrm/CRM/Member/Page/Tab.php
Normal 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]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
102
sites/all/modules/civicrm/CRM/Member/Page/UserDashboard.php
Normal file
102
sites/all/modules/civicrm/CRM/Member/Page/UserDashboard.php
Normal 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();
|
||||
}
|
||||
|
||||
}
|
137
sites/all/modules/civicrm/CRM/Member/PseudoConstant.php
Normal file
137
sites/all/modules/civicrm/CRM/Member/PseudoConstant.php
Normal file
|
@ -0,0 +1,137 @@
|
|||
<?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 holds all the Pseudo constants that are specific to the civimember component. This avoids
|
||||
* polluting the core class and isolates the mass mailer class
|
||||
*/
|
||||
class CRM_Member_PseudoConstant extends CRM_Core_PseudoConstant {
|
||||
|
||||
/**
|
||||
* Membership types.
|
||||
* @var array
|
||||
*/
|
||||
private static $membershipType;
|
||||
|
||||
/**
|
||||
* Membership types.
|
||||
* @var array
|
||||
*/
|
||||
private static $membershipStatus;
|
||||
|
||||
/**
|
||||
* Get all the membership types.
|
||||
*
|
||||
*
|
||||
* @param int $id
|
||||
* @param bool $force
|
||||
*
|
||||
* @return array
|
||||
* array reference of all membership types if any
|
||||
*/
|
||||
public static function membershipType($id = NULL, $force = TRUE) {
|
||||
if (!self::$membershipType || $force) {
|
||||
CRM_Core_PseudoConstant::populate(self::$membershipType,
|
||||
'CRM_Member_DAO_MembershipType',
|
||||
FALSE, 'name', 'is_active', NULL, 'weight', 'id', TRUE
|
||||
);
|
||||
}
|
||||
if ($id) {
|
||||
if (array_key_exists($id, self::$membershipType)) {
|
||||
return self::$membershipType[$id];
|
||||
}
|
||||
else {
|
||||
$result = NULL;
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
return self::$membershipType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the membership statuss.
|
||||
*
|
||||
*
|
||||
* @param int $id
|
||||
* @param null $cond
|
||||
* @param string $column
|
||||
* @param bool $force
|
||||
*
|
||||
* @param bool $allStatus
|
||||
*
|
||||
* @return array
|
||||
* array reference of all membership statuses if any
|
||||
*/
|
||||
public static function &membershipStatus($id = NULL, $cond = NULL, $column = 'name', $force = FALSE, $allStatus = FALSE) {
|
||||
if (self::$membershipStatus === NULL) {
|
||||
self::$membershipStatus = array();
|
||||
}
|
||||
|
||||
$cacheKey = $column;
|
||||
if ($cond) {
|
||||
$cacheKey .= "_{$cond}";
|
||||
}
|
||||
if (!isset(self::$membershipStatus[$cacheKey]) || $force) {
|
||||
CRM_Core_PseudoConstant::populate(self::$membershipStatus[$cacheKey],
|
||||
'CRM_Member_DAO_MembershipStatus',
|
||||
$allStatus, $column, 'is_active', $cond, 'weight'
|
||||
);
|
||||
}
|
||||
|
||||
$value = NULL;
|
||||
if ($id) {
|
||||
$value = CRM_Utils_Array::value($id, self::$membershipStatus[$cacheKey]);
|
||||
}
|
||||
else {
|
||||
$value = self::$membershipStatus[$cacheKey];
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush given pseudoconstant so it can be reread from db
|
||||
* next time it's requested.
|
||||
*
|
||||
*
|
||||
* @param bool|string $name pseudoconstant to be flushed
|
||||
*/
|
||||
public static function flush($name = 'cache') {
|
||||
if (isset(self::$$name)) {
|
||||
self::$$name = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
567
sites/all/modules/civicrm/CRM/Member/Selector/Search.php
Normal file
567
sites/all/modules/civicrm/CRM/Member/Selector/Search.php
Normal file
|
@ -0,0 +1,567 @@
|
|||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class is used to retrieve and display a range of
|
||||
* contacts that match the given criteria (specifically for
|
||||
* results of advanced search options.
|
||||
*/
|
||||
class CRM_Member_Selector_Search extends CRM_Core_Selector_Base implements CRM_Core_Selector_API {
|
||||
|
||||
/**
|
||||
* This defines two actions- View and Edit.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $_links = NULL;
|
||||
|
||||
/**
|
||||
* We use desc to remind us what that column is, name is used in the tpl
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $_columnHeaders;
|
||||
|
||||
/**
|
||||
* Properties of contact we're interested in displaying
|
||||
* @var array
|
||||
*/
|
||||
static $_properties = array(
|
||||
'contact_id',
|
||||
'membership_id',
|
||||
'contact_type',
|
||||
'sort_name',
|
||||
'membership_type',
|
||||
'join_date',
|
||||
'membership_start_date',
|
||||
'membership_end_date',
|
||||
'membership_source',
|
||||
'status_id',
|
||||
'member_is_test',
|
||||
'owner_membership_id',
|
||||
'membership_status',
|
||||
'member_campaign_id',
|
||||
);
|
||||
|
||||
/**
|
||||
* Are we restricting ourselves to a single contact
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_single = FALSE;
|
||||
|
||||
/**
|
||||
* Are we restricting ourselves to a single contact
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_limit = NULL;
|
||||
|
||||
/**
|
||||
* What context are we being invoked from
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_context = NULL;
|
||||
|
||||
/**
|
||||
* QueryParams is the array returned by exportValues called on
|
||||
* the HTML_QuickForm_Controller for that page.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $_queryParams;
|
||||
|
||||
/**
|
||||
* Represent the type of selector.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_action;
|
||||
|
||||
/**
|
||||
* The additional clause that we restrict the search with.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_memberClause = NULL;
|
||||
|
||||
/**
|
||||
* The query object.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_query;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param array $queryParams
|
||||
* Array of parameters for query.
|
||||
* @param \const|int $action - action of search basic or advanced.
|
||||
* @param string $memberClause
|
||||
* If the caller wants to further restrict the search (used in memberships).
|
||||
* @param bool $single
|
||||
* Are we dealing only with one contact?.
|
||||
* @param int $limit
|
||||
* How many memberships do we want returned.
|
||||
*
|
||||
* @param string $context
|
||||
*
|
||||
* @return \CRM_Member_Selector_Search
|
||||
*/
|
||||
public function __construct(
|
||||
&$queryParams,
|
||||
$action = CRM_Core_Action::NONE,
|
||||
$memberClause = NULL,
|
||||
$single = FALSE,
|
||||
$limit = NULL,
|
||||
$context = 'search'
|
||||
) {
|
||||
// submitted form values
|
||||
$this->_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 bool $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' => ts('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 int $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 int $action
|
||||
*
|
||||
* @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']);
|
||||
$links = self::links('all',
|
||||
$this->_isPaymentProcessor,
|
||||
$this->_accessContribution,
|
||||
$this->_key,
|
||||
$this->_context,
|
||||
$isCancelSupported
|
||||
);
|
||||
|
||||
// check permissions
|
||||
$finTypeId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $result->membership_type_id, 'financial_type_id');
|
||||
$finType = CRM_Contribute_PseudoConstant::financialType($finTypeId);
|
||||
if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()
|
||||
&& !CRM_Core_Permission::check('edit contributions of type ' . $finType)
|
||||
) {
|
||||
unset($links[CRM_Core_Action::UPDATE]);
|
||||
}
|
||||
if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() &&
|
||||
!CRM_Core_Permission::check('delete contributions of type ' . $finType)
|
||||
) {
|
||||
unset($links[CRM_Core_Action::DELETE]);
|
||||
}
|
||||
$row['action'] = CRM_Core_Action::formLink($links,
|
||||
$currentMask,
|
||||
array(
|
||||
'id' => $result->membership_id,
|
||||
'cid' => $result->contact_id,
|
||||
'cxt' => $this->_context,
|
||||
),
|
||||
ts('Renew') . '...',
|
||||
FALSE,
|
||||
'membership.selector.row',
|
||||
'Membership',
|
||||
$result->membership_id
|
||||
);
|
||||
}
|
||||
else {
|
||||
$links = self::links('view');
|
||||
$row['action'] = CRM_Core_Action::formLink($links, $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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alphabet query.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function alphabetQuery() {
|
||||
return $this->_query->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get query.
|
||||
*
|
||||
* @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');
|
||||
}
|
||||
|
||||
}
|
113
sites/all/modules/civicrm/CRM/Member/StateMachine/Search.php
Normal file
113
sites/all/modules/civicrm/CRM/Member/StateMachine/Search.php
Normal file
|
@ -0,0 +1,113 @@
|
|||
<?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_StateMachine_Search extends CRM_Core_StateMachine {
|
||||
|
||||
/**
|
||||
* The task that the wizard is currently processing.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_task;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param object $controller
|
||||
* @param \const|int $action
|
||||
*/
|
||||
public function __construct($controller, $action = CRM_Core_Action::NONE) {
|
||||
parent::__construct($controller, $action);
|
||||
|
||||
$this->_pages = array();
|
||||
|
||||
$this->_pages['CRM_Member_Form_Search'] = NULL;
|
||||
list($task, $result) = $this->taskName($controller, 'Search');
|
||||
$this->_task = $task;
|
||||
|
||||
if (is_array($task)) {
|
||||
foreach ($task as $t) {
|
||||
$this->_pages[$t] = NULL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$this->_pages[$task] = NULL;
|
||||
}
|
||||
if ($result) {
|
||||
$this->_pages['CRM_Member_Form_Task_Result'] = NULL;
|
||||
}
|
||||
$this->addSequentialPages($this->_pages, $action);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the form name based on the action. This allows us
|
||||
* to avoid using conditional state machine, much more efficient
|
||||
* and simpler
|
||||
*
|
||||
* @param CRM_Core_Controller $controller
|
||||
* The controller object.
|
||||
*
|
||||
* @param string $formName
|
||||
*
|
||||
* @return string
|
||||
* the name of the form that will handle the task
|
||||
*/
|
||||
public function taskName($controller, $formName = 'Search') {
|
||||
// total hack, check POST vars and then session to determine stuff
|
||||
$value = CRM_Utils_Array::value('task', $_POST);
|
||||
if (!isset($value)) {
|
||||
$value = $this->_controller->get('task');
|
||||
}
|
||||
$this->_controller->set('task', $value);
|
||||
return CRM_Member_Task::getTask($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the form name of the task.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTaskFormName() {
|
||||
return CRM_Utils_String::getClassName($this->_task);
|
||||
}
|
||||
|
||||
/**
|
||||
* Since this is a state machine for search and we want to come back to the same state
|
||||
* we dont want to issue a reset of the state session when we are done processing a task
|
||||
*/
|
||||
public function shouldReset() {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
196
sites/all/modules/civicrm/CRM/Member/Task.php
Normal file
196
sites/all/modules/civicrm/CRM/Member/Task.php
Normal file
|
@ -0,0 +1,196 @@
|
|||
<?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 to represent the actions that can be performed on a group of
|
||||
* contacts (CiviMember)
|
||||
* used by the search forms
|
||||
*
|
||||
*/
|
||||
class CRM_Member_Task {
|
||||
const DELETE_MEMBERS = 1, PRINT_MEMBERS = 2, EXPORT_MEMBERS = 3, EMAIL_CONTACTS = 4, BATCH_MEMBERS = 5;
|
||||
|
||||
/**
|
||||
* The task array
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $_tasks = NULL;
|
||||
|
||||
/**
|
||||
* The optional task array
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $_optionalTasks = NULL;
|
||||
|
||||
/**
|
||||
* These tasks are the core set of tasks that the user can perform
|
||||
* on a contact / group of contacts
|
||||
*
|
||||
* @return array
|
||||
* the set of tasks for a group of contacts
|
||||
*/
|
||||
public static function &tasks() {
|
||||
if (!(self::$_tasks)) {
|
||||
self::$_tasks = array(
|
||||
1 => array(
|
||||
'title' => ts('Delete memberships'),
|
||||
'class' => 'CRM_Member_Form_Task_Delete',
|
||||
'result' => FALSE,
|
||||
),
|
||||
2 => array(
|
||||
'title' => ts('Print selected rows'),
|
||||
'class' => 'CRM_Member_Form_Task_Print',
|
||||
'result' => FALSE,
|
||||
),
|
||||
3 => array(
|
||||
'title' => ts('Export members'),
|
||||
'class' => array(
|
||||
'CRM_Export_Form_Select',
|
||||
'CRM_Export_Form_Map',
|
||||
),
|
||||
'result' => FALSE,
|
||||
),
|
||||
4 => array(
|
||||
'title' => ts('Email - send now'),
|
||||
'class' => 'CRM_Member_Form_Task_Email',
|
||||
'result' => TRUE,
|
||||
),
|
||||
5 => array(
|
||||
'title' => ts('Update multiple memberships'),
|
||||
'class' => array(
|
||||
'CRM_Member_Form_Task_PickProfile',
|
||||
'CRM_Member_Form_Task_Batch',
|
||||
),
|
||||
'result' => TRUE,
|
||||
),
|
||||
6 => array(
|
||||
'title' => ts('Mailing labels - print'),
|
||||
'class' => array(
|
||||
'CRM_Member_Form_Task_Label',
|
||||
),
|
||||
'result' => TRUE,
|
||||
),
|
||||
7 => array(
|
||||
'title' => ts('Print/merge document for memberships'),
|
||||
'class' => 'CRM_Member_Form_Task_PDFLetter',
|
||||
'result' => FALSE,
|
||||
),
|
||||
);
|
||||
|
||||
//CRM-4418, check for delete
|
||||
if (!CRM_Core_Permission::check('delete in CiviMember')) {
|
||||
unset(self::$_tasks[1]);
|
||||
}
|
||||
//CRM-12920 - check for edit permission
|
||||
if (!CRM_Core_Permission::check('edit memberships')) {
|
||||
unset(self::$_tasks[5]);
|
||||
}
|
||||
|
||||
CRM_Utils_Hook::searchTasks('membership', self::$_tasks);
|
||||
asort(self::$_tasks);
|
||||
}
|
||||
|
||||
return self::$_tasks;
|
||||
}
|
||||
|
||||
/**
|
||||
* These tasks are the core set of task titles
|
||||
* on members
|
||||
*
|
||||
* @return array
|
||||
* the set of task titles
|
||||
*/
|
||||
public static function &taskTitles() {
|
||||
self::tasks();
|
||||
$titles = array();
|
||||
foreach (self::$_tasks as $id => $value) {
|
||||
$titles[$id] = $value['title'];
|
||||
}
|
||||
return $titles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show tasks selectively based on the permission level
|
||||
* of the user
|
||||
*
|
||||
* @param int $permission
|
||||
*
|
||||
* @return array
|
||||
* set of tasks that are valid for the user
|
||||
*/
|
||||
public static function &permissionedTaskTitles($permission) {
|
||||
$tasks = array();
|
||||
if (($permission == CRM_Core_Permission::EDIT)
|
||||
|| CRM_Core_Permission::check('edit memberships')
|
||||
) {
|
||||
$tasks = self::taskTitles();
|
||||
}
|
||||
else {
|
||||
$tasks = array(
|
||||
3 => self::$_tasks[3]['title'],
|
||||
4 => self::$_tasks[4]['title'],
|
||||
);
|
||||
//CRM-4418,
|
||||
if (CRM_Core_Permission::check('delete in CiviMember')) {
|
||||
$tasks[1] = self::$_tasks[1]['title'];
|
||||
}
|
||||
}
|
||||
return $tasks;
|
||||
}
|
||||
|
||||
/**
|
||||
* These tasks are the core set of tasks that the user can perform
|
||||
* on members
|
||||
*
|
||||
* @param int $value
|
||||
*
|
||||
* @return array
|
||||
* the set of tasks for a group of members
|
||||
*/
|
||||
public static function getTask($value) {
|
||||
self::tasks();
|
||||
if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) {
|
||||
// make the print task by default
|
||||
$value = 2;
|
||||
}
|
||||
return array(
|
||||
self::$_tasks[$value]['class'],
|
||||
self::$_tasks[$value]['result'],
|
||||
);
|
||||
}
|
||||
|
||||
}
|
109
sites/all/modules/civicrm/CRM/Member/Tokens.php
Normal file
109
sites/all/modules/civicrm/CRM/Member/Tokens.php
Normal file
|
@ -0,0 +1,109 @@
|
|||
<?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 |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class CRM_Member_Tokens
|
||||
*
|
||||
* Generate "member.*" tokens.
|
||||
*
|
||||
* This TokenSubscriber was produced by refactoring the code from the
|
||||
* scheduled-reminder system with the goal of making that system
|
||||
* more flexible. The current implementation is still coupled to
|
||||
* scheduled-reminders. It would be good to figure out a more generic
|
||||
* implementation which is not tied to scheduled reminders, although
|
||||
* that is outside the current scope.
|
||||
*/
|
||||
class CRM_Member_Tokens extends \Civi\Token\AbstractTokenSubscriber {
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct('membership', array_merge(
|
||||
array(
|
||||
'fee' => ts('Membership Fee'),
|
||||
'id' => ts('Membership ID'),
|
||||
'join_date' => ts('Membership Join Date'),
|
||||
'start_date' => ts('Membership Start Date'),
|
||||
'end_date' => ts('Membership End Date'),
|
||||
'status' => ts('Membership Status'),
|
||||
'type' => ts('Membership Type'),
|
||||
),
|
||||
CRM_Utils_Token::getCustomFieldTokens('Membership')
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function checkActive(\Civi\Token\TokenProcessor $processor) {
|
||||
// Extracted from scheduled-reminders code. See the class description.
|
||||
return
|
||||
!empty($processor->context['actionMapping'])
|
||||
&& $processor->context['actionMapping']->getEntity() === 'civicrm_membership';
|
||||
}
|
||||
|
||||
/**
|
||||
* Alter action schedule query.
|
||||
*
|
||||
* @param \Civi\ActionSchedule\Event\MailingQueryEvent $e
|
||||
*/
|
||||
public function alterActionScheduleQuery(\Civi\ActionSchedule\Event\MailingQueryEvent $e) {
|
||||
if ($e->mapping->getEntity() !== 'civicrm_membership') {
|
||||
return;
|
||||
}
|
||||
|
||||
// FIXME: `select('e.*')` seems too broad.
|
||||
$e->query
|
||||
->select('e.*')
|
||||
->select('mt.minimum_fee as fee, e.id as id , e.join_date, e.start_date, e.end_date, ms.name as status, mt.name as type')
|
||||
->join('mt', "!casMailingJoinType civicrm_membership_type mt ON e.membership_type_id = mt.id")
|
||||
->join('ms', "!casMailingJoinType civicrm_membership_status ms ON e.status_id = ms.id");
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function evaluateToken(\Civi\Token\TokenRow $row, $entity, $field, $prefetch = NULL) {
|
||||
$actionSearchResult = $row->context['actionSearchResult'];
|
||||
|
||||
if (in_array($field, array('start_date', 'end_date', 'join_date'))) {
|
||||
$row->tokens($entity, $field, \CRM_Utils_Date::customFormat($actionSearchResult->$field));
|
||||
}
|
||||
elseif (isset($actionSearchResult->$field)) {
|
||||
$row->tokens($entity, $field, $actionSearchResult->$field);
|
||||
}
|
||||
elseif ($cfID = \CRM_Core_BAO_CustomField::getKeyID($field)) {
|
||||
$row->customToken($entity, $cfID, $actionSearchResult->entity_id);
|
||||
}
|
||||
else {
|
||||
$row->tokens($entity, $field, '');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
89
sites/all/modules/civicrm/CRM/Member/xml/Menu/Member.xml
Normal file
89
sites/all/modules/civicrm/CRM/Member/xml/Menu/Member.xml
Normal file
|
@ -0,0 +1,89 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1" ?>
|
||||
|
||||
<menu>
|
||||
<item>
|
||||
<path>civicrm/member</path>
|
||||
<title>CiviMember Dashboard</title>
|
||||
<page_callback>CRM_Member_Page_DashBoard</page_callback>
|
||||
<access_arguments>access CiviMember</access_arguments>
|
||||
<page_type>1</page_type>
|
||||
<weight>700</weight>
|
||||
<component>CiviMember</component>
|
||||
</item>
|
||||
<item>
|
||||
<path>civicrm/member/add</path>
|
||||
<title>New Membership</title>
|
||||
<page_callback>CRM_Member_Page_Tab</page_callback>
|
||||
<path_arguments>action=add</path_arguments>
|
||||
<access_arguments>access CiviMember</access_arguments>
|
||||
<component>CiviMember</component>
|
||||
</item>
|
||||
<item>
|
||||
<path>civicrm/admin/member/membershipType</path>
|
||||
<title>Membership Types</title>
|
||||
<page_callback>CRM_Member_Page_MembershipType</page_callback>
|
||||
<desc>Define the types of memberships you want to offer. For each type, you can specify a 'name' (Gold Member, Honor Society Member...), a description, duration, and a minimum fee.</desc>
|
||||
<adminGroup>CiviMember</adminGroup>
|
||||
<icon>admin/small/membership_type.png</icon>
|
||||
<weight>370</weight>
|
||||
</item>
|
||||
<item>
|
||||
<path>civicrm/admin/member/membershipStatus</path>
|
||||
<title>Membership Status Rules</title>
|
||||
<page_callback>CRM_Member_Page_MembershipStatus</page_callback>
|
||||
<desc>Status 'rules' define the current status for a membership based on that membership's start and end dates. You can adjust the default status options and rules as needed to meet your needs.</desc>
|
||||
<adminGroup>CiviMember</adminGroup>
|
||||
<icon>admin/small/membership_status.png</icon>
|
||||
<weight>380</weight>
|
||||
</item>
|
||||
<item>
|
||||
<path>civicrm/admin/setting/preferences/member</path>
|
||||
<title>CiviMember Component Settings</title>
|
||||
<page_callback>CRM_Admin_Form_Preferences_Member</page_callback>
|
||||
<desc>Configure global CiviMember behaviors.</desc>
|
||||
<access_arguments>access CiviMember,administer CiviCRM</access_arguments>
|
||||
<adminGroup>CiviMember</adminGroup>
|
||||
<weight>390</weight>
|
||||
</item>
|
||||
<item>
|
||||
<path>civicrm/contact/view/membership</path>
|
||||
<path_arguments>force=1,cid=%%cid%%</path_arguments>
|
||||
<title>Memberships</title>
|
||||
<page_callback>CRM_Member_Page_Tab</page_callback>
|
||||
<weight>2</weight>
|
||||
</item>
|
||||
<item>
|
||||
<path>civicrm/membership/view</path>
|
||||
<title>Memberships</title>
|
||||
<page_callback>CRM_Member_Form_MembershipView</page_callback>
|
||||
<access_arguments>access CiviMember</access_arguments>
|
||||
<weight>390</weight>
|
||||
</item>
|
||||
<item>
|
||||
<path>civicrm/member/search</path>
|
||||
<title>Find Memberships</title>
|
||||
<page_callback>CRM_Member_Controller_Search</page_callback>
|
||||
<access_arguments>access CiviMember</access_arguments>
|
||||
<page_type>1</page_type>
|
||||
<weight>710</weight>
|
||||
</item>
|
||||
<item>
|
||||
<path>civicrm/member/import</path>
|
||||
<title>Import Memberships</title>
|
||||
<page_callback>CRM_Member_Import_Controller</page_callback>
|
||||
<access_arguments>access CiviMember,edit memberships</access_arguments>
|
||||
<page_type>1</page_type>
|
||||
<weight>720</weight>
|
||||
</item>
|
||||
<item>
|
||||
<path>civicrm/ajax/memType</path>
|
||||
<page_callback>CRM_Member_Page_AJAX::getMemberTypeDefaults</page_callback>
|
||||
<access_arguments>access CiviCRM,access CiviMember</access_arguments>
|
||||
</item>
|
||||
<item>
|
||||
<path>civicrm/admin/member/membershipType/add</path>
|
||||
<title>Membership Types</title>
|
||||
<page_callback>CRM_Member_Form_MembershipType</page_callback>
|
||||
<access_arguments>access CiviMember,administer CiviCRM</access_arguments>
|
||||
</item>
|
||||
</menu>
|
Loading…
Add table
Add a link
Reference in a new issue