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