| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.4 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2013 | |
| 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-2013 |
| 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 | // docs inherited from interface |
| 56 | public function getManagedEntities() { |
| 57 | // Use hook_civicrm_caseTypes to build a list of OptionValues |
| 58 | // In the long run, we may want more specialized logic for this, but |
| 59 | // this design is fairly convenient and will allow us to replace it |
| 60 | // without changing the hook_civicrm_caseTypes interface. |
| 61 | $entities = array(); |
| 62 | |
| 63 | $caseTypes = array(); |
| 64 | CRM_Utils_Hook::caseTypes($caseTypes); |
| 65 | |
| 66 | $proc = new CRM_Case_XMLProcessor(); |
| 67 | $caseTypesGroupId = civicrm_api3('OptionGroup', 'getvalue', array('name' => 'case_type', 'return' => 'id')); |
| 68 | if (!is_numeric($caseTypesGroupId)) { |
| 69 | throw new CRM_Core_Exception("Found invalid ID for OptionGroup (case_type)"); |
| 70 | } |
| 71 | foreach ($caseTypes as $name => $caseType) { |
| 72 | $xml = $proc->retrieve($name); |
| 73 | if (!$xml) { |
| 74 | throw new CRM_Core_Exception("Failed to load XML for case type (" . $name . ")"); |
| 75 | } |
| 76 | |
| 77 | if (isset($caseType['module'], $caseType['name'], $caseType['file'])) { |
| 78 | $entities[] = array( |
| 79 | 'module' => $caseType['module'], |
| 80 | 'name' => $caseType['name'], |
| 81 | 'entity' => 'OptionValue', |
| 82 | 'params' => array( |
| 83 | 'version' => 3, |
| 84 | 'name' => $caseType['name'], |
| 85 | 'label' => (string) $xml->name, |
| 86 | 'description' => (string) $xml->description, // CRM_Utils_Array::value('description', $caseType, ''), |
| 87 | 'option_group_id' => $caseTypesGroupId, |
| 88 | 'is_reserved' => 1, |
| 89 | ), |
| 90 | ); |
| 91 | } |
| 92 | else { |
| 93 | throw new CRM_Core_Exception("Invalid case type"); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | return $entities; |
| 98 | } |
| 99 | |
| 100 | // docs inherited from interface |
| 101 | public function getPermissions($getAllUnconditionally = FALSE) { |
| 102 | return array( |
| 103 | 'delete in CiviCase', |
| 104 | 'administer CiviCase', |
| 105 | 'access my cases and activities', |
| 106 | 'access all cases and activities', |
| 107 | 'add cases', |
| 108 | ); |
| 109 | } |
| 110 | |
| 111 | // docs inherited from interface |
| 112 | public function getUserDashboardElement() { |
| 113 | return array(); |
| 114 | } |
| 115 | |
| 116 | // docs inherited from interface |
| 117 | public function registerTab() { |
| 118 | return array('title' => ts('Cases'), |
| 119 | 'url' => 'case', |
| 120 | 'weight' => 50, |
| 121 | ); |
| 122 | } |
| 123 | |
| 124 | // docs inherited from interface |
| 125 | public function registerAdvancedSearchPane() { |
| 126 | return array('title' => ts('Cases'), |
| 127 | 'weight' => 50, |
| 128 | ); |
| 129 | } |
| 130 | |
| 131 | // docs inherited from interface |
| 132 | public function getActivityTypes() { |
| 133 | return NULL; |
| 134 | } |
| 135 | |
| 136 | // add shortcut to Create New |
| 137 | public function creatNewShortcut(&$shortCuts) { |
| 138 | if (CRM_Core_Permission::check('access all cases and activities') || |
| 139 | CRM_Core_Permission::check('add cases') |
| 140 | ) { |
| 141 | $atype = CRM_Core_OptionGroup::getValue('activity_type', |
| 142 | 'Open Case', |
| 143 | 'name' |
| 144 | ); |
| 145 | if ($atype) { |
| 146 | $shortCuts = array_merge($shortCuts, array( |
| 147 | array('path' => 'civicrm/case/add', |
| 148 | 'query' => "reset=1&action=add&atype=$atype&context=standalone", |
| 149 | 'ref' => 'new-case', |
| 150 | 'title' => ts('Case'), |
| 151 | ))); |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * (Setting Callback) |
| 158 | * Respond to changes in the "enable_components" setting |
| 159 | * |
| 160 | * If CiviCase is being enabled, load the case related sample data |
| 161 | * |
| 162 | * @param array $oldValue List of component names |
| 163 | * @param array $newValue List of component names |
| 164 | * @param array $metadata Specification of the setting (per *.settings.php) |
| 165 | */ |
| 166 | public static function onToggleComponents($oldValue, $newValue, $metadata) { |
| 167 | if ( |
| 168 | in_array('CiviCase', $newValue) |
| 169 | && |
| 170 | (!$oldValue || !in_array('CiviCase', $oldValue)) |
| 171 | ) { |
| 172 | $config = CRM_Core_Config::singleton(); |
| 173 | CRM_Admin_Form_Setting_Component::loadCaseSampleData($config->dsn, $config->sqlDir . 'case_sample.mysql'); |
| 174 | CRM_Admin_Form_Setting_Component::loadCaseSampleData($config->dsn, $config->sqlDir . 'case_sample1.mysql'); |
| 175 | if (!CRM_Case_BAO_Case::createCaseViews()) { |
| 176 | $msg = ts("Could not create the MySQL views for CiviCase. Your mysql user needs to have the 'CREATE VIEW' permission"); |
| 177 | CRM_Core_Error::fatal($msg); |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | |