[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/kernel/classes/ -> ezpdfexport.php (source)

   1  <?php
   2  //
   3  // Definition of eZRSSExport class
   4  //
   5  // Created on: <21-Nov-2003 15:59:56 kk>
   6  //
   7  // SOFTWARE NAME: eZ publish
   8  // SOFTWARE RELEASE: 3.9.0
   9  // BUILD VERSION: 17785
  10  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  11  // SOFTWARE LICENSE: GNU General Public License v2.0
  12  // NOTICE: >
  13  //   This program is free software; you can redistribute it and/or
  14  //   modify it under the terms of version 2.0  of the GNU General
  15  //   Public License as published by the Free Software Foundation.
  16  //
  17  //   This program is distributed in the hope that it will be useful,
  18  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  19  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20  //   GNU General Public License for more details.
  21  //
  22  //   You should have received a copy of version 2.0 of the GNU General
  23  //   Public License along with this program; if not, write to the Free
  24  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25  //   MA 02110-1301, USA.
  26  //
  27  //
  28  
  29  /*! \file ezrssexport.php
  30  */
  31  
  32  /*!
  33    \class for storing PDF exports
  34  
  35    RSSExport is used to create RSS feeds from published content. See kernel/rss for more files.
  36  */
  37  
  38  include_once ( 'kernel/classes/ezpersistentobject.php' );
  39  include_once ( 'kernel/classes/ezrssexportitem.php' );
  40  
  41  define( "EZ_PDFEXPORT_VERSION_VALID", 0 );
  42  define( "EZ_PDFEXPORT_VERSION_DRAFT", 1 );
  43  
  44  define( "EZ_PDFEXPORT_CREATE_ONCE",  1 );
  45  define( "EZ_PDFEXPORT_CREATE_ONFLY", 2 );
  46  
  47  class eZPDFExport extends eZPersistentObject
  48  {
  49      /*!
  50       Initializes a new RSSExport.
  51      */
  52      function eZPDFExport( $row )
  53      {
  54          $this->eZPersistentObject( $row );
  55      }
  56  
  57      /*!
  58       \reimp
  59      */
  60      function definition()
  61      {
  62          return array( 'fields' => array( 'id' => array( 'name' => 'ID',
  63                                                          'datatype' => 'integer',
  64                                                          'default' => 0,
  65                                                          'required' => true ),
  66                                           'title' => array( 'name' => 'Title',
  67                                                             'datatype' => 'string',
  68                                                             'default' => ezi18n( 'kernel/pdfexport', 'New PDF Export' ),
  69                                                             'required' => true ),
  70                                           'show_frontpage' => array( 'name' => 'DisplayFrontpage',
  71                                                                         'datatype' => 'integer',
  72                                                                         'default' => 1,
  73                                                                         'required' => true ),
  74                                           'intro_text' => array( 'name' => 'IntroText',
  75                                                                  'datatype' => 'text',
  76                                                                  'default' => '',
  77                                                                  'required' => false ),
  78                                           'sub_text' => array( 'name' => 'SubText',
  79                                                                'datatype' => 'text',
  80                                                                'default' => '',
  81                                                                'required' => false ),
  82                                           'source_node_id' => array( 'name' => 'SourceNodeID',
  83                                                                      'datatype' => 'int',
  84                                                                      'default' => '',
  85                                                                      'required' => true,
  86                                                                      'foreign_class' => 'eZContentObjectTreeNode',
  87                                                                      'foreign_attribute' => 'node_id',
  88                                                                      'multiplicity' => '1..*' ),
  89                                           'site_access' => array( 'name' => 'SiteAccess',
  90                                                                   'datatype' => 'string',
  91                                                                   'default' => '',
  92                                                                   'required' => true ),
  93                                           'modified' => array( 'name' => 'Modified',
  94                                                                'datatype' => 'integer',
  95                                                                'default' => 0,
  96                                                                'required' => true ),
  97                                           'modifier_id' => array( 'name' => 'ModifierID',
  98                                                                   'datatype' => 'integer',
  99                                                                   'default' => 0,
 100                                                                   'required' => true,
 101                                                                   'foreign_class' => 'eZUser',
 102                                                                   'foreign_attribute' => 'contentobject_id',
 103                                                                   'multiplicity' => '1..*' ),
 104                                           'created' => array( 'name' => 'Created',
 105                                                               'datatype' => 'integer',
 106                                                               'default' => 0,
 107                                                               'required' => true ),
 108                                           'creator_id' => array( 'name' => 'CreatorID',
 109                                                                  'datatype' => 'integer',
 110                                                                  'default' => 0,
 111                                                                  'required' => true,
 112                                                                  'foreign_class' => 'eZUser',
 113                                                                  'foreign_attribute' => 'contentobject_id',
 114                                                                  'multiplicity' => '1..*' ),
 115                                           'export_structure' => array( 'name' => 'ExportStructure',
 116                                                                        'datatype' => 'string',
 117                                                                        'default' => 'tree',
 118                                                                        'required' => false ),
 119                                           'export_classes' => array( 'name' => 'ExportClasses',
 120                                                                      'datatype' => 'string',
 121                                                                      'default' => 0,
 122                                                                      'required' => false ),
 123                                           'pdf_filename' => array( 'name' => 'PDFFileName',
 124                                                                     'datatype' => 'string',
 125                                                                     'default' => 'file.pdf',
 126                                                                     'required' => true ),
 127                                           'status' => array( 'name' => 'Status',
 128                                                              'datatype' => 'integer',
 129                                                              'default' => EZ_PDFEXPORT_CREATE_ONCE,
 130                                                              'required' => true ),
 131                                           'version' => array( 'name' => 'Version',
 132                                                               'datatype' => 'integer',
 133                                                               'default' => 0,
 134                                                               'required' => true ) ),
 135                        'keys' => array( 'id', 'version' ),
 136                        'function_attributes' => array ( 'modifier' => 'modifier',
 137                                                         'source_node' => 'sourceNode',
 138                                                         'filepath' => 'filepath',
 139                                                         'export_classes_array' => 'exportClassesArray' ),
 140                        'increment_key' => 'id',
 141                        'sort' => array( 'title' => 'asc' ),
 142                        'class_name' => 'eZPDFExport',
 143                        'name' => 'ezpdf_export' );
 144      }
 145  
 146      /*!
 147       \static
 148       Creates a new RSS Export with the new RSS Export
 149       \param User ID
 150      */
 151      function create( $user_id )
 152      {
 153          $config =& eZINI::instance( 'site.ini' );
 154          $dateTime = time();
 155          $row = array( 'id' => null,
 156                        'title' => ezi18n( 'kernel/pdfexport', 'New PDF Export' ),
 157                        'show_frontpage' => 1,
 158                        'intro_text' => '',
 159                        'sub_text' => '',
 160                        'source_node_id' => 0,
 161                        'export_structure' => 'tree',
 162                        'export_classes' => '',
 163                        'site_access' => '',
 164                        'pdf_filename' => 'file.pdf',
 165                        'modifier_id' => $user_id,
 166                        'modified' => $dateTime,
 167                        'creator_id' => $user_id,
 168                        'created' => $dateTime,
 169                        'status' => 0,
 170                        'version' => 1 );
 171          return new eZPDFExport( $row );
 172      }
 173  
 174      /*!
 175       Store Object to database
 176       \note Transaction unsafe. If you call several transaction unsafe methods you must enclose
 177       the calls within a db transaction; thus within db->begin and db->commit.
 178      */
 179      function store( $publish = false )
 180      {
 181          include_once ( 'kernel/classes/datatypes/ezuser/ezuser.php' );
 182  
 183          if ( $publish )
 184          {
 185              $originalVersion = $this->attribute( 'version' );
 186              $this->setAttribute( 'version', EZ_PDFEXPORT_VERSION_VALID );
 187          }
 188          $user =& eZUser::currentUser();
 189          $this->setAttribute( 'modified', time() );
 190          $this->setAttribute( 'modifier_id', $user->attribute( 'contentobject_id' ) );
 191  
 192          $db =& eZDB::instance();
 193          $db->begin();
 194          eZPersistentObject::store();
 195          if ( $publish )
 196          {
 197              $this->setAttribute( 'version', EZ_PDFEXPORT_VERSION_DRAFT );
 198              $this->remove();
 199              $this->setAttribute( 'version', $originalVersion );
 200          }
 201          $db->commit();
 202      }
 203  
 204      /*!
 205       \static
 206        Fetches the RSS Export by ID.
 207  
 208       \param RSS Export ID
 209      */
 210      function fetch( $id, $asObject = true, $version = EZ_PDFEXPORT_VERSION_VALID )
 211      {
 212          return eZPersistentObject::fetchObject( eZPDFExport::definition(),
 213                                                  null,
 214                                                  array( 'id' => $id,
 215                                                         'version' => $version ),
 216                                                  $asObject );
 217      }
 218  
 219      /*!
 220       \reimp
 221       \transaction unsafe.
 222      */
 223      function remove()
 224      {
 225          if ( $this->attribute( 'version' ) == EZ_PDFEXPORT_VERSION_VALID &&
 226               $this->attribute( 'status' ) != EZ_PDFEXPORT_CREATE_ONFLY )
 227          {
 228              $sys =& eZSys::instance();
 229              $storage_dir = $sys->storageDirectory();
 230  
 231              $filename = $storage_dir . '/pdf/' . $this->attribute( 'pdf_filename' );
 232              if ( file_exists( $filename ) )
 233              {
 234                  unlink( $filename );
 235              }
 236          }
 237          eZPersistentObject::remove();
 238      }
 239  
 240      /*!
 241       \static
 242        Fetches complete list of RSS Exports.
 243      */
 244      function fetchList( $asObject = true )
 245      {
 246          return eZPersistentObject::fetchObjectList( eZPDFExport::definition(),
 247                                                      null,
 248                                                      array( 'version' => EZ_PDFEXPORT_VERSION_VALID ),
 249                                                      null,
 250                                                      null,
 251                                                      $asObject );
 252      }
 253  
 254      function &modifier()
 255      {
 256          if ( isset( $this->ModifierID ) and $this->ModifierID )
 257          {
 258              include_once ( 'kernel/classes/datatypes/ezuser/ezuser.php' );
 259              $user = eZUser::fetch( $this->ModifierID );
 260          }
 261          else
 262              $user = null;
 263          return $user;
 264      }
 265  
 266      function &sourceNode()
 267      {
 268          if ( isset( $this->SourceNodeID ) and $this->SourceNodeID )
 269          {
 270              include_once ( 'kernel/classes/ezcontentobjecttreenode.php' );
 271              $sourceNode = eZContentObjectTreeNode::fetch( $this->SourceNodeID );
 272          }
 273          else
 274              $sourceNode = null;
 275          return $sourceNode;
 276      }
 277  
 278      function &filepath()
 279      {
 280          $sys =& eZSys::instance();
 281          $storage_dir = $sys->storageDirectory();
 282          $filePath = $storage_dir . '/pdf/' . $this->attribute( 'pdf_filename' );
 283          return $filePath;
 284      }
 285  
 286      function &exportClassesArray()
 287      {
 288          $exportClassesArray = explode( ':',  eZPersistentObject::attribute( 'export_classes' ) );
 289          return $exportClassesArray;
 290      }
 291  
 292      function countGeneratingOnceExports( $filename = '' )
 293      {
 294          $conditions = array( 'version' => EZ_PDFEXPORT_VERSION_VALID,
 295                               'status' =>  EZ_PDFEXPORT_CREATE_ONCE,
 296                               'pdf_filename' => $filename );
 297  
 298          if ( $filename === '' && isset( $this ) )
 299          {
 300              $conditions['pdf_filename'] = $this->attribute( 'pdf_filename' );
 301              $conditions['id'] = array( '<>', $this->attribute( 'id' ) );
 302          }
 303  
 304          $queryResult = eZPersistentObject::fetchObjectList( eZPDFExport::definition(),
 305                                                              array(),
 306                                                              $conditions,
 307                                                              null,
 308                                                              null,
 309                                                              false,
 310                                                              null,
 311                                                              array( array( 'operation' => 'count( * )',
 312                                                                            'name' => 'count' ) ) );
 313  
 314          if ( isset( $queryResult[0]['count'] ) )
 315          {
 316              return ( int ) $queryResult[0]['count'];
 317          }
 318          return 0;
 319  
 320      }
 321  
 322  }
 323  
 324  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7