| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.7 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2017 | |
| 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-2017 |
| 35 | */ |
| 36 | class CRM_Case_Info extends CRM_Core_Component_Info { |
| 37 | |
| 38 | |
| 39 | /** |
| 40 | * @inheritDoc |
| 41 | */ |
| 42 | protected $keyword = 'case'; |
| 43 | |
| 44 | /** |
| 45 | * @inheritDoc |
| 46 | * @return array |
| 47 | */ |
| 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 | |
| 58 | /** |
| 59 | * @inheritDoc |
| 60 | */ |
| 61 | public function getAngularModules() { |
| 62 | global $civicrm_root; |
| 63 | |
| 64 | $result = array(); |
| 65 | $result['crmCaseType'] = include "$civicrm_root/ang/crmCaseType.ang.php"; |
| 66 | return $result; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * @inheritDoc |
| 71 | * @return array |
| 72 | * @throws CRM_Core_Exception |
| 73 | */ |
| 74 | public function getManagedEntities() { |
| 75 | $entities = array_merge( |
| 76 | CRM_Case_ManagedEntities::createManagedCaseTypes(), |
| 77 | CRM_Case_ManagedEntities::createManagedActivityTypes(CRM_Case_XMLRepository::singleton(), CRM_Core_ManagedEntities::singleton()), |
| 78 | CRM_Case_ManagedEntities::createManagedRelationshipTypes(CRM_Case_XMLRepository::singleton(), CRM_Core_ManagedEntities::singleton()) |
| 79 | ); |
| 80 | return $entities; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * @inheritDoc |
| 85 | * @param bool $getAllUnconditionally |
| 86 | * @param bool $descriptions |
| 87 | * Whether to return permission descriptions |
| 88 | * |
| 89 | * @return array |
| 90 | */ |
| 91 | public function getPermissions($getAllUnconditionally = FALSE, $descriptions = FALSE) { |
| 92 | $permissions = array( |
| 93 | 'delete in CiviCase' => array( |
| 94 | ts('delete in CiviCase'), |
| 95 | ts('Delete cases'), |
| 96 | ), |
| 97 | 'administer CiviCase' => array( |
| 98 | ts('administer CiviCase'), |
| 99 | ts('Define case types, access deleted cases'), |
| 100 | ), |
| 101 | 'access my cases and activities' => array( |
| 102 | ts('access my cases and activities'), |
| 103 | ts('View and edit only those cases managed by this user'), |
| 104 | ), |
| 105 | 'access all cases and activities' => array( |
| 106 | ts('access all cases and activities'), |
| 107 | ts('View and edit all cases (for visible contacts)'), |
| 108 | ), |
| 109 | 'add cases' => array( |
| 110 | ts('add cases'), |
| 111 | ts('Open a new case'), |
| 112 | ), |
| 113 | ); |
| 114 | |
| 115 | if (!$descriptions) { |
| 116 | foreach ($permissions as $name => $attr) { |
| 117 | $permissions[$name] = array_shift($attr); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | return $permissions; |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * @inheritDoc |
| 126 | */ |
| 127 | public function getReferenceCounts($dao) { |
| 128 | $result = array(); |
| 129 | if ($dao instanceof CRM_Core_DAO_OptionValue) { |
| 130 | /** @var $dao CRM_Core_DAO_OptionValue */ |
| 131 | $activity_type_gid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'activity_type', 'id', 'name'); |
| 132 | if ($activity_type_gid == $dao->option_group_id) { |
| 133 | $count = CRM_Case_XMLRepository::singleton() |
| 134 | ->getActivityReferenceCount($dao->name); |
| 135 | if ($count > 0) { |
| 136 | $result[] = array( |
| 137 | 'name' => 'casetypexml:activities', |
| 138 | 'type' => 'casetypexml', |
| 139 | 'count' => $count, |
| 140 | ); |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | elseif ($dao instanceof CRM_Contact_DAO_RelationshipType) { |
| 145 | /** @var $dao CRM_Contact_DAO_RelationshipType */ |
| 146 | $count = CRM_Case_XMLRepository::singleton() |
| 147 | ->getRelationshipReferenceCount($dao->{CRM_Case_XMLProcessor::REL_TYPE_CNAME}); |
| 148 | if ($count > 0) { |
| 149 | $result[] = array( |
| 150 | 'name' => 'casetypexml:relationships', |
| 151 | 'type' => 'casetypexml', |
| 152 | 'count' => $count, |
| 153 | ); |
| 154 | } |
| 155 | } |
| 156 | return $result; |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * @inheritDoc |
| 161 | * @return array |
| 162 | */ |
| 163 | public function getUserDashboardElement() { |
| 164 | return array(); |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * @inheritDoc |
| 169 | * @return array |
| 170 | */ |
| 171 | public function registerTab() { |
| 172 | return array( |
| 173 | 'title' => ts('Cases'), |
| 174 | 'url' => 'case', |
| 175 | 'weight' => 50, |
| 176 | ); |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * @inheritDoc |
| 181 | * @return array |
| 182 | */ |
| 183 | public function registerAdvancedSearchPane() { |
| 184 | return array( |
| 185 | 'title' => ts('Cases'), |
| 186 | 'weight' => 50, |
| 187 | ); |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * @inheritDoc |
| 192 | * @return null |
| 193 | */ |
| 194 | public function getActivityTypes() { |
| 195 | return NULL; |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * add shortcut to Create New. |
| 200 | * @param $shortCuts |
| 201 | */ |
| 202 | public function creatNewShortcut(&$shortCuts) { |
| 203 | if (CRM_Core_Permission::check('access all cases and activities') || |
| 204 | CRM_Core_Permission::check('add cases') |
| 205 | ) { |
| 206 | $activityType = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Open Case'); |
| 207 | if ($activityType) { |
| 208 | $shortCuts = array_merge($shortCuts, array( |
| 209 | array( |
| 210 | 'path' => 'civicrm/case/add', |
| 211 | 'query' => "reset=1&action=add&atype={$activityType}&context=standalone", |
| 212 | 'ref' => 'new-case', |
| 213 | 'title' => ts('Case'), |
| 214 | ), |
| 215 | )); |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | /** |
| 221 | * (Setting Callback) |
| 222 | * Respond to changes in the "enable_components" setting |
| 223 | * |
| 224 | * If CiviCase is being enabled, load the case related sample data |
| 225 | * |
| 226 | * @param array $oldValue |
| 227 | * List of component names. |
| 228 | * @param array $newValue |
| 229 | * List of component names. |
| 230 | * @param array $metadata |
| 231 | * Specification of the setting (per *.settings.php). |
| 232 | */ |
| 233 | public static function onToggleComponents($oldValue, $newValue, $metadata) { |
| 234 | if ( |
| 235 | in_array('CiviCase', $newValue) |
| 236 | && |
| 237 | (!$oldValue || !in_array('CiviCase', $oldValue)) |
| 238 | ) { |
| 239 | $pathToCaseSampleTpl = __DIR__ . '/xml/configuration.sample/'; |
| 240 | CRM_Admin_Form_Setting_Component::loadCaseSampleData($pathToCaseSampleTpl . 'case_sample.mysql.tpl'); |
| 241 | if (!CRM_Case_BAO_Case::createCaseViews()) { |
| 242 | $msg = ts("Could not create the MySQL views for CiviCase. Your mysql user needs to have the 'CREATE VIEW' permission"); |
| 243 | CRM_Core_Error::fatal($msg); |
| 244 | } |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * @return array |
| 250 | * Array(string $value => string $label). |
| 251 | */ |
| 252 | public static function getRedactOptions() { |
| 253 | return array( |
| 254 | 'default' => ts('Default'), |
| 255 | '0' => ts('Do not redact emails'), |
| 256 | '1' => ts('Redact emails'), |
| 257 | ); |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * @return array |
| 262 | * Array(string $value => string $label). |
| 263 | */ |
| 264 | public static function getMultiClientOptions() { |
| 265 | return array( |
| 266 | 'default' => ts('Default'), |
| 267 | '0' => ts('Single client per case'), |
| 268 | '1' => ts('Multiple client per case'), |
| 269 | ); |
| 270 | } |
| 271 | |
| 272 | /** |
| 273 | * @return array |
| 274 | * Array(string $value => string $label). |
| 275 | */ |
| 276 | public static function getSortOptions() { |
| 277 | return array( |
| 278 | 'default' => ts('Default'), |
| 279 | '0' => ts('Definition order'), |
| 280 | '1' => ts('Alphabetical order'), |
| 281 | ); |
| 282 | } |
| 283 | |
| 284 | } |