類別Users的繼承圖:

公開方法(Public Methods) | |
| Users () | |
| authenticateUser ($user, $pass) | |
| getUserInfo ($user, $pass) | |
| getUserInfoFromUsername ($username) | |
| getUserInfoFromId ($userid, $extendedInfo=false) | |
| _getUserInfoFromQuery ($sql_query, $extendedInfo=false) | |
| _fillUserInformation ($query_result, $extraInfo=false) | |
| getUsersBlogs ($userid, $status=BLOG_STATUS_ALL) | |
| getAllUsers ($status=USER_STATUS_ALL, $includeExtraInfo=false, $page=-1, $itemsPerPage=DEFAULT_ITEMS_PER_PAGE) | |
| updateUser ($userInfo) | |
| addUser (&$user) | |
| getBlogUsers ($blogId, $includeOwner=true, $status=USER_STATUS_ALL) | |
| disableUser ($userId) | |
| deleteUser ($userId) | |
| getNumUsers ($status=USER_STATUS_ALL) | |
| userExists ($userName) | |
| getUserBlogId ($username) | |
| emailExists ($email) | |
定義在 users.class.php 檔案之第 15 行.
|
|
Initializes the model 定義在 users.class.php 檔案之第 21 行. 參考 Model::Model(). 00022 { 00023 $this->Model(); 00024 00025 $this->usercache = Array(); 00026 00027 $this->perms = new UserPermissions(); 00028 }
|
|
||||||||||||
|
Given a result record from a Execute call, it will fill in the fields of the object, so that we don't have to repeat the same code too many times 定義在 users.class.php 檔案之第 157 行. 參考 $userInfo, 及 getUsersBlogs(). 被參考於 _getUserInfoFromQuery(), getAllUsers(), 及 getBlogUsers(). 00158 { 00159 $userInfo = new UserInfo( $query_result["user"], $query_result["password"], 00160 $query_result["email"], 00161 $query_result["about"], 00162 $query_result["full_name"], 00163 $query_result["resource_picture_id"], 00164 unserialize($query_result["properties"]), 00165 $query_result["id"]); 00166 00167 if( $extraInfo ) { 00168 // load this data if explicitely required! 00169 $userBlogs = $this->getUsersBlogs($userInfo->getId(), BLOG_STATUS_ACTIVE); 00170 $userInfo->setBlogs($userBlogs); 00171 } 00172 00173 // set some permissions 00174 //$userInfo->setSiteAdmin($this->perms->isSiteAdmin( $userInfo->getId())); 00175 $userInfo->setSiteAdmin( $query_result["site_admin"] ); 00176 $userInfo->setStatus( $query_result["status"] ); 00177 00178 return $userInfo; 00179 }
|
|
||||||||||||
|
More common code used by several functions Private function used to fill in all the fields of UserInfo objects given a row of the database. 定義在 users.class.php 檔案之第 136 行. 參考 $result, $userInfo, _fillUserInformation(), 及 Model::Execute(). 被參考於 getUserInfo(), getUserInfoFromId(), 及 getUserInfoFromUsername(). 00137 { 00138 $result = $this->Execute( $sql_query ); 00139 if( !$result ) 00140 return false; 00141 00142 if( $result->RowCount() == 0 ) 00143 return false; 00144 00145 $info = $result->FetchRow( $result ); 00146 00147 $userInfo = $this->_fillUserInformation( $info, $extendedInfo ); 00148 00149 return $userInfo; 00150 }
|
|
|
Adds a user to the database.
定義在 users.class.php 檔案之第 289 行. 參考 $query, $result, $user, Model::Execute(), 及 Db::qstr(). 00290 { 00291 $query = "INSERT INTO ".$this->getPrefix()."users(user,password,email,about,full_name, 00292 resource_picture_id,properties,status) 00293 VALUES ('".Db::qstr($user->getUserName())."','".md5($user->getPassword())."','". 00294 Db::qstr($user->getEmail())."','".Db::qstr($user->getAboutMyself())."','". 00295 Db::qstr($user->getFullName())."', '". 00296 Db::qstr($user->getPictureId())."', '". 00297 Db::qstr(serialize($user->getProperties()))."', '". 00298 Db::qstr($user->getStatus())."');"; 00299 00300 $result = $this->Execute( $query ); 00301 00302 if( !$result ) 00303 return false; 00304 00305 $userId = $this->_db->Insert_ID(); 00306 00307 $user->setId( $userId ); 00308 00309 return $userId; 00310 }
|
|
||||||||||||
|
Returns true if the user is in the database and the username and password match
定義在 users.class.php 檔案之第 38 行. 參考 $query, $result, $user, Model::Execute(), 及 Db::qstr(). 00039 { 00040 $query = "SELECT * FROM ".$this->getPrefix()."users 00041 WHERE user = '".Db::qstr($user)."' AND password = '".md5($pass)."' 00042 AND status = '".USER_STATUS_ACTIVE."'"; 00043 00044 $result = $this->Execute( $query ); 00045 00046 if( $result == false ) 00047 return false; 00048 00049 if( $result->RecordCount() == 1 ) 00050 return true; 00051 else 00052 return false; 00053 }
|
|
|
Removes users from the database
定義在 users.class.php 檔案之第 381 行. 參考 $query, $result, 及 Model::Execute(). 00382 { 00383 // first, delete all of his/her permissions 00384 $perms = new UserPermissions(); 00385 $perms->revokeUserPermissions( $userId ); 00386 00387 $query = "DELETE FROM ".$this->getPrefix()."users WHERE id = $userId;"; 00388 00389 $result = $this->Execute( $query ); 00390 00391 if( !$result ) 00392 return false; 00393 00394 if( $this->_db->Affected_Rows() == 0 ) 00395 return false; 00396 00397 return true; 00398 }
|
|
|
disables a user
定義在 users.class.php 檔案之第 359 行. 參考 $query, $result, Model::Execute(), 及 Db::qstr(). 00360 { 00361 $query = "UPDATE ".$this->getPrefix()."users 00362 SET status = '".USER_STATUS_DISABLED."' 00363 WHERE id = '".Db::qstr($userId)."'"; 00364 00365 $result = $this->Execute( $query ); 00366 00367 if( !$result ) 00368 return false; 00369 00370 if( $this->_db->Affected_Rows() == 0 ) 00371 return false; 00372 00373 return true; 00374 }
|
|
|
check if the email account has been registered
定義在 users.class.php 檔案之第 462 行. 參考 $query, $result, 及 Db::qstr(). 00462 { 00463 $query = "SELECT email 00464 FROM ".$this->getPrefix()."users 00465 WHERE email = '".Db::qstr($email)."'"; 00466 00467 $result = $this->_db->Execute($query); 00468 00469 if($result && $result->RecordCount() >= 1) 00470 return true; 00471 else 00472 return false; 00473 }
|
|
||||||||||||||||||||
|
Returns an array with all the users available in the database
定義在 users.class.php 檔案之第 236 行. 參考 $query, $result, $users, _fillUserInformation(), 及 Model::Execute(). 00237 { 00238 if( $status != USER_STATUS_ALL ) 00239 $where = "WHERE status = '".Db::qstr($status)."'"; 00240 00241 $query = "SELECT * FROM ".$this->getPrefix()."users $where ORDER BY id ASC $limits"; 00242 00243 $result = $this->Execute( $query, $page, $itemsPerPage ); 00244 00245 $users = Array(); 00246 00247 while ($info = $result->FetchRow( $result )) 00248 array_push( $users, $this->_fillUserInformation( $info, $includeExtraInfo )); 00249 00250 return $users; 00251 }
|
|
||||||||||||||||
|
Returns an array with all the users that belong to the given blog.
定義在 users.class.php 檔案之第 321 行. 參考 $query, $result, $users, _fillUserInformation(), Model::Execute(), 及 Model::getPrefix(). 00322 { 00323 $users = Array(); 00324 $prefix = $this->getPrefix(); 00325 00326 // get the information about the owner, if requested so 00327 if( $includeOwner ) { 00328 $query = "SELECT {$prefix}users.* FROM {$prefix}users, {$prefix}blogs 00329 WHERE {$prefix}users.id = {$prefix}blogs.owner_id AND {$prefix}blogs.id = '".Db::qstr($blogId)."';"; 00330 $result = $this->Execute( $query ); 00331 00332 if( !$result ) 00333 return false; 00334 00335 $row = $result->FetchRow(); 00336 array_push( $users, $this->_fillUserInformation( $row )); 00337 } 00338 00339 // now get the other users who have permission for that blog. 00340 $query2 = "SELECT {$prefix}users.* FROM {$prefix}users, {$prefix}users_permissions 00341 WHERE {$prefix}users.id = {$prefix}users_permissions.user_id 00342 AND {$prefix}users_permissions.blog_id = '".Db::qstr($blogId)."';"; 00343 $result2 = $this->Execute( $query2 ); 00344 if( !$result2 ) // if error, return what we have so far... 00345 return $users; 00346 00347 while( $row = $result2->FetchRow()) { 00348 array_push( $users, $this->_fillUserInformation($row)); 00349 } 00350 00351 return $users; 00352 }
|
|
|
returns the total number of users
定義在 users.class.php 檔案之第 405 行. 參考 Model::getNumItems(), 及 Model::getPrefix(). 00406 { 00407 $prefix = $this->getPrefix(); 00408 $table = "{$prefix}users"; 00409 if( $status != USER_STATUS_ALL ) 00410 $cond = "status = '".Db::qstr($status)."'"; 00411 00412 return( $this->getNumItems( $table, $cond )); 00413 }
|
|
|
get the blogid of user own 定義在 users.class.php 檔案之第 429 行. 參考 $blogs, $result, $username, 及 getUserInfoFromUsername(). 00430 { 00431 // default blog id 00432 $blogId = 1; 00433 00434 $usersBlogs = Array(); 00435 $blogs = new Blogs(); 00436 00437 $userinfo = $this->getUserInfoFromUsername($username); 00438 // if userinfo is null, this maybe because username is not exists.. 00439 // return 0 means, should go to summary page 00440 if(!$userinfo) return 0; 00441 $userid = $userinfo->getId(); 00442 $userid = $userinfo->getId(); 00443 00444 // check if the user is the owner of any blog 00445 $owner = "SELECT id FROM ".$this->getPrefix()."blogs WHERE owner_id = ".$userid.";"; 00446 $result = $this->_db->Execute( $owner ); 00447 00448 if(!$result) 00449 return $blogId; 00450 00451 while( $row = $result->FetchRow($result)) { 00452 $blogId = $row["id"]; 00453 } 00454 00455 return $blogId; 00456 }
|
|
||||||||||||
|
Returns all the information associated to the user given
定義在 users.class.php 檔案之第 62 行. 參考 $query, $user, $userInfo, _getUserInfoFromQuery(), 及 Model::getPrefix(). 00063 { 00064 $prefix = $this->getPrefix(); 00065 $query = "SELECT u.id AS id, u.user AS user, u.password AS password, u.email AS email, 00066 u.about AS about, u.full_name AS full_name, u.properties AS properties, 00067 u.resource_picture_id AS resource_picture_id, 00068 IF(p.permission_id = 1, 1, 0 ) AS site_admin, 00069 u.status AS status 00070 FROM {$prefix}users u LEFT JOIN {$prefix}users_permissions p ON u.id = p.user_id 00071 WHERE u.user = '".Db::qstr($user)."' AND u.password = '".md5($pass)."' 00072 ORDER BY blog_id"; 00073 00074 $userInfo = $this->_getUserInfoFromQuery( $query ); 00075 00076 return $userInfo; 00077 }
|
|
||||||||||||
|
Retrieves the user infromation but given only a userid
定義在 users.class.php 檔案之第 107 行. 參考 $query, $userInfo, _getUserInfoFromQuery(), 及 Model::getPrefix(). 00108 { 00109 if( isset($this->usercache[$userid])) { 00110 $userInfo = $this->usercache[$userid]; 00111 } 00112 else { 00113 $prefix = $this->getPrefix(); 00114 $query = "SELECT u.id AS id, u.user AS user, u.password AS password, u.email AS email, 00115 u.about AS about, u.full_name AS full_name, u.properties AS properties, 00116 u.resource_picture_id AS resource_picture_id, 00117 IF(p.permission_id = 1, 1, 0 ) AS site_admin, 00118 u.status AS status 00119 FROM {$prefix}users u LEFT JOIN {$prefix}users_permissions p ON u.id = p.user_id 00120 WHERE u.id = $userid ORDER BY blog_id"; 00121 00122 $userInfo = $this->_getUserInfoFromQuery( $query, $extendedInfo ); 00123 00124 $this->usercache[$userid] = $userInfo; 00125 } 00126 00127 return $userInfo; 00128 }
|
|
|
Retrieves the user information but given only a username
定義在 users.class.php 檔案之第 85 行. 參考 $query, $userInfo, $username, _getUserInfoFromQuery(), 及 Model::getPrefix(). 被參考於 getUserBlogId(), 及 userExists(). 00086 { 00087 $prefix = $this->getPrefix(); 00088 $query = "SELECT u.id AS id, u.user AS user, u.password AS password, u.email AS email, 00089 u.about AS about, u.full_name AS full_name, u.properties AS properties, 00090 u.resource_picture_id AS resource_picture_id, 00091 IF(p.permission_id = 1, 1, 0 ) AS site_admin, 00092 u.status AS status 00093 FROM {$prefix}users u LEFT JOIN {$prefix}users_permissions p ON u.id = p.user_id 00094 WHERE u.user = '".Db::qstr($username)."' ORDER BY blog_id"; 00095 00096 $userInfo = $this->_getUserInfoFromQuery( $query ); 00097 00098 return $userInfo; 00099 }
|
|
||||||||||||
|
Returns an array of BlogInfo objects with the information of all the blogs to which a user belongs
定義在 users.class.php 檔案之第 188 行. 參考 $blogs, $result, Model::Execute(), 及 Model::getPrefix(). 被參考於 _fillUserInformation(). 00189 { 00190 $usersBlogs = Array(); 00191 $blogs = new Blogs(); 00192 $ids = Array(); 00193 00194 // check if the user is the owner of any blog 00195 $prefix = $this->getPrefix(); 00196 $owner = "SELECT * FROM {$prefix}blogs WHERE owner_id = ".$userid; 00197 if( $status != BLOG_STATUS_ALL ) 00198 $owner .= " AND status = '".Db::qstr( $status )."'"; 00199 00200 $result = $this->Execute( $owner ); 00201 00202 while( $row = $result->FetchRow($result)) { 00203 $usersBlogs[] = $blogs->_fillBlogInformation( $row ); 00204 $ids[] = $row["id"]; 00205 } 00206 00207 // and now check to which other blogs he or she belongs 00208 $otherBlogs = "SELECT b.* FROM {$prefix}blogs b, {$prefix}users_permissions p 00209 WHERE p.user_id = '".Db::qstr($userid)."' AND b.id = p.blog_id"; 00210 if( !empty($usersBlogs)) { 00211 $blogIds = implode( ",", $ids ); 00212 $otherBlogs .= " AND p.blog_id NOT IN (".$blogIds.")"; 00213 } 00214 if( $status != BLOG_STATUS_ALL ) 00215 $otherBlogs .= " AND b.status = '".Db::qstr( $status )."'"; 00216 00217 $result = $this->Execute( $otherBlogs ); 00218 // now we know to which he or she belongs, so we only have 00219 // to load the information about those blogs 00220 while( $row = $result->FetchRow($result)) { 00221 $usersBlogs[] = $blogs->_fillBlogInformation( $row ); 00222 } 00223 00224 return $usersBlogs; 00225 }
|
|
|
Updates the information related to a user
定義在 users.class.php 檔案之第 260 行. 參考 $query, $result, $userInfo, 及 Model::Execute(). 00261 { 00262 $query = "UPDATE ".$this->getPrefix(). 00263 "users SET email = '".$userInfo->getEmail(). 00264 "', about = '".Db::qstr($userInfo->getAboutMyself()). 00265 "', password = '".$userInfo->getPassword(). 00266 "', full_name = '".Db::qstr($userInfo->getFullName()). 00267 "', resource_picture_id = '".Db::qstr($userInfo->getPictureId()). 00268 "', properties = '".Db::qstr(serialize($userInfo->getProperties())). 00269 "', status = '".Db::qstr($userInfo->getStatus()). 00270 "' WHERE id = ".$userInfo->getId().";"; 00271 00272 // update the users table 00273 $result = $this->Execute( $query ); 00274 00275 // and now update the permissions, if there has been any change 00276 $perms = new UserPermissions(); 00277 $perms->updateSiteAdmin( $userInfo->getId(), $userInfo->isSiteAdmin()); 00278 00279 return $result; 00280 }
|
|
|
returns true if the given username exists
定義在 users.class.php 檔案之第 421 行. 00422 { 00423 return( $this->getUserInfoFromUsername( $userName )); 00424 }
|