Merge pull request #3280 from atif-shaikh/CiviCoreBugs
[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 public function getInfo() {
46 return array(
47 'name' => 'CiviCase',
48 'translatedName' => ts('CiviCase'),
49 'title' => ts('CiviCase Engine'),
50 'search' => 1,
51 'showActivitiesInCore' => 0,
52 );
53 }
54
55 /**
56 * {@inheritDoc}
57 */
58 public function getAngularModules() {
59 $result = array();
60 $result['crmCaseType'] = array(
61 'ext' => 'civicrm',
62 'js' => array('js/angular-crmCaseType.js'),
63 'css' => array('css/angular-crmCaseType.css'),
64 );
65 // Need full OptionValue records
66 $actStatuses = civicrm_api3('OptionValue', 'get', array('option_group_id' => 'activity_status'));
67 $actTypes = civicrm_api3('OptionValue', 'get', array('option_group_id' => 'activity_type'));
68 CRM_Core_Resources::singleton()->addSetting(array(
69 'crmCaseType' => array(
70 'actStatuses' => array_values($actStatuses['values']),
71 'actTypes' => array_values($actTypes['values']),
72 //CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'name'),
73 ),
74 ));
75 return $result;
76 }
77
78 // docs inherited from interface
79 public function getManagedEntities() {
80 // Use hook_civicrm_caseTypes to build a list of OptionValues
81 // In the long run, we may want more specialized logic for this, but
82 // this design is fairly convenient and will allow us to replace it
83 // without changing the hook_civicrm_caseTypes interface.
84 $entities = array();
85
86 $caseTypes = array();
87 CRM_Utils_Hook::caseTypes($caseTypes);
88
89 $proc = new CRM_Case_XMLProcessor();
90 foreach ($caseTypes as $name => $caseType) {
91 $xml = $proc->retrieve($name);
92 if (!$xml) {
93 throw new CRM_Core_Exception("Failed to load XML for case type (" . $name . ")");
94 }
95
96 if (isset($caseType['module'], $caseType['name'], $caseType['file'])) {
97 $entities[] = array(
98 'module' => $caseType['module'],
99 'name' => $caseType['name'],
100 'entity' => 'CaseType',
101 'params' => array(
102 'version' => 3,
103 'name' => $caseType['name'],
104 'title' => (string) $xml->name,
105 'description' => (string) $xml->description,
106 'is_reserved' => 1,
107 'is_active' => 1,
108 'weight' => $xml->weight ? $xml->weight : 1,
109 ),
110 );
111 }
112 else {
113 throw new CRM_Core_Exception("Invalid case type");
114 }
115 }
116
117 return $entities;
118 }
119
120 // docs inherited from interface
121 public function getPermissions($getAllUnconditionally = FALSE) {
122 return array(
123 'delete in CiviCase',
124 'administer CiviCase',
125 'access my cases and activities',
126 'access all cases and activities',
127 'add cases',
128 );
129 }
130
131 // docs inherited from interface
132 public function getUserDashboardElement() {
133 return array();
134 }
135
136 // docs inherited from interface
137 public function registerTab() {
138 return array('title' => ts('Cases'),
139 'url' => 'case',
140 'weight' => 50,
141 );
142 }
143
144 // docs inherited from interface
145 public function registerAdvancedSearchPane() {
146 return array('title' => ts('Cases'),
147 'weight' => 50,
148 );
149 }
150
151 // docs inherited from interface
152 public function getActivityTypes() {
153 return NULL;
154 }
155
156 // add shortcut to Create New
157 public function creatNewShortcut(&$shortCuts) {
158 if (CRM_Core_Permission::check('access all cases and activities') ||
159 CRM_Core_Permission::check('add cases')
160 ) {
161 $atype = CRM_Core_OptionGroup::getValue('activity_type',
162 'Open Case',
163 'name'
164 );
165 if ($atype) {
166 $shortCuts = array_merge($shortCuts, array(
167 array('path' => 'civicrm/case/add',
168 'query' => "reset=1&action=add&atype=$atype&context=standalone",
169 'ref' => 'new-case',
170 'title' => ts('Case'),
171 )));
172 }
173 }
174 }
175
176 /**
177 * (Setting Callback)
178 * Respond to changes in the "enable_components" setting
179 *
180 * If CiviCase is being enabled, load the case related sample data
181 *
182 * @param array $oldValue List of component names
183 * @param array $newValue List of component names
184 * @param array $metadata Specification of the setting (per *.settings.php)
185 */
186 public static function onToggleComponents($oldValue, $newValue, $metadata) {
187 if (
188 in_array('CiviCase', $newValue)
189 &&
190 (!$oldValue || !in_array('CiviCase', $oldValue))
191 ) {
192 $config = CRM_Core_Config::singleton();
193 CRM_Admin_Form_Setting_Component::loadCaseSampleData($config->dsn, $config->sqlDir . 'case_sample.mysql');
194 if (!CRM_Case_BAO_Case::createCaseViews()) {
195 $msg = ts("Could not create the MySQL views for CiviCase. Your mysql user needs to have the 'CREATE VIEW' permission");
196 CRM_Core_Error::fatal($msg);
197 }
198 }
199 }
200 }
201