[ Index ] |
|
Code source de LifeType 1.2.4 |
1 <?php 2 3 lt_include( PLOG_CLASS_PATH."class/dao/model.class.php" ); 4 lt_include( PLOG_CLASS_PATH."class/dao/userstatus.class.php" ); 5 lt_include( PLOG_CLASS_PATH."class/dao/blogstatus.class.php" ); 6 lt_include( PLOG_CLASS_PATH."class/dao/daocacheconstants.properties.php" ); 7 8 /** 9 * This is the base class that defines the methods that all user-data providers must implement. 10 * It also provides some common methods that will be shared by all user-data providers and that therefore 11 * should exist in the parent class rather than being copied many times in the child classes. 12 * 13 * \ingroup User_Data_Providers 14 */ 15 class BaseUserDataProvider extends Model 16 { 17 18 var $_providerConfig; 19 20 /** 21 * Constructor of the class 22 * 23 * @param providerConfig a Properties object with information about the 24 * provider-specific parameters, which may vary depending on the provider 25 */ 26 function BaseUserDataProvider( $providerConfig ) 27 { 28 $this->Model(); 29 30 $this->_providerConfig = $providerConfig; 31 } 32 33 /** 34 * Returns the config specific data 35 * 36 * @return a Properties object with the provider configuration, as it was defined 37 * in the userdata.properties.php file 38 */ 39 function getProviderConfiguration() 40 { 41 return( $this->_providerConfig ); 42 } 43 44 /** 45 * Returns true if the user is in the database and the username 46 * and password match 47 * 48 * @param user Username of the user who we'd like to authenticate 49 * @param pass Password of the user 50 * @return true if user and password correct or false otherwise. 51 */ 52 function authenticateUser( $user, $pass ) 53 { 54 } 55 56 /** 57 * Returns all the information associated to the user given 58 * 59 * @param user Username of the user from who we'd like to get the information 60 * @param pass Password of the user we'd like to get the information 61 * @return Returns a UserInfo object with the requested information, or false otherwise. 62 */ 63 function getUserInfo( $user, $pass ) 64 { 65 } 66 67 /** 68 * Retrieves the user information but given only a username 69 * 70 * @param username The username of the user 71 * @return Returns a UserInfo object with the requested information, or false otherwise. 72 */ 73 function getUserInfoFromUsername( $username ) 74 { 75 } 76 77 /** 78 * Retrieves the user infromation but given only a userid 79 * 80 * @param userId User ID of the user from whom we'd like to get the information 81 * @return Returns a UserInfo object with the requested information, or false otherwise. 82 */ 83 function getUserInfoFromId( $userid, $extendedInfo = false ) 84 { 85 } 86 87 /** 88 * Returns an array of BlogInfo objects with the information of all the blogs to which 89 * a user belongs 90 * 91 * @param userId Identifier of the user 92 * @return An array of BlogInfo objects to whom the user belongs. 93 */ 94 function getUsersBlogs( $userid, $status = BLOG_STATUS_ALL ) 95 { 96 lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" ); 97 $usersBlogs = Array(); 98 $blogs = new Blogs(); 99 $ids = Array(); 100 101 // check if the user is the owner of any blog 102 $prefix = $this->getPrefix(); 103 $owner = "SELECT * FROM {$prefix}blogs WHERE owner_id = ".$userid; 104 if( $status != BLOG_STATUS_ALL ) 105 $owner .= " AND status = '".Db::qstr( $status )."'"; 106 107 $result = $this->Execute( $owner ); 108 109 while( $row = $result->FetchRow($result)) { 110 $usersBlogs[] = $blogs->mapRow( $row ); 111 $ids[] = $row["id"]; 112 } 113 $result->Close(); 114 115 // and now check to which other blogs he or she belongs 116 $otherBlogs = "SELECT DISTINCT p.blog_id AS blog_id FROM {$prefix}users_permissions p, {$prefix}blogs b 117 WHERE p.user_id = '".Db::qstr($userid)."' AND b.id = p.blog_id"; 118 if( !empty($usersBlogs)) { 119 $blogIds = implode( ",", $ids ); 120 $otherBlogs .= " AND p.blog_id NOT IN (".$blogIds.")"; 121 } 122 if( $status != BLOG_STATUS_ALL ) 123 $otherBlogs .= " AND b.status = '".Db::qstr( $status )."'"; 124 125 $result = $this->Execute( $otherBlogs ); 126 // now we know to which he or she belongs, so we only have 127 // to load the information about those blogs 128 while( $row = $result->FetchRow($result)) { 129 $id = $row["blog_id"]; 130 $usersBlogs[] = $blogs->getBlogInfo( $id ); 131 } 132 $result->Close(); 133 134 sort($usersBlogs); 135 136 return $usersBlogs; 137 } 138 139 /** 140 * @private 141 */ 142 function mapRow( $query_result ) 143 { 144 lt_include( PLOG_CLASS_PATH."class/dao/userinfo.class.php" ); 145 146 isset( $query_result["properties"] ) ? $properties = unserialize( $query_result["properties"] ) : $properties = Array(); 147 148 $userInfo = new UserInfo( $query_result["user"], 149 $query_result["password"], 150 $query_result["email"], 151 $query_result["about"], 152 $query_result["full_name"], 153 $query_result["resource_picture_id"], 154 $properties, 155 $query_result["id"]); 156 157 // set some permissions 158 isset( $query_result["site_admin"] ) ? $siteAdmin = $query_result["site_admin"] : $siteAdmin = 0; 159 $userInfo->setSiteAdmin( $siteAdmin ); 160 $userInfo->setStatus( $query_result["status"] ); 161 162 return $userInfo; 163 } 164 165 /** 166 * Returns an array with all the users available in the database 167 * 168 * @param status 169 * @param searchTerms 170 * @param orderBy 171 * @param page 172 * @param itemsPerPage 173 * @return An array containing all the users. 174 */ 175 function getAllUsers( $status = USER_STATUS_ALL, $searchTerms = "", $orderBy = "", $page = -1, $itemsPerPage = DEFAULT_ITEMS_PER_PAGE ) 176 { 177 } 178 179 /** 180 * Updates the information related to a user. This method should be called by child classes 181 * so the user permissions (which are plog-specific) can be updated at the same time! 182 * 183 * @param userInfo An UserInfo object containing the <b>already udpated</b> information of the 184 * user we would like to update. 185 * @return Returns true if ok or false otherwise. 186 */ 187 function updateUser( $userInfo ) 188 { 189 lt_include( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" ); 190 return( true ); 191 } 192 193 /** 194 * Adds a user to the database. 195 * 196 * @param user An UserInfo object with the necessary information 197 * @return Returns the identifier assigned to the user, or false if there was any error. It will also modify the 198 * UserInfo object passed by parameter and set its database id. 199 */ 200 function addUser( &$user ) 201 { 202 } 203 204 /** 205 * Returns an array with all the users that belong to the given 206 * blog. 207 * 208 * @param blogId The blog identifier. 209 * @param includeOwner Wether to include the owner of the blog or not. 210 * @param status 211 * @param searchTerms 212 * @return An array with the information about the users who belong in 213 * one way or another to that blog. 214 */ 215 function getBlogUsers( $blogId, $includeOwner = true, $status = USER_STATUS_ALL, $searchTerms = "" ) 216 { 217 $users = Array(); 218 $prefix = $this->getPrefix(); 219 220 // get the information about the owner, if requested so 221 if( $includeOwner ) { 222 lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" ); 223 $blogs = new Blogs(); 224 $blogInfo = $blogs->getBlogInfo( $blogId ); 225 array_push( $users, $this->getUserInfoFromId( $blogInfo->getOwnerId())); 226 } 227 228 // now get the other users who have permission for that blog. 229 $query2 = "SELECT DISTINCT user_id FROM {$prefix}users_permissions WHERE blog_id = '".Db::qstr( $blogId )."'"; 230 $result2 = $this->Execute( $query2 ); 231 if( !$result2 ) // if error, return what we have so far... 232 return $users; 233 234 while( $row = $result2->FetchRow()) { 235 array_push( $users, $this->getUserInfoFromId( $row["user_id"] )); 236 } 237 $result2->Close(); 238 239 return $users; 240 } 241 242 /** 243 * Removes users from the database 244 * 245 * @param userId The identifier of the user we are trying to remove 246 */ 247 function deleteUser( $userId ) 248 { 249 } 250 251 /** 252 * returns the total number of users 253 * 254 * @param status 255 * @param searchTerms 256 * @return total number of users 257 */ 258 function getNumUsers( $status = USER_STATUS_ALL, $searchTerms = "" ) 259 { 260 } 261 262 /** 263 * check if the email account has been registered 264 * @return true if the email account has been registered 265 */ 266 function emailExists($email) 267 { 268 } 269 270 /** 271 * @final 272 * Grants the given user is the login_perm. This is something that all integrations 273 * must use or else users won't be allowed to log in. 274 * 275 * @param userInfo A UserInfo object 276 * @return True if successful or false otherwise 277 */ 278 function grantLoginPermission( $userInfo ) 279 { 280 lt_include( PLOG_CLASS_PATH."class/dao/permissions.class.php" ); 281 lt_include( PLOG_CLASS_PATH."class/dao/userpermission.class.php" ); 282 lt_include( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" ); 283 284 $perms = new Permissions(); 285 $loginPerm = $perms->getPermissionByName( "login_perm" ); 286 $perm = new UserPermission( $userInfo->getId(), // user id 287 0, // it's a global permission, no blog id needed 288 $loginPerm->getId() // id of the permission 289 ); 290 $userPerms = new UserPermissions(); 291 $userPerms->grantPermission( $perm, true ); 292 } 293 } 294 ?>
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 |
![]() |