eZ Publish  [4.0]
ezusersetting.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZUserSetting class
00004 //
00005 //
00006 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00007 // SOFTWARE NAME: eZ Publish
00008 // SOFTWARE RELEASE: 4.0.x
00009 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS
00010 // SOFTWARE LICENSE: GNU General Public License v2.0
00011 // NOTICE: >
00012 //   This program is free software; you can redistribute it and/or
00013 //   modify it under the terms of version 2.0  of the GNU General
00014 //   Public License as published by the Free Software Foundation.
00015 //
00016 //   This program is distributed in the hope that it will be useful,
00017 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 //   GNU General Public License for more details.
00020 //
00021 //   You should have received a copy of version 2.0 of the GNU General
00022 //   Public License along with this program; if not, write to the Free
00023 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00024 //   MA 02110-1301, USA.
00025 //
00026 //
00027 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00028 //
00029 
00030 /*!
00031   \class eZUserSetting ezusersetting.php
00032   \ingroup eZDatatype
00033 
00034 */
00035 
00036 //include_once( 'kernel/classes/ezpersistentobject.php' );
00037 
00038 class eZUserSetting extends eZPersistentObject
00039 {
00040     function eZUserSetting( $row )
00041     {
00042         $this->eZPersistentObject( $row );
00043     }
00044 
00045     static function definition()
00046     {
00047         return array( 'fields' => array( 'user_id' => array( 'name' => 'UserID',
00048                                                              'datatype' => 'integer',
00049                                                              'default' => 0,
00050                                                              'required' => true,
00051                                                              'foreign_class' => 'eZUser',
00052                                                              'foreign_attribute' => 'contentobject_id',
00053                                                              'multiplicity' => '0..1' ),
00054                                          'is_enabled' => array( 'name' => 'IsEnabled',
00055                                                                 'datatype' => 'integer',
00056                                                                 'default' => 0,
00057                                                                 'required' => true ),
00058                                          'max_login' => array( 'name' => 'MaxLogin',
00059                                                                'datatype' => 'integer',
00060                                                                'default' => 0,
00061                                                                'required' => true ) ),
00062                       'keys' => array( 'user_id' ),
00063                       'relations' => array( 'user_id' => array( 'class' => 'ezuser',
00064                                                                 'field' => 'contentobject_id' ) ),
00065                       'class_name' => 'eZUserSetting',
00066                       'name' => 'ezuser_setting' );
00067     }
00068 
00069     static function create( $userID, $isEnabled )
00070     {
00071         $row = array( 'user_id' => $userID,
00072                       'is_enabled' => $isEnabled,
00073                       'max_login' => null );
00074         return new eZUserSetting( $row );
00075     }
00076 
00077 
00078     /*!
00079      \reimp
00080     */
00081     function setAttribute( $attr, $val )
00082     {
00083         switch( $attr )
00084         {
00085             case 'is_enabled':
00086             {
00087                 if ( !$val )
00088                 {
00089                     $user = eZUser::fetch( $this->UserID );
00090                     if ( $user )
00091                     {
00092                         eZUser::removeSessionData( $this->UserID );
00093                     }
00094                 }
00095             } break;
00096         }
00097 
00098         eZPersistentObject::setAttribute( $attr, $val );
00099     }
00100 
00101     /*!
00102      Fetch message object with \a $userID
00103     */
00104     static function fetch( $userID,  $asObject = true  )
00105     {
00106         return eZPersistentObject::fetchObject( eZUserSetting::definition(),
00107                                                     null,
00108                                                     array('user_id' => $userID ),
00109                                                     $asObject );
00110     }
00111 
00112     /*!
00113      Fetch all settings from database
00114     */
00115     static function fetchAll( $asObject = true )
00116     {
00117         return eZPersistentObject::fetchObjectList( eZUserSetting::definition(),
00118                                                     null,
00119                                                     null,
00120                                                     null,
00121                                                     null,
00122                                                     $asObject );
00123     }
00124 
00125     static function removeByUserID( $userID )
00126     {
00127         eZPersistentObject::removeObject( eZUserSetting::definition(),
00128                                           array( 'user_id' => $userID ) );
00129     }
00130 
00131     /// \privatesection
00132     public $UserID;
00133     public $IsEnabled;
00134     public $MaxLogin;
00135 }
00136 
00137 ?>