commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / civicrm / CRM / Case / Info.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
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('ang/crmCaseType.js'),
68 'css' => array('ang/crmCaseType.css'),
69 'partials' => array('ang/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 * @param bool $descriptions
98 * Whether to return permission descriptions
99 *
100 * @return array
101 */
102 public function getPermissions($getAllUnconditionally = FALSE, $descriptions = FALSE) {
103 $permissions = array(
104 'delete in CiviCase' => array(
105 ts('delete in CiviCase'),
106 ts('Delete Cases'),
107 ),
108 'administer CiviCase' => array(
109 ts('administer CiviCase'),
110 ),
111 'access my cases and activities' => array(
112 ts('access my cases and activities'),
113 ),
114 'access all cases and activities' => array(
115 ts('access all cases and activities'),
116 ),
117 'add cases' => array(
118 ts('add cases'),
119 ),
120 );
121
122 if (!$descriptions) {
123 foreach ($permissions as $name => $attr) {
124 $permissions[$name] = array_shift($attr);
125 }
126 }
127
128 return $permissions;
129 }
130
131 /**
132 * @inheritDoc
133 */
134 public function getReferenceCounts($dao) {
135 $result = array();
136 if ($dao instanceof CRM_Core_DAO_OptionValue) {
137 /** @var $dao CRM_Core_DAO_OptionValue */
138 $activity_type_gid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'activity_type', 'id', 'name');
139 if ($activity_type_gid == $dao->option_group_id) {
140 $count = CRM_Case_XMLRepository::singleton()
141 ->getActivityReferenceCount($dao->name);
142 if ($count > 0) {
143 $result[] = array(
144 'name' => 'casetypexml:activities',
145 'type' => 'casetypexml',
146 'count' => $count,
147 );
148 }
149 }
150 }
151 elseif ($dao instanceof CRM_Contact_DAO_RelationshipType) {
152 /** @var $dao CRM_Contact_DAO_RelationshipType */
153 $count = CRM_Case_XMLRepository::singleton()
154 ->getRelationshipReferenceCount($dao->{CRM_Case_XMLProcessor::REL_TYPE_CNAME});
155 if ($count > 0) {
156 $result[] = array(
157 'name' => 'casetypexml:relationships',
158 'type' => 'casetypexml',
159 'count' => $count,
160 );
161 }
162 }
163 return $result;
164 }
165
166 /**
167 * @inheritDoc
168 * @return array
169 */
170 public function getUserDashboardElement() {
171 return array();
172 }
173
174 /**
175 * @inheritDoc
176 * @return array
177 */
178 public function registerTab() {
179 return array(
180 'title' => ts('Cases'),
181 'url' => 'case',
182 'weight' => 50,
183 );
184 }
185
186 /**
187 * @inheritDoc
188 * @return array
189 */
190 public function registerAdvancedSearchPane() {
191 return array(
192 'title' => ts('Cases'),
193 'weight' => 50,
194 );
195 }
196
197 /**
198 * @inheritDoc
199 * @return null
200 */
201 public function getActivityTypes() {
202 return NULL;
203 }
204
205 /**
206 * add shortcut to Create New.
207 * @param $shortCuts
208 */
209 public function creatNewShortcut(&$shortCuts) {
210 if (CRM_Core_Permission::check('access all cases and activities') ||
211 CRM_Core_Permission::check('add cases')
212 ) {
213 $atype = CRM_Core_OptionGroup::getValue('activity_type',
214 'Open Case',
215 'name'
216 );
217 if ($atype) {
218 $shortCuts = array_merge($shortCuts, array(
219 array(
220 'path' => 'civicrm/case/add',
221 'query' => "reset=1&action=add&atype=$atype&context=standalone",
222 'ref' => 'new-case',
223 'title' => ts('Case'),
224 ),
225 ));
226 }
227 }
228 }
229
230 /**
231 * (Setting Callback)
232 * Respond to changes in the "enable_components" setting
233 *
234 * If CiviCase is being enabled, load the case related sample data
235 *
236 * @param array $oldValue
237 * List of component names.
238 * @param array $newValue
239 * List of component names.
240 * @param array $metadata
241 * Specification of the setting (per *.settings.php).
242 */
243 public static function onToggleComponents($oldValue, $newValue, $metadata) {
244 if (
245 in_array('CiviCase', $newValue)
246 &&
247 (!$oldValue || !in_array('CiviCase', $oldValue))
248 ) {
249 $pathToCaseSampleTpl = __DIR__ . '/xml/configuration.sample/';
250 $config = CRM_Core_Config::singleton();
251 CRM_Admin_Form_Setting_Component::loadCaseSampleData($config->dsn, $pathToCaseSampleTpl . 'case_sample.mysql.tpl');
252 if (!CRM_Case_BAO_Case::createCaseViews()) {
253 $msg = ts("Could not create the MySQL views for CiviCase. Your mysql user needs to have the 'CREATE VIEW' permission");
254 CRM_Core_Error::fatal($msg);
255 }
256 }
257 }
258
259 }