Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
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 | |
e7112fa7 | 34 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
35 | * $Id$ |
36 | * | |
37 | */ | |
38 | class CRM_Case_Info extends CRM_Core_Component_Info { | |
39 | ||
40 | ||
e7c15cb6 CW |
41 | /** |
42 | * @inheritDoc | |
43 | */ | |
6a488035 TO |
44 | protected $keyword = 'case'; |
45 | ||
4c6ce474 | 46 | /** |
e7c15cb6 | 47 | * @inheritDoc |
4c6ce474 EM |
48 | * @return array |
49 | */ | |
6a488035 TO |
50 | public function getInfo() { |
51 | return array( | |
52 | 'name' => 'CiviCase', | |
53 | 'translatedName' => ts('CiviCase'), | |
54 | 'title' => ts('CiviCase Engine'), | |
55 | 'search' => 1, | |
56 | 'showActivitiesInCore' => 0, | |
57 | ); | |
58 | } | |
59 | ||
4c58e251 | 60 | /** |
e7c15cb6 | 61 | * @inheritDoc |
4c58e251 TO |
62 | */ |
63 | public function getAngularModules() { | |
64 | $result = array(); | |
d08319ae TO |
65 | $result['crmCaseType'] = array( |
66 | 'ext' => 'civicrm', | |
5a173b92 TO |
67 | 'js' => array('ang/crmCaseType.js'), |
68 | 'css' => array('ang/crmCaseType.css'), | |
69 | 'partials' => array('ang/crmCaseType'), | |
d08319ae | 70 | ); |
8c7e0ae8 | 71 | |
dc7a657e TO |
72 | CRM_Core_Resources::singleton()->addSetting(array( |
73 | 'crmCaseType' => array( | |
9625aad1 | 74 | 'REL_TYPE_CNAME' => CRM_Case_XMLProcessor::REL_TYPE_CNAME, |
dc7a657e TO |
75 | ), |
76 | )); | |
4c58e251 TO |
77 | return $result; |
78 | } | |
79 | ||
4c6ce474 | 80 | /** |
e7c15cb6 | 81 | * @inheritDoc |
4c6ce474 EM |
82 | * @return array |
83 | * @throws CRM_Core_Exception | |
84 | */ | |
78650402 | 85 | public function getManagedEntities() { |
32e74b94 TO |
86 | $entities = array_merge( |
87 | CRM_Case_ManagedEntities::createManagedCaseTypes(), | |
88 | CRM_Case_ManagedEntities::createManagedActivityTypes(CRM_Case_XMLRepository::singleton(), CRM_Core_ManagedEntities::singleton()), | |
89 | CRM_Case_ManagedEntities::createManagedRelationshipTypes(CRM_Case_XMLRepository::singleton(), CRM_Core_ManagedEntities::singleton()) | |
90 | ); | |
78650402 N |
91 | return $entities; |
92 | } | |
93 | ||
4c6ce474 | 94 | /** |
e7c15cb6 | 95 | * @inheritDoc |
4c6ce474 | 96 | * @param bool $getAllUnconditionally |
221b21b4 AH |
97 | * @param bool $descriptions |
98 | * Whether to return permission descriptions | |
4c6ce474 EM |
99 | * |
100 | * @return array | |
101 | */ | |
221b21b4 AH |
102 | public function getPermissions($getAllUnconditionally = FALSE, $descriptions = FALSE) { |
103 | $permissions = array( | |
104 | 'delete in CiviCase' => array( | |
105 | ts('delete in CiviCase'), | |
106 | ts('Delete Cases'), | |
107 | ), | |
108 | 'administer CiviCase' => array( | |
109 | ts('administer CiviCase'), | |
110 | ), | |
111 | 'access my cases and activities' => array( | |
112 | ts('access my cases and activities'), | |
113 | ), | |
114 | 'access all cases and activities' => array( | |
115 | ts('access all cases and activities'), | |
116 | ), | |
117 | 'add cases' => array( | |
118 | ts('add cases'), | |
119 | ), | |
6a488035 | 120 | ); |
221b21b4 AH |
121 | |
122 | if (!$descriptions) { | |
123 | foreach ($permissions as $name => $attr) { | |
124 | $permissions[$name] = array_shift($attr); | |
125 | } | |
126 | } | |
127 | ||
128 | return $permissions; | |
6a488035 TO |
129 | } |
130 | ||
168f458e | 131 | /** |
e7c15cb6 | 132 | * @inheritDoc |
168f458e TO |
133 | */ |
134 | public function getReferenceCounts($dao) { | |
135 | $result = array(); | |
136 | if ($dao instanceof CRM_Core_DAO_OptionValue) { | |
137 | /** @var $dao CRM_Core_DAO_OptionValue */ | |
138 | $activity_type_gid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'activity_type', 'id', 'name'); | |
139 | if ($activity_type_gid == $dao->option_group_id) { | |
140 | $count = CRM_Case_XMLRepository::singleton() | |
141 | ->getActivityReferenceCount($dao->name); | |
142 | if ($count > 0) { | |
143 | $result[] = array( | |
144 | 'name' => 'casetypexml:activities', | |
145 | 'type' => 'casetypexml', | |
146 | 'count' => $count, | |
147 | ); | |
148 | } | |
149 | } | |
150 | } | |
151 | elseif ($dao instanceof CRM_Contact_DAO_RelationshipType) { | |
152 | /** @var $dao CRM_Contact_DAO_RelationshipType */ | |
153 | $count = CRM_Case_XMLRepository::singleton() | |
154 | ->getRelationshipReferenceCount($dao->{CRM_Case_XMLProcessor::REL_TYPE_CNAME}); | |
155 | if ($count > 0) { | |
156 | $result[] = array( | |
157 | 'name' => 'casetypexml:relationships', | |
158 | 'type' => 'casetypexml', | |
159 | 'count' => $count, | |
160 | ); | |
161 | } | |
162 | } | |
163 | return $result; | |
164 | } | |
165 | ||
4c6ce474 | 166 | /** |
e7c15cb6 | 167 | * @inheritDoc |
4c6ce474 EM |
168 | * @return array |
169 | */ | |
6a488035 TO |
170 | public function getUserDashboardElement() { |
171 | return array(); | |
172 | } | |
173 | ||
4c6ce474 | 174 | /** |
e7c15cb6 | 175 | * @inheritDoc |
4c6ce474 EM |
176 | * @return array |
177 | */ | |
6a488035 | 178 | public function registerTab() { |
e547f744 | 179 | return array( |
353ffa53 | 180 | 'title' => ts('Cases'), |
6a488035 TO |
181 | 'url' => 'case', |
182 | 'weight' => 50, | |
183 | ); | |
184 | } | |
185 | ||
4c6ce474 | 186 | /** |
e7c15cb6 | 187 | * @inheritDoc |
4c6ce474 EM |
188 | * @return array |
189 | */ | |
6a488035 | 190 | public function registerAdvancedSearchPane() { |
e547f744 | 191 | return array( |
353ffa53 | 192 | 'title' => ts('Cases'), |
6a488035 TO |
193 | 'weight' => 50, |
194 | ); | |
195 | } | |
196 | ||
4c6ce474 | 197 | /** |
e7c15cb6 | 198 | * @inheritDoc |
4c6ce474 EM |
199 | * @return null |
200 | */ | |
6a488035 TO |
201 | public function getActivityTypes() { |
202 | return NULL; | |
203 | } | |
204 | ||
4c6ce474 | 205 | /** |
fe482240 | 206 | * add shortcut to Create New. |
4c6ce474 EM |
207 | * @param $shortCuts |
208 | */ | |
6a488035 TO |
209 | public function creatNewShortcut(&$shortCuts) { |
210 | if (CRM_Core_Permission::check('access all cases and activities') || | |
211 | CRM_Core_Permission::check('add cases') | |
212 | ) { | |
213 | $atype = CRM_Core_OptionGroup::getValue('activity_type', | |
214 | 'Open Case', | |
215 | 'name' | |
216 | ); | |
217 | if ($atype) { | |
218 | $shortCuts = array_merge($shortCuts, array( | |
e547f744 | 219 | array( |
353ffa53 TO |
220 | 'path' => 'civicrm/case/add', |
221 | 'query' => "reset=1&action=add&atype=$atype&context=standalone", | |
222 | 'ref' => 'new-case', | |
223 | 'title' => ts('Case'), | |
c301f76e | 224 | ), |
353ffa53 | 225 | )); |
6a488035 TO |
226 | } |
227 | } | |
228 | } | |
2bc3bd8f TO |
229 | |
230 | /** | |
231 | * (Setting Callback) | |
232 | * Respond to changes in the "enable_components" setting | |
233 | * | |
234 | * If CiviCase is being enabled, load the case related sample data | |
235 | * | |
64bd5a0e TO |
236 | * @param array $oldValue |
237 | * List of component names. | |
238 | * @param array $newValue | |
239 | * List of component names. | |
240 | * @param array $metadata | |
241 | * Specification of the setting (per *.settings.php). | |
2bc3bd8f TO |
242 | */ |
243 | public static function onToggleComponents($oldValue, $newValue, $metadata) { | |
e6d720bb TO |
244 | if ( |
245 | in_array('CiviCase', $newValue) | |
246 | && | |
247 | (!$oldValue || !in_array('CiviCase', $oldValue)) | |
2bc3bd8f | 248 | ) { |
e547f744 | 249 | $pathToCaseSampleTpl = __DIR__ . '/xml/configuration.sample/'; |
2bc3bd8f | 250 | $config = CRM_Core_Config::singleton(); |
d72f7af5 | 251 | CRM_Admin_Form_Setting_Component::loadCaseSampleData($config->dsn, $pathToCaseSampleTpl . 'case_sample.mysql.tpl'); |
2bc3bd8f TO |
252 | if (!CRM_Case_BAO_Case::createCaseViews()) { |
253 | $msg = ts("Could not create the MySQL views for CiviCase. Your mysql user needs to have the 'CREATE VIEW' permission"); | |
254 | CRM_Core_Error::fatal($msg); | |
255 | } | |
256 | } | |
257 | } | |
96025800 | 258 | |
6a488035 | 259 | } |