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( 'kernel/classes/ezpackagecreationhandler.php' );
00041
00042 class eZContentObjectPackageCreator extends eZPackageCreationHandler
00043 {
00044
00045
00046
00047 function eZContentObjectPackageCreator( $id )
00048 {
00049 $steps = array();
00050 $steps[] = array( 'id' => 'object',
00051 'name' => ezi18n( 'kernel/package', 'Content objects to include' ),
00052 'methods' => array( 'initialize' => 'initializeObjectList',
00053 'load' => 'loadObjectList',
00054 'validate' => 'validateObjectList' ),
00055 'template' => 'object_select.tpl' );
00056 $steps[] = array( 'id' => 'object_limits',
00057 'name' => ezi18n( 'kernel/package', 'Content object limits' ),
00058 'methods' => array( 'initialize' => 'initializeObjectLimits',
00059 'load' => 'loadObjectLimits',
00060 'validate' => 'validateObjectLimits' ),
00061 'template' => 'object_limit.tpl' );
00062 $steps[] = $this->packageInformationStep();
00063 $steps[] = $this->packageMaintainerStep();
00064 $steps[] = $this->packageChangelogStep();
00065 $this->eZPackageCreationHandler( $id,
00066 ezi18n( 'kernel/package', 'Content object export' ),
00067 $steps );
00068 }
00069
00070
00071
00072
00073
00074 function finalize( &$package, &$http, &$persistentData )
00075 {
00076 $this->createPackage( $package, $http, $persistentData, $cleanupFiles );
00077
00078 $objectHandler = eZPackage::packageHandler( 'ezcontentobject' );
00079 $nodeList = $persistentData['node_list'];
00080 $options = $persistentData['object_options'];
00081
00082 foreach( $nodeList as $nodeInfo )
00083 {
00084 $objectHandler->addNode( $nodeInfo['id'], $nodeInfo['type'] == 'subtree' );
00085 }
00086 $objectHandler->generatePackage( $package, $options );
00087
00088 $package->setAttribute( 'is_active', true );
00089 $package->store();
00090 }
00091
00092
00093
00094
00095
00096 function packageInitialState( &$package, &$persistentData )
00097 {
00098 return 'stable';
00099 }
00100
00101
00102
00103
00104 function packageType( &$package, &$persistentData )
00105 {
00106 return 'contentobject';
00107 }
00108
00109 function initializeObjectList( &$package, &$http, $step, &$persistentData, &$tpl )
00110 {
00111 $persistentData['node_list'] = array();
00112 }
00113
00114 function loadObjectList( &$package, &$http, $step, &$persistentData, &$tpl, &$module )
00115 {
00116 if ( $http->hasPostVariable( 'AddSubtree' ) )
00117 {
00118 include_once( 'kernel/classes/ezcontentbrowse.php' );
00119 eZContentBrowse::browse( array( 'action_name' => 'FindLimitationSubtree',
00120 'description_template' => 'design:package/creators/ezcontentobject/browse_subtree.tpl',
00121 'from_page' => '/package/create',
00122 'persistent_data' => array( 'PackageStep' => $http->postVariable( 'PackageStep' ),
00123 'CreatorItemID' => $http->postVariable( 'CreatorItemID' ),
00124 'CreatorStepID' => $http->postVariable( 'CreatorStepID' ),
00125 'Subtree' => 1 ) ),
00126 $module );
00127 }
00128 else if ( $http->hasPostVariable( 'AddNode' ) )
00129 {
00130 include_once( 'kernel/classes/ezcontentbrowse.php' );
00131 eZContentBrowse::browse( array( 'action_name' => 'FindLimitationNode',
00132 'description_template' => 'design:package/creators/ezcontentobject/browse_node.tpl',
00133 'from_page' => '/package/create',
00134 'persistent_data' => array( 'PackageStep' => $http->postVariable( 'PackageStep' ),
00135 'CreatorItemID' => $http->postVariable( 'CreatorItemID' ),
00136 'CreatorStepID' => $http->postVariable( 'CreatorStepID' ),
00137 'Node' => 1) ),
00138 $module );
00139 }
00140 else if( $http->hasPostVariable( 'RemoveSelected' ) )
00141 {
00142 foreach ( array_keys( $persistentData['node_list'] ) as $key )
00143 {
00144 if ( in_array( $persistentData['node_list'][$key]['id'], $http->postVariable( 'DeleteIDArray' ) ) )
00145 {
00146 unset( $persistentData['node_list'][$key] );
00147 }
00148 }
00149 }
00150 else if( $http->hasPostVariable( 'SelectedNodeIDArray' ) && !$http->hasPostVariable( 'BrowseCancelButton' ) )
00151 {
00152 if ( $http->hasPostVariable( 'Subtree' ) &&
00153 $http->hasPostVariable( 'Subtree' ) == 1 )
00154 {
00155 foreach( $http->postVariable( 'SelectedNodeIDArray' ) as $nodeID )
00156 {
00157 $persistentData['node_list'][] = array( 'id' => $nodeID,
00158 'type' => 'subtree' );
00159 }
00160 }
00161 else if ( $http->hasPostVariable( 'Node' ) &&
00162 $http->hasPostVariable( 'Node' ) == 1 )
00163 {
00164 foreach( $http->postVariable( 'SelectedNodeIDArray' ) as $nodeID )
00165 {
00166 $persistentData['node_list'][] = array( 'id' => $nodeID,
00167 'type' => 'node' );
00168 }
00169 }
00170 }
00171
00172 $tpl->setVariable( 'node_list', $persistentData['node_list'] );
00173 }
00174
00175
00176
00177
00178 function validateObjectList( &$package, &$http, $currentStepID, &$stepMap, &$persistentData, &$errorList )
00179 {
00180 if ( count( $persistentData['node_list'] ) == 0 )
00181 {
00182 $errorList[] = array( 'field' => ezi18n( 'kernel/package', 'Selected nodes' ),
00183 'description' => ezi18n( 'kernel/package', 'You must select one or more node(s)/subtree(s) for export.' ) );
00184 return false;
00185 }
00186
00187 return true;
00188 }
00189
00190 function initializeObjectLimits( &$package, &$http, $step, &$persistentData, &$tpl )
00191 {
00192 $persistentData['object_options'] = array( 'include_classes' => 1,
00193 'include_templates' => 1,
00194 'site_access_array' => array(),
00195 'versions' => 'current',
00196 'language_array' => array(),
00197 'node_assignment' => 'selected',
00198 'related_objects' => 'selected',
00199 'embed_objects' => 'selected' );
00200
00201 include_once( 'lib/ezutils/classes/ezini.php' );
00202 $ini =& eZINI::instance();
00203 $persistentData['object_options']['site_access_array'] = array( $ini->variable( 'SiteSettings', 'DefaultAccess' ) );
00204
00205 include_once( 'kernel/classes/ezcontentobject.php' );
00206 $availableLanguages = eZContentObject::translationList();
00207 foreach ( $availableLanguages as $language )
00208 {
00209 $persistentData['object_options']['language_array'][] = $language->attribute( 'locale_code' );
00210 }
00211 }
00212
00213 function loadObjectLimits( &$package, &$http, $step, &$persistentData, &$tpl, &$module )
00214 {
00215 include_once( 'lib/ezutils/classes/ezini.php' );
00216 $ini =& eZINI::instance();
00217 $availableSiteAccesses = $ini->variable( 'SiteAccessSettings', 'RelatedSiteAccessList' );
00218
00219 include_once( 'kernel/classes/ezcontentobject.php' );
00220 $availableLanguages = eZContentObject::translationList();
00221 $availableLanguageArray = array();
00222 foreach ( $availableLanguages as $language )
00223 {
00224 $availableLanguageArray[] = array( 'name' => $language->attribute( 'language_name' ),
00225 'locale' => $language->attribute( 'locale_code' ) );
00226 }
00227
00228 $tpl->setVariable( 'available_site_accesses', $availableSiteAccesses );
00229 $tpl->setVariable( 'available_languages', $availableLanguageArray );
00230 $tpl->setVariable( 'options', $persistentData['object_options'] );
00231 }
00232
00233
00234
00235
00236 function validateObjectLimits( &$package, &$http, $currentStepID, &$stepMap, &$persistentData, &$errorList )
00237 {
00238 $options =& $persistentData['object_options'];
00239
00240 $options['include_classes'] = $http->hasPostVariable( 'IncludeClasses' ) ? $http->postVariable( 'IncludeClasses' ) : false;
00241 $options['include_templates'] = $http->hasPostVariable( 'IncludeTemplates' ) ? $http->postVariable( 'IncludeTemplates' ) : false;
00242 $options['site_access_array'] = $http->postVariable( 'SiteAccesses' );
00243 $options['versions'] = $http->postVariable( 'VersionExport' );
00244 $options['language_array'] = $http->postVariable( 'Languages' );
00245 $options['node_assignment'] = $http->postVariable( 'NodeAssignment' );
00246 $options['related_objects'] = $http->postVariable( 'RelatedObjects' );
00247 $options['minimal_template_set'] = $http->hasPostVariable( 'MinimalTemplateSet' ) ? $http->postVariable( 'MinimalTemplateSet' ) : false;
00248
00249 $result = true;
00250 if ( count( $persistentData['object_options']['language_array'] ) == 0 )
00251 {
00252 $errorList[] = array( 'field' => ezi18n( 'kernel/package', 'Selected nodes' ),
00253 'description' => ezi18n( 'kernel/package', 'You must choose one or more languages.' ) );
00254 $result = false;
00255 }
00256
00257 if ( $persistentData['object_options']['include_templates'] &&
00258 count( $persistentData['object_options']['site_access_array'] ) == 0 )
00259 {
00260 $errorList[] = array( 'field' => ezi18n( 'kernel/package', 'Selected nodes' ),
00261 'description' => ezi18n( 'kernel/package', 'You must choose one or more site access.' ) );
00262 $result = false;
00263 }
00264
00265 return $result;
00266 }
00267
00268
00269
00270
00271
00272 function generatePackageInformation( &$packageInformation, &$package, &$http, $step, &$persistentData )
00273 {
00274 $nodeList = $persistentData['node_list'];
00275 $options = $persistentData['object_options'];
00276 $nodeCount = 0;
00277 $description = 'This package contains the following nodes :' . "\n";
00278 $nodeNames = array();
00279 foreach( $nodeList as $nodeInfo )
00280 {
00281 $contentNode = eZContentObjectTreeNode::fetch( $nodeInfo['id'] );
00282 $description .= $contentNode->attribute( 'name' ) . ' - ' . $nodeInfo['type'] . "\n";
00283 $nodeNames[] = trim( $contentNode->attribute( 'name' ) );
00284 if ( $nodeInfo['type'] == 'node' )
00285 {
00286 ++$nodeCount;
00287 }
00288 else if ( $nodeInfo['type'] == 'subtree' )
00289 {
00290 $nodeCount += $contentNode->subTreeCount();
00291 }
00292 }
00293
00294 $packageInformation['name'] = implode( ',', $nodeNames );
00295 $packageInformation['summary'] = implode( ', ', $nodeNames );
00296 $packageInformation['description'] = $description;
00297 }
00298
00299 }
00300 ?>