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
61 * @see CRM_Utils_Hook::managed
62 * @throws CRM_Core_Exception
64 public static function createManagedActivityTypes(CRM_Case_XMLRepository
$xmlRepo, CRM_Core_ManagedEntities
$me) {
66 $validActTypes = CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, TRUE, 'name');
68 $actTypes = $xmlRepo->getAllDeclaredActivityTypes();
69 foreach ($actTypes as $actType) {
71 'module' => 'civicrm',
72 'name' => "civicase:act:$actType",
73 'entity' => 'OptionValue',
75 'cleanup' => 'unused',
78 'option_group_id' => 'activity_type',
81 'description' => $actType,
82 'component_id' => 'CiviCase',
86 // We'll create managed-entity if this record doesn't exist yet
87 // or if we previously decided to manage this record.
88 if (!in_array($actType, $validActTypes)) {
91 elseif ($me->get($managed['module'], $managed['name'])) {
100 * Get a list of managed relationship-types by searching CiviCase XML files
103 * @see CRM_Utils_Hook::managed
104 * @throws CRM_Core_Exception
106 public static function createManagedRelationshipTypes(CRM_Case_XMLRepository
$xmlRepo, CRM_Core_ManagedEntities
$me) {
109 $p = new CRM_Case_XMLProcessor();
110 $validRelTypes = $p->allRelationshipTypes();
112 $relTypes = $xmlRepo->getAllDeclaredRelationshipTypes();
113 foreach ($relTypes as $relType) {
115 'module' => 'civicrm',
116 'name' => "civicase:rel:$relType",
117 'entity' => 'RelationshipType',
119 'cleanup' => 'unused',
122 'name_a_b' => "$relType is",
123 'name_b_a' => $relType,
124 'label_a_b' => "$relType is",
125 'label_b_a' => $relType,
126 'description' => $relType,
127 'contact_type_a' => 'Individual',
128 'contact_type_b' => 'Individual',
129 'contact_sub_type_a' => NULL,
130 'contact_sub_type_b' => NULL,
134 // We'll create managed-entity if this record doesn't exist yet
135 // or if we previously decided to manage this record.
136 if (!in_array($relType, $validRelTypes)) {
137 $result[] = $managed;
139 elseif ($me->get($managed['module'], $managed['name'])) {
140 $result[] = $managed;