Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
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 | ||
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', | |
67 | 'js' => array('js/angular-crmCaseType.js'), | |
68 | 'css' => array('css/angular-crmCaseType.css'), | |
69 | ); | |
8c7e0ae8 | 70 | |
dc7a657e TO |
71 | CRM_Core_Resources::singleton()->addSetting(array( |
72 | 'crmCaseType' => array( | |
9625aad1 | 73 | 'REL_TYPE_CNAME' => CRM_Case_XMLProcessor::REL_TYPE_CNAME, |
dc7a657e TO |
74 | ), |
75 | )); | |
4c58e251 TO |
76 | return $result; |
77 | } | |
78 | ||
4c6ce474 | 79 | /** |
e7c15cb6 | 80 | * @inheritDoc |
4c6ce474 EM |
81 | * @return array |
82 | * @throws CRM_Core_Exception | |
83 | */ | |
78650402 | 84 | public function getManagedEntities() { |
32e74b94 TO |
85 | $entities = array_merge( |
86 | CRM_Case_ManagedEntities::createManagedCaseTypes(), | |
87 | CRM_Case_ManagedEntities::createManagedActivityTypes(CRM_Case_XMLRepository::singleton(), CRM_Core_ManagedEntities::singleton()), | |
88 | CRM_Case_ManagedEntities::createManagedRelationshipTypes(CRM_Case_XMLRepository::singleton(), CRM_Core_ManagedEntities::singleton()) | |
89 | ); | |
78650402 N |
90 | return $entities; |
91 | } | |
92 | ||
4c6ce474 | 93 | /** |
e7c15cb6 | 94 | * @inheritDoc |
4c6ce474 EM |
95 | * @param bool $getAllUnconditionally |
96 | * | |
97 | * @return array | |
98 | */ | |
33777e4a | 99 | public function getPermissions($getAllUnconditionally = FALSE) { |
6a488035 TO |
100 | return array( |
101 | 'delete in CiviCase', | |
102 | 'administer CiviCase', | |
103 | 'access my cases and activities', | |
104 | 'access all cases and activities', | |
105 | 'add cases', | |
106 | ); | |
107 | } | |
108 | ||
168f458e | 109 | /** |
e7c15cb6 | 110 | * @inheritDoc |
168f458e TO |
111 | */ |
112 | public function getReferenceCounts($dao) { | |
113 | $result = array(); | |
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); | |
120 | if ($count > 0) { | |
121 | $result[] = array( | |
122 | 'name' => 'casetypexml:activities', | |
123 | 'type' => 'casetypexml', | |
124 | 'count' => $count, | |
125 | ); | |
126 | } | |
127 | } | |
128 | } | |
129 | elseif ($dao instanceof CRM_Contact_DAO_RelationshipType) { | |
130 | /** @var $dao CRM_Contact_DAO_RelationshipType */ | |
131 | $count = CRM_Case_XMLRepository::singleton() | |
132 | ->getRelationshipReferenceCount($dao->{CRM_Case_XMLProcessor::REL_TYPE_CNAME}); | |
133 | if ($count > 0) { | |
134 | $result[] = array( | |
135 | 'name' => 'casetypexml:relationships', | |
136 | 'type' => 'casetypexml', | |
137 | 'count' => $count, | |
138 | ); | |
139 | } | |
140 | } | |
141 | return $result; | |
142 | } | |
143 | ||
4c6ce474 | 144 | /** |
e7c15cb6 | 145 | * @inheritDoc |
4c6ce474 EM |
146 | * @return array |
147 | */ | |
6a488035 TO |
148 | public function getUserDashboardElement() { |
149 | return array(); | |
150 | } | |
151 | ||
4c6ce474 | 152 | /** |
e7c15cb6 | 153 | * @inheritDoc |
4c6ce474 EM |
154 | * @return array |
155 | */ | |
6a488035 | 156 | public function registerTab() { |
e547f744 | 157 | return array( |
353ffa53 | 158 | 'title' => ts('Cases'), |
6a488035 TO |
159 | 'url' => 'case', |
160 | 'weight' => 50, | |
161 | ); | |
162 | } | |
163 | ||
4c6ce474 | 164 | /** |
e7c15cb6 | 165 | * @inheritDoc |
4c6ce474 EM |
166 | * @return array |
167 | */ | |
6a488035 | 168 | public function registerAdvancedSearchPane() { |
e547f744 | 169 | return array( |
353ffa53 | 170 | 'title' => ts('Cases'), |
6a488035 TO |
171 | 'weight' => 50, |
172 | ); | |
173 | } | |
174 | ||
4c6ce474 | 175 | /** |
e7c15cb6 | 176 | * @inheritDoc |
4c6ce474 EM |
177 | * @return null |
178 | */ | |
6a488035 TO |
179 | public function getActivityTypes() { |
180 | return NULL; | |
181 | } | |
182 | ||
4c6ce474 | 183 | /** |
4f1f1f2a | 184 | * add shortcut to Create New |
4c6ce474 EM |
185 | * @param $shortCuts |
186 | */ | |
6a488035 TO |
187 | public function creatNewShortcut(&$shortCuts) { |
188 | if (CRM_Core_Permission::check('access all cases and activities') || | |
189 | CRM_Core_Permission::check('add cases') | |
190 | ) { | |
191 | $atype = CRM_Core_OptionGroup::getValue('activity_type', | |
192 | 'Open Case', | |
193 | 'name' | |
194 | ); | |
195 | if ($atype) { | |
196 | $shortCuts = array_merge($shortCuts, array( | |
e547f744 | 197 | array( |
353ffa53 TO |
198 | 'path' => 'civicrm/case/add', |
199 | 'query' => "reset=1&action=add&atype=$atype&context=standalone", | |
200 | 'ref' => 'new-case', | |
201 | 'title' => ts('Case'), | |
202 | ) | |
203 | )); | |
6a488035 TO |
204 | } |
205 | } | |
206 | } | |
2bc3bd8f TO |
207 | |
208 | /** | |
209 | * (Setting Callback) | |
210 | * Respond to changes in the "enable_components" setting | |
211 | * | |
212 | * If CiviCase is being enabled, load the case related sample data | |
213 | * | |
64bd5a0e TO |
214 | * @param array $oldValue |
215 | * List of component names. | |
216 | * @param array $newValue | |
217 | * List of component names. | |
218 | * @param array $metadata | |
219 | * Specification of the setting (per *.settings.php). | |
2bc3bd8f TO |
220 | */ |
221 | public static function onToggleComponents($oldValue, $newValue, $metadata) { | |
e6d720bb TO |
222 | if ( |
223 | in_array('CiviCase', $newValue) | |
224 | && | |
225 | (!$oldValue || !in_array('CiviCase', $oldValue)) | |
2bc3bd8f | 226 | ) { |
e547f744 | 227 | $pathToCaseSampleTpl = __DIR__ . '/xml/configuration.sample/'; |
2bc3bd8f | 228 | $config = CRM_Core_Config::singleton(); |
d72f7af5 | 229 | CRM_Admin_Form_Setting_Component::loadCaseSampleData($config->dsn, $pathToCaseSampleTpl . 'case_sample.mysql.tpl'); |
2bc3bd8f TO |
230 | if (!CRM_Case_BAO_Case::createCaseViews()) { |
231 | $msg = ts("Could not create the MySQL views for CiviCase. Your mysql user needs to have the 'CREATE VIEW' permission"); | |
232 | CRM_Core_Error::fatal($msg); | |
233 | } | |
234 | } | |
235 | } | |
6a488035 | 236 | } |