eZ Publish  [4.0]
ezcontentbrowsebookmark.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZContentBrowseBookmark class
00004 //
00005 // Created on: <29-Apr-2003 15:32:53 sp>
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 ezcontentbrowsebookmark.php
00032 */
00033 
00034 /*!
00035   \class eZContentBrowseBookmark ezcontentbrowsebookmark.php
00036   \brief Handles bookmarking nodes for users
00037 
00038   Allows the creation and fetching of bookmark lists for users.
00039   The bookmark list is used in the browse page to allow quick navigation and selection.
00040 
00041   Creating a new bookmark item is done with
00042 \code
00043 $userID = eZUser::currentUserID();
00044 $nodeID = 2;
00045 $nodeName = 'Node';
00046 eZContentBrowseBookmark::createNew( $userID, $nodeID, $nodeName )
00047 \endcode
00048 
00049   Fetching the list is done with
00050 \code
00051 $userID = eZUser::currentUserID();
00052 eZContentBrowseBookmark::fetchListForUser( $userID )
00053 \endcode
00054 
00055 */
00056 
00057 //include_once( 'kernel/classes/ezcontentobjecttreenode.php' );
00058 
00059 class eZContentBrowseBookmark extends eZPersistentObject
00060 {
00061     /*!
00062      \reimp
00063     */
00064     function eZContentBrowseBookmark( $row )
00065     {
00066         $this->eZPersistentObject( $row );
00067     }
00068 
00069     /*!
00070      \reimp
00071     */
00072     static function definition()
00073     {
00074         return array( "fields" => array( "id" => array( 'name' => 'ID',
00075                                                         'datatype' => 'integer',
00076                                                         'default' => 0,
00077                                                         'required' => true ),
00078                                          "user_id" => array( 'name' => 'UserID',
00079                                                              'datatype' => 'integer',
00080                                                              'default' => 0,
00081                                                              'required' => true,
00082                                                              'foreign_class' => 'eZUser',
00083                                                              'foreign_attribute' => 'contentobject_id',
00084                                                              'multiplicity' => '1..*' ),
00085                                          "node_id" => array( 'name' => "NodeID",
00086                                                              'datatype' => 'integer',
00087                                                              'default' => 0,
00088                                                              'required' => true,
00089                                                              'foreign_class' => 'eZContentObjectTreeNode',
00090                                                              'foreign_attribute' => 'node_id',
00091                                                              'multiplicity' => '1..*' ),
00092                                          "name" => array( 'name' => "Name",
00093                                                           'datatype' => 'string',
00094                                                           'default' => '',
00095                                                           'required' => true ) ),
00096                       "keys" => array( "id" ),
00097                       "function_attributes" => array( 'node' => 'fetchNode',
00098                                                       'contentobject_id' => 'contentObjectID' ),
00099                       "increment_key" => "id",
00100                       "sort" => array( "id" => "asc" ),
00101                       "class_name" => "eZContentBrowseBookmark",
00102                       "name" => "ezcontentbrowsebookmark" );
00103 
00104     }
00105 
00106     /*!
00107      \static
00108      \return the bookmark item \a $bookmarkID.
00109     */
00110     static function fetch( $bookmarkID )
00111     {
00112         return eZPersistentObject::fetchObject( eZContentBrowseBookmark::definition(),
00113                                                 null, array( 'id' => $bookmarkID ), true );
00114     }
00115 
00116     /*!
00117      \static
00118      \return the bookmark list for user \a $userID.
00119     */
00120     static function fetchListForUser( $userID, $offset = false, $limit = false )
00121     {
00122         $objectList = eZPersistentObject::fetchObjectList( eZContentBrowseBookmark::definition(),
00123                                                             null,
00124                                                             array( 'user_id' => $userID ),
00125                                                             array( 'id' => 'desc' ),
00126                                                             array( 'offset' => $offset, 'length' => $limit ),
00127                                                             true );
00128         return $objectList;
00129     }
00130 
00131     /*!
00132      \static
00133      Creates a new bookmark item for user \a $userID with node id \a $nodeID and name \a $nodeName.
00134      The new item is returned.
00135      \note Transaction unsafe. If you call several transaction unsafe methods you must enclose
00136      the calls within a db transaction; thus within db->begin and db->commit.
00137     */
00138     static function createNew( $userID, $nodeID, $nodeName )
00139     {
00140         $db = eZDB::instance();
00141         $db->begin();
00142         $userID =(int) $userID;
00143         $nodeID =(int) $nodeID;
00144         $nodeName = $db->escapeString( $nodeName );
00145         $db->query( "DELETE FROM ezcontentbrowsebookmark WHERE node_id=$nodeID and user_id=$userID" );
00146         $bookmark = new eZContentBrowseBookmark( array( 'user_id' => $userID,
00147                                                         'node_id' => $nodeID,
00148                                                         'name' => $nodeName ) );
00149         $bookmark->store();
00150         $db->commit();
00151         return $bookmark;
00152     }
00153 
00154     /*!
00155      \return the tree node which this item refers to.
00156     */
00157     function fetchNode()
00158     {
00159         return eZContentObjectTreeNode::fetch( $this->attribute( 'node_id' ) );
00160     }
00161 
00162     /*!
00163      \return the content object ID of the tree node which this item refers to.
00164     */
00165     function contentObjectID()
00166     {
00167         $node = $this->fetchNode();
00168         if ( $node )
00169         {
00170             return $node->attribute( 'contentobject_id' );
00171         }
00172 
00173         return false;
00174     }
00175 
00176     /*!
00177      \static
00178      Removes all bookmark entries for all users.
00179      \note Transaction unsafe. If you call several transaction unsafe methods you must enclose
00180      the calls within a db transaction; thus within db->begin and db->commit.
00181     */
00182     static function cleanup()
00183     {
00184         $db = eZDB::instance();
00185         $db->query( "DELETE FROM ezcontentbrowsebookmark" );
00186     }
00187 
00188     /*!
00189      \static
00190      Removes all bookmark entries for node.
00191      \note Transaction unsafe. If you call several transaction unsafe methods you must enclose
00192      the calls within a db transaction; thus within db->begin and db->commit.
00193     */
00194     static function removeByNodeID( $nodeID )
00195     {
00196         $db = eZDB::instance();
00197         $nodeID =(int) $nodeID;
00198         $db->query( "DELETE FROM ezcontentbrowsebookmark WHERE node_id=$nodeID" );
00199     }
00200 }
00201 
00202 ?>