eZ Publish  [4.0]
ezcollaborationitemstatus.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZCollaborationItemStatus class
00004 //
00005 // Created on: <30-Jan-2003 13:51:22 amos>
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 ezcollaborationitemstatus.php
00032 */
00033 
00034 /*!
00035   \class eZCollaborationItemStatus ezcollaborationitemstatus.php
00036   \brief The class eZCollaborationItemStatus does
00037 
00038 */
00039 
00040 //include_once( 'kernel/classes/ezpersistentobject.php' );
00041 //include_once( 'kernel/classes/datatypes/ezuser/ezuser.php' );
00042 
00043 class eZCollaborationItemStatus extends eZPersistentObject
00044 {
00045     /*!
00046      Constructor
00047     */
00048     function eZCollaborationItemStatus( $row )
00049     {
00050         $this->eZPersistentObject( $row );
00051     }
00052 
00053     static function definition()
00054     {
00055         return array( 'fields' => array( 'collaboration_id' => array( 'name' => 'CollaborationID',
00056                                                                       'datatype' => 'integer',
00057                                                                       'default' => 0,
00058                                                                       'required' => true,
00059                                                                       'foreign_class' => 'eZCollaborationItem',
00060                                                                       'foreign_attribute' => 'id',
00061                                                                       'multiplicity' => '1..*' ),
00062                                          'user_id' => array( 'name' => 'UserID',
00063                                                              'datatype' => 'integer',
00064                                                              'default' => 0,
00065                                                              'required' => true,
00066                                                              'foreign_class' => 'eZUser',
00067                                                              'foreign_attribute' => 'contentobject_id',
00068                                                              'multiplicity' => '1..*' ),
00069                                          'is_read' => array( 'name' => 'IsRead',
00070                                                              'datatype' => 'integer',
00071                                                              'default' => 0,
00072                                                              'required' => true ),
00073                                          'is_active' => array( 'name' => 'IsActive',
00074                                                                'datatype' => 'integer',
00075                                                                'default' => 1,
00076                                                                'required' => true ),
00077                                          'last_read' => array( 'name' => 'LastRead',
00078                                                                'datatype' => 'integer',
00079                                                                'default' => 0,
00080                                                                'required' => true ) ),
00081                       'keys' => array( 'collaboration_id', 'user_id' ),
00082                       'class_name' => 'eZCollaborationItemStatus',
00083                       'name' => 'ezcollab_item_status' );
00084     }
00085 
00086     static function create( $collaborationID, $userID = false )
00087     {
00088         if ( $userID === false )
00089             $userID = eZUser::currentUserID();
00090         $row = array(
00091             'collaboration_id' => $collaborationID,
00092             'user_id' => $userID,
00093             'is_read' => false,
00094             'is_active' => true,
00095             'last_read' => 0 );
00096         return $GLOBALS['eZCollaborationItemStatusCache'][$collaborationID][$userID] = new eZCollaborationItemStatus( $row );
00097     }
00098 
00099     function store( $fieldFilters = null )
00100     {
00101         $stored = eZPersistentObject::store( $fieldFilters );
00102         $this->updateCache();
00103         return $stored;
00104     }
00105 
00106     function updateCache()
00107     {
00108         $userID = $this->UserID;
00109         $collaborationID = $this->CollaborationID;
00110         $GLOBALS['eZCollaborationItemStatusCache'][$collaborationID][$userID] = $this;
00111     }
00112 
00113     static function fetch( $collaborationID, $userID = false, $asObject = true )
00114     {
00115         if ( $userID === false )
00116         {
00117             $userID = eZUser::currentUserID();
00118         }
00119         if ( !isset( $GLOBALS['eZCollaborationItemStatusCache'][$collaborationID][$userID] ) )
00120         {
00121             $conditions = array( 'collaboration_id' => $collaborationID,
00122                                  'user_id' => $userID );
00123             $GLOBALS['eZCollaborationItemStatusCache'][$collaborationID][$userID] = eZPersistentObject::fetchObject(
00124                 eZCollaborationItemStatus::definition(),
00125                 null,
00126                 $conditions,
00127                 $asObject );
00128         }
00129         return $GLOBALS['eZCollaborationItemStatusCache'][$collaborationID][$userID];
00130     }
00131 
00132     static function setLastRead( $collaborationID, $userID = false, $timestamp = false )
00133     {
00134         if ( $timestamp === false )
00135             $timestamp = time();
00136 
00137         eZCollaborationItemStatus::updateFields( $collaborationID, $userID, array( 'last_read' => $timestamp,
00138                                                                                    'is_read' => 1 ) );
00139     }
00140 
00141     static function updateFields( $collaborationID, $userID = false, $fields )
00142     {
00143         if ( $userID === false )
00144             $userID = eZUser::currentUserID();
00145 
00146         eZPersistentObject::updateObjectList( array( 'definition' => eZCollaborationItemStatus::definition(),
00147                                                      'update_fields' => $fields,
00148                                                      'conditions' => array( 'collaboration_id' => $collaborationID,
00149                                                                             'user_id' => $userID ) ) );
00150         $statusObject =& $GLOBALS['eZCollaborationItemStatusCache'][$collaborationID][$userID];
00151         if ( isset( $statusObject ) )
00152         {
00153             foreach ( $fields as $field => $value )
00154             {
00155                 $statusObject->setAttribute( $field, $value );
00156             }
00157         }
00158     }
00159 
00160 }
00161 
00162 ?>