[ Index ]
 

Code source de eZ Publish 3.9.0

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

title

Body

[fermer]

/kernel/classes/datatypes/ezimage/ -> ezimagefile.php (source)

   1  <?php
   2  //
   3  // Definition of eZImageFile class
   4  //
   5  // Created on: <30-Apr-2002 16:47:08 bf>
   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  /*!
  30    \class eZImageFile ezimagefile.php
  31    \ingroup eZDatatype
  32    \brief The class eZImageFile handles registered images
  33  
  34  */
  35  
  36  include_once ( 'lib/ezdb/classes/ezdb.php' );
  37  include_once ( 'kernel/classes/ezpersistentobject.php' );
  38  
  39  class eZImageFile extends eZPersistentObject
  40  {
  41      function eZImageFile( $row )
  42      {
  43          $this->eZPersistentObject( $row );
  44      }
  45  
  46      function definition()
  47      {
  48          return array( 'fields' => array( 'id' => array( 'name' => 'id',
  49                                                          'datatype' => 'integer',
  50                                                          'default' => 0,
  51                                                          'required' => true ),
  52                                           'contentobject_attribute_id' => array( 'name' => 'ContentObjectAttributeID',
  53                                                                                  'datatype' => 'integer',
  54                                                                                  'default' => 0,
  55                                                                                  'required' => true,
  56                                                                                  'foreign_class' => 'eZContentObjectAttribute',
  57                                                                                  'foreign_attribute' => 'id',
  58                                                                                  'multiplicity' => '1..*' ),
  59                                           'filepath' => array( 'name' => 'Filepath',
  60                                                                'datatype' => 'string',
  61                                                                'default' => '',
  62                                                                'required' => true ) ),
  63                        'keys' => array( 'id' ),
  64                        'class_name' => 'eZImageFile',
  65                        'name' => 'ezimagefile' );
  66      }
  67  
  68      function create( $contentObjectAttributeID, $filepath  )
  69      {
  70          $row = array( "contentobject_attribute_id" => $contentObjectAttributeID,
  71                        "filepath" => $filepath );
  72          return new eZImageFile( $row );
  73      }
  74  
  75      function &fetchForContentObjectAttribute( $contentObjectAttributeID, $asObject = false )
  76      {
  77          $rows = eZPersistentObject::fetchObjectList( eZImageFile::definition(),
  78                                                        null,
  79                                                        array( "contentobject_attribute_id" => $contentObjectAttributeID ),
  80                                                        null,
  81                                                        null,
  82                                                        $asObject );
  83          if ( !$asObject )
  84          {
  85              $files = array();
  86              foreach ( array_keys( $rows ) as $rowKey )
  87              {
  88                  $row =& $rows[$rowKey];
  89                  $files[] = $row['filepath'];
  90              }
  91              $files = array_unique( $files );
  92              return $files;
  93          }
  94          else
  95              return $rows;
  96      }
  97      /*!
  98        \return An array of ids and versions of ezimage ezcontentobject_attributes have \a $filepath.
  99      */
 100      function fetchImageAttributesByFilepath( $filepath )
 101      {
 102         $db = eZDB::instance();
 103         $filepath = $db->escapeString( $filepath );
 104         $query = "SELECT id, version
 105                   FROM   ezcontentobject_attribute
 106                   WHERE  data_type_string = 'ezimage' and
 107                          data_text like '%url=\"$filepath\"%'";
 108  
 109         $rows = $db->arrayQuery( $query );
 110         return $rows;
 111      }
 112  
 113      function fetchByFilepath( $contentObjectAttributeID, $filepath, $asObject = true )
 114      {
 115          // Fetch by file path without $contentObjectAttributeID
 116          if ( $contentObjectAttributeID === false )
 117              return eZPersistentObject::fetchObject( eZImageFile::definition(),
 118                                                      null,
 119                                                      array( 'filepath' => $filepath ),
 120                                                      $asObject );
 121  
 122          return eZPersistentObject::fetchObject( eZImageFile::definition(),
 123                                                  null,
 124                                                  array( 'contentobject_attribute_id' => $contentObjectAttributeID,
 125                                                         'filepath' => $filepath ),
 126                                                  $asObject );
 127      }
 128  
 129      function moveFilepath( $contentObjectAttributeID, $oldFilepath, $newFilepath )
 130      {
 131          $db =& eZDB::instance();
 132          $db->begin();
 133  
 134          eZImageFile::removeFilepath( $contentObjectAttributeID, $oldFilepath );
 135          $result = eZImageFile::appendFilepath( $contentObjectAttributeID, $newFilepath );
 136  
 137          $db->commit();
 138          return $result;
 139      }
 140  
 141      function appendFilepath( $contentObjectAttributeID, $filepath, $ignoreUnique = false )
 142      {
 143          if ( empty( $filepath ) )
 144              return false;
 145  
 146          if ( !$ignoreUnique )
 147          {
 148              // Fetch ezimagefile objects having the $filepath
 149              $imageFiles = eZImageFile::fetchByFilePath( false, $filepath, false );
 150              // Checking If the filePath already exists in ezimagefile table
 151              if ( isset( $imageFiles[ 'contentobject_attribute_id' ] ) )
 152                  return false;
 153          }
 154          $fileObject = eZImageFile::fetchByFilePath( $contentObjectAttributeID, $filepath );
 155          if ( $fileObject )
 156              return false;
 157          $fileObject = eZImageFile::create( $contentObjectAttributeID, $filepath );
 158          $fileObject->store();
 159          return true;
 160      }
 161  
 162      function removeFilepath( $contentObjectAttributeID, $filepath )
 163      {
 164          if ( empty( $filepath ) )
 165              return false;
 166          $fileObject = eZImageFile::fetchByFilePath( $contentObjectAttributeID, $filepath );
 167          if ( !$fileObject )
 168              return false;
 169          $fileObject->remove();
 170          return true;
 171      }
 172  
 173      function removeForContentObjectAttribute( $contentObjectAttributeID )
 174      {
 175          if ( isset( $this ) and
 176               get_class( $this ) == 'ezimagefile' )
 177              $instance =& $this;
 178          else
 179              $instance =& eZImageFile::instance();
 180          $instance->remove( array( 'contentobject_attribute_id' => $contentObjectAttributeID ) );
 181      }
 182  
 183      function &instance()
 184      {
 185          $instance =& $GLOBALS['eZImageFileInstance'];
 186          if ( !isset( $instance ) )
 187          {
 188              $instance = new eZImageFile( array() );
 189          }
 190          return $instance;
 191      }
 192  
 193  
 194      /// \privatesection
 195      var $ID;
 196      var $ContentObjectAttributeID;
 197      var $Filepath;
 198  }
 199  
 200  ?>


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