|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZCollaborationProfile class 00004 // 00005 // Created on: <28-Jan-2003 16:45:06 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 ezcollaborationprofile.php 00032 */ 00033 00034 /*! 00035 \class eZCollaborationProfile ezcollaborationprofile.php 00036 \brief The class eZCollaborationProfile does 00037 00038 */ 00039 00040 //include_once( 'kernel/classes/ezpersistentobject.php' ); 00041 //include_once( 'kernel/classes/ezcollaborationgroup.php' ); 00042 00043 class eZCollaborationProfile extends eZPersistentObject 00044 { 00045 /*! 00046 Constructor 00047 */ 00048 function eZCollaborationProfile( $row ) 00049 { 00050 $this->eZPersistentObject( $row ); 00051 } 00052 00053 static function definition() 00054 { 00055 return array( 'fields' => array( 'id' => array( 'name' => 'ID', 00056 'datatype' => 'integer', 00057 'default' => 0, 00058 'required' => true ), 00059 'user_id' => array( 'name' => 'UserID', 00060 'datatype' => 'integer', 00061 'default' => 0, 00062 'required' => true, 00063 'foreign_class' => 'eZUser', 00064 'foreign_attribute' => 'contentobject_id', 00065 'multiplicity' => '1..*' ), 00066 'main_group' => array( 'name' => 'MainGroup', 00067 'datatype' => 'integer', 00068 'default' => 0, 00069 'required' => true, 00070 'foreign_class' => 'eZCollaborationGroup', 00071 'foreign_attribute' => 'id', 00072 'multiplicity' => '1..*' ), 00073 'data_text1' => array( 'name' => 'DataText1', 00074 'datatype' => 'text', 00075 'default' => '', 00076 'required' => true ), 00077 'created' => array( 'name' => 'Created', 00078 'datatype' => 'integer', 00079 'default' => 0, 00080 'required' => true ), 00081 'modified' => array( 'name' => 'Modified', 00082 'datatype' => 'integer', 00083 'default' => 0, 00084 'required' => true ) ), 00085 'keys' => array( 'id' ), 00086 'increment_key' => 'id', 00087 'class_name' => 'eZCollaborationProfile', 00088 'name' => 'ezcollab_profile' ); 00089 } 00090 00091 static function create( $userID, $mainGroup = 0 ) 00092 { 00093 $date_time = time(); 00094 $row = array( 'id' => null, 00095 'user_id' => $userID, 00096 'main_group' => $mainGroup, 00097 'created' => $date_time, 00098 'modified' => $date_time ); 00099 $newCollaborationProfile = new eZCollaborationProfile( $row ); 00100 return $newCollaborationProfile; 00101 } 00102 00103 static function fetch( $id, $asObject = true ) 00104 { 00105 $conditions = array( "id" => $id ); 00106 return eZPersistentObject::fetchObject( eZCollaborationProfile::definition(), 00107 null, 00108 $conditions, 00109 $asObject ); 00110 } 00111 00112 static function fetchByUser( $userID, $asObject = true ) 00113 { 00114 $conditions = array( "user_id" => $userID ); 00115 return eZPersistentObject::fetchObject( eZCollaborationProfile::definition(), 00116 null, 00117 $conditions, 00118 $asObject ); 00119 } 00120 00121 /*! 00122 \note Transaction unsafe. If you call several transaction unsafe methods you must enclose 00123 the calls within a db transaction; thus within db->begin and db->commit. 00124 */ 00125 static function instance( $userID = false ) 00126 { 00127 if ( $userID === false ) 00128 { 00129 $user = eZUser::currentUser(); 00130 $userID = $user->attribute( 'contentobject_id' ); 00131 } 00132 $instance =& $GLOBALS["eZCollaborationProfile-$userID"]; 00133 if ( !isset( $instance ) ) 00134 { 00135 $instance = eZCollaborationProfile::fetchByUser( $userID ); 00136 if ( $instance === null ) 00137 { 00138 $group = eZCollaborationGroup::instantiate( $userID, ezi18n( 'kernel/classes', 'Inbox' ) ); 00139 $instance = eZCollaborationProfile::create( $userID, $group->attribute( 'id' ) ); 00140 $instance->store(); 00141 } 00142 } 00143 return $instance; 00144 } 00145 00146 } 00147 00148 ?>