Example #1
0
 /**
  * Parses the XML
  *
  * @return void
  */
 protected function parseXML()
 {
     global $_CB_framework;
     $this->name = $this->_tableBrowserModel->attributes('name');
     $this->table = $this->_tableBrowserModel->attributes('table');
     $this->label = $this->_tableBrowserModel->attributes('label');
     $this->description = $this->_tableBrowserModel->attributes('description');
     $this->class = $this->_tableBrowserModel->attributes('class');
     $this->fields = array();
     $this->listFieldsRows = $this->_tableBrowserModel->getElementByPath('listfields/rows');
     $this->orderbyfields = $this->_tableBrowserModel->getElementByPath('orderby');
     $this->groupbyfields = $this->_tableBrowserModel->getElementByPath('groupby');
     $this->quicksearchfields = $this->_tableBrowserModel->getElementByPath('quicksearchfields');
     $this->filters = $this->_tableBrowserModel->getElementByPath('filters');
     $this->whereColumns = $this->_tableBrowserModel->getElementByPath('where');
     $this->batchprocess = $this->_tableBrowserModel->getElementByPath('batchprocess');
     $this->statistics = $this->_tableBrowserModel->getElementByPath('statistics');
     $this->toolbarmenu = $this->_tableBrowserModel->getElementByPath('toolbarmenu');
     if ($this->listFieldsRows) {
         $limit = $this->listFieldsRows->attributes('limit');
         if (!$limit) {
             $limit = $_CB_framework->getCfg('list_limit');
         }
         $this->limit = $limit;
         $limits = $this->listFieldsRows->attributes('limits');
         if ($limits) {
             $this->limits = explode(',', $limits);
         }
         foreach ($this->listFieldsRows as $field) {
             /** @var SimpleXMLElement $field */
             $this->registryEditVew->resolveXmlParamType($field);
             $allowOrdering = $field->attributes('allowordering');
             if ($allowOrdering) {
                 $name = $field->attributes('name');
                 $label = CBTxt::T($field->attributes('label'));
                 $ordering = explode(',', $allowOrdering);
                 if (in_array('ascending', $ordering) && !$this->orderbyfields->getChildByNameAttr('ordergroup', 'name', $name . '_asc')) {
                     $asc = '<?xml version="1.0" encoding="UTF-8"?>' . '<ordergroup name="' . htmlspecialchars($name) . '_asc" label="' . htmlspecialchars(CBTxt::T('FIELD_ASCENDING', '[field] ascending', array('[field]' => $label != '' ? $label : $name))) . '">' . '<field name="' . htmlspecialchars($name) . '" ordering="ASC" />' . '</ordergroup>';
                     $ascXml = new SimpleXMLElement($asc);
                     $this->orderbyfields->addChildWithDescendants($ascXml);
                 }
                 if (in_array('descending', $ordering) && !$this->orderbyfields->getChildByNameAttr('ordergroup', 'name', $name . '_desc')) {
                     $desc = '<?xml version="1.0" encoding="UTF-8"?>' . '<ordergroup name="' . htmlspecialchars($name) . '_desc" label="' . htmlspecialchars(CBTxt::T('FIELD_DESCENDING', '[field] descending', array('[field]' => $label != '' ? $label : $name))) . '">' . '<field name="' . htmlspecialchars($name) . '" ordering="DESC" />' . '</ordergroup>';
                     $descXml = new SimpleXMLElement($desc);
                     $this->orderbyfields->addChildWithDescendants($descXml);
                 }
             }
         }
     }
 }
	/**
	 * @param  SimpleXMLElement  $fromXml
	 * @param  SimpleXMLElement  $toXml
	 * @param  callable|null     $substitutesFunction
	 * @param  string            $keyAttribute
	 */
	private static function extendNodeAndChildren( SimpleXMLElement $fromXml, SimpleXMLElement $toXml, $substitutesFunction, $keyAttribute )
	{
		if ( ! ( $fromXml->getName() === $toXml->getName() && $fromXml->attributes( $keyAttribute ) === $toXml->attributes( $keyAttribute ) ) ) {
			return;
		}

		foreach ( $fromXml->children() as $fromChild ) {

			if ( $fromChild->attributes( $keyAttribute ) !== null ) {
				$toChild	=	$toXml->getChildByNameAttr( $fromChild->getName(), $keyAttribute, $fromChild->attributes( $keyAttribute ) );
			} elseif ( count( $fromChild->attributes() ) > 0 ) {
				$toChild	=	$toXml->getChildByNameAttributes( $fromChild->getName(), $fromChild->attributes() );
			} elseif ( trim( $fromXml->data() ) != '' ) {
				$toChildren	=	$toXml->xpath( $fromXml->getName() . '[text()="' . addcslashes( $fromXml->data(), '"' ) . '"]' );
				$toChild	=	( count( $toChildren ) > 0 ) ? $toChildren[0] : null;
			} else {
				/* No attributes nor data: search single child with no attributes: */
				$toChildren	=	$toXml->xpath( $fromChild->getName() . '[count(@*)=0]' );

				if ( count( $toChildren ) == 1 ) {
					$toChild		=	$toChildren[0];
				} else {
					/* No attributes nor data: search single child with attributes: */
					$toChildren		=	$toXml->xpath( $fromChild->getName() );

					if ( count( $toChildren ) == 1 ) {
						$toChild	=	$toChildren[0];
					} else {
						$toChild	=	null;
					}
				}
			}
			if ( $toChild ) {
				self::extendNodeAndChildren( $fromChild, $toChild, $substitutesFunction, $keyAttribute );
				continue;
			}

			$insertAfter			=	$fromChild->attributes( 'insert-node-after' );

			if ( $insertAfter ) {
				$toChild			=	$toXml->getChildByNameAttr( $fromChild->getName(), $keyAttribute, $insertAfter );

				if ( $toChild ) {
					$toChild->insertNodeAndChildrenAfter( $fromChild, $substitutesFunction );
				}
				continue;
			}

			$insertBefore			=	$fromChild->attributes( 'insert-node-before' );

			if ( $insertBefore ) {
				$toChild			=	$toXml->getChildByNameAttr( $fromChild->getName(), $keyAttribute, $insertBefore );

				if ( $toChild ) {
					$toChild->insertNodeAndChildrenBefore( $fromChild, $substitutesFunction );
				}
				continue;
			}

			$toXml->addChildWithDescendants( $fromChild, $substitutesFunction );
		}
	}