Merge pull request #15422 from artfulrobot/queue-parallel
[civicrm-core.git] / CRM / Core / ShowHideBlocks.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 */
17class 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();
84 $template->assign_by_ref('hideBlocks', $hide);
85 $template->assign_by_ref('showBlocks', $show);
86 }
87
88 /**
f9e31d7f 89 * Add a value to the show array.
6a488035 90 *
6a0b768e
TO
91 * @param string $name
92 * Id to be added.
6a488035 93 */
00be9182 94 public function addShow($name) {
6a488035
TO
95 $this->_show[$name] = 1;
96 if (array_key_exists($name, $this->_hide)) {
97 unset($this->_hide[$name]);
98 }
99 }
100
101 /**
f9e31d7f 102 * Add a value to the hide array.
6a488035 103 *
6a0b768e
TO
104 * @param string $name
105 * Id to be added.
6a488035 106 */
00be9182 107 public function addHide($name) {
6a488035
TO
108 $this->_hide[$name] = 1;
109 if (array_key_exists($name, $this->_show)) {
110 unset($this->_show[$name]);
111 }
112 }
113
6a488035 114}