Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezpdfexport.php
Go to the documentation of this file.
1 <?php
18 class eZPDFExport extends eZPersistentObject
19 {
20 public $ModifierID;
21 public $SourceNodeID;
22 const VERSION_VALID = 0;
23 const VERSION_DRAFT = 1;
24
25 const CREATE_ONCE = 1;
26 const CREATE_ONFLY = 2;
27
28 static function definition()
29 {
30 return array( 'fields' => array( 'id' => array( 'name' => 'ID',
31 'datatype' => 'integer',
32 'default' => 0,
33 'required' => true ),
34 'title' => array( 'name' => 'Title',
35 'datatype' => 'string',
36 'default' => ezpI18n::tr( 'kernel/pdfexport', 'New PDF Export' ),
37 'required' => true ),
38 'show_frontpage' => array( 'name' => 'DisplayFrontpage',
39 'datatype' => 'integer',
40 'default' => 1,
41 'required' => true ),
42 'intro_text' => array( 'name' => 'IntroText',
43 'datatype' => 'text',
44 'default' => '',
45 'required' => false ),
46 'sub_text' => array( 'name' => 'SubText',
47 'datatype' => 'text',
48 'default' => '',
49 'required' => false ),
50 'source_node_id' => array( 'name' => 'SourceNodeID',
51 'datatype' => 'int',
52 'default' => '',
53 'required' => true,
54 'foreign_class' => 'eZContentObjectTreeNode',
55 'foreign_attribute' => 'node_id',
56 'multiplicity' => '1..*' ),
57 'site_access' => array( 'name' => 'SiteAccess',
58 'datatype' => 'string',
59 'default' => '',
60 'required' => true ),
61 'modified' => array( 'name' => 'Modified',
62 'datatype' => 'integer',
63 'default' => 0,
64 'required' => true ),
65 'modifier_id' => array( 'name' => 'ModifierID',
66 'datatype' => 'integer',
67 'default' => 0,
68 'required' => true,
69 'foreign_class' => 'eZUser',
70 'foreign_attribute' => 'contentobject_id',
71 'multiplicity' => '1..*' ),
72 'created' => array( 'name' => 'Created',
73 'datatype' => 'integer',
74 'default' => 0,
75 'required' => true ),
76 'creator_id' => array( 'name' => 'CreatorID',
77 'datatype' => 'integer',
78 'default' => 0,
79 'required' => true,
80 'foreign_class' => 'eZUser',
81 'foreign_attribute' => 'contentobject_id',
82 'multiplicity' => '1..*' ),
83 'export_structure' => array( 'name' => 'ExportStructure',
84 'datatype' => 'string',
85 'default' => 'tree',
86 'required' => false ),
87 'export_classes' => array( 'name' => 'ExportClasses',
88 'datatype' => 'string',
89 'default' => 0,
90 'required' => false ),
91 'pdf_filename' => array( 'name' => 'PDFFileName',
92 'datatype' => 'string',
93 'default' => 'file.pdf',
94 'required' => true ),
95 'status' => array( 'name' => 'Status',
96 'datatype' => 'integer',
97 'default' => eZPDFExport::CREATE_ONCE,
98 'required' => true ),
99 'version' => array( 'name' => 'Version',
100 'datatype' => 'integer',
101 'default' => 0,
102 'required' => true ) ),
103 'keys' => array( 'id', 'version' ),
104 'function_attributes' => array ( 'modifier' => 'modifier',
105 'source_node' => 'sourceNode',
106 'filepath' => 'filepath',
107 'export_classes_array' => 'exportClassesArray' ),
108 'increment_key' => 'id',
109 'sort' => array( 'title' => 'asc' ),
110 'class_name' => 'eZPDFExport',
111 'name' => 'ezpdf_export' );
112 }
113
119 static function create( $user_id )
120 {
121 $config = eZINI::instance( 'site.ini' );
122 $dateTime = time();
123 $row = array( 'id' => null,
124 'title' => ezpI18n::tr( 'kernel/pdfexport', 'New PDF Export' ),
125 'show_frontpage' => 1,
126 'intro_text' => '',
127 'sub_text' => '',
128 'source_node_id' => 0,
129 'export_structure' => 'tree',
130 'export_classes' => '',
131 'site_access' => '',
132 'pdf_filename' => 'file.pdf',
133 'modifier_id' => $user_id,
134 'modified' => $dateTime,
135 'creator_id' => $user_id,
136 'created' => $dateTime,
137 'status' => 0,
138 'version' => 1 );
139 return new eZPDFExport( $row );
140 }
141
147 function store( $publish = false )
148 {
149 if ( $publish )
150 {
151 $originalVersion = $this->attribute( 'version' );
152 $this->setAttribute( 'version', eZPDFExport::VERSION_VALID );
153 }
154 $user = eZUser::currentUser();
155 $this->setAttribute( 'modified', time() );
156 $this->setAttribute( 'modifier_id', $user->attribute( 'contentobject_id' ) );
157
158 $db = eZDB::instance();
159 $db->begin();
160 parent::store();
161 if ( $publish )
162 {
163 $this->setAttribute( 'version', eZPDFExport::VERSION_DRAFT );
164 $this->remove();
165 $this->setAttribute( 'version', $originalVersion );
166 }
167 $db->commit();
168 }
169
176 static function fetch( $id, $asObject = true, $version = eZPDFExport::VERSION_VALID )
177 {
178 return eZPersistentObject::fetchObject( eZPDFExport::definition(),
179 null,
180 array( 'id' => $id,
181 'version' => $version ),
182 $asObject );
183 }
184
188 function remove( $conditions = null, $extraConditions = null )
189 {
190 if ( $this->attribute( 'version' ) == eZPDFExport::VERSION_VALID &&
191 $this->attribute( 'status' ) != eZPDFExport::CREATE_ONFLY )
192 {
193 $sys = eZSys::instance();
194 $storage_dir = $sys->storageDirectory();
195
196 $filename = $storage_dir . '/pdf/' . $this->attribute( 'pdf_filename' );
197 if ( file_exists( $filename ) )
198 {
199 unlink( $filename );
200 }
201 }
202 parent::remove( $conditions, $extraConditions);
203 }
204
209 static function fetchList( $asObject = true )
210 {
211 return eZPersistentObject::fetchObjectList( eZPDFExport::definition(),
212 null,
213 array( 'version' => eZPDFExport::VERSION_VALID ),
214 null,
215 null,
216 $asObject );
217 }
218
219 function modifier()
220 {
221 if ( isset( $this->ModifierID ) and $this->ModifierID )
222 {
223 return eZUser::fetch( $this->ModifierID );
224 }
225
226 return null;
227 }
228
229 function sourceNode()
230 {
231 if ( isset( $this->SourceNodeID ) and $this->SourceNodeID )
232 {
233 return eZContentObjectTreeNode::fetch( $this->SourceNodeID );
234 }
235
236 return null;
237 }
238
239 function filepath()
240 {
241 $sys = eZSys::instance();
242 $storage_dir = $sys->storageDirectory();
243 return $storage_dir . '/pdf/' . $this->attribute( 'pdf_filename' );
244 }
245
246 function exportClassesArray()
247 {
248 return explode( ':', $this->attribute( 'export_classes' ) );
249 }
250
251 function countGeneratingOnceExports( $filename = '' )
252 {
253 $conditions = array( 'version' => eZPDFExport::VERSION_VALID,
254 'status' => eZPDFExport::CREATE_ONCE,
255 'pdf_filename' => $filename );
256
257 if ( $filename === '' && isset( $this ) )
258 {
259 $conditions['pdf_filename'] = $this->attribute( 'pdf_filename' );
260 $conditions['id'] = array( '<>', $this->attribute( 'id' ) );
261 }
262
263 $queryResult = eZPersistentObject::fetchObjectList( eZPDFExport::definition(),
264 array(),
265 $conditions,
266 false,
267 null,
268 false,
269 null,
270 array( array( 'operation' => 'count( * )',
271 'name' => 'count' ) ) );
272 if ( isset( $queryResult[0]['count'] ) )
273 {
274 return ( int ) $queryResult[0]['count'];
275 }
276 return 0;
277
278 }
279
280 }
281
282 ?>
eZContentObjectTreeNode\fetch
static fetch( $nodeID=false, $lang=false, $asObject=true, $conditions=false)
Definition: ezcontentobjecttreenode.php:3058
eZDB\instance
static instance( $databaseImplementation=false, $databaseParameters=false, $forceNewInstance=false)
Definition: ezdb.php:117
eZPDFExport
class for storing PDF exports
Definition: ezpdfexport.php:19
eZPDFExport\$SourceNodeID
$SourceNodeID
Definition: ezpdfexport.php:21
eZPDFExport\CREATE_ONFLY
const CREATE_ONFLY
Definition: ezpdfexport.php:26
eZPDFExport\VERSION_VALID
const VERSION_VALID
Definition: ezpdfexport.php:22
eZPDFExport\VERSION_DRAFT
const VERSION_DRAFT
Definition: ezpdfexport.php:23
eZPDFExport\filepath
filepath()
Definition: ezpdfexport.php:239
eZPDFExport\modifier
modifier()
Definition: ezpdfexport.php:219
eZPDFExport\exportClassesArray
exportClassesArray()
Definition: ezpdfexport.php:246
eZPDFExport\definition
static definition()
Definition: ezpdfexport.php:28
eZPDFExport\create
static create( $user_id)
Definition: ezpdfexport.php:119
eZPDFExport\countGeneratingOnceExports
countGeneratingOnceExports( $filename='')
Definition: ezpdfexport.php:251
eZPDFExport\store
store( $publish=false)
Definition: ezpdfexport.php:147
eZPDFExport\fetch
static fetch( $id, $asObject=true, $version=eZPDFExport::VERSION_VALID)
Definition: ezpdfexport.php:176
eZPDFExport\CREATE_ONCE
const CREATE_ONCE
Definition: ezpdfexport.php:25
eZPDFExport\sourceNode
sourceNode()
Definition: ezpdfexport.php:229
eZPDFExport\$ModifierID
$ModifierID
Definition: ezpdfexport.php:20
eZPDFExport\fetchList
static fetchList( $asObject=true)
Definition: ezpdfexport.php:209
eZPersistentObject
Definition: ezpersistentobject.php:33
eZPersistentObject\fetchObject
static fetchObject( $def, $field_filters, $conds, $asObject=true, $grouping=null, $custom_fields=null)
Definition: ezpersistentobject.php:213
eZPersistentObject\setAttribute
setAttribute( $attr, $val)
Definition: ezpersistentobject.php:1374
eZPersistentObject\attribute
attribute( $attr, $noFunction=false)
Definition: ezpersistentobject.php:1329
eZPersistentObject\fetchObjectList
static fetchObjectList( $def, $field_filters=null, $conds=null, $sorts=null, $limit=null, $asObject=true, $grouping=false, $custom_fields=null, $custom_tables=null, $custom_conds=null)
Definition: ezpersistentobject.php:806
eZSys\instance
static instance()
Definition: ezsys.php:1272
eZUser\fetch
static fetch( $id, $asObject=true)
Definition: ezuser.php:351
eZUser\currentUser
static currentUser()
Definition: ezuser.php:1716
ezpI18n\tr
static tr( $context, $source, $comment=null, $arguments=null)
Definition: ezpi18n.php:86
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.