3 class CRM_Case_ManagedEntities
{
6 * Get a list of managed-entities representing auto-generated case-types
7 * using hook_civicrm_caseTypes.
10 * @see CRM_Utils_Hook::managed
11 * @throws CRM_Core_Exception
13 public static function createManagedCaseTypes() {
16 // Use hook_civicrm_caseTypes to build a list of OptionValues
17 // In the long run, we may want more specialized logic for this, but
18 // this design is fairly convenient and will allow us to replace it
19 // without changing the hook_civicrm_caseTypes interface.
22 CRM_Utils_Hook
::caseTypes($caseTypes);
24 $proc = new CRM_Case_XMLProcessor();
25 foreach ($caseTypes as $name => $caseType) {
26 $xml = $proc->retrieve($name);
28 throw new CRM_Core_Exception("Failed to load XML for case type (" . $name . ")");
31 if (isset($caseType['module'], $caseType['name'], $caseType['file'])) {
33 'module' => $caseType['module'],
34 'name' => $caseType['name'],
35 'entity' => 'CaseType',
38 'name' => $caseType['name'],
39 'title' => (string) $xml->name
,
40 'description' => (string) $xml->description
,
43 'weight' => $xml->weight ?
$xml->weight
: 1,
48 throw new CRM_Core_Exception("Invalid case type");
55 * Get a list of managed activity-types by searching CiviCase XML files
58 * @see CRM_Utils_Hook::managed
59 * @throws CRM_Core_Exception
61 public static function createManagedActivityTypes(CRM_Case_XMLRepository
$xmlRepo, CRM_Core_ManagedEntities
$me) {
63 $validActTypes = CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, TRUE, 'name');
65 $actTypes = $xmlRepo->getAllDeclaredActivityTypes();
66 foreach ($actTypes as $actType) {
68 'module' => 'civicrm',
69 'name' => "civicase:act:$actType",
70 'entity' => 'OptionValue',
72 'cleanup' => 'unused',
75 'option_group_id' => 'activity_type',
78 'description' => $actType,
79 'component_id' => 'CiviCase',
83 // We'll create managed-entity if this record doesn't exist yet
84 // or if we previously decided to manage this record.
85 if (!in_array($actType, $validActTypes)) {
88 elseif ($me->get($managed['module'], $managed['name'])) {
97 * Get a list of managed relationship-types by searching CiviCase XML files
100 * @see CRM_Utils_Hook::managed
101 * @throws CRM_Core_Exception
103 public static function createManagedRelationshipTypes(CRM_Case_XMLRepository
$xmlRepo, CRM_Core_ManagedEntities
$me) {
106 $p = new CRM_Case_XMLProcessor();
107 $validRelTypes = $p->allRelationshipTypes();
109 $relTypes = $xmlRepo->getAllDeclaredRelationshipTypes();
110 foreach ($relTypes as $relType) {
112 'module' => 'civicrm',
113 'name' => "civicase:rel:$relType",
114 'entity' => 'RelationshipType',
116 'cleanup' => 'unused',
119 'name_a_b' => "$relType is",
120 'name_b_a' => $relType,
121 'label_a_b' => "$relType is",
122 'label_b_a' => $relType,
123 'description' => $relType,
124 'contact_type_a' => 'Individual',
125 'contact_type_b' => 'Individual',
126 'contact_sub_type_a' => NULL,
127 'contact_sub_type_b' => NULL,
131 // We'll create managed-entity if this record doesn't exist yet
132 // or if we previously decided to manage this record.
133 if (!in_array($relType, $validRelTypes)) {
134 $result[] = $managed;
136 elseif ($me->get($managed['module'], $managed['name'])) {
137 $result[] = $managed;