Merge pull request #2061 from civicrm/4.3
[civicrm-core.git] / CRM / Member / PseudoConstant.php
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 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2013
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 /**
43 * membership types
44 * @var array
45 * @static
46 */
47 private static $membershipType;
48
49 /**
50 * membership types
51 * @var array
52 * @static
53 */
54 private static $membershipStatus;
55
56 /**
57 * Get all the membership types
58 *
59 * @access public
60 *
61 * @return array - array reference of all membership types if any
62 * @static
63 */
64 public static function &membershipType($id = NULL, $force = FALSE) {
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 /**
84 * Get all the membership statuss
85 *
86 * @access public
87 *
88 * @return array - array reference of all membership statuss if any
89 * @static
90 */
91 public static function &membershipStatus($id = NULL, $cond = NULL, $column = 'name', $force = FALSE) {
92 if (self::$membershipStatus === NULL) {
93 self::$membershipStatus = array();
94 }
95
96 $cacheKey = $column;
97 if ($cond) {
98 $cacheKey .= "_{$cond}";
99 }
100 if (!isset(self::$membershipStatus[$cacheKey]) || $force) {
101 CRM_Core_PseudoConstant::populate(self::$membershipStatus[$cacheKey],
102 'CRM_Member_DAO_MembershipStatus',
103 FALSE, $column, 'is_active', $cond, 'weight'
104 );
105 }
106
107 $value = NULL;
108 if ($id) {
109 $value = CRM_Utils_Array::value($id, self::$membershipStatus[$cacheKey]);
110 }
111 else {
112 $value = self::$membershipStatus[$cacheKey];
113 }
114
115 return $value;
116 }
117
118 /**
119 * Flush given pseudoconstant so it can be reread from db
120 * next time it's requested.
121 *
122 * @access public
123 * @static
124 *
125 * @param boolean $name pseudoconstant to be flushed
126 *
127 */
128 public static function flush($name = 'cache') {
129 if (isset(self::$$name)) {
130 self::$$name = NULL;
131 }
132 }
133 }
134