Commit ada0d440 authored by jaapjansma's avatar jaapjansma
Browse files

added relationships for membership type

parent 41f7579b
......@@ -34,6 +34,9 @@ class CRM_Civiconfig_Entity_MembershipType extends CRM_Civiconfig_Entity {
// get duration unit and interval
$this->getDuration($params, $existing);
// get relationship types
$this->getRelationshipTypes($params, $existing);
if (empty($params['description'])) {
$params['description'] = CRM_Civiconfig_Utils::buildLabelFromName($params['name']);
}
......@@ -41,6 +44,27 @@ class CRM_Civiconfig_Entity_MembershipType extends CRM_Civiconfig_Entity {
parent::prepareParams($params, $existing);
}
/**
* Method to retrieve or relationship types
*
* @param array $params params that will be used for entity creation
* @param array $existing
*/
private function getRelationshipTypes(array &$params, array $existing = []) {
if (!isset($params['relationship_type']) || !is_array($params['relationship_type'])) {
return;
}
foreach($params['relationship_type'] as $rel_type) {
try {
$params['relationship_type_id'][] = civicrm_api3('RelationshipType', 'getvalue', array('name_a_b' => $rel_type, 'return' => 'id'));
$params['relationship_direction'][] = 'a_b';
} catch (CiviCRM_API3_Exception $e) {
$params['relationship_type_id'] = civicrm_api3('RelationshipType', 'getvalue', array('name_b_a' => $rel_type, 'return' => 'id'));
$params['relationship_direction'][] = 'b_a';
}
}
}
/**
* Method to retrieve or default duration unit and interval for a membership type (required by api)
* Rules:
......@@ -197,4 +221,4 @@ class CRM_Civiconfig_Entity_MembershipType extends CRM_Civiconfig_Entity {
$params = array(1 => array($visibility, 'String'), 2 => array($membershipTypeId, 'Integer'));
CRM_Core_DAO::executeQuery($query, $params);
}
}
\ No newline at end of file
}
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