}
if (!empty($relType['id'])) {
$roleDetails['id'] = $relType['id'];
- $roleDetails['direction'] = 'a_b';
+ $roleDetails['direction'] = 'b_a';
}
// Check if its a b_a label
try {
}
else {
$roleDetails['id'] = $relTypeBa['id'];
- $roleDetails['direction'] = 'b_a';
+ $roleDetails['direction'] = 'a_b';
}
}
$caseRoles[$roleDetails['id']] = $roleDetails;
}
elseif ($dao instanceof CRM_Contact_DAO_RelationshipType) {
/** @var $dao CRM_Contact_DAO_RelationshipType */
- $count = CRM_Case_XMLRepository::singleton()
- ->getRelationshipReferenceCount($dao->label_a_b);
+
+ // Need to look both directions, but no need to translate case role
+ // direction from XML perspective to client-based perspective
+ $xmlRepo = CRM_Case_XMLRepository::singleton();
+ $count = $xmlRepo->getRelationshipReferenceCount($dao->label_a_b);
+ if ($dao->label_a_b != $dao->label_b_a) {
+ $count += $xmlRepo->getRelationshipReferenceCount($dao->label_b_a);
+ }
if ($count > 0) {
$result[] = [
'name' => 'casetypexml:relationships',
*/
public static $activityTypes = NULL;
- /**
- * FIXME: This does *NOT* belong in a static property, but we're too late in
- * the 4.5-cycle to do the necessary cleanup.
- *
- * Format is array(int $id => string $relTypeCname).
- *
- * @var array|null
- */
- public static $relationshipTypes = NULL;
-
/**
* @param $caseType
*
}
/**
+ * Get all relationship type labels
+ *
+ * TODO: These should probably be names, but under legacy behavior this has
+ * been labels.
+ *
+ * @param bool $fromXML
+ * Is this to be used for lookup of values from XML?
+ * Relationships are recorded in XML from the perspective of the non-client
+ * while relationships in the UI and everywhere else are from the
+ * perspective of the client. Since the XML can't be expected to be
+ * switched, the direction needs to be translated.
* @return array
*/
- public function &allRelationshipTypes() {
- if (self::$relationshipTypes === NULL) {
+ public function &allRelationshipTypes($fromXML = FALSE) {
+ if (!isset(Civi::$statics[__CLASS__]['reltypes'][$fromXML])) {
$relationshipInfo = CRM_Core_PseudoConstant::relationshipType('label', TRUE);
- self::$relationshipTypes = [];
+ Civi::$statics[__CLASS__]['reltypes'][$fromXML] = [];
foreach ($relationshipInfo as $id => $info) {
- self::$relationshipTypes[$id . '_b_a'] = $info['label_b_a'];
+ Civi::$statics[__CLASS__]['reltypes'][$fromXML][$id . '_b_a'] = ($fromXML) ? $info['label_a_b'] : $info['label_b_a'];
if ($info['label_b_a'] !== $info['label_a_b']) {
- self::$relationshipTypes[$id . '_a_b'] = $info['label_a_b'];
+ Civi::$statics[__CLASS__]['reltypes'][$fromXML][$id . '_a_b'] = ($fromXML) ? $info['label_b_a'] : $info['label_a_b'];
}
}
}
- return self::$relationshipTypes;
+ return Civi::$statics[__CLASS__]['reltypes'][$fromXML];
}
/**
*/
public static function flushStaticCaches() {
self::$activityTypes = NULL;
- self::$relationshipTypes = NULL;
+ unset(Civi::$statics[__CLASS__]['reltypes']);
}
}
* @return array|mixed
*/
public function &caseRoles($caseRolesXML, $isCaseManager = FALSE) {
- $relationshipTypes = &$this->allRelationshipTypes();
+ // Look up relationship types according to the XML convention (described
+ // from perspective of non-client) but return the labels according to the UI
+ // convention (described from perspective of client)
+ $relationshipTypes = &$this->allRelationshipTypes(TRUE);
+ $relationshipTypesToReturn = &$this->allRelationshipTypes(FALSE);
$result = [];
foreach ($caseRolesXML as $caseRoleXML) {
}
if (!$isCaseManager) {
- $result[$relationshipTypeID] = $relationshipTypeName;
+ $result[$relationshipTypeID] = $relationshipTypesToReturn[$relationshipTypeID];
}
elseif ($relationshipTypeXML->manager == 1) {
return $relationshipTypeID;
* @throws Exception
*/
public function createRelationships($relationshipTypeName, &$params) {
- $relationshipTypes = &$this->allRelationshipTypes();
+ // The relationshipTypeName is coming from XML, so the argument should be
+ // `TRUE`
+ $relationshipTypes = &$this->allRelationshipTypes(TRUE);
// get the relationship
$relationshipType = array_search($relationshipTypeName, $relationshipTypes);
}
/**
+ * Relationships are straight from XML, described from perspective of non-client
+ *
* @param SimpleXMLElement $caseTypeXML
*
* @return array<string> symbolic relationship-type names
}
/**
+ * Relationships are straight from XML, described from perspective of non-client
+ *
* @return array<string> symbolic-names of relationship-types
*/
public function getAllDeclaredRelationshipTypes() {