params = $params; $this->settings = $settings; // increase instance counter static::$instance_counter++; } /** * Proxy for immediately accessing the object and bind data. * * @param array $params The form params to bind. * @param array $settings The form settings to bind. * * @return VBOParamsRendering */ public static function getInstance(array $params = [], array $settings = []) { return new static($params, $settings); } /** * Sets the name to be used for rendering the param fields. * * @param string $name The name to use. * * @return self */ public function setInputName($name) { $this->inputName = (string) $name; return $this; } /** * Renders the injected form params and returns the HTML code. * * @param bool $load_assets Whether to load the necessary assets. * * @return string */ public function getHtml($load_assets = true) { if (!$this->params) { return ''; } $html = ''; foreach ($this->params as $param_name => $param_config) { if (empty($param_name)) { continue; } $labelparts = explode('//', (isset($param_config['label']) ? $param_config['label'] : '')); $label = $labelparts[0]; $labelhelp = isset($labelparts[1]) ? $labelparts[1] : ''; if (!empty($param_config['help'])) { $labelhelp = $param_config['help']; } $nested_style = (isset($param_config['nested']) && $param_config['nested']); $hidden_wrapper = false; if (isset($param_config['conditional']) && isset($this->params[$param_config['conditional']])) { $check_cond = isset($this->params[$param_config['conditional']]['default']) ? $this->params[$param_config['conditional']]['default'] : null; $check_cond = isset($this->settings[$param_config['conditional']]) ? $this->settings[$param_config['conditional']] : $check_cond; if (!is_null($check_cond) && (!$check_cond || !strcasecmp($check_cond, 'off'))) { // hide current field because the field to who this is dependant is "off" or disabled (i.e. 0) $hidden_wrapper = true; } } $html .= '
'; } // JS helper functions $html .= $this->getScripts(); return $html; } /** * Loads the requested assets, if any. * * @param bool $load_once True to unset the assets after loading. * * @return void */ public function loadAssets($load_once = false) { $doc = JFactory::getDocument(); foreach ($this->assets as $asset_type => $asset_elements) { if ($asset_type === 'select2') { // build list of selectors $ids_list = implode(', ', array_map(function($el) { return "#{$el}"; }, $asset_elements)); // check for asset options $asset_options = $this->assets['select2_options'] ?? null; $asset_options_str = $asset_options ? json_encode($asset_options) : ''; // add script declaration VikBooking::getVboApplication()->loadSelect2(); $doc->addScriptDeclaration( <<