eZ Publish  [4.0]
ezcontentclasspackagecreator.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZContentClassPackageCreator class
00004 //
00005 // Created on: <21-Nov-2003 12:39:59 amos>
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 ezcontentclasspackagecreator.php
00032 */
00033 
00034 /*!
00035   \ingroup package
00036   \class eZContentClassPackageCreator ezcontentclasspackagecreator.php
00037   \brief A package creator for content classes
00038 
00039 */
00040 
00041 //include_once( 'kernel/classes/ezpackagecreationhandler.php' );
00042 
00043 class eZContentClassPackageCreator extends eZPackageCreationHandler
00044 {
00045     /*!
00046      \reimp
00047     */
00048     function eZContentClassPackageCreator( $id )
00049     {
00050         $steps = array();
00051         $steps[] = array( 'id' => 'class',
00052                           'name' => ezi18n( 'kernel/package', 'Content classes to include' ),
00053                           'methods' => array( 'initialize' => 'initializeClassData',
00054                                               'validate' => 'validateClassData',
00055                                               'commit' => 'commitClassData' ),
00056                           'template' => 'class.tpl' );
00057         $steps[] = $this->packageInformationStep();
00058         $steps[] = $this->packageMaintainerStep();
00059         $steps[] = $this->packageChangelogStep();
00060         $this->eZPackageCreationHandler( $id,
00061                                          ezi18n( 'kernel/package', 'Content class export' ),
00062                                          $steps );
00063     }
00064 
00065     /*!
00066      \reimp
00067      Creates the package and adds the selected content classes.
00068     */
00069     function finalize( &$package, $http, &$persistentData )
00070     {
00071         $this->createPackage( $package, $http, $persistentData, $cleanupFiles );
00072 
00073         $classHandler = eZPackage::packageHandler( 'ezcontentclass' );
00074         $classList = $persistentData['classlist'];
00075         foreach ( $classList as $classID )
00076         {
00077             $classHandler->addClass( $package, $classID );
00078         }
00079         $package->setAttribute( 'is_active', true );
00080         $package->store();
00081     }
00082 
00083     /*!
00084      \reimp
00085      Returns \c 'stable', content class packages are always stable.
00086     */
00087     function packageInitialState( $package, &$persistentData )
00088     {
00089         return 'stable';
00090     }
00091 
00092     /*!
00093      \return \c 'contentclass'.
00094     */
00095     function packageType( $package, &$persistentData )
00096     {
00097         return 'contentclass';
00098     }
00099 
00100     function initializeClassData( $package, $http, $step, &$persistentData, $tpl )
00101     {
00102     }
00103 
00104     /*!
00105      Checks if at least one content class has been selected.
00106     */
00107     function validateClassData( $package, $http, $currentStepID, &$stepMap, &$persistentData, &$errorList )
00108     {
00109         $classList = array();
00110         if ( $http->hasPostVariable( 'ClassList' ) )
00111             $classList = $http->postVariable( 'ClassList' );
00112 
00113         $persistentData['classlist'] = $classList;
00114 
00115         $result = true;
00116         if ( count( $classList ) == 0 )
00117         {
00118             $errorList[] = array( 'field' => ezi18n( 'kernel/package', 'Class list' ),
00119                                   'description' => ezi18n( 'kernel/package', 'You must select at least one class for inclusion' ) );
00120             $result = false;
00121         }
00122         return $result;
00123     }
00124 
00125     function commitClassData( $package, $http, $step, &$persistentData, $tpl )
00126     {
00127     }
00128 
00129     /*!
00130      \reimp
00131      Fetches the selected content classes and generates a name, summary and description from the selection.
00132     */
00133     function generatePackageInformation( &$packageInformation, $package, $http, $step, &$persistentData )
00134     {
00135         $classList = $persistentData['classlist'];
00136 
00137         if ( count( $classList ) == 1 )
00138         {
00139             $classID = $classList[0];
00140             $class = eZContentClass::fetch( $classID );
00141             if ( $class )
00142             {
00143                 $packageInformation['name'] = $class->attribute( 'name' );
00144                 $packageInformation['summary'] = 'Export of content class ' . $class->attribute( 'name' );
00145                 $packageInformation['description'] = 'This package contains an exported definition of the content class ' . $class->attribute( 'name' ) . ' which can be imported to another eZ Publish site';
00146             }
00147         }
00148         else if ( count( $classList ) > 1 )
00149         {
00150             $classNames = array();
00151             foreach ( $classList as $classID )
00152             {
00153                 $class = eZContentClass::fetch( $classID );
00154                 if ( $class )
00155                 {
00156                     $classNames[] = $class->attribute( 'name' );
00157                 }
00158             }
00159             $packageInformation['name'] = count( $classList ) . ' Classes';
00160             $packageInformation['summary'] = 'Export of ' . count( $classList ) . ' content classes';
00161             $description = 'This package contains exported definitions of the following content classes:' . "\n";
00162             foreach ( $classNames as $className )
00163             {
00164                 $description .= '- ' . $className . "\n";
00165             }
00166             $packageInformation['description'] = $description;
00167         }
00168     }
00169 }
00170 
00171 ?>