Commit 9b10ad88 authored by ErikHommel's avatar ErikHommel
Browse files

toevoegen lidmaatschap types en activity types + custom velden voor archie en salesforce id

parent ad2ea287
<?php
use CRM_Acqconfigitems_ExtensionUtil as E;
/**
* Class for ActivityType configuration
*
* @author Erik Hommel (CiviCooP) <erik.hommel@civicoop.org>
* @date 10 Jul 2019
* @license AGPL-3.0
*/
class CRM_Acqconfigitems_ActivityType extends CRM_Acqconfigitems_OptionValue {
/**
* Overridden parent method to validate params for create
*
* @param $params
* @throws API_Exception when missing mandatory params
*/
protected function validateCreateParams($params) {
if (!isset($params['name']) || empty($params['name'])) {
throw new API_Exception(E::ts('Missing mandatory param name in ') . __METHOD__, 9925);
}
$this->_apiParams = $params;
try {
$this->_apiParams['option_group_id'] = $this->getOptionGroupId();
} catch (CiviCRM_API3_Exception $ex) {
throw new API_Exception(E::ts('Unable to find option group for activity_type in ') . __METHOD__
. E::ts(', contact your system administrator'), 9926);
}
}
/**
* Method to get option group id for activity type
*
* @return array
* @throws CiviCRM_API3_Exception
*/
public function getOptionGroupId() {
return civicrm_api3('OptionGroup', 'Getvalue', ['name' => 'activity_type', 'return' => 'id']);
}
}
\ No newline at end of file
......@@ -20,6 +20,7 @@ class CRM_Acqconfigitems_ConfigItems {
* CRM_Acqconfigitem_ConfigItems constructor.
*
* @throws API_Exception
* @throws CiviCRM_API3_Exception
*/
public function __construct() {
// Get the directory of the extension based on the name.
......@@ -32,12 +33,15 @@ class CRM_Acqconfigitems_ConfigItems {
}
$this->_resourcesPath = $resourcesPath;
$this->setContactTypes();
$this->setActivityTypes();
$this->setRelationshipTypes();
$this->setOptionGroups();
$this->setGroups();
$this->setMembershipTypes();
//$this->setTags();
// customData as last one because it might need one of the previous ones (option group, relationship types, activity types)
$this->setCustomData();
// after custom data so we have them all
}
/**
......@@ -54,6 +58,47 @@ class CRM_Acqconfigitems_ConfigItems {
return self::$_singleton;
}
/**
* Method to create activity types
*
* @throws API_Exception when resource file not found
* @access protected
*/
protected function setActivityTypes() {
$jsonFile = $this->_resourcesPath . 'activity_types.json';
if (!file_exists($jsonFile)) {
throw new API_Exception(E::ts('Could not load activity_types configuration file for extension,
activity your system administrator!'), 9932);
}
$activityTypesJson = file_get_contents($jsonFile);
$activityTypes = json_decode($activityTypesJson, TRUE);
foreach ($activityTypes as $name => $activityTypeParams) {
$activityType = new CRM_Acqconfigitems_ActivityType();
$activityType->create($activityTypeParams);
}
}
/**
* Method to create membership types
*
* @throws API_Exception when resource file not found
* @access protected
*/
protected function setMembershipTypes() {
$jsonFile = $this->_resourcesPath . 'membership_types.json';
if (!file_exists($jsonFile)) {
throw new API_Exception(E::ts('Could not load membership_types configuration file for extension,
activity your system administrator!'), 9932);
}
$membershipTypesJson = file_get_contents($jsonFile);
$membershipTypes = json_decode($membershipTypesJson, TRUE);
foreach ($membershipTypes as $name => $membershipTypeParams) {
$membershipType = new CRM_Acqconfigitems_MembershipType();
$membershipType->create($membershipTypeParams);
}
}
/**
* Method to create option groups
*
......@@ -167,26 +212,6 @@ class CRM_Acqconfigitems_ConfigItems {
$relationshipType->disableRelationshipType("Benefits Specialist is");
}
/**
* Method to create activity types
*
* @throws API_Exception when resource file not found
* @access protected
*/
protected function setActivityTypes() {
$jsonFile = $this->_resourcesPath . 'activity_types.json';
if (!file_exists($jsonFile)) {
throw new API_Exception(E::ts('Could not load activity_types configuration file for extension,
activity your system administrator!'), 9932);
}
$activityTypesJson = file_get_contents($jsonFile);
$activityTypes = json_decode($activityTypesJson, TRUE);
foreach ($activityTypes as $name => $activityTypeParams) {
$activityType = new CRM_Acqconfigitems_ActivityType();
$activityType->create($activityTypeParams);
}
}
/**
* Method to create campaign types
*
......
<?php
use CRM_Acqconfigitems_ExtensionUtil as E;
/**
* Class for Membership Type configuration
*
* @author Erik Hommel (CiviCooP) <erik.hommel@civicoop.org>
* @date 10 July 2019
* @license AGPL-3.0
*/
class CRM_Acqconfigitems_MembershipType {
protected $_apiParams = [];
/**
* Method to validate params for create
*
* @param $params
* @throws Exception when missing mandatory params
*/
protected function validateCreateParams($params) {
if (!isset($params['name']) || empty($params['name'])) {
throw new Exception('Missing mandatory param name in ' . __METHOD__);
}
$this->_apiParams = $params;
// members always of Acquire default organization
$this->_apiParams['member_of_contact_id'] = CRM_Acqgeneriek_AcqConfig::singleton()->getAcqContactId();
}
/**
* Method to create membership type
*
* @param array $params
* @return mixed
* @throws Exception when error from API MembershipType Create
*/
public function create($params) {
$this->validateCreateParams($params);
$existing = $this->getWithName($this->_apiParams['name']);
if (isset($existing['id'])) {
$this->_apiParams['id'] = $existing['id'];
}
if (!isset($this->_apiParams['label']) || empty($this->_apiParams['label'])) {
$this->_apiParams['label'] = CRM_Acqconfigitems_Utils::buildLabelFromName($this->_apiParams['name']);
}
// if financial type, retrieve financial type id
if (isset($this->_apiParams['financial_type'])) {
$financialTypeId = $this->getFinancialTypeIdWithName($this->_apiParams['financial_type']);
if ($financialTypeId) {
$this->_apiParams['financial_type_id'] = $financialTypeId;
unset($this->_apiParams['financial_type']);
}
}
// if relationship_type, retrieve relationship type id with names
if (isset($this->_apiParams['relationship_type_id'])) {
$relationshipTypeNames = $this->_apiParams['relationship_type_id'];
if (!is_array($relationshipTypeNames)) {
$relationshipTypeNames = [$relationshipTypeNames];
}
$this->_apiParams['relationship_type_id'] = [];
$this->_apiParams['relationship_direction'] = [];
foreach($relationshipTypeNames as $relationshipTypeName) {
$relationshipType = $this->getRelationshipTypeIdWithName($relationshipTypeName);
if ($relationshipType) {
list ($relTypeId, $relTypeDir) = $relationshipType;
$this->_apiParams['relationship_type_id'][] = $relTypeId;
$this->_apiParams['relationship_direction'][] = $relTypeDir;
}
}
}
$this->_apiParams['is_active'] = 1;
try {
civicrm_api3('MembershipType', 'Create', $this->_apiParams);
}
catch (CiviCRM_API3_Exception $ex) {
throw new Exception(E::ts('Could not create or update membership type with name ') . $this->_apiParams['name']
. E::ts(' in ') . __METHOD__ . E::ts(', error from API MembershipType Create: ') . $ex->getMessage());
}
}
/**
* Method to get membership type with name
*
* @param string $membershipTypeName
* @return array|bool
* @access public
* @static
*/
public function getWithName($membershipTypeName) {
try {
return civicrm_api3('MembershipType', 'Getsingle', ['name' => $membershipTypeName]);
}
catch (CiviCRM_API3_Exception $ex) {
return FALSE;
}
}
/**
* Method to disable membership type
*
* @param $membershipTypeName
*/
public function disableMembershipType($membershipTypeName) {
if (!empty($membershipTypeName)) {
// catch any errors and ignore (disabling can be done manually if problems)
try {
// get membership type with name
$membershipTypeId = civicrm_api3('MembershipType', 'getvalue', ['name' => $membershipTypeName, 'return' => 'id']);
$sqlMembershipType = "UPDATE civicrm_membership_type SET is_active = %1 WHERE id = %2";
CRM_Core_DAO::executeQuery($sqlMembershipType, [
1 => [0, 'Integer'],
2 => [$membershipTypeId, 'Integer'],
]);
}
catch (CiviCRM_API3_Exception $ex) {
}
}
}
/**
* Method to enable membership type
*
* @param $membershipTypeName
*/
public function enableMembershipType($membershipTypeName) {
if (!empty($membershipTypeName)) {
// catch any errors and ignore (disabling can be done manually if problems)
try {
// get membership type with name
$membershipTypeId = civicrm_api3('MembershipType', 'getvalue', ['name' => $membershipTypeName, 'return' => 'id']);
$sqlMembershipType = "UPDATE civicrm_membership_type SET is_active = %1 WHERE id = %2";
CRM_Core_DAO::executeQuery($sqlMembershipType, [
1 => [1, 'Integer'],
2 => [$membershipTypeId, 'Integer'],
]);
}
catch (CiviCRM_API3_Exception $ex) {
}
}
}
/**
* Method to uninstall membership type
*
* @param $membershipTypeName
*/
public function uninstallMembershipType($membershipTypeName) {
if (!empty($membershipTypeName)) {
// catch any errors and ignore (disabling can be done manually if problems)
try {
// get membership type with name
$membershipTypeId = civicrm_api3('MembershipType', 'getvalue', ['name' => $membershipTypeName, 'return' => 'id']);
civicrm_api3('MembershipType', 'delete', ['id' => $membershipTypeId]);
}
catch (CiviCRM_API3_Exception $ex) {
}
}
}
/**
* Method to get the financial type id with name
*
* @param $name
* @return bool|int
*/
public function getFinancialTypeIdWithName($name) {
$query = "SELECT id FROM civicrm_financial_type WHERE name = %1";
$financialTypeId = CRM_Core_DAO::singleValueQuery($query, [1 => [$name, 'String']]);
if ($financialTypeId) {
return $financialTypeId;
}
return FALSE;
}
/**
* Method to get the relationship type id with name_a_b and name_b_a
*
* @param string $name
* @return false|array(relationship_id and a_b|b_a)
*/
public function getRelationshipTypeIdWithName($name) {
$query = "
SELECT id, 'a_b' as direction FROM civicrm_relationship_type WHERE name_a_b = %1
UNION
SELECT id, 'b_a' as direction FROM civicrm_relationship_type WHERE name_b_a = %1
";
$dao = CRM_Core_DAO::executeQuery($query, [1 => [$name, 'String']]);
if ($dao->fetch()) {
return [$dao->id, $dao->direction];
}
return FALSE;
}
}
{
"acq_interne_taak":
{
"name": "acq_interne_taak",
"label":"Interne Taak"
}
}
\ No newline at end of file
......@@ -76,6 +76,30 @@
"is_active": 1,
"is_required": 0,
"weight": 60
},
"acq_archie_id": {
"name": "acq_archie_id",
"column_name": "acq_archie_id",
"label": "ID in Archie",
"data_type": "String",
"html_type": "Text",
"is_searchable": 1,
"is_view": 1,
"is_active": 1,
"is_required": 0,
"weight": 70
},
"acq_salesforce_id": {
"name": "acq_salesforce_id",
"column_name": "acq_salesforce_id",
"label": "ID in Salesforce",
"data_type": "String",
"html_type": "Text",
"is_searchable": 1,
"is_view": 1,
"is_active": 1,
"is_required": 0,
"weight": 80
}
}
}
......
{
"Bedrijfslid":
{
"name": "Bedrijfslid",
"description":"Bedrijf is lid, werknemers van het bedrijf zijn gerelateerde leden.",
"domain_id": 1,
"financial_type": "Contributie",
"duration_unit": "year",
"duration_interval": 1,
"period_type": "rolling",
"relationship_type_id": ["Employer of", "Employee of"],
"weight": 1,
"is_active": 1
},
"Persoonslid":
{
"name": "Persoonslid",
"description":"Persoon die individueel lid is.",
"domain_id": 1,
"financial_type": "Contributie",
"duration_unit": "year",
"duration_interval": 1,
"period_type": "rolling",
"weight": 1,
"is_active": 1
}
}
\ No newline at end of file
......@@ -20,6 +20,10 @@
<compatibility>
<ver>5.12</ver>
</compatibility>
<requires>
<ext>de.systopia.identitytracker</ext>
<ext>acqgeneriek</ext>
</requires>
<comments>Extension is being developed</comments>
<civix>
<namespace>CRM/Acqconfigitems</namespace>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment