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 include_once( "kernel/classes/ezcontentobjecttreenode.php" );
00040
00041
00042 class eZContentObjectTrashNode extends eZContentObjectTreeNode
00043 {
00044
00045
00046
00047 function eZContentObjectTrashNode( $row = array() )
00048 {
00049 $this->eZPersistentObject( $row );
00050 }
00051
00052 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(
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
00136 'original_parent' => 'originalParent',
00137 'original_parent_path_id_string' => 'originalParentPathIdentificationString'
00138 ),
00139 'class_name' => 'eZContentObjectTrashNode',
00140 'name' => 'ezcontentobject_trash' );
00141 }
00142
00143
00144 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
00172 function purgeForObject( $contentObjectID )
00173 {
00174 if ( !is_numeric( $contentObjectID ) )
00175 return false;
00176 $db =& eZDB::instance();
00177 $db->begin();
00178 $db->query( "DELETE FROM ezcontentobject_trash WHERE contentobject_id='$contentObjectID'" );
00179 $db->commit();
00180 }
00181
00182 function fetchListForObject( $objectID, $asObject = true, $offset = false, $limit = false )
00183 {
00184 return false;
00185 }
00186
00187
00188
00189
00190 function &trashList( $params = false, $asCount = false )
00191 {
00192 if ( $params === false )
00193 {
00194 $params = array( 'Offset' => false,
00195 'Limit' => false,
00196 'SortBy' => false,
00197 'AttributeFilter' => false,
00198 );
00199 }
00200
00201 $offset = ( isset( $params['Offset'] ) && is_numeric( $params['Offset'] ) ) ? $params['Offset'] : false;
00202 $limit = ( isset( $params['Limit'] ) && is_numeric( $params['Limit'] ) ) ? $params['Limit'] : false;
00203 $asObject = ( isset( $params['AsObject'] ) ) ? $params['AsObject'] : true;
00204 $objectNameFilter = ( isset( $params['ObjectNameFilter'] ) ) ? $params['ObjectNameFilter'] : false;
00205
00206 if ( $asCount )
00207 {
00208 $sqlSorting = '';
00209 }
00210 else
00211 {
00212
00213 $params[ 'SortBy' ] = array( array( 'name' ) );
00214 $sortingInfo = eZContentObjectTreeNode::createSortingSQLStrings( $params['SortBy'], 'ezcot' );
00215 if ( $sortingInfo['sortingFields'] )
00216 $sqlSorting = " ORDER BY $sortingInfo[sortingFields]";
00217 else
00218 $sqlSorting = '';
00219 }
00220 $useVersionName = true;
00221 $versionNameTables = eZContentObjectTreeNode::createVersionNameTablesSQLString ( $useVersionName );
00222 $versionNameTargets = eZContentObjectTreeNode::createVersionNameTargetsSQLString( $useVersionName );
00223 $versionNameJoins = eZContentObjectTreeNode::createVersionNameJoinsSQLString ( $useVersionName, false, false, false, 'ezcot' );
00224
00225 $languageFilter = ' AND ' . eZContentLanguage::languagesSQLFilter( 'ezcontentobject' );
00226
00227 $objectNameFilterSQL = eZContentObjectTreeNode::createObjectNameFilterConditionSQLString( $objectNameFilter );
00228
00229 $limitation = ( isset( $params['Limitation'] ) && is_array( $params['Limitation'] ) ) ? $params['Limitation']: false;
00230 $limitationList = eZContentObjectTreeNode::getLimitationList( $limitation );
00231 $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL( $limitationList, 'ezcontentobject_trash', 'ezcot' );
00232
00233 if ( $asCount )
00234 {
00235 $query = "SELECT count(*) as count \n";
00236 }
00237 else
00238 {
00239 $query = "SELECT
00240 ezcontentobject.*,
00241 ezcot.*,
00242 ezcontentclass.serialized_name_list as class_serialized_name_list,
00243 ezcontentclass.identifier as class_identifier
00244 $versionNameTargets \n";
00245 }
00246 $query .= "FROM
00247 ezcontentobject_trash ezcot,
00248 ezcontentobject,
00249 ezcontentclass
00250 $versionNameTables
00251 $sqlPermissionChecking[from]
00252 WHERE
00253 ezcontentclass.version=0 AND
00254 ezcot.contentobject_id = ezcontentobject.id AND
00255 ezcontentclass.id = ezcontentobject.contentclass_id AND
00256 $versionNameJoins
00257 $sqlPermissionChecking[where]
00258 $objectNameFilterSQL
00259 $languageFilter
00260 $sqlSorting
00261 ";
00262
00263 $db =& eZDB::instance();
00264 if ( !$offset && !$limit )
00265 $trashRowsArray = $db->arrayQuery( $query );
00266 else
00267 $trashRowsArray = $db->arrayQuery( $query, array( 'offset' => $offset,
00268 'limit' => $limit ) );
00269
00270
00271 $db->dropTempTableList( $sqlPermissionChecking['temp_tables'] );
00272
00273 if ( $asCount )
00274 {
00275 return $trashRowsArray[0]['count'];
00276 }
00277 else if ( $asObject )
00278 {
00279 $retTrashNodes = array();
00280 foreach ( array_keys( $trashRowsArray ) as $key )
00281 {
00282 $trashRow =& $trashRowsArray[ $key ];
00283 $retTrashNodes[] = new eZContentObjectTrashNode( $trashRow );
00284 }
00285 return $retTrashNodes;
00286 }
00287 else
00288 {
00289 return $trashRowsArray;
00290 }
00291 }
00292
00293 function trashListCount( $params = false )
00294 {
00295 return eZContentObjectTrashNode::trashList( $params, true );
00296 }
00297
00298 function &originalParent()
00299 {
00300 $parent = eZContentObjectTreeNode::fetch( $this->attribute( 'parent_node_id' ) );
00301 $thisPathArray = $this->attribute( 'path_array' );
00302
00303 if ( is_object( $parent ) and count( $thisPathArray ) > 0 )
00304 {
00305 $realParentPathArray = $parent->attribute( 'path_array' );
00306 $realParentPath = implode( '/', $realParentPathArray );
00307
00308 array_pop( $thisPathArray );
00309 $thisParentPath = implode( '/', $thisPathArray );
00310
00311 if ( $thisParentPath == $realParentPath )
00312 {
00313
00314 return $parent;
00315 }
00316 }
00317
00318 $ret = null;
00319 return $ret;
00320 }
00321
00322 function &originalParentPathIdentificationString()
00323 {
00324 $originalParent =& $this->originalParent();
00325 if ( $originalParent )
00326 {
00327 return $originalParent->attribute( 'path_identification_string' );
00328 }
00329
00330 $path = $this->attribute( 'path_identification_string' );
00331 $path = substr( $path, 0, strrpos( $path, '/') );
00332 return $path;
00333 }
00334 }
00335
00336 ?>