public static function createManagedRelationshipTypes(CRM_Case_XMLRepository $xmlRepo, CRM_Core_ManagedEntities $me) {
$result = array();
- $p = new CRM_Case_XMLProcessor();
- $validRelTypes = $p->allRelationshipTypes();
+ if (!isset(Civi::$statics[__CLASS__]['reltypes'])) {
+ $relationshipInfo = CRM_Core_PseudoConstant::relationshipType('label', TRUE, NULL);
+ Civi::$statics[__CLASS__]['reltypes'] = CRM_Utils_Array::collect(CRM_Case_XMLProcessor::REL_TYPE_CNAME, $relationshipInfo);
+ }
+ $validRelTypes = Civi::$statics[__CLASS__]['reltypes'];
$relTypes = $xmlRepo->getAllDeclaredRelationshipTypes();
foreach ($relTypes as $relType) {
* Db column name/label.
* @param bool $reset
* Reset relationship types if true.
- *
+ * @param bool|NULL $isActive
+ * Filter by is_active. NULL to disable.
*
* @return array
* array reference of all relationship types.
*/
- public static function &relationshipType($valueColumnName = 'label', $reset = FALSE) {
- if (!CRM_Utils_Array::value($valueColumnName, self::$relationshipType) || $reset) {
- self::$relationshipType[$valueColumnName] = array();
+ public static function &relationshipType($valueColumnName = 'label', $reset = FALSE, $isActive = 1) {
+ $cacheKey = $valueColumnName . '::' . $isActive;
+ if (!CRM_Utils_Array::value($cacheKey, self::$relationshipType) || $reset) {
+ self::$relationshipType[$cacheKey] = array();
//now we have name/label columns CRM-3336
$column_a_b = "{$valueColumnName}_a_b";
$relationshipTypeDAO = new CRM_Contact_DAO_RelationshipType();
$relationshipTypeDAO->selectAdd();
$relationshipTypeDAO->selectAdd("id, {$column_a_b}, {$column_b_a}, contact_type_a, contact_type_b, contact_sub_type_a, contact_sub_type_b");
- $relationshipTypeDAO->is_active = 1;
+ if ($isActive !== NULL) {
+ $relationshipTypeDAO->is_active = $isActive;
+ }
$relationshipTypeDAO->find();
while ($relationshipTypeDAO->fetch()) {
- self::$relationshipType[$valueColumnName][$relationshipTypeDAO->id] = array(
+ self::$relationshipType[$cacheKey][$relationshipTypeDAO->id] = array(
'id' => $relationshipTypeDAO->id,
$column_a_b => $relationshipTypeDAO->$column_a_b,
$column_b_a => $relationshipTypeDAO->$column_b_a,
}
}
- return self::$relationshipType[$valueColumnName];
+ return self::$relationshipType[$cacheKey];
}
/**