Commit | Line | Data |
---|---|---|
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 | class CRM_Core_ShowHideBlocks { | |
18 | ||
6a488035 | 19 | /** |
f9e31d7f | 20 | * The array of ids of blocks that will be shown. |
6a488035 TO |
21 | * |
22 | * @var array | |
23 | */ | |
24 | protected $_show; | |
25 | ||
26 | /** | |
f9e31d7f | 27 | * The array of ids of blocks that will be hidden. |
6a488035 TO |
28 | * |
29 | * @var array | |
30 | */ | |
31 | protected $_hide; | |
32 | ||
33 | /** | |
f9e31d7f | 34 | * Class constructor. |
6a488035 | 35 | * |
6a0b768e TO |
36 | * @param array $show |
37 | * Initial value of show array. | |
38 | * @param array $hide | |
39 | * Initial value of hide array. | |
6a488035 | 40 | * |
e0b82b44 | 41 | * @return \CRM_Core_ShowHideBlocks the newly created object |
6a488035 | 42 | */ |
00be9182 | 43 | public function __construct($show = NULL, $hide = NULL) { |
6a488035 TO |
44 | if (!empty($show)) { |
45 | $this->_show = $show; | |
46 | } | |
47 | else { | |
be2fb01f | 48 | $this->_show = []; |
6a488035 TO |
49 | } |
50 | ||
51 | if (!empty($hide)) { | |
52 | $this->_hide = $hide; | |
53 | } | |
54 | else { | |
be2fb01f | 55 | $this->_hide = []; |
6a488035 TO |
56 | } |
57 | } | |
58 | ||
6a488035 | 59 | /** |
f9e31d7f | 60 | * Add the values from this class to the template. |
6a488035 | 61 | */ |
00be9182 | 62 | public function addToTemplate() { |
6a488035 TO |
63 | $hide = $show = ''; |
64 | ||
65 | $first = TRUE; | |
66 | foreach (array_keys($this->_hide) as $h) { | |
67 | if (!$first) { | |
68 | $hide .= ','; | |
69 | } | |
70 | $hide .= "'$h'"; | |
71 | $first = FALSE; | |
72 | } | |
73 | ||
74 | $first = TRUE; | |
75 | foreach (array_keys($this->_show) as $s) { | |
76 | if (!$first) { | |
77 | $show .= ','; | |
78 | } | |
79 | $show .= "'$s'"; | |
80 | $first = FALSE; | |
81 | } | |
82 | ||
83 | $template = CRM_Core_Smarty::singleton(); | |
570eb116 | 84 | $template->ensureVariablesAreAssigned(['elemType']); |
6a488035 TO |
85 | $template->assign_by_ref('hideBlocks', $hide); |
86 | $template->assign_by_ref('showBlocks', $show); | |
87 | } | |
88 | ||
89 | /** | |
f9e31d7f | 90 | * Add a value to the show array. |
6a488035 | 91 | * |
6a0b768e TO |
92 | * @param string $name |
93 | * Id to be added. | |
6a488035 | 94 | */ |
00be9182 | 95 | public function addShow($name) { |
6a488035 TO |
96 | $this->_show[$name] = 1; |
97 | if (array_key_exists($name, $this->_hide)) { | |
98 | unset($this->_hide[$name]); | |
99 | } | |
100 | } | |
101 | ||
102 | /** | |
f9e31d7f | 103 | * Add a value to the hide array. |
6a488035 | 104 | * |
6a0b768e TO |
105 | * @param string $name |
106 | * Id to be added. | |
6a488035 | 107 | */ |
00be9182 | 108 | public function addHide($name) { |
6a488035 TO |
109 | $this->_hide[$name] = 1; |
110 | if (array_key_exists($name, $this->_show)) { | |
111 | unset($this->_show[$name]); | |
112 | } | |
113 | } | |
114 | ||
6a488035 | 115 | } |