Merge pull request #18480 from eileenmcnaughton/dom_org
[civicrm-core.git] / CRM / Member / PseudoConstant.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 */
17
18/**
19 * This class holds all the Pseudo constants that are specific to the civimember component. This avoids
20 * polluting the core class and isolates the mass mailer class
21 */
22class CRM_Member_PseudoConstant extends CRM_Core_PseudoConstant {
23
24 /**
fe482240 25 * Membership types.
6a488035 26 * @var array
6a488035
TO
27 */
28 private static $membershipType;
29
30 /**
fe482240 31 * Membership types.
6a488035 32 * @var array
6a488035
TO
33 */
34 private static $membershipStatus;
35
36 /**
fe482240 37 * Get all the membership types.
6a488035 38 *
6a488035 39 *
100fef9d 40 * @param int $id
6c8f6e67
EM
41 * @param bool $force
42 *
a6c01b45
CW
43 * @return array
44 * array reference of all membership types if any
6a488035 45 */
08fd4b45 46 public static function membershipType($id = NULL, $force = TRUE) {
6a488035
TO
47 if (!self::$membershipType || $force) {
48 CRM_Core_PseudoConstant::populate(self::$membershipType,
49 'CRM_Member_DAO_MembershipType',
7a897d9a 50 FALSE, 'name', 'is_active', NULL, 'weight', 'id'
6a488035
TO
51 );
52 }
53 if ($id) {
54 if (array_key_exists($id, self::$membershipType)) {
55 return self::$membershipType[$id];
56 }
57 else {
58 $result = NULL;
59 return $result;
60 }
61 }
62 return self::$membershipType;
63 }
64
65 /**
fe482240 66 * Get all the membership statuss.
6a488035 67 *
6a488035 68 *
100fef9d 69 * @param int $id
6c8f6e67
EM
70 * @param null $cond
71 * @param string $column
72 * @param bool $force
73 *
ad37ac8e 74 * @param bool $allStatus
75 *
a6c01b45 76 * @return array
971e129b 77 * array reference of all membership statuses if any
6a488035 78 */
7ff60806 79 public static function &membershipStatus($id = NULL, $cond = NULL, $column = 'name', $force = FALSE, $allStatus = FALSE) {
6a488035 80 if (self::$membershipStatus === NULL) {
be2fb01f 81 self::$membershipStatus = [];
6a488035
TO
82 }
83
84 $cacheKey = $column;
85 if ($cond) {
86 $cacheKey .= "_{$cond}";
87 }
88 if (!isset(self::$membershipStatus[$cacheKey]) || $force) {
89 CRM_Core_PseudoConstant::populate(self::$membershipStatus[$cacheKey],
90 'CRM_Member_DAO_MembershipStatus',
7ff60806 91 $allStatus, $column, 'is_active', $cond, 'weight'
6a488035
TO
92 );
93 }
94
95 $value = NULL;
96 if ($id) {
9c1bc317 97 $value = self::$membershipStatus[$cacheKey][$id] ?? NULL;
6a488035
TO
98 }
99 else {
100 $value = self::$membershipStatus[$cacheKey];
101 }
102
103 return $value;
104 }
105
106 /**
107 * Flush given pseudoconstant so it can be reread from db
108 * next time it's requested.
109 *
6a488035 110 *
da6b46f4 111 * @param bool|string $name pseudoconstant to be flushed
6a488035 112 */
3fb36592 113 public static function flush($name = 'cache') {
b09fe5ed 114 if (isset(self::$$name)) {
fa56270d 115 self::$$name = NULL;
353ffa53 116 }
14b9e069 117 // The preferred source of membership pseudoconstants is in fact the Core class.
118 // which buildOptions accesses - better flush that too.
119 CRM_Core_PseudoConstant::flush();
6a488035 120 }
96025800 121
6a488035 122}