Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
6a488035 TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * This class holds all the Pseudo constants that are specific to the civimember component. This avoids | |
38 | * polluting the core class and isolates the mass mailer class | |
39 | */ | |
40 | class CRM_Member_PseudoConstant extends CRM_Core_PseudoConstant { | |
41 | ||
42 | /** | |
fe482240 | 43 | * Membership types. |
6a488035 | 44 | * @var array |
6a488035 TO |
45 | */ |
46 | private static $membershipType; | |
47 | ||
48 | /** | |
fe482240 | 49 | * Membership types. |
6a488035 | 50 | * @var array |
6a488035 TO |
51 | */ |
52 | private static $membershipStatus; | |
53 | ||
54 | /** | |
fe482240 | 55 | * Get all the membership types. |
6a488035 | 56 | * |
6a488035 | 57 | * |
100fef9d | 58 | * @param int $id |
6c8f6e67 EM |
59 | * @param bool $force |
60 | * | |
a6c01b45 CW |
61 | * @return array |
62 | * array reference of all membership types if any | |
6a488035 | 63 | */ |
08fd4b45 | 64 | public static function membershipType($id = NULL, $force = TRUE) { |
6a488035 TO |
65 | if (!self::$membershipType || $force) { |
66 | CRM_Core_PseudoConstant::populate(self::$membershipType, | |
67 | 'CRM_Member_DAO_MembershipType', | |
68 | FALSE, 'name', 'is_active', NULL, 'weight', 'id', TRUE | |
69 | ); | |
70 | } | |
71 | if ($id) { | |
72 | if (array_key_exists($id, self::$membershipType)) { | |
73 | return self::$membershipType[$id]; | |
74 | } | |
75 | else { | |
76 | $result = NULL; | |
77 | return $result; | |
78 | } | |
79 | } | |
80 | return self::$membershipType; | |
81 | } | |
82 | ||
83 | /** | |
fe482240 | 84 | * Get all the membership statuss. |
6a488035 | 85 | * |
6a488035 | 86 | * |
100fef9d | 87 | * @param int $id |
6c8f6e67 EM |
88 | * @param null $cond |
89 | * @param string $column | |
90 | * @param bool $force | |
91 | * | |
a6c01b45 CW |
92 | * @return array |
93 | * array reference of all membership statuss if any | |
6a488035 | 94 | */ |
7ff60806 | 95 | public static function &membershipStatus($id = NULL, $cond = NULL, $column = 'name', $force = FALSE, $allStatus = FALSE) { |
6a488035 TO |
96 | if (self::$membershipStatus === NULL) { |
97 | self::$membershipStatus = array(); | |
98 | } | |
99 | ||
100 | $cacheKey = $column; | |
101 | if ($cond) { | |
102 | $cacheKey .= "_{$cond}"; | |
103 | } | |
104 | if (!isset(self::$membershipStatus[$cacheKey]) || $force) { | |
105 | CRM_Core_PseudoConstant::populate(self::$membershipStatus[$cacheKey], | |
106 | 'CRM_Member_DAO_MembershipStatus', | |
7ff60806 | 107 | $allStatus, $column, 'is_active', $cond, 'weight' |
6a488035 TO |
108 | ); |
109 | } | |
110 | ||
111 | $value = NULL; | |
112 | if ($id) { | |
113 | $value = CRM_Utils_Array::value($id, self::$membershipStatus[$cacheKey]); | |
114 | } | |
115 | else { | |
116 | $value = self::$membershipStatus[$cacheKey]; | |
117 | } | |
118 | ||
119 | return $value; | |
120 | } | |
121 | ||
122 | /** | |
123 | * Flush given pseudoconstant so it can be reread from db | |
124 | * next time it's requested. | |
125 | * | |
6a488035 | 126 | * |
da6b46f4 | 127 | * @param bool|string $name pseudoconstant to be flushed |
6a488035 | 128 | */ |
3fb36592 | 129 | public static function flush($name = 'cache') { |
b09fe5ed | 130 | if (isset(self::$$name)) { |
fa56270d | 131 | self::$$name = NULL; |
353ffa53 | 132 | } |
6a488035 | 133 | } |
96025800 | 134 | |
6a488035 | 135 | } |