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