Update Copywrite year to be 2019
[civicrm-core.git] / CRM / Case / Info.php
CommitLineData
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 */
36class CRM_Case_Info extends CRM_Core_Component_Info {
37
38
e7c15cb6
CW
39 /**
40 * @inheritDoc
41 */
6a488035
TO
42 protected $keyword = 'case';
43
4c6ce474 44 /**
e7c15cb6 45 * @inheritDoc
4c6ce474
EM
46 * @return array
47 */
6a488035
TO
48 public function getInfo() {
49 return array(
50 'name' => 'CiviCase',
51 'translatedName' => ts('CiviCase'),
52 'title' => ts('CiviCase Engine'),
53 'search' => 1,
54 'showActivitiesInCore' => 0,
55 );
56 }
57
4c58e251 58 /**
e7c15cb6 59 * @inheritDoc
4c58e251
TO
60 */
61 public function getAngularModules() {
8456e727 62 global $civicrm_root;
8c7e0ae8 63
8456e727
TO
64 $result = array();
65 $result['crmCaseType'] = include "$civicrm_root/ang/crmCaseType.ang.php";
4c58e251
TO
66 return $result;
67 }
68
4c6ce474 69 /**
e7c15cb6 70 * @inheritDoc
4c6ce474
EM
71 * @return array
72 * @throws CRM_Core_Exception
73 */
78650402 74 public function getManagedEntities() {
32e74b94
TO
75 $entities = array_merge(
76 CRM_Case_ManagedEntities::createManagedCaseTypes(),
77 CRM_Case_ManagedEntities::createManagedActivityTypes(CRM_Case_XMLRepository::singleton(), CRM_Core_ManagedEntities::singleton()),
78 CRM_Case_ManagedEntities::createManagedRelationshipTypes(CRM_Case_XMLRepository::singleton(), CRM_Core_ManagedEntities::singleton())
79 );
78650402
N
80 return $entities;
81 }
82
4c6ce474 83 /**
e7c15cb6 84 * @inheritDoc
4c6ce474 85 * @param bool $getAllUnconditionally
221b21b4
AH
86 * @param bool $descriptions
87 * Whether to return permission descriptions
4c6ce474
EM
88 *
89 * @return array
90 */
221b21b4
AH
91 public function getPermissions($getAllUnconditionally = FALSE, $descriptions = FALSE) {
92 $permissions = array(
93 'delete in CiviCase' => array(
94 ts('delete in CiviCase'),
174a1918 95 ts('Delete cases'),
221b21b4
AH
96 ),
97 'administer CiviCase' => array(
98 ts('administer CiviCase'),
174a1918 99 ts('Define case types, access deleted cases'),
221b21b4
AH
100 ),
101 'access my cases and activities' => array(
102 ts('access my cases and activities'),
174a1918 103 ts('View and edit only those cases managed by this user'),
221b21b4
AH
104 ),
105 'access all cases and activities' => array(
106 ts('access all cases and activities'),
174a1918 107 ts('View and edit all cases (for visible contacts)'),
221b21b4
AH
108 ),
109 'add cases' => array(
110 ts('add cases'),
174a1918 111 ts('Open a new case'),
221b21b4 112 ),
6a488035 113 );
221b21b4
AH
114
115 if (!$descriptions) {
116 foreach ($permissions as $name => $attr) {
117 $permissions[$name] = array_shift($attr);
118 }
119 }
120
121 return $permissions;
6a488035
TO
122 }
123
168f458e 124 /**
e7c15cb6 125 * @inheritDoc
168f458e
TO
126 */
127 public function getReferenceCounts($dao) {
128 $result = array();
129 if ($dao instanceof CRM_Core_DAO_OptionValue) {
130 /** @var $dao CRM_Core_DAO_OptionValue */
131 $activity_type_gid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'activity_type', 'id', 'name');
132 if ($activity_type_gid == $dao->option_group_id) {
133 $count = CRM_Case_XMLRepository::singleton()
134 ->getActivityReferenceCount($dao->name);
135 if ($count > 0) {
136 $result[] = array(
137 'name' => 'casetypexml:activities',
138 'type' => 'casetypexml',
139 'count' => $count,
140 );
141 }
142 }
143 }
144 elseif ($dao instanceof CRM_Contact_DAO_RelationshipType) {
145 /** @var $dao CRM_Contact_DAO_RelationshipType */
146 $count = CRM_Case_XMLRepository::singleton()
147 ->getRelationshipReferenceCount($dao->{CRM_Case_XMLProcessor::REL_TYPE_CNAME});
148 if ($count > 0) {
149 $result[] = array(
150 'name' => 'casetypexml:relationships',
151 'type' => 'casetypexml',
152 'count' => $count,
153 );
154 }
155 }
156 return $result;
157 }
158
4c6ce474 159 /**
e7c15cb6 160 * @inheritDoc
4c6ce474
EM
161 * @return array
162 */
6a488035
TO
163 public function getUserDashboardElement() {
164 return array();
165 }
166
4c6ce474 167 /**
e7c15cb6 168 * @inheritDoc
4c6ce474
EM
169 * @return array
170 */
6a488035 171 public function registerTab() {
e547f744 172 return array(
353ffa53 173 'title' => ts('Cases'),
6a488035
TO
174 'url' => 'case',
175 'weight' => 50,
176 );
177 }
178
b04115b4
CW
179 /**
180 * @inheritDoc
181 * @return string
182 */
183 public function getIcon() {
184 return 'crm-i fa-folder-open-o';
185 }
186
4c6ce474 187 /**
e7c15cb6 188 * @inheritDoc
4c6ce474
EM
189 * @return array
190 */
6a488035 191 public function registerAdvancedSearchPane() {
e547f744 192 return array(
353ffa53 193 'title' => ts('Cases'),
6a488035
TO
194 'weight' => 50,
195 );
196 }
197
4c6ce474 198 /**
e7c15cb6 199 * @inheritDoc
4c6ce474
EM
200 * @return null
201 */
6a488035
TO
202 public function getActivityTypes() {
203 return NULL;
204 }
205
4c6ce474 206 /**
fe482240 207 * add shortcut to Create New.
4c6ce474
EM
208 * @param $shortCuts
209 */
6a488035
TO
210 public function creatNewShortcut(&$shortCuts) {
211 if (CRM_Core_Permission::check('access all cases and activities') ||
212 CRM_Core_Permission::check('add cases')
213 ) {
972a6042 214 $activityType = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Open Case');
215 if ($activityType) {
6a488035 216 $shortCuts = array_merge($shortCuts, array(
e547f744 217 array(
353ffa53 218 'path' => 'civicrm/case/add',
972a6042 219 'query' => "reset=1&action=add&atype={$activityType}&context=standalone",
353ffa53
TO
220 'ref' => 'new-case',
221 'title' => ts('Case'),
c301f76e 222 ),
353ffa53 223 ));
6a488035
TO
224 }
225 }
226 }
2bc3bd8f
TO
227
228 /**
229 * (Setting Callback)
230 * Respond to changes in the "enable_components" setting
231 *
232 * If CiviCase is being enabled, load the case related sample data
233 *
64bd5a0e
TO
234 * @param array $oldValue
235 * List of component names.
236 * @param array $newValue
237 * List of component names.
238 * @param array $metadata
239 * Specification of the setting (per *.settings.php).
2bc3bd8f
TO
240 */
241 public static function onToggleComponents($oldValue, $newValue, $metadata) {
e6d720bb
TO
242 if (
243 in_array('CiviCase', $newValue)
244 &&
245 (!$oldValue || !in_array('CiviCase', $oldValue))
2bc3bd8f 246 ) {
e547f744 247 $pathToCaseSampleTpl = __DIR__ . '/xml/configuration.sample/';
02b862ef 248 CRM_Admin_Form_Setting_Component::loadCaseSampleData($pathToCaseSampleTpl . 'case_sample.mysql.tpl');
2bc3bd8f
TO
249 if (!CRM_Case_BAO_Case::createCaseViews()) {
250 $msg = ts("Could not create the MySQL views for CiviCase. Your mysql user needs to have the 'CREATE VIEW' permission");
251 CRM_Core_Error::fatal($msg);
252 }
253 }
254 }
96025800 255
b83de994
TO
256 /**
257 * @return array
258 * Array(string $value => string $label).
259 */
260 public static function getRedactOptions() {
261 return array(
ec61a2b2 262 'default' => ts('Default'),
b83de994
TO
263 '0' => ts('Do not redact emails'),
264 '1' => ts('Redact emails'),
265 );
266 }
267
268 /**
269 * @return array
270 * Array(string $value => string $label).
271 */
272 public static function getMultiClientOptions() {
273 return array(
ec61a2b2 274 'default' => ts('Default'),
b83de994
TO
275 '0' => ts('Single client per case'),
276 '1' => ts('Multiple client per case'),
277 );
278 }
279
280 /**
281 * @return array
282 * Array(string $value => string $label).
283 */
284 public static function getSortOptions() {
285 return array(
ec61a2b2 286 'default' => ts('Default'),
b83de994
TO
287 '0' => ts('Definition order'),
288 '1' => ts('Alphabetical order'),
289 );
290 }
291
6a488035 292}