Merge pull request #24131 from seamuslee001/elavon_guzzle
[civicrm-core.git] / CRM / Core / ShowHideBlocks.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17 class CRM_Core_ShowHideBlocks {
18
19 /**
20 * The array of ids of blocks that will be shown.
21 *
22 * @var array
23 */
24 protected $_show;
25
26 /**
27 * The array of ids of blocks that will be hidden.
28 *
29 * @var array
30 */
31 protected $_hide;
32
33 /**
34 * Class constructor.
35 *
36 * @param array|null $show
37 * Initial value of show array.
38 * @param array|null $hide
39 * Initial value of hide array.
40 *
41 * @return \CRM_Core_ShowHideBlocks the newly created object
42 */
43 public function __construct($show = NULL, $hide = NULL) {
44 if (!empty($show)) {
45 $this->_show = $show;
46 }
47 else {
48 $this->_show = [];
49 }
50
51 if (!empty($hide)) {
52 $this->_hide = $hide;
53 }
54 else {
55 $this->_hide = [];
56 }
57 }
58
59 /**
60 * Add the values from this class to the template.
61 */
62 public function addToTemplate() {
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();
84 $template->ensureVariablesAreAssigned(['elemType']);
85 $template->assign_by_ref('hideBlocks', $hide);
86 $template->assign_by_ref('showBlocks', $show);
87 }
88
89 /**
90 * Add a value to the show array.
91 *
92 * @param string $name
93 * Id to be added.
94 */
95 public function addShow($name) {
96 $this->_show[$name] = 1;
97 if (array_key_exists($name, $this->_hide)) {
98 unset($this->_hide[$name]);
99 }
100 }
101
102 /**
103 * Add a value to the hide array.
104 *
105 * @param string $name
106 * Id to be added.
107 */
108 public function addHide($name) {
109 $this->_hide[$name] = 1;
110 if (array_key_exists($name, $this->_show)) {
111 unset($this->_show[$name]);
112 }
113 }
114
115 }