3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * This class introduces component to the system and provides all the
14 * information about it. It needs to extend CRM_Core_Component_Info
18 * @copyright CiviCRM LLC https://civicrm.org/licensing
20 class CRM_Case_Info
extends CRM_Core_Component_Info
{
27 protected $keyword = 'case';
33 public function getInfo() {
36 'translatedName' => ts('CiviCase'),
37 'title' => ts('CiviCase Engine'),
39 'showActivitiesInCore' => Civi
::settings()->get('civicaseShowCaseActivities') ??
0,
46 public function getAngularModules() {
50 $result['crmCaseType'] = include "$civicrm_root/ang/crmCaseType.ang.php";
57 * @throws CRM_Core_Exception
59 public function getManagedEntities() {
60 $entities = array_merge(
61 CRM_Case_ManagedEntities
::createManagedCaseTypes(),
62 CRM_Case_ManagedEntities
::createManagedActivityTypes(CRM_Case_XMLRepository
::singleton(), CRM_Core_ManagedEntities
::singleton()),
63 CRM_Case_ManagedEntities
::createManagedRelationshipTypes(CRM_Case_XMLRepository
::singleton(), CRM_Core_ManagedEntities
::singleton())
70 * @param bool $getAllUnconditionally
71 * @param bool $descriptions
72 * Whether to return permission descriptions
76 public function getPermissions($getAllUnconditionally = FALSE, $descriptions = FALSE) {
78 'delete in CiviCase' => [
79 ts('delete in CiviCase'),
82 'administer CiviCase' => [
83 ts('administer CiviCase'),
84 ts('Define case types, access deleted cases'),
86 'access my cases and activities' => [
87 ts('access my cases and activities'),
88 ts('View and edit only those cases managed by this user'),
90 'access all cases and activities' => [
91 ts('access all cases and activities'),
92 ts('View and edit all cases (for visible contacts)'),
96 ts('Open a new case'),
100 if (!$descriptions) {
101 foreach ($permissions as $name => $attr) {
102 $permissions[$name] = array_shift($attr);
112 public function getReferenceCounts($dao) {
114 if ($dao instanceof CRM_Core_DAO_OptionValue
) {
115 /** @var $dao CRM_Core_DAO_OptionValue */
116 $activity_type_gid = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionGroup', 'activity_type', 'id', 'name');
117 if ($activity_type_gid == $dao->option_group_id
) {
118 $count = CRM_Case_XMLRepository
::singleton()
119 ->getActivityReferenceCount($dao->name
);
122 'name' => 'casetypexml:activities',
123 'type' => 'casetypexml',
129 elseif ($dao instanceof CRM_Contact_DAO_RelationshipType
) {
130 /** @var $dao CRM_Contact_DAO_RelationshipType */
132 // Need to look both directions, but no need to translate case role
133 // direction from XML perspective to client-based perspective
134 $xmlRepo = CRM_Case_XMLRepository
::singleton();
135 $count = $xmlRepo->getRelationshipReferenceCount($dao->label_a_b
);
136 if ($dao->label_a_b
!= $dao->label_b_a
) {
137 $count +
= $xmlRepo->getRelationshipReferenceCount($dao->label_b_a
);
141 'name' => 'casetypexml:relationships',
142 'type' => 'casetypexml',
154 public function getUserDashboardElement() {
162 public function registerTab() {
164 'title' => ts('Cases'),
174 public function getIcon() {
175 return 'crm-i fa-folder-open-o';
182 public function registerAdvancedSearchPane() {
184 'title' => ts('Cases'),
193 public function getActivityTypes() {
198 * add shortcut to Create New.
201 public function creatNewShortcut(&$shortCuts) {
202 if (CRM_Core_Permission
::check('access all cases and activities') ||
203 CRM_Core_Permission
::check('add cases')
205 $activityType = CRM_Core_PseudoConstant
::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Open Case');
207 $shortCuts = array_merge($shortCuts, [
209 'path' => 'civicrm/case/add',
210 'query' => "reset=1&action=add&atype={$activityType}&context=standalone",
212 'title' => ts('Case'),
221 * Respond to changes in the "enable_components" setting
223 * If CiviCase is being enabled, load the case related sample data
225 * @param array $oldValue
226 * List of component names.
227 * @param array $newValue
228 * List of component names.
229 * @param array $metadata
230 * Specification of the setting (per *.settings.php).
232 public static function onToggleComponents($oldValue, $newValue, $metadata) {
234 in_array('CiviCase', $newValue)
236 (!$oldValue ||
!in_array('CiviCase', $oldValue))
238 $pathToCaseSampleTpl = __DIR__
. '/xml/configuration.sample/';
239 self
::loadCaseSampleData($pathToCaseSampleTpl . 'case_sample.mysql.tpl');
240 if (!CRM_Case_BAO_Case
::createCaseViews()) {
241 $msg = ts("Could not create the MySQL views for CiviCase. Your mysql user needs to have the 'CREATE VIEW' permission");
242 CRM_Core_Error
::fatal($msg);
248 * Load case sample data.
250 * @param string $fileName
251 * @param bool $lineMode
253 public static function loadCaseSampleData($fileName, $lineMode = FALSE) {
254 $dao = new CRM_Core_DAO();
255 $db = $dao->getDatabaseConnection();
257 $domain = new CRM_Core_DAO_Domain();
259 $multiLingual = (bool) $domain->locales
;
260 $smarty = CRM_Core_Smarty
::singleton();
261 $smarty->assign('multilingual', $multiLingual);
262 $smarty->assign('locales', explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $domain->locales
));
266 $string = $smarty->fetch($fileName);
267 // change \r\n to fix windows issues
268 $string = str_replace("\r\n", "\n", $string);
270 //get rid of comments starting with # and --
272 $string = preg_replace("/^#[^\n]*$/m", "\n", $string);
273 $string = preg_replace("/^(--[^-]).*/m", "\n", $string);
275 $queries = preg_split('/;$/m', $string);
276 foreach ($queries as $query) {
277 $query = trim($query);
278 if (!empty($query)) {
279 $res = &$db->query($query);
280 if (PEAR
::isError($res)) {
281 die("Cannot execute $query: " . $res->getMessage());
287 $fd = fopen($fileName, "r");
288 while ($string = fgets($fd)) {
289 $string = preg_replace("/^#[^\n]*$/m", "\n", $string);
290 $string = preg_replace("/^(--[^-]).*/m", "\n", $string);
292 $string = trim($string);
293 if (!empty($string)) {
294 $res = &$db->query($string);
295 if (PEAR
::isError($res)) {
296 die("Cannot execute $string: " . $res->getMessage());
305 * Array(string $value => string $label).
307 public static function getRedactOptions() {
309 'default' => ts('Default'),
310 '0' => ts('Do not redact emails'),
311 '1' => ts('Redact emails'),
317 * Array(string $value => string $label).
319 public static function getMultiClientOptions() {
321 'default' => ts('Default'),
322 '0' => ts('Single client per case'),
323 '1' => ts('Multiple client per case'),
329 * Array(string $value => string $label).
331 public static function getSortOptions() {
333 'default' => ts('Default'),
334 '0' => ts('Definition order'),
335 '1' => ts('Alphabetical order'),