| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.7 | |
| 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 | * |
| 30 | * @package CRM |
| 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
| 32 | */ |
| 33 | |
| 34 | /** |
| 35 | * This class holds all the Pseudo constants that are specific for CiviCase. |
| 36 | */ |
| 37 | class CRM_Case_PseudoConstant extends CRM_Core_PseudoConstant { |
| 38 | |
| 39 | /** |
| 40 | * Case statues |
| 41 | * @var array |
| 42 | */ |
| 43 | static $caseStatus = array(); |
| 44 | |
| 45 | /** |
| 46 | * Redaction rules |
| 47 | * @var array |
| 48 | */ |
| 49 | static $redactionRule; |
| 50 | |
| 51 | /** |
| 52 | * Case type |
| 53 | * @var array |
| 54 | */ |
| 55 | static $caseType = array(); |
| 56 | |
| 57 | /** |
| 58 | * Encounter Medium |
| 59 | * @var array |
| 60 | */ |
| 61 | static $encounterMedium = array(); |
| 62 | |
| 63 | /** |
| 64 | * Activity type |
| 65 | * @var array |
| 66 | */ |
| 67 | static $activityTypeList = array(); |
| 68 | |
| 69 | /** |
| 70 | * Get all the case statues. |
| 71 | * |
| 72 | * |
| 73 | * @param string $column |
| 74 | * @param bool $onlyActive |
| 75 | * @param null $condition |
| 76 | * @param bool $fresh |
| 77 | * |
| 78 | * @return array |
| 79 | * array reference of all case statues |
| 80 | */ |
| 81 | public static function caseStatus($column = 'label', $onlyActive = TRUE, $condition = NULL, $fresh = FALSE) { |
| 82 | $cacheKey = "{$column}_" . (int) $onlyActive; |
| 83 | if (!$condition) { |
| 84 | $condition = 'AND filter = 0'; |
| 85 | } |
| 86 | |
| 87 | if (!isset(self::$caseStatus[$cacheKey]) || $fresh) { |
| 88 | self::$caseStatus[$cacheKey] = CRM_Core_OptionGroup::values('case_status', |
| 89 | FALSE, FALSE, FALSE, $condition, |
| 90 | $column, $onlyActive, $fresh |
| 91 | ); |
| 92 | } |
| 93 | |
| 94 | return self::$caseStatus[$cacheKey]; |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Get all the redaction rules. |
| 99 | * |
| 100 | * |
| 101 | * @param null $filter |
| 102 | * |
| 103 | * @return array |
| 104 | * array reference of all redaction rules |
| 105 | */ |
| 106 | public static function redactionRule($filter = NULL) { |
| 107 | // if ( ! self::$redactionRule ) { |
| 108 | self::$redactionRule = array(); |
| 109 | |
| 110 | if ($filter === 0) { |
| 111 | $condition = " AND (v.filter = 0 OR v.filter IS NULL)"; |
| 112 | } |
| 113 | elseif ($filter === 1) { |
| 114 | $condition = " AND v.filter = 1"; |
| 115 | } |
| 116 | elseif ($filter === NULL) { |
| 117 | $condition = NULL; |
| 118 | } |
| 119 | |
| 120 | self::$redactionRule = CRM_Core_OptionGroup::values('redaction_rule', TRUE, FALSE, FALSE, $condition); |
| 121 | // } |
| 122 | return self::$redactionRule; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Get all the case type. |
| 127 | * |
| 128 | * |
| 129 | * @param string $column |
| 130 | * @param bool $onlyActive |
| 131 | * |
| 132 | * @return array |
| 133 | * array reference of all case type |
| 134 | */ |
| 135 | public static function caseType($column = 'title', $onlyActive = TRUE) { |
| 136 | if ($onlyActive) { |
| 137 | $condition = " is_active = 1 "; |
| 138 | } |
| 139 | else { |
| 140 | $condition = NULL; |
| 141 | } |
| 142 | $caseType = NULL; |
| 143 | // FIXME: deprecated? |
| 144 | CRM_Core_PseudoConstant::populate( |
| 145 | $caseType, |
| 146 | 'CRM_Case_DAO_CaseType', |
| 147 | TRUE, |
| 148 | $column, |
| 149 | '', |
| 150 | $condition, |
| 151 | 'weight', |
| 152 | 'id' |
| 153 | ); |
| 154 | |
| 155 | return $caseType; |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Get all the Encounter Medium. |
| 160 | * |
| 161 | * |
| 162 | * @param string $column |
| 163 | * @param bool $onlyActive |
| 164 | * |
| 165 | * @return array |
| 166 | * array reference of all Encounter Medium. |
| 167 | */ |
| 168 | public static function encounterMedium($column = 'label', $onlyActive = TRUE) { |
| 169 | $cacheKey = "{$column}_" . (int) $onlyActive; |
| 170 | if (!isset(self::$encounterMedium[$cacheKey])) { |
| 171 | self::$encounterMedium[$cacheKey] = CRM_Core_OptionGroup::values('encounter_medium', |
| 172 | FALSE, FALSE, FALSE, NULL, |
| 173 | $column, $onlyActive |
| 174 | ); |
| 175 | } |
| 176 | |
| 177 | return self::$encounterMedium[$cacheKey]; |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * Get all Activity types for the CiviCase component. |
| 182 | * |
| 183 | * The static array activityType is returned |
| 184 | * |
| 185 | * @param bool $indexName |
| 186 | * True return activity name in array. |
| 187 | * key else activity id as array key. |
| 188 | * |
| 189 | * @param bool $all |
| 190 | * |
| 191 | * |
| 192 | * @return array |
| 193 | * array reference of all activity types. |
| 194 | */ |
| 195 | public static function &caseActivityType($indexName = TRUE, $all = FALSE) { |
| 196 | $cache = (int) $indexName . '_' . (int) $all; |
| 197 | |
| 198 | if (!array_key_exists($cache, self::$activityTypeList)) { |
| 199 | self::$activityTypeList[$cache] = array(); |
| 200 | |
| 201 | $query = " |
| 202 | SELECT v.label as label ,v.value as value, v.name as name, v.description as description |
| 203 | FROM civicrm_option_value v, |
| 204 | civicrm_option_group g |
| 205 | WHERE v.option_group_id = g.id |
| 206 | AND g.name = 'activity_type' |
| 207 | AND v.is_active = 1 |
| 208 | AND g.is_active = 1"; |
| 209 | |
| 210 | if (!$all) { |
| 211 | $componentId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Component', |
| 212 | 'CiviCase', |
| 213 | 'id', 'name' |
| 214 | ); |
| 215 | $query .= " AND v.component_id = {$componentId} "; |
| 216 | } |
| 217 | |
| 218 | $query .= " ORDER BY v.weight"; |
| 219 | |
| 220 | $dao = CRM_Core_DAO::executeQuery($query); |
| 221 | |
| 222 | $activityTypes = array(); |
| 223 | while ($dao->fetch()) { |
| 224 | if ($indexName) { |
| 225 | $index = $dao->name; |
| 226 | } |
| 227 | else { |
| 228 | $index = $dao->value; |
| 229 | } |
| 230 | $activityTypes[$index] = array(); |
| 231 | $activityTypes[$index]['id'] = $dao->value; |
| 232 | $activityTypes[$index]['label'] = $dao->label; |
| 233 | $activityTypes[$index]['name'] = $dao->name; |
| 234 | $activityTypes[$index]['description'] = $dao->description; |
| 235 | } |
| 236 | self::$activityTypeList[$cache] = $activityTypes; |
| 237 | } |
| 238 | return self::$activityTypeList[$cache]; |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * Flush given pseudoconstant so it can be reread from db |
| 243 | * next time it's requested. |
| 244 | * |
| 245 | * |
| 246 | * @param bool|string $name pseudoconstant to be flushed |
| 247 | */ |
| 248 | public static function flush($name = 'cache') { |
| 249 | if (isset(self::$$name)) { |
| 250 | self::$$name = NULL; |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | } |