/** * returns HTML code for the filters * * @param SimpleXMLElement[] $items The xml items to parse output * @param string $type The type of xml items (e.g. filter, batch, import, export...) * @param RegistryEditView $editRowView The edit view for the row * @param string $htmlFormatting The HTML formatting for the filters ( 'table', 'td', 'none' ) * @return array */ function xmlItems($items, $type, $editRowView, $htmlFormatting = 'none') { $lists = array(); if (count($items) > 0) { $valueObj = new Registry(); $saveName = array(); foreach ($items as $k => $v) { $valname = $type . '_' . $v['name']; $valueObj->set($valname, $v['value']); /** @var $v SimpleXMLElement[] */ $saveName[$k] = $v['xml']->attributes('name'); /** @noinspection PhpUndefinedMethodInspection */ $items[$k]['xml']->addAttribute('name', $type . '_' . $saveName[$k]); /** @var $v array */ $editRowView->setSelectValues($v['xml'], $v['selectValues']); } $renderedViews = array(); foreach ($items as $k => $v) { /** @var $v SimpleXMLElement[] */ $viewName = $v['xml']->attributes('view'); if ($viewName) { /** @noinspection PhpUndefinedMethodInspection */ $view = $items[$k]['xmlparent']->getChildByNameAttr('view', 'name', $viewName); if (!$view) { echo 'filter view ' . $viewName . ' not defined in filters'; } } else { /** @noinspection PhpUndefinedMethodInspection */ $view = $items[$k]['xml']->getElementByPath('view'); } $value = $items[$k]['value']; if ($value !== null && $value !== '') { /** @noinspection PhpUndefinedMethodInspection */ $classes = $items[$k]['xml']->attributes('cssclass'); /** @noinspection PhpUndefinedMethodInspection */ $items[$k]['xml']->addAttribute('cssclass', $classes . ' focus'); } if ($view) { if (!$viewName || !in_array($viewName, $renderedViews)) { /** @var SimpleXMLElement $view */ $htmlFormattingView = $view->attributes('viewformatting'); if ($htmlFormattingView == '') { $htmlFormattingView = $htmlFormatting; } $lists[$k] = '<div class="cb' . htmlspecialchars(ucfirst($type)) . ' cb' . htmlspecialchars(ucfirst($type)) . 'View">' . $editRowView->renderEditRowView($view, $valueObj, $this, $this->_options, 'param', $htmlFormattingView) . '</div>'; } if ($viewName) { $renderedViews[] = $viewName; } } else { $editRowView->pushModelOfData($valueObj); $editRowView->extendParamAttributes($items[$k]['xml'], $this->control_name()); $result = $editRowView->renderParam($items[$k]['xml'], $this->control_name(), false); $editRowView->popModelOfData(); if ($result[0] || $result[1] || $result[2]) { $lists[$k] = '<div class="cb' . htmlspecialchars(ucfirst($type)) . '">' . ($result[0] ? '<span class="cbLabelSpan">' . $result[0] . '</span> ' : null) . '<span class="cbFieldSpan">' . $result[1] . '</span>' . ($result[2] ? ' <span class="cbDescrSpan">' . $result[2] . '</span>' : null) . '</div>'; } } } foreach ($items as $k => $v) { /** @noinspection PhpUndefinedMethodInspection */ $items[$k]['xml']->addAttribute('name', $saveName[$k]); } } return $lists; }
/** * Renders as ECHO HTML code of a table * * @param SimpleXMLElement $modelOfView The model of the view * @param RegistryInterface|RegistryInterface[] $modelOfData The data of the model ( $row object ) * @param DrawController $controllerView The controller that will be drawing the view * @param array $options The input request options * @param string $viewType The view type ( 'view', 'param', 'depends': means: <param> tag => param, <field> tag => view ) * @param string $htmlFormatting The HTML/array formatting to do ( 'table', 'td', 'none', 'fieldsListArray' ) * @return array|string array if $htmlFormatting == 'fieldsListArray', otherwise html string */ function renderEditRowView( &$modelOfView, &$modelOfData, &$controllerView, $options, $viewType = 'depends', $htmlFormatting = 'table' ) { global $_CB_framework; if ( $this->_parentModelOfView === null ) { $this->setParentView( $modelOfView ); } $this->pushModelOfData( $modelOfData ); $this->_controllerView = $controllerView; $this->_options = $options; if ( $this->_extendViewParser ) { $html = $this->_extendViewParser->renderEditRowView( $modelOfView, $modelOfData, $controllerView, $options, $viewType, $htmlFormatting ); if ( $html ) { return $html; } } $html = array(); if ( $htmlFormatting == 'table' ) { $html[] = '<table class="table table-noborder">'; $label = $modelOfView->attributes( 'label' ); $description = $modelOfView->attributes( 'description' ); if ( $label ) { // add the params label to the display $html[] = '<tr>' . '<th colspan="3">' . CBTxt::Th( $label ) . '</th>' . '</tr>'; } if ( $description ) { // add the params description to the display $html[] = '<tr>' . '<td colspan="3">' . CBTxt::Th( $description ) . '</td>' . '</tr>'; } } elseif ( $htmlFormatting == 'div' ) { $html[] = '<div class="cbformdiv">'; $label = $modelOfView->attributes( 'label' ); $description = $modelOfView->attributes( 'description' ); if ( $label || $description ) { $html[] = '<div class="cb_form_line cbclearboth cb_form_header">'; if ( $label ) { // add the params label to the display $html[] = '<h2 class="cb_form_header_label">' . CBTxt::Th( $label ) . '</h2>'; } if ( $description ) { // add the params description to the display $html[] = '<p class="cb_form_header_description">' . CBTxt::Th( $description ) . '</p>'; } $html[] = '</div>'; } } $this->_methods = get_class_methods( get_class( $this ) ); $this->_jsif = array(); $this->_jsrepeat = false; $this->_jsselect2 = false; $tabs = new cbTabs( 0, $_CB_framework->getUi() ); $html[] = $this->renderAllParams( $modelOfView, $controllerView->control_name(), $tabs, $viewType, $htmlFormatting ); if ( $htmlFormatting == 'table' ) { $html[] = '</table>'; } elseif ( $htmlFormatting == 'div' ) { $html[] = '</div>'; } if ( $htmlFormatting != 'fieldsListArray' ) { $jsCode = $this->_compileJsCode(); if ( $jsCode ) { $_CB_framework->document->addHeadScriptDeclaration( $jsCode ); } if ( $this->_jsrepeat ) { static $repeat = 0; if ( ! $repeat++ ) { $_CB_framework->outputCbJQuery( "$( '.cbRepeat' ).cbrepeat();", 'cbrepeat' ); } } if ( $this->_jsselect2 ) { static $select2 = 0; if ( ! $select2++ ) { $js = "$( '.cbSelect' ).cbselect({" . "language: {" . "errorLoading: function() {" . "return '" . addslashes( CBTxt::T( 'The results could not be loaded.' ) ) . "';" . "}," . "inputTooLong: function() {" . "return '" . addslashes( CBTxt::T( 'Search input too long.' ) ) . "';" . "}," . "inputTooShort: function() {" . "return '" . addslashes( CBTxt::T( 'Search input too short.' ) ) . "';" . "}," . "loadingMore: function() {" . "return '" . addslashes( CBTxt::T( 'Loading more results...' ) ) . "';" . "}," . "maximumSelected: function() {" . "return '" . addslashes( CBTxt::T( 'You cannot select any more choices.' ) ) . "';" . "}," . "noResults: function() {" . "return '" . addslashes( CBTxt::T( 'No results found.' ) ) . "';" . "}," . "searching: function() {" . "return '" . addslashes( CBTxt::T( 'Searching...' ) ) . "';" . "}" . "}," . "selectAllText: '" . addslashes( CBTxt::T( 'Select All' ) ) . "'," . "allSelected: '" . addslashes( CBTxt::T( 'All Selected' ) ) . "'," . "noMatchesFound: '" . addslashes( CBTxt::T( 'No matches found.' ) ) . "'," . "countSelected: '" . addslashes( CBTxt::T( '# of % selected' ) ) . "'" . "});"; $_CB_framework->outputCbJQuery( $js, 'cbselect' ); } } } return ( $htmlFormatting == 'fieldsListArray' ? $this->arrayValuesMerge( $html ) : implode( "\n", $html ) ); }
/** * Renders as ECHO HTML code * * @param SimpleXMLElement $modelView * @param RegistryInterface[] $modelRows * @param DrawController $controllerView * @param array $options * @param boolean $htmlFormatting * @return string */ protected function renderMenu(&$modelView, &$modelRows, &$controllerView, $options, $htmlFormatting) { $renderer = new RegistryEditView($this->input, $this->_db, $this->_pluginParams, $this->_types, $this->_actions, $this->_views, $this->_pluginObject, $this->_tabid); $renderer->setParentView($modelView); $renderer->setModelOfDataRows($modelRows); $name = $modelView->attributes('name'); $label = $modelView->attributes('label'); $description = $modelView->attributes('description'); $action = $modelView->attributes('action'); $width = $modelView->attributes('width'); $height = $modelView->attributes('height'); $icon = $modelView->attributes('icon'); $iconwidth = $modelView->attributes('iconwidth'); $iconheight = $modelView->attributes('iconheight'); $iconhover = $modelView->attributes('iconhover'); if (!$icon && !$modelView->attributes('buttonclass')) { $modelView->addAttribute('buttonclass', 'default'); } if (!$modelView->attributes('textclass')) { $modelView->addAttribute('textclass', 'primary'); } $cssclass = RegistryEditView::buildClasses($modelView); if ($label) { $header = '<div class="cbButtonMenuItemLabel"><span>' . CBTxt::Th($label) . '</span></div>'; } else { $header = null; } if (count($modelView->children()) > 0) { $modelHtml = $renderer->renderEditRowView($modelView, $modelRows, $controllerView, $options, 'view', 'span'); } else { $modelHtml = null; } $footer = $modelHtml ? '<div class="cbButtonMenuItemData">' . $modelHtml . '</div>' : null; $attributes = ' class="cbButtonMenuItem' . ($cssclass ? ' ' . htmlspecialchars($cssclass) : '') . '"'; if ($width || $height) { $attributes .= ' style="' . ($width ? 'width:' . htmlspecialchars($width) . ';' : '') . ($height ? 'height:' . htmlspecialchars($height) . ';' : '') . '"'; } if ($description) { $tooltipTitle = addslashes(CBTxt::Th($label)); $tooltip = addslashes(CBTxt::Th($description)); $attributes = cbTooltip(null, $tooltip, $tooltipTitle, null, null, null, null, $attributes); } $return = '<div' . $attributes . '>'; if ($action) { $data = null; // see later if we need to put data here... $link = $controllerView->drawUrl($action, $modelView, $data, 0, true); if ($link) { $return .= '<a href="' . $link . '" class="cbButtonMenuItemLink">'; } } else { $link = null; } if ($icon) { $renderer->substituteName($icon, false); $icon = RegistryEditView::pathFromXML($icon, $modelView, $this->_pluginObject, 'live'); } if ($iconhover) { $renderer->substituteName($iconhover, false); $iconhover = RegistryEditView::pathFromXML($iconhover, $modelView, $this->_pluginObject, 'live'); } if ($iconwidth || $iconheight) { $iconattributes = ' style="' . ($iconwidth ? 'width:' . htmlspecialchars($iconwidth) : '') . ($iconheight ? 'height:' . htmlspecialchars($iconheight) : '') . '"'; } else { $iconattributes = null; } $return .= '<div class="cbButtonMenuItemInner' . ($name ? ' cbDIIM' . htmlspecialchars($name) : '') . '">' . $header . ($icon ? '<img src="' . htmlspecialchars($icon) . '" alt="" class="cbButtonMenuItemImg"' . ($iconattributes ? ' ' . $iconattributes : '') . ' />' : null) . ($iconhover ? '<img src="' . htmlspecialchars($iconhover) . '" alt="" class="cbButtonMenuItemImgHover"' . ($iconattributes ? ' ' . $iconattributes : '') . ' />' : null) . $footer . '</div>'; if ($action && $link) { $return .= '</a>'; } $return .= '</div>'; return $return; }
/** * Draws the control, or the default text area if a setup file is not found * * @param string $tag_path The XML path to the params (by default 'params') * @param string $grand_parent_path [optional] First find as grand-parent that node (if exists) * @param string $parent_tag [optional] Then find as parent that node (if exists) * @param string $parent_attr [optional] but parent with that attribute having * @param string $parent_attrvalue [optional] that value * @param string $control_name The control name (by default 'params') * @param boolean $paramstextarea If there are no params XML descriptor should params be represented just as a textarea of the raw params (to avoid loosing them) ? * @param string $viewType View type ( 'view', 'param', 'depends': means: <param> tag => param, <field> tag => view ) * @param string $htmlFormatting HTML formatting type for params ( 'table', 'td', 'none', 'fieldsListArray' ) * @return string|array HTML or values if $htmlFormatting = 'fieldsListArray' */ function draw($tag_path = 'params', $grand_parent_path = null, $parent_tag = null, $parent_attr = null, $parent_attrvalue = null, $control_name = 'params', $paramstextarea = true, $viewType = 'depends', $htmlFormatting = 'table') { if ($this->_xml) { $element = $this->_xml; if ($element && $element->getName() == $this->_maintagname && $element->attributes($this->_attrname) == $this->_attrvalue) { if ($grand_parent_path != null) { $element = $element->getElementByPath($grand_parent_path); if (!$element) { return null; } } if ($parent_tag != null && $parent_attr != null && $parent_attrvalue != null) { $element = $element->getChildByNameAttr($parent_tag, $parent_attr, $parent_attrvalue); if ($element) { if ($tag_path) { /** @var SimpleXMLElement $element */ $element = $element->getElementByPath($tag_path); } if ($element !== false) { $this->_xmlElem =& $element; } } } else { $element = $element->getElementByPath($tag_path); if ($element !== false) { $this->_xmlElem = $element; } } } elseif (!$tag_path) { $this->_xmlElem = $element; } } if ($this->_xmlElem !== null) { $controllerView = new DrawController($this->input, $this->_xmlElem, $this->_actions, $this->_options); $controllerView->setControl_name($control_name); $editRowView = new RegistryEditView($this->input, $this->_db, $this->_pluginParams, $this->_types, $this->_actions, $this->_views, $this->_pluginObject, $this->_tabId); $modelOfDataRows = $this->registry->getStorage(); $editRowView->setModelOfDataRows($modelOfDataRows); if ($this->_extendViewParser) { $editRowView->setExtendedViewParser($this->_extendViewParser); } return $editRowView->renderEditRowView($this->_xmlElem, $this->registry, $controllerView, $this->_options, $viewType, $htmlFormatting); } else { if ($paramstextarea) { return "<textarea name=\"{$control_name}\" cols=\"40\" rows=\"10\" class=\"text_area\">" . htmlspecialchars($this->registry->asJson()) . "</textarea>"; } else { return null; } } }
/** * Renders as ECHO HTML code of a table * * @param SimpleXMLElement $modelOfView The model of the view * @param RegistryInterface $modelOfData The data of the model ( $row object ) * @param DrawController $controllerView The controller that will be drawing the view * @param array $options The input request options * @param string $viewType The view type ( 'view', 'param', 'depends': means: <param> tag => param, <field> tag => view ) * @param string $htmlFormatting The HTML/array formatting to do ( 'table', 'td', 'none', 'fieldsListArray' ) * @return array|string array if $htmlFormatting == 'fieldsListArray', otherwise html string */ public function renderEditRowView(&$modelOfView, &$modelOfData, &$controllerView, $options, $viewType = 'depends', $htmlFormatting = 'table') { return $this->registryEditView->renderEditRowView($modelOfView, $modelOfData, $controllerView, $options, $viewType, $htmlFormatting); }