| 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 $show |
| 37 | * Initial value of show array. |
| 38 | * @param array $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->assign_by_ref('hideBlocks', $hide); |
| 85 | $template->assign_by_ref('showBlocks', $show); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Add a value to the show array. |
| 90 | * |
| 91 | * @param string $name |
| 92 | * Id to be added. |
| 93 | */ |
| 94 | public function addShow($name) { |
| 95 | $this->_show[$name] = 1; |
| 96 | if (array_key_exists($name, $this->_hide)) { |
| 97 | unset($this->_hide[$name]); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Add a value to the hide array. |
| 103 | * |
| 104 | * @param string $name |
| 105 | * Id to be added. |
| 106 | */ |
| 107 | public function addHide($name) { |
| 108 | $this->_hide[$name] = 1; |
| 109 | if (array_key_exists($name, $this->_show)) { |
| 110 | unset($this->_show[$name]); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | } |