4 * Class CRM_Case_ManagedEntities
6 class CRM_Case_ManagedEntities
{
9 * Get a list of managed-entities representing auto-generated case-types
10 * using hook_civicrm_caseTypes.
13 * @see CRM_Utils_Hook::managed
14 * @throws CRM_Core_Exception
16 public static function createManagedCaseTypes() {
19 // Use hook_civicrm_caseTypes to build a list of OptionValues
20 // In the long run, we may want more specialized logic for this, but
21 // this design is fairly convenient and will allow us to replace it
22 // without changing the hook_civicrm_caseTypes interface.
25 CRM_Utils_Hook
::caseTypes($caseTypes);
27 $proc = new CRM_Case_XMLProcessor();
28 foreach ($caseTypes as $name => $caseType) {
29 $xml = $proc->retrieve($name);
31 throw new CRM_Core_Exception("Failed to load XML for case type (" . $name . ")");
34 if (isset($caseType['module'], $caseType['name'], $caseType['file'])) {
36 'module' => $caseType['module'],
37 'name' => $caseType['name'],
38 'entity' => 'CaseType',
41 'name' => $caseType['name'],
42 'title' => (string) $xml->name
,
43 'description' => (string) $xml->description
,
46 'weight' => $xml->weight ?
$xml->weight
: 1,
51 throw new CRM_Core_Exception("Invalid case type");
58 * Get a list of managed activity-types by searching CiviCase XML files.
60 * @param \CRM_Case_XMLRepository $xmlRepo
61 * @param \CRM_Core_ManagedEntities $me
64 * @see CRM_Utils_Hook::managed
66 public static function createManagedActivityTypes(CRM_Case_XMLRepository
$xmlRepo, CRM_Core_ManagedEntities
$me) {
68 $validActTypes = CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, TRUE, 'name');
70 $actTypes = $xmlRepo->getAllDeclaredActivityTypes();
71 foreach ($actTypes as $actType) {
73 'module' => 'civicrm',
74 'name' => "civicase:act:$actType",
75 'entity' => 'OptionValue',
77 'cleanup' => 'unused',
80 'option_group_id' => 'activity_type',
83 'description' => $actType,
84 'component_id' => 'CiviCase',
88 // We'll create managed-entity if this record doesn't exist yet
89 // or if we previously decided to manage this record.
90 if (!in_array($actType, $validActTypes)) {
93 elseif ($me->get($managed['module'], $managed['name'])) {
102 * Get a list of managed relationship-types by searching CiviCase XML files.
104 * @param \CRM_Case_XMLRepository $xmlRepo
105 * @param \CRM_Core_ManagedEntities $me
108 * @see CRM_Utils_Hook::managed
110 public static function createManagedRelationshipTypes(CRM_Case_XMLRepository
$xmlRepo, CRM_Core_ManagedEntities
$me) {
113 if (!isset(Civi
::$statics[__CLASS__
]['reltypes'])) {
114 $relationshipInfo = CRM_Core_PseudoConstant
::relationshipType('label', TRUE, NULL);
115 Civi
::$statics[__CLASS__
]['reltypes'] = CRM_Utils_Array
::collect(CRM_Case_XMLProcessor
::REL_TYPE_CNAME
, $relationshipInfo);
117 $validRelTypes = Civi
::$statics[__CLASS__
]['reltypes'];
119 $relTypes = $xmlRepo->getAllDeclaredRelationshipTypes();
120 foreach ($relTypes as $relType) {
122 'module' => 'civicrm',
123 'name' => "civicase:rel:$relType",
124 'entity' => 'RelationshipType',
126 'cleanup' => 'unused',
129 'name_a_b' => "$relType is",
130 'name_b_a' => $relType,
131 'label_a_b' => "$relType is",
132 'label_b_a' => $relType,
133 'description' => $relType,
134 'contact_type_a' => 'Individual',
135 'contact_type_b' => 'Individual',
136 'contact_sub_type_a' => NULL,
137 'contact_sub_type_b' => NULL,
141 // We'll create managed-entity if this record doesn't exist yet
142 // or if we previously decided to manage this record.
143 if (!in_array($relType, $validRelTypes)) {
144 $result[] = $managed;
146 elseif ($me->get($managed['module'], $managed['name'])) {
147 $result[] = $managed;