00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 include_once( "lib/ezxml/classes/ezxml.php" );
00041
00042 class eZMatrixDefinition
00043 {
00044
00045
00046
00047 function eZMatrixDefinition()
00048 {
00049 $this->ColumnNames = array();
00050 }
00051
00052
00053 function decodeClassAttribute( $xmlString )
00054 {
00055 $xml = new eZXML();
00056 $dom =& $xml->domTree( $xmlString );
00057 if ( strlen ( $xmlString ) != 0 )
00058 {
00059 $columns = $dom->elementsByName( "column-name" );
00060 $columnList = array();
00061 foreach ( $columns as $columnElement )
00062 {
00063 $columnList[] = array( 'name' => $columnElement->textContent(),
00064 'identifier' => $columnElement->attributeValue( 'id' ),
00065 'index' => $columnElement->attributeValue( 'idx' ) );
00066 }
00067 $this->ColumnNames =& $columnList;
00068 }
00069 else
00070 {
00071 $this->addColumn( );
00072 $this->addColumn( );
00073 }
00074
00075 }
00076
00077 function attributes()
00078 {
00079 return array( 'columns' );
00080 }
00081
00082 function hasAttribute( $attr )
00083 {
00084 return in_array( $attr, $this->attributes() );
00085 }
00086
00087 function &attribute( $attr )
00088 {
00089 if ( $attr == 'columns' )
00090 {
00091 return $this->ColumnNames;
00092 }
00093 else
00094 {
00095 eZDebug::writeError( "Attribute '$attr' does not exist", 'eZMatrixDefinition::attribute' );
00096 $retValue = null;
00097 return $retValue;
00098 }
00099 }
00100
00101 function &xmlString( )
00102 {
00103 $doc = new eZDOMDocument( "Matrix" );
00104 $root = $doc->createElementNode( "ezmatrix" );
00105 $doc->setRoot( $root );
00106
00107 foreach ( $this->ColumnNames as $columnName )
00108 {
00109 $columnNameNode = $doc->createElementNode( 'column-name' );
00110 $columnNameNode->appendAttribute( $doc->createAttributeNode( 'id', $columnName['identifier'] ) );
00111 $columnNameNode->appendAttribute( $doc->createAttributeNode( 'idx', $columnName['index'] ) );
00112 $textNode = $doc->createTextNode( $columnName['name'] );
00113 $columnNameNode->appendChild( $textNode );
00114 $root->appendChild( $columnNameNode );
00115 unset( $columnNameNode );
00116 unset( $textNode );
00117 }
00118
00119 $xml = $doc->toString();
00120
00121 return $xml;
00122 }
00123
00124 function addColumn( $name = false , $id = false )
00125 {
00126 if ( $name == false )
00127 {
00128 $name = 'Col_' . ( count( $this->ColumnNames ) );
00129 }
00130
00131 if ( $id == false )
00132 {
00133
00134 include_once( 'lib/ezi18n/classes/ezchartransform.php' );
00135 $trans =& eZCharTransform::instance();
00136 $id = $trans->transformByGroup( $name, 'identifier' );
00137 }
00138
00139 $this->ColumnNames[] = array( 'name' => $name,
00140 'identifier' => $id,
00141 'index' => count( $this->ColumnNames ) );
00142 }
00143
00144 function removeColumn( $index )
00145 {
00146 if ( $index == 0 && count( $this->ColumnNames ) == 1 )
00147 {
00148 $this->ColumnNames = array();
00149 }
00150 else
00151 {
00152 unset( $this->ColumnNames[$index] );
00153 }
00154 }
00155
00156 var $ColumnNames;
00157
00158 }
00159
00160 ?>