00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 class GauffrUser extends GauffrPersistentObject
00020 {
00021
00022 protected $ID;
00023 public $GroupID;
00024 public $Login;
00025 public $Mail;
00026
00027
00028 public $Credential = array();
00029 public $Extended = array();
00030
00031
00032
00033
00034
00035
00036
00037
00038 public function getState()
00039 {
00040 return array(
00041 'ID' => $this->ID,
00042 'GroupID' => $this->GroupID,
00043 'Login' => $this->Login,
00044 'Mail' => $this->Mail,
00045 );
00046 }
00047
00048
00049
00050
00051
00052
00053
00054
00055 private static function getPrefetchRelations()
00056 {
00057 return array(
00058 'GauffrCredential' => new ezcPersistentRelationFindDefinition(
00059 'GauffrCredential'
00060 ),
00061 'GauffrUserExtended' => new ezcPersistentRelationFindDefinition(
00062 'GauffrUserExtended'
00063 )
00064 );
00065 }
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 public static function fetchUserByID( $id )
00083 {
00084 $session = self::getPersistentSessionInstance();
00085
00086 try {
00087 return $session->load( 'GauffrUser', $id );
00088 }
00089 catch ( ezcPersistentObjectNotFoundException $e ) {
00090 return false;
00091 }
00092 }
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102 public static function fetchWithRelatedObjectsUserByID( $id )
00103 {
00104 $session = self::getPersistentSessionInstance();
00105
00106 try {
00107 $user = $session->load( 'GauffrUser', $id );
00108 }
00109 catch ( ezcPersistentObjectNotFoundException $e ) {
00110 return false;
00111 }
00112
00113
00114 $user->Credential = $user->getCredential();
00115 $user->Extended = $user->getExtended();
00116
00117 return $user;
00118 }
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 public static function fetchUserByLogin($login)
00133 {
00134 return self::fetchPersistantObjectByAttribute( 'GauffrUser', 'Login', $login );
00135 }
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149 public static function fetchUserByAltLogin($alt_login)
00150 {
00151 $extended = GauffrUserExtended::unique( self::fetchPersistantObjectByAttribute( 'GauffrUserExtended', 'AltLogin', $alt_login ) );
00152 if ( !$extended )
00153 return false;
00154
00155 $session = self::getPersistentSessionInstance();
00156 $user = GauffrUser::unique( $session->getRelatedObjects( $extended, 'GauffrUser' ) );
00157 $user->Extended = $extended;
00158
00159 return $user;
00160 }
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 public static function fetchUserByMail($mail)
00175 {
00176 return self::fetchPersistantObjectByAttribute( 'GauffrUser', 'Mail', $mail );
00177 }
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190 public function getCredential()
00191 {
00192
00193 $identitySession = self::getPersistentSessionIdentity();
00194 try {
00195 return $identitySession->getRelatedObjects( $this, 'GauffrCredential' );
00196 }
00197
00198
00199 catch (ezcPersistentIdentityMissingException $e) {
00200 $session = self::getPersistentSessionInstance();
00201 return $session->getRelatedObjects( $this, 'GauffrCredential' );
00202 }
00203 }
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213 public function hasCredentialByID( $id )
00214 {
00215 $credential = $this->getCredential();
00216 if ( isset($credential[$id]) && $credential[$id]->Can )
00217 return true;
00218 else
00219 return false;
00220 }
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230 public function hasCredentialByIdentifier( $identifier )
00231 {
00232 $credential = $this->getCredential();
00233
00234 if ( empty($credential) )
00235 return false;
00236
00237 $gauffrslave = GauffrUser::unique(GauffrSlave::fetchSlaveByIdentifier($identifier));
00238
00239 if ( !$gauffrslave )
00240 return false;
00241
00242 $id = $gauffrslave->getID();
00243
00244 if ( isset($credential[$id]) && $credential[$id]->Can )
00245 return true;
00246 else
00247 return false;
00248 }
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261 public function getExtended()
00262 {
00263
00264 $identitySession = self::getPersistentSessionIdentity();
00265 try {
00266 $extended = $identitySession->getRelatedObjects( $this, 'GauffrUserExtended' );
00267 return reset($extended);
00268 }
00269
00270
00271 catch (ezcPersistentIdentityMissingException $e) {
00272 $session = self::getPersistentSessionInstance();
00273 $extended = $session->getRelatedObjects( $this, 'GauffrUserExtended' );
00274 return reset($extended);
00275 }
00276 }
00277
00278 }
00279
00280 ?>