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
00041 include_once( 'kernel/classes/ezpersistentobject.php' );
00042
00043 define( "EZ_PDFEXPORT_VERSION_VALID", 0 );
00044 define( "EZ_PDFEXPORT_VERSION_DRAFT", 1 );
00045
00046 define( "EZ_PDFEXPORT_CREATE_ONCE", 1 );
00047 define( "EZ_PDFEXPORT_CREATE_ONFLY", 2 );
00048
00049 class eZPDFExport extends eZPersistentObject
00050 {
00051
00052
00053
00054 function eZPDFExport( $row )
00055 {
00056 $this->eZPersistentObject( $row );
00057 }
00058
00059
00060
00061
00062 function definition()
00063 {
00064 return array( 'fields' => array( 'id' => array( 'name' => 'ID',
00065 'datatype' => 'integer',
00066 'default' => 0,
00067 'required' => true ),
00068 'title' => array( 'name' => 'Title',
00069 'datatype' => 'string',
00070 'default' => ezi18n( 'kernel/pdfexport', 'New PDF Export' ),
00071 'required' => true ),
00072 'show_frontpage' => array( 'name' => 'DisplayFrontpage',
00073 'datatype' => 'integer',
00074 'default' => 1,
00075 'required' => true ),
00076 'intro_text' => array( 'name' => 'IntroText',
00077 'datatype' => 'text',
00078 'default' => '',
00079 'required' => false ),
00080 'sub_text' => array( 'name' => 'SubText',
00081 'datatype' => 'text',
00082 'default' => '',
00083 'required' => false ),
00084 'source_node_id' => array( 'name' => 'SourceNodeID',
00085 'datatype' => 'int',
00086 'default' => '',
00087 'required' => true,
00088 'foreign_class' => 'eZContentObjectTreeNode',
00089 'foreign_attribute' => 'node_id',
00090 'multiplicity' => '1..*' ),
00091 'site_access' => array( 'name' => 'SiteAccess',
00092 'datatype' => 'string',
00093 'default' => '',
00094 'required' => true ),
00095 'modified' => array( 'name' => 'Modified',
00096 'datatype' => 'integer',
00097 'default' => 0,
00098 'required' => true ),
00099 'modifier_id' => array( 'name' => 'ModifierID',
00100 'datatype' => 'integer',
00101 'default' => 0,
00102 'required' => true,
00103 'foreign_class' => 'eZUser',
00104 'foreign_attribute' => 'contentobject_id',
00105 'multiplicity' => '1..*' ),
00106 'created' => array( 'name' => 'Created',
00107 'datatype' => 'integer',
00108 'default' => 0,
00109 'required' => true ),
00110 'creator_id' => array( 'name' => 'CreatorID',
00111 'datatype' => 'integer',
00112 'default' => 0,
00113 'required' => true,
00114 'foreign_class' => 'eZUser',
00115 'foreign_attribute' => 'contentobject_id',
00116 'multiplicity' => '1..*' ),
00117 'export_structure' => array( 'name' => 'ExportStructure',
00118 'datatype' => 'string',
00119 'default' => 'tree',
00120 'required' => false ),
00121 'export_classes' => array( 'name' => 'ExportClasses',
00122 'datatype' => 'string',
00123 'default' => 0,
00124 'required' => false ),
00125 'pdf_filename' => array( 'name' => 'PDFFileName',
00126 'datatype' => 'string',
00127 'default' => 'file.pdf',
00128 'required' => true ),
00129 'status' => array( 'name' => 'Status',
00130 'datatype' => 'integer',
00131 'default' => EZ_PDFEXPORT_CREATE_ONCE,
00132 'required' => true ),
00133 'version' => array( 'name' => 'Version',
00134 'datatype' => 'integer',
00135 'default' => 0,
00136 'required' => true ) ),
00137 'keys' => array( 'id', 'version' ),
00138 'function_attributes' => array ( 'modifier' => 'modifier',
00139 'source_node' => 'sourceNode',
00140 'filepath' => 'filepath',
00141 'export_classes_array' => 'exportClassesArray' ),
00142 'increment_key' => 'id',
00143 'sort' => array( 'title' => 'asc' ),
00144 'class_name' => 'eZPDFExport',
00145 'name' => 'ezpdf_export' );
00146 }
00147
00148
00149
00150
00151
00152
00153 function create( $user_id )
00154 {
00155 $config =& eZINI::instance( 'site.ini' );
00156 $dateTime = time();
00157 $row = array( 'id' => null,
00158 'title' => ezi18n( 'kernel/pdfexport', 'New PDF Export' ),
00159 'show_frontpage' => 1,
00160 'intro_text' => '',
00161 'sub_text' => '',
00162 'source_node_id' => 0,
00163 'export_structure' => 'tree',
00164 'export_classes' => '',
00165 'site_access' => '',
00166 'pdf_filename' => 'file.pdf',
00167 'modifier_id' => $user_id,
00168 'modified' => $dateTime,
00169 'creator_id' => $user_id,
00170 'created' => $dateTime,
00171 'status' => 0,
00172 'version' => 1 );
00173 return new eZPDFExport( $row );
00174 }
00175
00176
00177
00178
00179
00180
00181 function store( $publish = false )
00182 {
00183 include_once( 'kernel/classes/datatypes/ezuser/ezuser.php' );
00184
00185 if ( $publish )
00186 {
00187 $originalVersion = $this->attribute( 'version' );
00188 $this->setAttribute( 'version', EZ_PDFEXPORT_VERSION_VALID );
00189 }
00190 $user =& eZUser::currentUser();
00191 $this->setAttribute( 'modified', time() );
00192 $this->setAttribute( 'modifier_id', $user->attribute( 'contentobject_id' ) );
00193
00194 $db =& eZDB::instance();
00195 $db->begin();
00196 eZPersistentObject::store();
00197 if ( $publish )
00198 {
00199 $this->setAttribute( 'version', EZ_PDFEXPORT_VERSION_DRAFT );
00200 $this->remove();
00201 $this->setAttribute( 'version', $originalVersion );
00202 }
00203 $db->commit();
00204 }
00205
00206
00207
00208
00209
00210
00211
00212 function fetch( $id, $asObject = true, $version = EZ_PDFEXPORT_VERSION_VALID )
00213 {
00214 return eZPersistentObject::fetchObject( eZPDFExport::definition(),
00215 null,
00216 array( 'id' => $id,
00217 'version' => $version ),
00218 $asObject );
00219 }
00220
00221
00222
00223
00224
00225 function remove()
00226 {
00227 if ( $this->attribute( 'version' ) == EZ_PDFEXPORT_VERSION_VALID &&
00228 $this->attribute( 'status' ) != EZ_PDFEXPORT_CREATE_ONFLY )
00229 {
00230 $sys =& eZSys::instance();
00231 $storage_dir = $sys->storageDirectory();
00232
00233 $filename = $storage_dir . '/pdf/' . $this->attribute( 'pdf_filename' );
00234 if ( file_exists( $filename ) )
00235 {
00236 unlink( $filename );
00237 }
00238 }
00239 eZPersistentObject::remove();
00240 }
00241
00242
00243
00244
00245
00246 function fetchList( $asObject = true )
00247 {
00248 return eZPersistentObject::fetchObjectList( eZPDFExport::definition(),
00249 null,
00250 array( 'version' => EZ_PDFEXPORT_VERSION_VALID ),
00251 null,
00252 null,
00253 $asObject );
00254 }
00255
00256 function &modifier()
00257 {
00258 if ( isset( $this->ModifierID ) and $this->ModifierID )
00259 {
00260 include_once( 'kernel/classes/datatypes/ezuser/ezuser.php' );
00261 $user = eZUser::fetch( $this->ModifierID );
00262 }
00263 else
00264 $user = null;
00265 return $user;
00266 }
00267
00268 function &sourceNode()
00269 {
00270 if ( isset( $this->SourceNodeID ) and $this->SourceNodeID )
00271 {
00272 include_once( 'kernel/classes/ezcontentobjecttreenode.php' );
00273 $sourceNode = eZContentObjectTreeNode::fetch( $this->SourceNodeID );
00274 }
00275 else
00276 $sourceNode = null;
00277 return $sourceNode;
00278 }
00279
00280 function &filepath()
00281 {
00282 $sys =& eZSys::instance();
00283 $storage_dir = $sys->storageDirectory();
00284 $filePath = $storage_dir . '/pdf/' . $this->attribute( 'pdf_filename' );
00285 return $filePath;
00286 }
00287
00288 function &exportClassesArray()
00289 {
00290 $exportClassesArray = explode( ':', eZPersistentObject::attribute( 'export_classes' ) );
00291 return $exportClassesArray;
00292 }
00293
00294 function countGeneratingOnceExports( $filename = '' )
00295 {
00296 $conditions = array( 'version' => EZ_PDFEXPORT_VERSION_VALID,
00297 'status' => EZ_PDFEXPORT_CREATE_ONCE,
00298 'pdf_filename' => $filename );
00299
00300 if ( $filename === '' && isset( $this ) )
00301 {
00302 $conditions['pdf_filename'] = $this->attribute( 'pdf_filename' );
00303 $conditions['id'] = array( '<>', $this->attribute( 'id' ) );
00304 }
00305
00306 $queryResult = eZPersistentObject::fetchObjectList( eZPDFExport::definition(),
00307 array(),
00308 $conditions,
00309 false,
00310 null,
00311 false,
00312 null,
00313 array( array( 'operation' => 'count( * )',
00314 'name' => 'count' ) ) );
00315 if ( isset( $queryResult[0]['count'] ) )
00316 {
00317 return ( int ) $queryResult[0]['count'];
00318 }
00319 return 0;
00320
00321 }
00322
00323 }
00324
00325 ?>