00001 <?php
00002
00003 lt_include( PLOG_CLASS_PATH."class/database/dbobject.class.php" );
00004 lt_include( PLOG_CLASS_PATH."class/dao/userstatus.class.php" );
00005 lt_include( PLOG_CLASS_PATH."class/dao/userpermission.class.php" );
00006
00013 class UserInfo extends DbObject
00014 {
00015
00016 var $_username;
00017 var $_password;
00018 var $_id;
00019 var $_aboutmyself;
00020 var $_email;
00021 var $_blogs;
00022 var $_siteAdmin;
00023 var $_fullName;
00024 var $_resourcePictureId;
00025 var $_resourcePicture;
00026 var $_status;
00027 var $_perms;
00028
00045 function UserInfo( $username, $password, $email, $aboutMyself, $fullName, $resourcePictureId = 0, $properties = Array(), $id = 0 )
00046 {
00047 $this->DbObject();
00048
00049 $this->setUsername( $username );
00050 $this->_password = $password;
00051 $this->_id = $id;
00052 $this->_aboutmyself = $aboutMyself;
00053 $this->_email = $email;
00054 $this->_blogs = "";
00055 $this->_fullName = $fullName;
00056 $this->_siteAdmin = 0;
00057 $this->setPictureId( $resourcePictureId );
00058 $this->setProperties( $properties );
00059 $this->_perms = Array();
00060
00061
00062 $this->setStatus( USER_STATUS_ACTIVE );
00063
00064 $this->_pk = "id";
00065 $this->_fields = Array(
00066 "user" => "getUsername",
00067 "password" => "getMD5Password",
00068 "email" => "getEmail",
00069 "full_name" => "getFullName",
00070 "about" => "getUnformattedAboutMyself",
00071 "properties" => "getProperties",
00072 "status" => "getStatus",
00073 "resource_picture_id" => "getPictureId",
00074 "site_admin" => "isSiteAdmin"
00075 );
00076 }
00077
00081 function getUsername()
00082 {
00083 return $this->_username;
00084 }
00085
00091 function getPassword()
00092 {
00093 return $this->_password;
00094 }
00095
00101 function getMD5Password()
00102 {
00103 if( strlen( $this->getPassword()) == 32 )
00104 $md5pass = $this->getPassword();
00105 else
00106 $md5pass = md5( $this->getPassword());
00107
00108 return( $md5pass );
00109 }
00110
00114 function getId()
00115 {
00116 return $this->_id;
00117 }
00118
00126 function getAboutMyself( $format = true )
00127 {
00128 $text = $this->_aboutmyself;
00129
00130 if( $format ) {
00131 lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
00132 $text = TextFilter::autoP( $text );
00133 }
00134
00135 return( $text );
00136 }
00137
00141 function getUnformattedAboutMyself()
00142 {
00143 return( $this->getAboutMyself( false ));
00144 }
00145
00146 function getEmail()
00147 {
00148 return $this->_email;
00149 }
00150
00151 function getBlogs()
00152 {
00153 if( $this->_blogs == null ) {
00154 lt_include( PLOG_CLASS_PATH."class/dao/users.class.php" );
00155 $users = new Users();
00156 $this->_blogs = $users->getUsersBlogs($this->getId());
00157 }
00158
00159 return( $this->_blogs );
00160 }
00161
00162 function getOwnBlogs()
00163 {
00164 $this->getBlogs();
00165
00166 $blogs = array();
00167 foreach($this->_blogs as $blog) {
00168 if( $blog->getOwnerId() == $this->getId() )
00169 array_push( $blogs, $blog );
00170 }
00171
00172 return( $blogs );
00173 }
00174
00175 function getFullName()
00176 {
00177 return $this->_fullName;
00178 }
00179
00180 function setUsername( $newUsername )
00181 {
00182 lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
00183
00184 $this->_username = Textfilter::filterAllHTML( $newUsername );
00185 }
00186
00187 function setPassword( $newPassword )
00188 {
00189 $this->_password = $newPassword;
00190 }
00191
00192 function setMD5Password( $newPassword )
00193 {
00194 $this->_password = md5($newPassword);
00195 }
00196
00197 function setId( $newId )
00198 {
00199 $this->_id = $newId;
00200 }
00201
00202 function setAboutMyself( $newAboutMyself )
00203 {
00204 $this->_aboutmyself = $newAboutMyself;
00205 }
00206
00207 function setEmail( $newEmail )
00208 {
00209 $this->_email = $newEmail;
00210 }
00211
00212 function setBlogs( $blogs )
00213 {
00214 $this->_blogs = $blogs;
00215 }
00216
00217 function isSiteAdmin()
00218 {
00219 if( $this->_siteAdmin == "" ) $this->_siteAdmin = 0;
00220 return $this->_siteAdmin;
00221 }
00222
00223 function setSiteAdmin( $siteAdmin )
00224 {
00225 $this->_siteAdmin = $siteAdmin;
00226 }
00227
00228 function setFullName( $fullName )
00229 {
00230 $this->_fullName = $fullName;
00231 }
00232
00233 function setPictureId( $resourceId )
00234 {
00235 $this->_resourcePictureId = $resourceId;
00236 $this->_resourcePicture = null;
00237 }
00238
00239 function getPictureId()
00240 {
00241 return $this->_resourcePictureId;
00242 }
00243
00244 function setPicture( $resource )
00245 {
00246 $this->_resourcePicture = $resource;
00247 $this->_resourcePictureId = $resource->getId();
00248 }
00249
00257 function getPicture()
00258 {
00259
00260 if( !$this->_resourcePicture && $this->hasPicture()) {
00261 $this->_loadPicture();
00262 }
00263
00264 return $this->_resourcePicture;
00265 }
00266
00272 function hasPicture()
00273 {
00274 return( $this->_resourcePictureId != 0 && $this->_resourcePictureId != "" && $this->_loadPicture() != null );
00275 }
00276
00281 function _loadPicture()
00282 {
00283 lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryresources.class.php" );
00284
00285 $resources = new GalleryResources();
00286 $picture = $resources->getResource( $this->_resourcePictureId );
00287
00288 if( !$picture )
00289 $this->_resourcePicture = null;
00290 else
00291 $this->_resourcePicture = $picture;
00292
00293 return( $this->_resourcePicture );
00294 }
00295
00301 function getStatus()
00302 {
00303 return( $this->_status );
00304 }
00305
00312 function setStatus( $status )
00313 {
00314 $this->_status = $status;
00315
00316 return true;
00317 }
00318
00322 function __sleep()
00323 {
00324 $this->perms = null;
00325 $this->_blogs = null;
00326
00327 return( parent::__sleep());
00328 }
00329
00330 function hasPermission( $permission, $blogId = 0 )
00331 {
00332 if( !isset($this->perms[$blogId] )) {
00333 lt_include( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
00334 $perms = new UserPermissions();
00335 $this->perms[$blogId] = $perms->getUserPermissions( $this->getId(), $blogId );
00336 }
00337
00338 return( isset( $this->perms[$blogId][$permission] ));
00339 }
00340
00341 function hasPermissionByName( $permName, $blogId = 0 )
00342 {
00343 $ok = false;
00344
00345 if( !isset($this->perms[$blogId] )) {
00346 lt_include( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
00347 $perms = new UserPermissions();
00348 $this->perms[$blogId] = $perms->getUserPermissions( $this->getId(), $blogId );
00349 }
00350
00351 foreach( $this->perms[$blogId] as $perm ) {
00352 if( $perm->getPermissionName() == $permName ) {
00353 $ok = true;
00354 break;
00355 }
00356 }
00357
00358 return( $ok );
00359 }
00360
00361 function getPermissions( $blogId = 0 )
00362 {
00363 if( !isset($this->perms[$blogId] )) {
00364 lt_include( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
00365 $perms = new UserPermissions();
00366 $this->perms[$blogId] = $perms->getUserPermissions( $this->getId(), $blogId );
00367 }
00368
00369 return( $this->perms[$blogId] );
00370 }
00371 }
00372 ?>