|
eZ Publish
[trunk]
|
00001 <?php 00002 /** 00003 * File containing the eZMatrixDefinition class. 00004 * 00005 * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved. 00006 * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 00007 * @version //autogentag// 00008 * @package kernel 00009 */ 00010 00011 /*! 00012 \class eZMatrixDefinition ezmatrixdefinition.php 00013 \ingroup eZDatatype 00014 \brief The class eZMatrixDefinition does 00015 00016 */ 00017 00018 class eZMatrixDefinition 00019 { 00020 /*! 00021 Constructor 00022 */ 00023 function eZMatrixDefinition() 00024 { 00025 $this->ColumnNames = array(); 00026 } 00027 00028 00029 function decodeClassAttribute( $xmlString ) 00030 { 00031 $dom = new DOMDocument( '1.0', 'utf-8' ); 00032 if ( strlen ( $xmlString ) != 0 ) 00033 { 00034 $success = $dom->loadXML( $xmlString ); 00035 $columns = $dom->getElementsByTagName( "column-name" ); 00036 $columnList = array(); 00037 foreach ( $columns as $columnElement ) 00038 { 00039 $columnList[] = array( 'name' => $columnElement->textContent, 00040 'identifier' => $columnElement->getAttribute( 'id' ), 00041 'index' => $columnElement->getAttribute( 'idx' ) ); 00042 } 00043 $this->ColumnNames = $columnList; 00044 } 00045 else 00046 { 00047 $this->addColumn( ); 00048 $this->addColumn( ); 00049 } 00050 00051 } 00052 00053 function attributes() 00054 { 00055 return array( 'columns' ); 00056 } 00057 00058 function hasAttribute( $attr ) 00059 { 00060 return in_array( $attr, $this->attributes() ); 00061 } 00062 00063 function attribute( $attr ) 00064 { 00065 if ( $attr == 'columns' ) 00066 { 00067 return $this->ColumnNames; 00068 } 00069 00070 eZDebug::writeError( "Attribute '$attr' does not exist", __METHOD__ ); 00071 return null; 00072 } 00073 00074 function xmlString( ) 00075 { 00076 $doc = new DOMDocument( '1.0', 'utf-8' ); 00077 $root = $doc->createElement( "ezmatrix" ); 00078 $doc->appendChild( $root ); 00079 00080 foreach ( $this->ColumnNames as $columnName ) 00081 { 00082 $columnNameNode = $doc->createElement( 'column-name' ); 00083 $columnNameNode->appendChild( $doc->createTextNode( $columnName['name'] ) ); 00084 $columnNameNode->setAttribute( 'id', $columnName['identifier'] ); 00085 $columnNameNode->setAttribute( 'idx', $columnName['index'] ); 00086 $root->appendChild( $columnNameNode ); 00087 unset( $columnNameNode ); 00088 unset( $textNode ); 00089 } 00090 00091 $xml = $doc->saveXML(); 00092 00093 return $xml; 00094 } 00095 00096 function addColumn( $name = false , $id = false ) 00097 { 00098 if ( $name == false ) 00099 { 00100 $name = 'Col_' . ( count( $this->ColumnNames ) ); 00101 } 00102 00103 if ( $id == false ) 00104 { 00105 // Initialize transformation system 00106 $trans = eZCharTransform::instance(); 00107 $id = $trans->transformByGroup( $name, 'identifier' ); 00108 } 00109 00110 $this->ColumnNames[] = array( 'name' => $name, 00111 'identifier' => $id, 00112 'index' => count( $this->ColumnNames ) ); 00113 } 00114 00115 function removeColumn( $index ) 00116 { 00117 if ( $index == 0 && count( $this->ColumnNames ) == 1 ) 00118 { 00119 $this->ColumnNames = array(); 00120 } 00121 else 00122 { 00123 unset( $this->ColumnNames[$index] ); 00124 } 00125 } 00126 00127 public $ColumnNames; 00128 00129 } 00130 00131 ?>