eZ Publish  [4.0]
ezcontentobjecttrashnode.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZContentObjectTrashNode class
00004 //
00005 // Created on: <20-Sep-2006 00:00:00 rl>
00006 //
00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00008 // SOFTWARE NAME: eZ Publish
00009 // SOFTWARE RELEASE: 4.0.x
00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS
00011 // SOFTWARE LICENSE: GNU General Public License v2.0
00012 // NOTICE: >
00013 //   This program is free software; you can redistribute it and/or
00014 //   modify it under the terms of version 2.0  of the GNU General
00015 //   Public License as published by the Free Software Foundation.
00016 //
00017 //   This program is distributed in the hope that it will be useful,
00018 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //   GNU General Public License for more details.
00021 //
00022 //   You should have received a copy of version 2.0 of the GNU General
00023 //   Public License along with this program; if not, write to the Free
00024 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00025 //   MA 02110-1301, USA.
00026 //
00027 //
00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00029 //
00030 
00031 /*! \file ezcontentobjecttrashnode.php
00032 */
00033 
00034 /*!
00035   \class eZContentObjectTrashNode ezcontentobjecttrashnode.php
00036   \brief The class eZContentObjectTrashNode
00037 */
00038 
00039 //include_once( "kernel/classes/ezcontentobjecttreenode.php" );
00040 
00041 //class eZContentObjectTrashNode extends eZPersistentObject
00042 class eZContentObjectTrashNode extends eZContentObjectTreeNode
00043 {
00044     /*!
00045      Constructor
00046     */
00047     function eZContentObjectTrashNode( $row = array() )
00048     {
00049         $this->eZPersistentObject( $row );
00050     }
00051 
00052     static function definition()
00053     {
00054         return array( 'fields' => array( 'node_id' => array( 'name' => 'NodeID',
00055                                                              'datatype' => 'integer',
00056                                                              'default' => 0,
00057                                                              'required' => true ),
00058                                          'parent_node_id' => array( 'name' => 'ParentNodeID',
00059                                                                     'datatype' => 'integer',
00060                                                                     'default' => 0,
00061                                                                     'required' => true ),
00062                                          'main_node_id' => array( 'name' => 'MainNodeID',
00063                                                                   'datatype' => 'integer',
00064                                                                   'default' => 0,
00065                                                                   'required' => true ),
00066                                          'contentobject_id' => array( 'name' => 'ContentObjectID',
00067                                                                       'datatype' => 'integer',
00068                                                                       'default' => 0,
00069                                                                       'required' => true,
00070                                                                       'foreign_class' => 'eZContentObject',
00071                                                                       'foreign_attribute' => 'id',
00072                                                                       'multiplicity' => '1..*' ),
00073                                          'contentobject_version' => array( 'name' => 'ContentObjectVersion',
00074                                                                            'datatype' => 'integer',
00075                                                                            'default' => 0,
00076                                                                            'required' => true ),
00077                                          'depth' => array( 'name' => 'Depth',
00078                                                            'datatype' => 'integer',
00079                                                            'default' => 0,
00080                                                            'required' => true ),
00081                                          'sort_field' => array( 'name' => 'SortField',
00082                                                                 'datatype' => 'integer',
00083                                                                 'default' => 1,
00084                                                                 'required' => true ),
00085                                          'sort_order' => array( 'name' => 'SortOrder',
00086                                                                 'datatype' => 'integer',
00087                                                                 'default' => 1,
00088                                                                 'required' => true ),
00089                                          'priority' => array( 'name' => 'Priority',
00090                                                               'datatype' => 'integer',
00091                                                               'default' => 0,
00092                                                               'required' => true ),
00093                                          'modified_subnode' => array( 'name' => 'ModifiedSubNode',
00094                                                                       'datatype' => 'integer',
00095                                                                       'default' => 0,
00096                                                                       'required' => true ),
00097                                          'path_string' => array( 'name' => 'PathString',
00098                                                                  'datatype' => 'string',
00099                                                                  'default' => '',
00100                                                                  'required' => true ),
00101                                          'path_identification_string' => array( 'name' => 'PathIdentificationString',
00102                                                                                 'datatype' => 'text',
00103                                                                                 'default' => '',
00104                                                                                 'required' => true ),
00105                                          'remote_id' => array( 'name' => 'RemoteID',
00106                                                                'datatype' => 'string',
00107                                                                'default' => '',
00108                                                                'required' => true ),
00109                                          'is_hidden' => array( 'name' => 'IsHidden',
00110                                                                'datatype' => 'integer',
00111                                                                'default' => 0,
00112                                                                'required' => true ),
00113                                          'is_invisible' => array( 'name' => 'IsInvisible',
00114                                                                   'datatype' => 'integer',
00115                                                                   'default' => 0,
00116                                                                   'required' => true )
00117                                           ),
00118 
00119                       'keys' => array( 'node_id' ),
00120                       'function_attributes' => array( // functional attributes derived from ezcontentobjecttreenode
00121                                                       'name' => 'getName',
00122                                                       'data_map' => 'dataMap',
00123                                                       'object' => 'object',
00124                                                       'contentobject_version_object' => 'contentObjectVersionObject',
00125                                                       'sort_array' => 'sortArray',
00126                                                       'can_read' => 'canRead',
00127                                                       'can_create' => 'canCreate',
00128                                                       'can_edit' => 'canEdit',
00129                                                       'can_remove' => 'canRemove',
00130                                                       'creator' => 'creator',
00131                                                       'path_array' => 'pathArray',
00132                                                       'parent' => 'fetchParent',
00133                                                       'class_identifier' => 'classIdentifier',
00134                                                       'class_name' => 'className',
00135                                                       // new functional attributes
00136                                                       'original_parent' => 'originalParent',
00137                                                       'original_parent_path_id_string' => 'originalParentPathIdentificationString'
00138                                                       ),
00139                       'class_name' => 'eZContentObjectTrashNode',
00140                       'name' => 'ezcontentobject_trash' );
00141     }
00142 
00143 
00144     static function createFromNode( $node )
00145     {
00146         $row = array( 'node_id' => $node->attribute( 'node_id' ),
00147                       'parent_node_id' => $node->attribute( 'parent_node_id' ),
00148                       'main_node_id' => $node->attribute( 'main_node_id' ),
00149                       'contentobject_id' => $node->attribute( 'contentobject_id' ),
00150                       'contentobject_version' => $node->attribute( 'contentobject_version' ),
00151                       'contentobject_is_published' => $node->attribute( 'contentobject_is_published' ),
00152                       'depth' => $node->attribute( 'depth' ),
00153                       'sort_field' => $node->attribute( 'sort_field' ),
00154                       'sort_order' => $node->attribute( 'sort_order' ),
00155                       'priority' => $node->attribute( 'priority' ),
00156                       'modified_subnode' => $node->attribute( 'modified_subnode' ),
00157                       'path_string' => $node->attribute( 'path_string' ),
00158                       'path_identification_string' => $node->attribute( 'path_identification_string' ),
00159                       'remote_id' => $node->attribute( 'remote_id' ),
00160                       'is_hidden' => $node->attribute( 'is_hidden' ),
00161                       'is_invisible' => $node->attribute( 'is_invisible' ) );
00162 
00163         $trashNode = new eZContentObjectTrashNode( $row );
00164         return $trashNode;
00165     }
00166 
00167     function storeToTrash()
00168     {
00169         $this->store();
00170 
00171         $db = eZDB::instance();
00172         $db->begin();
00173 
00174         $contentObject = $this->attribute( 'object' );
00175         $contentobjectAttributes = $contentObject->allContentObjectAttributes( $contentObject->attribute( 'id' ) );
00176         foreach ( $contentobjectAttributes as $contentobjectAttribute )
00177         {
00178             $dataType = $contentobjectAttribute->dataType();
00179             if ( !$dataType )
00180                 continue;
00181             $dataType->trashStoredObjectAttribute( $contentobjectAttribute );
00182         }
00183 
00184         $db->commit();
00185     }
00186 
00187     static function purgeForObject( $contentObjectID )
00188     {
00189         if ( !is_numeric( $contentObjectID ) )
00190             return false;
00191         $db = eZDB::instance();
00192         $db->begin();
00193         $db->query( "DELETE FROM ezcontentobject_trash WHERE contentobject_id='$contentObjectID'" );
00194         $db->commit();
00195     }
00196 
00197     static function fetchListForObject( $objectID, $asObject = true, $offset = false, $limit = false )
00198     {
00199         return false;
00200     }
00201 
00202     /*
00203       Analog of eZContentObjectTreeNode::subTreeByNodeID(Count)() method, see it for extending this method
00204     */
00205     static function trashList( $params = false, $asCount = false )
00206     {
00207         if ( $params === false )
00208         {
00209             $params = array( 'Offset'                   => false,
00210                              'Limit'                    => false,
00211                              'SortBy'                   => false,
00212                              'AttributeFilter'          => false,
00213                              );
00214         }
00215 
00216         $offset           = ( isset( $params['Offset'] ) && is_numeric( $params['Offset'] ) ) ? $params['Offset']             : false;
00217         $limit            = ( isset( $params['Limit']  ) && is_numeric( $params['Limit']  ) ) ? $params['Limit']              : false;
00218         $asObject         = ( isset( $params['AsObject']          ) )                         ? $params['AsObject']           : true;
00219         $objectNameFilter = ( isset( $params['ObjectNameFilter']  ) )                         ? $params['ObjectNameFilter']   : false;
00220 
00221         if ( $asCount )
00222         {
00223             $sqlSorting = '';
00224         }
00225         else
00226         {
00227             // default sorting by the object name, but it probably should be optional in future
00228             $params[ 'SortBy' ] = array( array( 'name' ) );
00229             $sortingInfo = eZContentObjectTreeNode::createSortingSQLStrings( $params['SortBy'], 'ezcot' );
00230             if ( $sortingInfo['sortingFields'] )
00231                 $sqlSorting = " ORDER BY $sortingInfo[sortingFields]";
00232             else
00233                 $sqlSorting = '';
00234         }
00235         $useVersionName     = true;
00236         $versionNameTables  = eZContentObjectTreeNode::createVersionNameTablesSQLString ( $useVersionName );
00237         $versionNameTargets = eZContentObjectTreeNode::createVersionNameTargetsSQLString( $useVersionName );
00238         $versionNameJoins   = eZContentObjectTreeNode::createVersionNameJoinsSQLString  ( $useVersionName, false, false, false, 'ezcot' );
00239 
00240         $languageFilter = ' AND ' . eZContentLanguage::languagesSQLFilter( 'ezcontentobject' );
00241 
00242         $objectNameFilterSQL = eZContentObjectTreeNode::createObjectNameFilterConditionSQLString( $objectNameFilter );
00243 
00244         $limitation = ( isset( $params['Limitation']  ) && is_array( $params['Limitation']  ) ) ? $params['Limitation']: false;
00245         $limitationList = eZContentObjectTreeNode::getLimitationList( $limitation );
00246         $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL( $limitationList, 'ezcontentobject_trash', 'ezcot' );
00247 
00248         if ( $asCount )
00249         {
00250             $query = "SELECT count(*) as count \n";
00251         }
00252         else
00253         {
00254             $query = "SELECT
00255                         ezcontentobject.*,
00256                         ezcot.*,
00257                         ezcontentclass.serialized_name_list as class_serialized_name_list,
00258                         ezcontentclass.identifier as class_identifier
00259                         $versionNameTargets \n";
00260         }
00261         $query .= "FROM
00262                         ezcontentobject_trash ezcot,
00263                         ezcontentobject,
00264                         ezcontentclass
00265                         $versionNameTables
00266                         $sqlPermissionChecking[from]
00267                    WHERE
00268                         ezcontentclass.version=0 AND
00269                         ezcot.contentobject_id = ezcontentobject.id  AND
00270                         ezcontentclass.id = ezcontentobject.contentclass_id AND
00271                         $versionNameJoins
00272                         $sqlPermissionChecking[where]
00273                         $objectNameFilterSQL
00274                         $languageFilter
00275                         $sqlSorting
00276                         ";
00277 
00278         $db = eZDB::instance();
00279         if ( !$offset && !$limit )
00280             $trashRowsArray = $db->arrayQuery( $query );
00281         else
00282             $trashRowsArray = $db->arrayQuery( $query, array( 'offset' => $offset,
00283                                                               'limit'  => $limit ) );
00284 
00285         // cleanup temp tables
00286         $db->dropTempTableList( $sqlPermissionChecking['temp_tables'] );
00287 
00288         if ( $asCount )
00289         {
00290             return $trashRowsArray[0]['count'];
00291         }
00292         else if ( $asObject )
00293         {
00294             $retTrashNodes = array();
00295             foreach ( array_keys( $trashRowsArray ) as $key )
00296             {
00297                 $trashRow =& $trashRowsArray[ $key ];
00298                 $retTrashNodes[] = new eZContentObjectTrashNode( $trashRow );
00299             }
00300             return $retTrashNodes;
00301         }
00302         else
00303         {
00304             return $trashRowsArray;
00305         }
00306     }
00307 
00308     static function trashListCount( $params = false )
00309     {
00310         return eZContentObjectTrashNode::trashList( $params, true );
00311     }
00312 
00313     function originalParent()
00314     {
00315         $parent = eZContentObjectTreeNode::fetch( $this->attribute( 'parent_node_id' ) );
00316         $thisPathArray = $this->attribute( 'path_array' );
00317 
00318         if ( is_object( $parent ) and count( $thisPathArray ) > 0 )
00319         {
00320             $realParentPathArray = $parent->attribute( 'path_array' );
00321             $realParentPath = implode( '/', $realParentPathArray );
00322 
00323             array_pop( $thisPathArray );
00324             $thisParentPath = implode( '/', $thisPathArray );
00325 
00326             if ( $thisParentPath == $realParentPath )
00327             {
00328                 // original parent exists at the same placement
00329                 return $parent;
00330             }
00331         }
00332         // original parent was moved or deleted
00333         $ret = null;
00334         return $ret;
00335     }
00336 
00337     function originalParentPathIdentificationString()
00338     {
00339         $originalParent = $this->originalParent();
00340         if ( $originalParent )
00341         {
00342             return $originalParent->attribute( 'path_identification_string' );
00343         }
00344         // original parent was moved or does not exist, return original parent path
00345         $path = $this->attribute( 'path_identification_string' );
00346         $path = substr( $path, 0, strrpos( $path, '/') );
00347         return $path;
00348     }
00349 }
00350 
00351 ?>