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