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