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