[ Index ] |
|
Code source de LifeType 1.2.4 |
1 <?php 2 3 lt_include( PLOG_CLASS_PATH."class/database/dbobject.class.php" ); 4 lt_include( PLOG_CLASS_PATH."class/dao/userstatus.class.php" ); 5 lt_include( PLOG_CLASS_PATH."class/dao/userpermission.class.php" ); 6 7 /** 8 * Represents a user in our application. Includes information such as the username, 9 * password, email, etc. 10 * 11 * \ingroup DAO 12 */ 13 class UserInfo extends DbObject 14 { 15 16 var $_username; 17 var $_password; 18 var $_id; 19 var $_aboutmyself; 20 var $_email; 21 var $_blogs; 22 var $_siteAdmin; 23 var $_fullName; 24 var $_resourcePictureId; 25 var $_resourcePicture; 26 var $_status; 27 var $_perms; 28 29 /** 30 * Constructor. Creates a new UserInfo object with the given information. 31 * 32 * @param username Uniquename assigned to this user. Please use the UsernameValidator class before 33 * assigning a username to make sure that the username complies with the rules set by the administrator 34 * of the site and that it has not been taken. This class does not perform any of these checks. 35 * @param password Unencrypted version of this password (passwords are saved encoded as MD5 strings) 36 * @param email Email address of the new user. 37 * @param aboutMyself Some text describing this user, if any. 38 * @param fullName Full name of this user. 39 * @param resourcePictureId Identifier of the picture used to identify this user, defaults to '0' (none) 40 * @param properties Associative array containing extra custom data, defaults to an empty array if not provided. 41 * @param id Identifier of the user, if known. It will be ignored if this is a new user, as the user id will be 42 * set after calling Users::addUser() 43 * @see Users::addUser() 44 */ 45 function UserInfo( $username, $password, $email, $aboutMyself, $fullName, $resourcePictureId = 0, $properties = Array(), $id = 0 ) 46 { 47 $this->DbObject(); 48 49 $this->setUsername( $username ); 50 $this->_password = $password; 51 $this->_id = $id; 52 $this->_aboutmyself = $aboutMyself; 53 $this->_email = $email; 54 $this->_blogs = ""; 55 $this->_fullName = $fullName; 56 $this->_siteAdmin = 0; 57 $this->setPictureId( $resourcePictureId ); 58 $this->setProperties( $properties ); 59 $this->_perms = Array(); 60 61 // by defaults, users are in status "active" 62 $this->setStatus( USER_STATUS_ACTIVE ); 63 64 $this->_pk = "id"; 65 $this->_fields = Array( 66 "user" => "getUsername", 67 "password" => "getMD5Password", 68 "email" => "getEmail", 69 "full_name" => "getFullName", 70 "about" => "getUnformattedAboutMyself", 71 "properties" => "getProperties", 72 "status" => "getStatus", 73 "resource_picture_id" => "getPictureId", 74 "site_admin" => "isSiteAdmin" 75 ); 76 } 77 78 /** 79 * @return returns the username 80 */ 81 function getUsername() 82 { 83 return $this->_username; 84 } 85 86 /** 87 * Returns the password. 88 * 89 * @param The password 90 */ 91 function getPassword() 92 { 93 return $this->_password; 94 } 95 96 /** 97 * Returns the password encoded as an MD5 string. 98 * 99 * @param The password encoded as an MD5 string. 100 */ 101 function getMD5Password() 102 { 103 if( strlen( $this->getPassword()) == 32 ) 104 $md5pass = $this->getPassword(); 105 else 106 $md5pass = md5( $this->getPassword()); 107 108 return( $md5pass ); 109 } 110 111 /** 112 * @return Returns the identifier assigned to this user. 113 */ 114 function getId() 115 { 116 return $this->_id; 117 } 118 119 /** 120 * Returns the text that was input in the 'about myself' text box 121 * in the admin interface 122 * 123 * @param format Whether basic formatting should be applied to the text 124 * @return Returns a string 125 */ 126 function getAboutMyself( $format = true ) 127 { 128 $text = $this->_aboutmyself; 129 130 if( $format ) { 131 lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" ); 132 $text = TextFilter::autoP( $text ); 133 } 134 135 return( $text ); 136 } 137 138 /** 139 * @return Returns the information about this user without any formatting. 140 */ 141 function getUnformattedAboutMyself() 142 { 143 return( $this->getAboutMyself( false )); 144 } 145 146 function getEmail() 147 { 148 return $this->_email; 149 } 150 151 function getBlogs() 152 { 153 if( $this->_blogs == null ) { 154 lt_include( PLOG_CLASS_PATH."class/dao/users.class.php" ); 155 $users = new Users(); 156 $this->_blogs = $users->getUsersBlogs($this->getId()); 157 } 158 159 return( $this->_blogs ); 160 } 161 162 function getOwnBlogs() 163 { 164 $this->getBlogs(); 165 166 $blogs = array(); 167 foreach($this->_blogs as $blog) { 168 if( $blog->getOwnerId() == $this->getId() ) 169 array_push( $blogs, $blog ); 170 } 171 172 return( $blogs ); 173 } 174 175 function getFullName() 176 { 177 return $this->_fullName; 178 } 179 180 function setUsername( $newUsername ) 181 { 182 lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" ); 183 184 $this->_username = Textfilter::filterAllHTML( $newUsername ); 185 } 186 187 function setPassword( $newPassword ) 188 { 189 $this->_password = $newPassword; 190 } 191 192 function setMD5Password( $newPassword ) 193 { 194 $this->_password = md5($newPassword); 195 } 196 197 function setId( $newId ) 198 { 199 $this->_id = $newId; 200 } 201 202 function setAboutMyself( $newAboutMyself ) 203 { 204 $this->_aboutmyself = $newAboutMyself; 205 } 206 207 function setEmail( $newEmail ) 208 { 209 $this->_email = $newEmail; 210 } 211 212 function setBlogs( $blogs ) 213 { 214 $this->_blogs = $blogs; 215 } 216 217 function isSiteAdmin() 218 { 219 if( $this->_siteAdmin == "" ) $this->_siteAdmin = 0; 220 return $this->_siteAdmin; 221 } 222 223 function setSiteAdmin( $siteAdmin ) 224 { 225 $this->_siteAdmin = $siteAdmin; 226 } 227 228 function setFullName( $fullName ) 229 { 230 $this->_fullName = $fullName; 231 } 232 233 function setPictureId( $resourceId ) 234 { 235 $this->_resourcePictureId = $resourceId; 236 $this->_resourcePicture = null; 237 } 238 239 function getPictureId() 240 { 241 return $this->_resourcePictureId; 242 } 243 244 function setPicture( $resource ) 245 { 246 $this->_resourcePicture = $resource; 247 $this->_resourcePictureId = $resource->getId(); 248 } 249 250 /** 251 * returns a GalleryResource object with the picture chosen by the user 252 * as his/her 'avatar'. I think it's better this way than if we just store 253 * a url pointing to an image 254 * 255 * @return a GalleryResource object 256 */ 257 function getPicture() 258 { 259 // only load if this user really has a picture... 260 if( !$this->_resourcePicture && $this->hasPicture()) { 261 $this->_loadPicture(); 262 } 263 264 return $this->_resourcePicture; 265 } 266 267 /** 268 * returns true if the user has selected a picture previously 269 * 270 *Ê@return a boolean value, true if there is a picture or false otherwise 271 */ 272 function hasPicture() 273 { 274 return( $this->_resourcePictureId != 0 && $this->_resourcePictureId != "" && $this->_loadPicture() != null ); 275 } 276 277 /** 278 * @private 279 * loads the user picture. Returns a GalleryObject if successful or false otherwise 280 */ 281 function _loadPicture() 282 { 283 lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryresources.class.php" ); 284 285 $resources = new GalleryResources(); 286 $picture = $resources->getResource( $this->_resourcePictureId ); 287 288 if( !$picture ) 289 $this->_resourcePicture = null; 290 else 291 $this->_resourcePicture = $picture; 292 293 return( $this->_resourcePicture ); 294 } 295 296 /** 297 * returns the status of the blog 298 * 299 * @return the current status of the blog 300 */ 301 function getStatus() 302 { 303 return( $this->_status ); 304 } 305 306 /** 307 * sets the current status of the blog 308 * 309 * @param status 310 * @return always true 311 */ 312 function setStatus( $status ) 313 { 314 $this->_status = $status; 315 316 return true; 317 } 318 319 /** 320 * @private 321 */ 322 function __sleep() 323 { 324 $this->perms = null; 325 $this->_blogs = null; 326 327 return( parent::__sleep()); 328 } 329 330 function hasPermission( $permission, $blogId = 0 ) 331 { 332 if( !isset($this->perms[$blogId] )) { 333 lt_include( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" ); 334 $perms = new UserPermissions(); 335 $this->perms[$blogId] = $perms->getUserPermissions( $this->getId(), $blogId ); 336 } 337 338 return( isset( $this->perms[$blogId][$permission] )); 339 } 340 341 function hasPermissionByName( $permName, $blogId = 0 ) 342 { 343 $ok = false; 344 345 if( !isset($this->perms[$blogId] )) { 346 lt_include( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" ); 347 $perms = new UserPermissions(); 348 $this->perms[$blogId] = $perms->getUserPermissions( $this->getId(), $blogId ); 349 } 350 351 foreach( $this->perms[$blogId] as $perm ) { 352 if( $perm->getPermissionName() == $permName ) { 353 $ok = true; 354 break; 355 } 356 } 357 358 return( $ok ); 359 } 360 361 function getPermissions( $blogId = 0 ) 362 { 363 if( !isset($this->perms[$blogId] )) { 364 lt_include( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" ); 365 $perms = new UserPermissions(); 366 $this->perms[$blogId] = $perms->getUserPermissions( $this->getId(), $blogId ); 367 } 368 369 return( $this->perms[$blogId] ); 370 } 371 } 372 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 21:04:15 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |