6cdfb926502d79765ef495e961a1a01dc6f9f194
[civicrm-core.git] / CRM / Case / Info.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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
34 * @copyright CiviCRM LLC (c) 2004-2014
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 /**
46 * @return array
47 */
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
58 /**
59 * {@inheritDoc}
60 */
61 public function getAngularModules() {
62 $result = array();
63 $result['crmCaseType'] = array(
64 'ext' => 'civicrm',
65 'js' => array('js/angular-crmCaseType.js'),
66 'css' => array('css/angular-crmCaseType.css'),
67 );
68 // Need full OptionValue records
69 $actStatuses = civicrm_api3('OptionValue', 'get', array('option_group_id' => 'activity_status'));
70 $actTypes = civicrm_api3('OptionValue', 'get', array(
71 'option_group_id' => 'activity_type',
72 'options' => array(
73 'sort' => 'name',
74 'limit' => 0,
75 ),
76 ));
77 $relTypes = civicrm_api3('RelationshipType', 'get', array(
78 'options' => array(
79 'sort' => CRM_Case_XMLProcessor::REL_TYPE_CNAME,
80 'limit' => 0,
81 )
82 ));
83
84 CRM_Core_Resources::singleton()->addSetting(array(
85 'crmCaseType' => array(
86 'actStatuses' => array_values($actStatuses['values']),
87 'actTypes' => array_values($actTypes['values']),
88 'relTypes' => array_values($relTypes['values']),
89 //CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'name'),
90
91 ),
92 ));
93 return $result;
94 }
95
96 // docs inherited from interface
97 /**
98 * @return array
99 * @throws CRM_Core_Exception
100 */
101 public function getManagedEntities() {
102 $entities = array_merge(
103 CRM_Case_ManagedEntities::createManagedCaseTypes(),
104 CRM_Case_ManagedEntities::createManagedActivityTypes(CRM_Case_XMLRepository::singleton(), CRM_Core_ManagedEntities::singleton()),
105 CRM_Case_ManagedEntities::createManagedRelationshipTypes(CRM_Case_XMLRepository::singleton(), CRM_Core_ManagedEntities::singleton())
106 );
107 return $entities;
108 }
109
110 // docs inherited from interface
111 /**
112 * @param bool $getAllUnconditionally
113 *
114 * @return array
115 */
116 public function getPermissions($getAllUnconditionally = FALSE) {
117 return array(
118 'delete in CiviCase',
119 'administer CiviCase',
120 'access my cases and activities',
121 'access all cases and activities',
122 'add cases',
123 );
124 }
125
126 /**
127 * {@inheritdoc}
128 */
129 public function getReferenceCounts($dao) {
130 $result = array();
131 if ($dao instanceof CRM_Core_DAO_OptionValue) {
132 /** @var $dao CRM_Core_DAO_OptionValue */
133 $activity_type_gid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'activity_type', 'id', 'name');
134 if ($activity_type_gid == $dao->option_group_id) {
135 $count = CRM_Case_XMLRepository::singleton()
136 ->getActivityReferenceCount($dao->name);
137 if ($count > 0) {
138 $result[] = array(
139 'name' => 'casetypexml:activities',
140 'type' => 'casetypexml',
141 'count' => $count,
142 );
143 }
144 }
145 }
146 elseif ($dao instanceof CRM_Contact_DAO_RelationshipType) {
147 /** @var $dao CRM_Contact_DAO_RelationshipType */
148 $count = CRM_Case_XMLRepository::singleton()
149 ->getRelationshipReferenceCount($dao->{CRM_Case_XMLProcessor::REL_TYPE_CNAME});
150 if ($count > 0) {
151 $result[] = array(
152 'name' => 'casetypexml:relationships',
153 'type' => 'casetypexml',
154 'count' => $count,
155 );
156 }
157 }
158 return $result;
159 }
160
161 // docs inherited from interface
162 /**
163 * @return array
164 */
165 public function getUserDashboardElement() {
166 return array();
167 }
168
169 // docs inherited from interface
170 /**
171 * @return array
172 */
173 public function registerTab() {
174 return array('title' => ts('Cases'),
175 'url' => 'case',
176 'weight' => 50,
177 );
178 }
179
180 // docs inherited from interface
181 /**
182 * @return array
183 */
184 public function registerAdvancedSearchPane() {
185 return array('title' => ts('Cases'),
186 'weight' => 50,
187 );
188 }
189
190 // docs inherited from interface
191 /**
192 * @return null
193 */
194 public function getActivityTypes() {
195 return NULL;
196 }
197
198 // add shortcut to Create New
199 /**
200 * @param $shortCuts
201 */
202 public function creatNewShortcut(&$shortCuts) {
203 if (CRM_Core_Permission::check('access all cases and activities') ||
204 CRM_Core_Permission::check('add cases')
205 ) {
206 $atype = CRM_Core_OptionGroup::getValue('activity_type',
207 'Open Case',
208 'name'
209 );
210 if ($atype) {
211 $shortCuts = array_merge($shortCuts, array(
212 array('path' => 'civicrm/case/add',
213 'query' => "reset=1&action=add&atype=$atype&context=standalone",
214 'ref' => 'new-case',
215 'title' => ts('Case'),
216 )));
217 }
218 }
219 }
220
221 /**
222 * (Setting Callback)
223 * Respond to changes in the "enable_components" setting
224 *
225 * If CiviCase is being enabled, load the case related sample data
226 *
227 * @param array $oldValue List of component names
228 * @param array $newValue List of component names
229 * @param array $metadata Specification of the setting (per *.settings.php)
230 */
231 public static function onToggleComponents($oldValue, $newValue, $metadata) {
232 if (
233 in_array('CiviCase', $newValue)
234 &&
235 (!$oldValue || !in_array('CiviCase', $oldValue))
236 ) {
237 $config = CRM_Core_Config::singleton();
238 CRM_Admin_Form_Setting_Component::loadCaseSampleData($config->dsn, $config->sqlDir . 'case_sample.mysql');
239 if (!CRM_Case_BAO_Case::createCaseViews()) {
240 $msg = ts("Could not create the MySQL views for CiviCase. Your mysql user needs to have the 'CREATE VIEW' permission");
241 CRM_Core_Error::fatal($msg);
242 }
243 }
244 }
245 }
246