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 */ | |
147 | $count = CRM_Case_XMLRepository::singleton() | |
41cf58d3 | 148 | ->getRelationshipReferenceCount($dao->label_a_b); |
168f458e | 149 | if ($count > 0) { |
be2fb01f | 150 | $result[] = [ |
168f458e TO |
151 | 'name' => 'casetypexml:relationships', |
152 | 'type' => 'casetypexml', | |
153 | 'count' => $count, | |
be2fb01f | 154 | ]; |
168f458e TO |
155 | } |
156 | } | |
157 | return $result; | |
158 | } | |
159 | ||
4c6ce474 | 160 | /** |
e7c15cb6 | 161 | * @inheritDoc |
4c6ce474 EM |
162 | * @return array |
163 | */ | |
6a488035 | 164 | public function getUserDashboardElement() { |
be2fb01f | 165 | return []; |
6a488035 TO |
166 | } |
167 | ||
4c6ce474 | 168 | /** |
e7c15cb6 | 169 | * @inheritDoc |
4c6ce474 EM |
170 | * @return array |
171 | */ | |
6a488035 | 172 | public function registerTab() { |
be2fb01f | 173 | return [ |
353ffa53 | 174 | 'title' => ts('Cases'), |
6a488035 TO |
175 | 'url' => 'case', |
176 | 'weight' => 50, | |
be2fb01f | 177 | ]; |
6a488035 TO |
178 | } |
179 | ||
b04115b4 CW |
180 | /** |
181 | * @inheritDoc | |
182 | * @return string | |
183 | */ | |
184 | public function getIcon() { | |
185 | return 'crm-i fa-folder-open-o'; | |
186 | } | |
187 | ||
4c6ce474 | 188 | /** |
e7c15cb6 | 189 | * @inheritDoc |
4c6ce474 EM |
190 | * @return array |
191 | */ | |
6a488035 | 192 | public function registerAdvancedSearchPane() { |
be2fb01f | 193 | return [ |
353ffa53 | 194 | 'title' => ts('Cases'), |
6a488035 | 195 | 'weight' => 50, |
be2fb01f | 196 | ]; |
6a488035 TO |
197 | } |
198 | ||
4c6ce474 | 199 | /** |
e7c15cb6 | 200 | * @inheritDoc |
4c6ce474 EM |
201 | * @return null |
202 | */ | |
6a488035 TO |
203 | public function getActivityTypes() { |
204 | return NULL; | |
205 | } | |
206 | ||
4c6ce474 | 207 | /** |
fe482240 | 208 | * add shortcut to Create New. |
4c6ce474 EM |
209 | * @param $shortCuts |
210 | */ | |
6a488035 TO |
211 | public function creatNewShortcut(&$shortCuts) { |
212 | if (CRM_Core_Permission::check('access all cases and activities') || | |
213 | CRM_Core_Permission::check('add cases') | |
214 | ) { | |
972a6042 | 215 | $activityType = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Open Case'); |
216 | if ($activityType) { | |
be2fb01f CW |
217 | $shortCuts = array_merge($shortCuts, [ |
218 | [ | |
353ffa53 | 219 | 'path' => 'civicrm/case/add', |
972a6042 | 220 | 'query' => "reset=1&action=add&atype={$activityType}&context=standalone", |
353ffa53 TO |
221 | 'ref' => 'new-case', |
222 | 'title' => ts('Case'), | |
be2fb01f CW |
223 | ], |
224 | ]); | |
6a488035 TO |
225 | } |
226 | } | |
227 | } | |
2bc3bd8f TO |
228 | |
229 | /** | |
230 | * (Setting Callback) | |
231 | * Respond to changes in the "enable_components" setting | |
232 | * | |
233 | * If CiviCase is being enabled, load the case related sample data | |
234 | * | |
64bd5a0e TO |
235 | * @param array $oldValue |
236 | * List of component names. | |
237 | * @param array $newValue | |
238 | * List of component names. | |
239 | * @param array $metadata | |
240 | * Specification of the setting (per *.settings.php). | |
2bc3bd8f TO |
241 | */ |
242 | public static function onToggleComponents($oldValue, $newValue, $metadata) { | |
e6d720bb TO |
243 | if ( |
244 | in_array('CiviCase', $newValue) | |
245 | && | |
246 | (!$oldValue || !in_array('CiviCase', $oldValue)) | |
2bc3bd8f | 247 | ) { |
e547f744 | 248 | $pathToCaseSampleTpl = __DIR__ . '/xml/configuration.sample/'; |
281db812 | 249 | self::loadCaseSampleData($pathToCaseSampleTpl . 'case_sample.mysql.tpl'); |
2bc3bd8f TO |
250 | if (!CRM_Case_BAO_Case::createCaseViews()) { |
251 | $msg = ts("Could not create the MySQL views for CiviCase. Your mysql user needs to have the 'CREATE VIEW' permission"); | |
252 | CRM_Core_Error::fatal($msg); | |
253 | } | |
254 | } | |
255 | } | |
96025800 | 256 | |
281db812 | 257 | /** |
258 | * Load case sample data. | |
259 | * | |
260 | * @param string $fileName | |
261 | * @param bool $lineMode | |
262 | */ | |
263 | public static function loadCaseSampleData($fileName, $lineMode = FALSE) { | |
264 | $dao = new CRM_Core_DAO(); | |
265 | $db = $dao->getDatabaseConnection(); | |
266 | ||
267 | $domain = new CRM_Core_DAO_Domain(); | |
268 | $domain->find(TRUE); | |
269 | $multiLingual = (bool) $domain->locales; | |
270 | $smarty = CRM_Core_Smarty::singleton(); | |
271 | $smarty->assign('multilingual', $multiLingual); | |
272 | $smarty->assign('locales', explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales)); | |
273 | ||
274 | if (!$lineMode) { | |
275 | ||
276 | $string = $smarty->fetch($fileName); | |
277 | // change \r\n to fix windows issues | |
278 | $string = str_replace("\r\n", "\n", $string); | |
279 | ||
280 | //get rid of comments starting with # and -- | |
281 | ||
282 | $string = preg_replace("/^#[^\n]*$/m", "\n", $string); | |
283 | $string = preg_replace("/^(--[^-]).*/m", "\n", $string); | |
284 | ||
285 | $queries = preg_split('/;$/m', $string); | |
286 | foreach ($queries as $query) { | |
287 | $query = trim($query); | |
288 | if (!empty($query)) { | |
289 | $res = &$db->query($query); | |
290 | if (PEAR::isError($res)) { | |
291 | die("Cannot execute $query: " . $res->getMessage()); | |
292 | } | |
293 | } | |
294 | } | |
295 | } | |
296 | else { | |
297 | $fd = fopen($fileName, "r"); | |
298 | while ($string = fgets($fd)) { | |
299 | $string = preg_replace("/^#[^\n]*$/m", "\n", $string); | |
300 | $string = preg_replace("/^(--[^-]).*/m", "\n", $string); | |
301 | ||
302 | $string = trim($string); | |
303 | if (!empty($string)) { | |
304 | $res = &$db->query($string); | |
305 | if (PEAR::isError($res)) { | |
306 | die("Cannot execute $string: " . $res->getMessage()); | |
307 | } | |
308 | } | |
309 | } | |
310 | } | |
311 | } | |
312 | ||
b83de994 TO |
313 | /** |
314 | * @return array | |
315 | * Array(string $value => string $label). | |
316 | */ | |
317 | public static function getRedactOptions() { | |
be2fb01f | 318 | return [ |
ec61a2b2 | 319 | 'default' => ts('Default'), |
b83de994 TO |
320 | '0' => ts('Do not redact emails'), |
321 | '1' => ts('Redact emails'), | |
be2fb01f | 322 | ]; |
b83de994 TO |
323 | } |
324 | ||
325 | /** | |
326 | * @return array | |
327 | * Array(string $value => string $label). | |
328 | */ | |
329 | public static function getMultiClientOptions() { | |
be2fb01f | 330 | return [ |
ec61a2b2 | 331 | 'default' => ts('Default'), |
b83de994 TO |
332 | '0' => ts('Single client per case'), |
333 | '1' => ts('Multiple client per case'), | |
be2fb01f | 334 | ]; |
b83de994 TO |
335 | } |
336 | ||
337 | /** | |
338 | * @return array | |
339 | * Array(string $value => string $label). | |
340 | */ | |
341 | public static function getSortOptions() { | |
be2fb01f | 342 | return [ |
ec61a2b2 | 343 | 'default' => ts('Default'), |
b83de994 TO |
344 | '0' => ts('Definition order'), |
345 | '1' => ts('Alphabetical order'), | |
be2fb01f | 346 | ]; |
b83de994 TO |
347 | } |
348 | ||
6a488035 | 349 | } |