CRM-14481 - crmCaseType - First pass at Angular-based case-type screen (view-only)
[civicrm-core.git] / CRM / Case / Info.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 /**
29 * This class introduces component to the system and provides all the
30 * information about it. It needs to extend CRM_Core_Component_Info
31 * abstract class.
32 *
33 * @package CRM
34 * @copyright CiviCRM LLC (c) 2004-2014
35 * $Id$
36 *
37 */
38 class CRM_Case_Info extends CRM_Core_Component_Info {
39
40
41 // docs inherited from interface
42 protected $keyword = 'case';
43
44 // docs inherited from interface
45 public function getInfo() {
46 return array(
47 'name' => 'CiviCase',
48 'translatedName' => ts('CiviCase'),
49 'title' => ts('CiviCase Engine'),
50 'search' => 1,
51 'showActivitiesInCore' => 0,
52 );
53 }
54
55 /**
56 * {@inheritDoc}
57 */
58 public function getAngularModules() {
59 $result = array();
60 $result['crmCaseType'] = array('ext' => 'civicrm', 'files' => array('js/angular-crmCaseType.js'));
61 return $result;
62 }
63
64 // docs inherited from interface
65 public function getManagedEntities() {
66 // Use hook_civicrm_caseTypes to build a list of OptionValues
67 // In the long run, we may want more specialized logic for this, but
68 // this design is fairly convenient and will allow us to replace it
69 // without changing the hook_civicrm_caseTypes interface.
70 $entities = array();
71
72 $caseTypes = array();
73 CRM_Utils_Hook::caseTypes($caseTypes);
74
75 $proc = new CRM_Case_XMLProcessor();
76 foreach ($caseTypes as $name => $caseType) {
77 $xml = $proc->retrieve($name);
78 if (!$xml) {
79 throw new CRM_Core_Exception("Failed to load XML for case type (" . $name . ")");
80 }
81
82 if (isset($caseType['module'], $caseType['name'], $caseType['file'])) {
83 $entities[] = array(
84 'module' => $caseType['module'],
85 'name' => $caseType['name'],
86 'entity' => 'CaseType',
87 'params' => array(
88 'version' => 3,
89 'name' => $caseType['name'],
90 'title' => (string) $xml->name,
91 'description' => (string) $xml->description,
92 'is_reserved' => 1,
93 'is_active' => 1,
94 'weight' => $xml->weight ? $xml->weight : 1,
95 ),
96 );
97 }
98 else {
99 throw new CRM_Core_Exception("Invalid case type");
100 }
101 }
102
103 return $entities;
104 }
105
106 // docs inherited from interface
107 public function getPermissions($getAllUnconditionally = FALSE) {
108 return array(
109 'delete in CiviCase',
110 'administer CiviCase',
111 'access my cases and activities',
112 'access all cases and activities',
113 'add cases',
114 );
115 }
116
117 // docs inherited from interface
118 public function getUserDashboardElement() {
119 return array();
120 }
121
122 // docs inherited from interface
123 public function registerTab() {
124 return array('title' => ts('Cases'),
125 'url' => 'case',
126 'weight' => 50,
127 );
128 }
129
130 // docs inherited from interface
131 public function registerAdvancedSearchPane() {
132 return array('title' => ts('Cases'),
133 'weight' => 50,
134 );
135 }
136
137 // docs inherited from interface
138 public function getActivityTypes() {
139 return NULL;
140 }
141
142 // add shortcut to Create New
143 public function creatNewShortcut(&$shortCuts) {
144 if (CRM_Core_Permission::check('access all cases and activities') ||
145 CRM_Core_Permission::check('add cases')
146 ) {
147 $atype = CRM_Core_OptionGroup::getValue('activity_type',
148 'Open Case',
149 'name'
150 );
151 if ($atype) {
152 $shortCuts = array_merge($shortCuts, array(
153 array('path' => 'civicrm/case/add',
154 'query' => "reset=1&action=add&atype=$atype&context=standalone",
155 'ref' => 'new-case',
156 'title' => ts('Case'),
157 )));
158 }
159 }
160 }
161
162 /**
163 * (Setting Callback)
164 * Respond to changes in the "enable_components" setting
165 *
166 * If CiviCase is being enabled, load the case related sample data
167 *
168 * @param array $oldValue List of component names
169 * @param array $newValue List of component names
170 * @param array $metadata Specification of the setting (per *.settings.php)
171 */
172 public static function onToggleComponents($oldValue, $newValue, $metadata) {
173 if (
174 in_array('CiviCase', $newValue)
175 &&
176 (!$oldValue || !in_array('CiviCase', $oldValue))
177 ) {
178 $config = CRM_Core_Config::singleton();
179 CRM_Admin_Form_Setting_Component::loadCaseSampleData($config->dsn, $config->sqlDir . 'case_sample.mysql');
180 if (!CRM_Case_BAO_Case::createCaseViews()) {
181 $msg = ts("Could not create the MySQL views for CiviCase. Your mysql user needs to have the 'CREATE VIEW' permission");
182 CRM_Core_Error::fatal($msg);
183 }
184 }
185 }
186 }
187