Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
6a488035 TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
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 | |
6b83d5bd | 34 | * @copyright CiviCRM LLC (c) 2004-2019 |
6a488035 TO |
35 | */ |
36 | class CRM_Case_Info extends CRM_Core_Component_Info { | |
37 | ||
38 | ||
e7c15cb6 | 39 | /** |
f157740d | 40 | * @var string |
e7c15cb6 CW |
41 | * @inheritDoc |
42 | */ | |
6a488035 TO |
43 | protected $keyword = 'case'; |
44 | ||
4c6ce474 | 45 | /** |
e7c15cb6 | 46 | * @inheritDoc |
4c6ce474 EM |
47 | * @return array |
48 | */ | |
6a488035 | 49 | public function getInfo() { |
be2fb01f | 50 | return [ |
6a488035 TO |
51 | 'name' => 'CiviCase', |
52 | 'translatedName' => ts('CiviCase'), | |
53 | 'title' => ts('CiviCase Engine'), | |
54 | 'search' => 1, | |
55 | 'showActivitiesInCore' => 0, | |
be2fb01f | 56 | ]; |
6a488035 TO |
57 | } |
58 | ||
4c58e251 | 59 | /** |
e7c15cb6 | 60 | * @inheritDoc |
4c58e251 TO |
61 | */ |
62 | public function getAngularModules() { | |
8456e727 | 63 | global $civicrm_root; |
8c7e0ae8 | 64 | |
be2fb01f | 65 | $result = []; |
8456e727 | 66 | $result['crmCaseType'] = include "$civicrm_root/ang/crmCaseType.ang.php"; |
4c58e251 TO |
67 | return $result; |
68 | } | |
69 | ||
4c6ce474 | 70 | /** |
e7c15cb6 | 71 | * @inheritDoc |
4c6ce474 EM |
72 | * @return array |
73 | * @throws CRM_Core_Exception | |
74 | */ | |
78650402 | 75 | public function getManagedEntities() { |
32e74b94 TO |
76 | $entities = array_merge( |
77 | CRM_Case_ManagedEntities::createManagedCaseTypes(), | |
78 | CRM_Case_ManagedEntities::createManagedActivityTypes(CRM_Case_XMLRepository::singleton(), CRM_Core_ManagedEntities::singleton()), | |
79 | CRM_Case_ManagedEntities::createManagedRelationshipTypes(CRM_Case_XMLRepository::singleton(), CRM_Core_ManagedEntities::singleton()) | |
80 | ); | |
78650402 N |
81 | return $entities; |
82 | } | |
83 | ||
4c6ce474 | 84 | /** |
e7c15cb6 | 85 | * @inheritDoc |
4c6ce474 | 86 | * @param bool $getAllUnconditionally |
221b21b4 AH |
87 | * @param bool $descriptions |
88 | * Whether to return permission descriptions | |
4c6ce474 EM |
89 | * |
90 | * @return array | |
91 | */ | |
221b21b4 | 92 | public function getPermissions($getAllUnconditionally = FALSE, $descriptions = FALSE) { |
be2fb01f CW |
93 | $permissions = [ |
94 | 'delete in CiviCase' => [ | |
221b21b4 | 95 | ts('delete in CiviCase'), |
174a1918 | 96 | ts('Delete cases'), |
be2fb01f CW |
97 | ], |
98 | 'administer CiviCase' => [ | |
221b21b4 | 99 | ts('administer CiviCase'), |
174a1918 | 100 | ts('Define case types, access deleted cases'), |
be2fb01f CW |
101 | ], |
102 | 'access my cases and activities' => [ | |
221b21b4 | 103 | ts('access my cases and activities'), |
174a1918 | 104 | ts('View and edit only those cases managed by this user'), |
be2fb01f CW |
105 | ], |
106 | 'access all cases and activities' => [ | |
221b21b4 | 107 | ts('access all cases and activities'), |
174a1918 | 108 | ts('View and edit all cases (for visible contacts)'), |
be2fb01f CW |
109 | ], |
110 | 'add cases' => [ | |
221b21b4 | 111 | ts('add cases'), |
174a1918 | 112 | ts('Open a new case'), |
be2fb01f CW |
113 | ], |
114 | ]; | |
221b21b4 AH |
115 | |
116 | if (!$descriptions) { | |
117 | foreach ($permissions as $name => $attr) { | |
118 | $permissions[$name] = array_shift($attr); | |
119 | } | |
120 | } | |
121 | ||
122 | return $permissions; | |
6a488035 TO |
123 | } |
124 | ||
168f458e | 125 | /** |
e7c15cb6 | 126 | * @inheritDoc |
168f458e TO |
127 | */ |
128 | public function getReferenceCounts($dao) { | |
be2fb01f | 129 | $result = []; |
168f458e TO |
130 | if ($dao instanceof CRM_Core_DAO_OptionValue) { |
131 | /** @var $dao CRM_Core_DAO_OptionValue */ | |
132 | $activity_type_gid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'activity_type', 'id', 'name'); | |
133 | if ($activity_type_gid == $dao->option_group_id) { | |
134 | $count = CRM_Case_XMLRepository::singleton() | |
135 | ->getActivityReferenceCount($dao->name); | |
136 | if ($count > 0) { | |
be2fb01f | 137 | $result[] = [ |
168f458e TO |
138 | 'name' => 'casetypexml:activities', |
139 | 'type' => 'casetypexml', | |
140 | 'count' => $count, | |
be2fb01f | 141 | ]; |
168f458e TO |
142 | } |
143 | } | |
144 | } | |
145 | elseif ($dao instanceof CRM_Contact_DAO_RelationshipType) { | |
146 | /** @var $dao CRM_Contact_DAO_RelationshipType */ | |
d0a94888 AF |
147 | |
148 | // Need to look both directions, but no need to translate case role | |
149 | // direction from XML perspective to client-based perspective | |
150 | $xmlRepo = CRM_Case_XMLRepository::singleton(); | |
151 | $count = $xmlRepo->getRelationshipReferenceCount($dao->label_a_b); | |
152 | if ($dao->label_a_b != $dao->label_b_a) { | |
153 | $count += $xmlRepo->getRelationshipReferenceCount($dao->label_b_a); | |
154 | } | |
168f458e | 155 | if ($count > 0) { |
be2fb01f | 156 | $result[] = [ |
168f458e TO |
157 | 'name' => 'casetypexml:relationships', |
158 | 'type' => 'casetypexml', | |
159 | 'count' => $count, | |
be2fb01f | 160 | ]; |
168f458e TO |
161 | } |
162 | } | |
163 | return $result; | |
164 | } | |
165 | ||
4c6ce474 | 166 | /** |
e7c15cb6 | 167 | * @inheritDoc |
4c6ce474 EM |
168 | * @return array |
169 | */ | |
6a488035 | 170 | public function getUserDashboardElement() { |
be2fb01f | 171 | return []; |
6a488035 TO |
172 | } |
173 | ||
4c6ce474 | 174 | /** |
e7c15cb6 | 175 | * @inheritDoc |
4c6ce474 EM |
176 | * @return array |
177 | */ | |
6a488035 | 178 | public function registerTab() { |
be2fb01f | 179 | return [ |
353ffa53 | 180 | 'title' => ts('Cases'), |
6a488035 TO |
181 | 'url' => 'case', |
182 | 'weight' => 50, | |
be2fb01f | 183 | ]; |
6a488035 TO |
184 | } |
185 | ||
b04115b4 CW |
186 | /** |
187 | * @inheritDoc | |
188 | * @return string | |
189 | */ | |
190 | public function getIcon() { | |
191 | return 'crm-i fa-folder-open-o'; | |
192 | } | |
193 | ||
4c6ce474 | 194 | /** |
e7c15cb6 | 195 | * @inheritDoc |
4c6ce474 EM |
196 | * @return array |
197 | */ | |
6a488035 | 198 | public function registerAdvancedSearchPane() { |
be2fb01f | 199 | return [ |
353ffa53 | 200 | 'title' => ts('Cases'), |
6a488035 | 201 | 'weight' => 50, |
be2fb01f | 202 | ]; |
6a488035 TO |
203 | } |
204 | ||
4c6ce474 | 205 | /** |
e7c15cb6 | 206 | * @inheritDoc |
4c6ce474 EM |
207 | * @return null |
208 | */ | |
6a488035 TO |
209 | public function getActivityTypes() { |
210 | return NULL; | |
211 | } | |
212 | ||
4c6ce474 | 213 | /** |
fe482240 | 214 | * add shortcut to Create New. |
4c6ce474 EM |
215 | * @param $shortCuts |
216 | */ | |
6a488035 TO |
217 | public function creatNewShortcut(&$shortCuts) { |
218 | if (CRM_Core_Permission::check('access all cases and activities') || | |
219 | CRM_Core_Permission::check('add cases') | |
220 | ) { | |
972a6042 | 221 | $activityType = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Open Case'); |
222 | if ($activityType) { | |
be2fb01f CW |
223 | $shortCuts = array_merge($shortCuts, [ |
224 | [ | |
353ffa53 | 225 | 'path' => 'civicrm/case/add', |
972a6042 | 226 | 'query' => "reset=1&action=add&atype={$activityType}&context=standalone", |
353ffa53 TO |
227 | 'ref' => 'new-case', |
228 | 'title' => ts('Case'), | |
be2fb01f CW |
229 | ], |
230 | ]); | |
6a488035 TO |
231 | } |
232 | } | |
233 | } | |
2bc3bd8f TO |
234 | |
235 | /** | |
236 | * (Setting Callback) | |
237 | * Respond to changes in the "enable_components" setting | |
238 | * | |
239 | * If CiviCase is being enabled, load the case related sample data | |
240 | * | |
64bd5a0e TO |
241 | * @param array $oldValue |
242 | * List of component names. | |
243 | * @param array $newValue | |
244 | * List of component names. | |
245 | * @param array $metadata | |
246 | * Specification of the setting (per *.settings.php). | |
2bc3bd8f TO |
247 | */ |
248 | public static function onToggleComponents($oldValue, $newValue, $metadata) { | |
e6d720bb TO |
249 | if ( |
250 | in_array('CiviCase', $newValue) | |
251 | && | |
252 | (!$oldValue || !in_array('CiviCase', $oldValue)) | |
2bc3bd8f | 253 | ) { |
e547f744 | 254 | $pathToCaseSampleTpl = __DIR__ . '/xml/configuration.sample/'; |
281db812 | 255 | self::loadCaseSampleData($pathToCaseSampleTpl . 'case_sample.mysql.tpl'); |
2bc3bd8f TO |
256 | if (!CRM_Case_BAO_Case::createCaseViews()) { |
257 | $msg = ts("Could not create the MySQL views for CiviCase. Your mysql user needs to have the 'CREATE VIEW' permission"); | |
258 | CRM_Core_Error::fatal($msg); | |
259 | } | |
260 | } | |
261 | } | |
96025800 | 262 | |
281db812 | 263 | /** |
264 | * Load case sample data. | |
265 | * | |
266 | * @param string $fileName | |
267 | * @param bool $lineMode | |
268 | */ | |
269 | public static function loadCaseSampleData($fileName, $lineMode = FALSE) { | |
270 | $dao = new CRM_Core_DAO(); | |
271 | $db = $dao->getDatabaseConnection(); | |
272 | ||
273 | $domain = new CRM_Core_DAO_Domain(); | |
274 | $domain->find(TRUE); | |
275 | $multiLingual = (bool) $domain->locales; | |
276 | $smarty = CRM_Core_Smarty::singleton(); | |
277 | $smarty->assign('multilingual', $multiLingual); | |
278 | $smarty->assign('locales', explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales)); | |
279 | ||
280 | if (!$lineMode) { | |
281 | ||
282 | $string = $smarty->fetch($fileName); | |
283 | // change \r\n to fix windows issues | |
284 | $string = str_replace("\r\n", "\n", $string); | |
285 | ||
286 | //get rid of comments starting with # and -- | |
287 | ||
288 | $string = preg_replace("/^#[^\n]*$/m", "\n", $string); | |
289 | $string = preg_replace("/^(--[^-]).*/m", "\n", $string); | |
290 | ||
291 | $queries = preg_split('/;$/m', $string); | |
292 | foreach ($queries as $query) { | |
293 | $query = trim($query); | |
294 | if (!empty($query)) { | |
295 | $res = &$db->query($query); | |
296 | if (PEAR::isError($res)) { | |
297 | die("Cannot execute $query: " . $res->getMessage()); | |
298 | } | |
299 | } | |
300 | } | |
301 | } | |
302 | else { | |
303 | $fd = fopen($fileName, "r"); | |
304 | while ($string = fgets($fd)) { | |
305 | $string = preg_replace("/^#[^\n]*$/m", "\n", $string); | |
306 | $string = preg_replace("/^(--[^-]).*/m", "\n", $string); | |
307 | ||
308 | $string = trim($string); | |
309 | if (!empty($string)) { | |
310 | $res = &$db->query($string); | |
311 | if (PEAR::isError($res)) { | |
312 | die("Cannot execute $string: " . $res->getMessage()); | |
313 | } | |
314 | } | |
315 | } | |
316 | } | |
317 | } | |
318 | ||
b83de994 TO |
319 | /** |
320 | * @return array | |
321 | * Array(string $value => string $label). | |
322 | */ | |
323 | public static function getRedactOptions() { | |
be2fb01f | 324 | return [ |
ec61a2b2 | 325 | 'default' => ts('Default'), |
b83de994 TO |
326 | '0' => ts('Do not redact emails'), |
327 | '1' => ts('Redact emails'), | |
be2fb01f | 328 | ]; |
b83de994 TO |
329 | } |
330 | ||
331 | /** | |
332 | * @return array | |
333 | * Array(string $value => string $label). | |
334 | */ | |
335 | public static function getMultiClientOptions() { | |
be2fb01f | 336 | return [ |
ec61a2b2 | 337 | 'default' => ts('Default'), |
b83de994 TO |
338 | '0' => ts('Single client per case'), |
339 | '1' => ts('Multiple client per case'), | |
be2fb01f | 340 | ]; |
b83de994 TO |
341 | } |
342 | ||
343 | /** | |
344 | * @return array | |
345 | * Array(string $value => string $label). | |
346 | */ | |
347 | public static function getSortOptions() { | |
be2fb01f | 348 | return [ |
ec61a2b2 | 349 | 'default' => ts('Default'), |
b83de994 TO |
350 | '0' => ts('Definition order'), |
351 | '1' => ts('Alphabetical order'), | |
be2fb01f | 352 | ]; |
b83de994 TO |
353 | } |
354 | ||
6a488035 | 355 | } |