Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06b69b18 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
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 | +--------------------------------------------------------------------+ | |
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 | |
06b69b18 | 34 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
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 | ||
78650402 N |
55 | // docs inherited from interface |
56 | public function getManagedEntities() { | |
57 | // Use hook_civicrm_caseTypes to build a list of OptionValues | |
58 | // In the long run, we may want more specialized logic for this, but | |
59 | // this design is fairly convenient and will allow us to replace it | |
60 | // without changing the hook_civicrm_caseTypes interface. | |
61 | $entities = array(); | |
62 | ||
63 | $caseTypes = array(); | |
64 | CRM_Utils_Hook::caseTypes($caseTypes); | |
65 | ||
66 | $proc = new CRM_Case_XMLProcessor(); | |
67 | foreach ($caseTypes as $name => $caseType) { | |
68 | $xml = $proc->retrieve($name); | |
69 | if (!$xml) { | |
70 | throw new CRM_Core_Exception("Failed to load XML for case type (" . $name . ")"); | |
71 | } | |
72 | ||
73 | if (isset($caseType['module'], $caseType['name'], $caseType['file'])) { | |
74 | $entities[] = array( | |
75 | 'module' => $caseType['module'], | |
76 | 'name' => $caseType['name'], | |
77 | 'entity' => 'CaseType', | |
78 | 'params' => array( | |
79 | 'version' => 3, | |
80 | 'name' => $caseType['name'], | |
81 | 'title' => (string) $xml->name, | |
82 | 'description' => (string) $xml->description, | |
83 | 'is_reserved' => 1, | |
84 | 'is_active' => 1, | |
85 | 'weight' => $xml->weight ? $xml->weight : 1, | |
86 | ), | |
87 | ); | |
88 | } | |
89 | else { | |
90 | throw new CRM_Core_Exception("Invalid case type"); | |
91 | } | |
92 | } | |
93 | ||
94 | return $entities; | |
95 | } | |
96 | ||
6a488035 | 97 | // docs inherited from interface |
33777e4a | 98 | public function getPermissions($getAllUnconditionally = FALSE) { |
6a488035 TO |
99 | return array( |
100 | 'delete in CiviCase', | |
101 | 'administer CiviCase', | |
102 | 'access my cases and activities', | |
103 | 'access all cases and activities', | |
104 | 'add cases', | |
105 | ); | |
106 | } | |
107 | ||
108 | // docs inherited from interface | |
109 | public function getUserDashboardElement() { | |
110 | return array(); | |
111 | } | |
112 | ||
113 | // docs inherited from interface | |
114 | public function registerTab() { | |
115 | return array('title' => ts('Cases'), | |
116 | 'url' => 'case', | |
117 | 'weight' => 50, | |
118 | ); | |
119 | } | |
120 | ||
121 | // docs inherited from interface | |
122 | public function registerAdvancedSearchPane() { | |
123 | return array('title' => ts('Cases'), | |
124 | 'weight' => 50, | |
125 | ); | |
126 | } | |
127 | ||
128 | // docs inherited from interface | |
129 | public function getActivityTypes() { | |
130 | return NULL; | |
131 | } | |
132 | ||
133 | // add shortcut to Create New | |
134 | public function creatNewShortcut(&$shortCuts) { | |
135 | if (CRM_Core_Permission::check('access all cases and activities') || | |
136 | CRM_Core_Permission::check('add cases') | |
137 | ) { | |
138 | $atype = CRM_Core_OptionGroup::getValue('activity_type', | |
139 | 'Open Case', | |
140 | 'name' | |
141 | ); | |
142 | if ($atype) { | |
143 | $shortCuts = array_merge($shortCuts, array( | |
144 | array('path' => 'civicrm/case/add', | |
145 | 'query' => "reset=1&action=add&atype=$atype&context=standalone", | |
146 | 'ref' => 'new-case', | |
147 | 'title' => ts('Case'), | |
148 | ))); | |
149 | } | |
150 | } | |
151 | } | |
2bc3bd8f TO |
152 | |
153 | /** | |
154 | * (Setting Callback) | |
155 | * Respond to changes in the "enable_components" setting | |
156 | * | |
157 | * If CiviCase is being enabled, load the case related sample data | |
158 | * | |
159 | * @param array $oldValue List of component names | |
160 | * @param array $newValue List of component names | |
161 | * @param array $metadata Specification of the setting (per *.settings.php) | |
162 | */ | |
163 | public static function onToggleComponents($oldValue, $newValue, $metadata) { | |
e6d720bb TO |
164 | if ( |
165 | in_array('CiviCase', $newValue) | |
166 | && | |
167 | (!$oldValue || !in_array('CiviCase', $oldValue)) | |
2bc3bd8f TO |
168 | ) { |
169 | $config = CRM_Core_Config::singleton(); | |
170 | CRM_Admin_Form_Setting_Component::loadCaseSampleData($config->dsn, $config->sqlDir . 'case_sample.mysql'); | |
2bc3bd8f TO |
171 | if (!CRM_Case_BAO_Case::createCaseViews()) { |
172 | $msg = ts("Could not create the MySQL views for CiviCase. Your mysql user needs to have the 'CREATE VIEW' permission"); | |
173 | CRM_Core_Error::fatal($msg); | |
174 | } | |
175 | } | |
176 | } | |
6a488035 TO |
177 | } |
178 |