eZ Publish  [4.0]
ezmatrixdefinition.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZMatrixDefinition class
00004 //
00005 // Created on: <03-Jun-2003 18:30:44 sp>
00006 //
00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00008 // SOFTWARE NAME: eZ Publish
00009 // SOFTWARE RELEASE: 4.0.x
00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS
00011 // SOFTWARE LICENSE: GNU General Public License v2.0
00012 // NOTICE: >
00013 //   This program is free software; you can redistribute it and/or
00014 //   modify it under the terms of version 2.0  of the GNU General
00015 //   Public License as published by the Free Software Foundation.
00016 //
00017 //   This program is distributed in the hope that it will be useful,
00018 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //   GNU General Public License for more details.
00021 //
00022 //   You should have received a copy of version 2.0 of the GNU General
00023 //   Public License along with this program; if not, write to the Free
00024 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00025 //   MA 02110-1301, USA.
00026 //
00027 //
00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00029 //
00030 
00031 /*! \file ezmatrixdefinition.php
00032 */
00033 
00034 /*!
00035   \class eZMatrixDefinition ezmatrixdefinition.php
00036   \ingroup eZDatatype
00037   \brief The class eZMatrixDefinition does
00038 
00039 */
00040 
00041 class eZMatrixDefinition
00042 {
00043     /*!
00044      Constructor
00045     */
00046     function eZMatrixDefinition()
00047     {
00048         $this->ColumnNames = array();
00049     }
00050 
00051 
00052     function decodeClassAttribute( $xmlString )
00053     {
00054         $dom = new DOMDocument( '1.0', 'utf-8' );
00055         if ( strlen ( $xmlString ) != 0 )
00056         {
00057             $success = $dom->loadXML( $xmlString );
00058             $columns = $dom->getElementsByTagName( "column-name" );
00059             $columnList = array();
00060             foreach ( $columns as $columnElement )
00061             {
00062                 $columnList[] = array( 'name' => $columnElement->textContent,
00063                                        'identifier' => $columnElement->getAttribute( 'id' ),
00064                                        'index' =>  $columnElement->getAttribute( 'idx' ) );
00065             }
00066             $this->ColumnNames = $columnList;
00067         }
00068         else
00069         {
00070             $this->addColumn( );
00071             $this->addColumn( );
00072         }
00073 
00074     }
00075 
00076     function attributes()
00077     {
00078         return array( 'columns' );
00079     }
00080 
00081     function hasAttribute( $attr )
00082     {
00083         return in_array( $attr, $this->attributes() );
00084     }
00085 
00086     function attribute( $attr )
00087     {
00088         if ( $attr == 'columns' )
00089         {
00090             return $this->ColumnNames;
00091         }
00092 
00093         eZDebug::writeError( "Attribute '$attr' does not exist", 'eZMatrixDefinition::attribute' );
00094         return null;
00095     }
00096 
00097     function xmlString( )
00098     {
00099         $doc = new DOMDocument( '1.0', 'utf-8' );
00100         $root = $doc->createElement( "ezmatrix" );
00101         $doc->appendChild( $root );
00102 
00103         foreach ( $this->ColumnNames as $columnName )
00104         {
00105             $columnNameNode = $doc->createElement( 'column-name' );
00106             $columnNameNode->appendChild( $doc->createTextNode( $columnName['name'] ) );
00107             $columnNameNode->setAttribute( 'id', $columnName['identifier'] );
00108             $columnNameNode->setAttribute( 'idx', $columnName['index'] );
00109             $root->appendChild( $columnNameNode );
00110             unset( $columnNameNode );
00111             unset( $textNode );
00112         }
00113 
00114         $xml = $doc->saveXML();
00115 
00116         return $xml;
00117     }
00118 
00119     function addColumn( $name = false , $id = false )
00120     {
00121         if ( $name == false )
00122         {
00123             $name = 'Col_' . ( count( $this->ColumnNames ) );
00124         }
00125 
00126         if ( $id == false )
00127         {
00128             // Initialize transformation system
00129             //include_once( 'lib/ezi18n/classes/ezchartransform.php' );
00130             $trans = eZCharTransform::instance();
00131             $id = $trans->transformByGroup( $name, 'identifier' );
00132         }
00133 
00134         $this->ColumnNames[] = array( 'name' => $name,
00135                                       'identifier' => $id,
00136                                       'index' => count( $this->ColumnNames ) );
00137     }
00138 
00139     function removeColumn( $index )
00140     {
00141         if ( $index == 0 && count( $this->ColumnNames ) == 1 )
00142         {
00143             $this->ColumnNames = array();
00144         }
00145         else
00146         {
00147             unset( $this->ColumnNames[$index] );
00148         }
00149     }
00150 
00151     public $ColumnNames;
00152 
00153 }
00154 
00155 ?>