[pLog-svn] r2039 - plog/branches/plog-1.1-ben/class/dao
ork at devel.plogworld.net
ork at devel.plogworld.net
Sun May 22 15:15:05 GMT 2005
Author: ork
Date: 2005-05-22 15:15:01 +0000 (Sun, 22 May 2005)
New Revision: 2039
Modified:
plog/branches/plog-1.1-ben/class/dao/userpermissions.class.php
Log:
just converted all TAB to spaces
Modified: plog/branches/plog-1.1-ben/class/dao/userpermissions.class.php
===================================================================
--- plog/branches/plog-1.1-ben/class/dao/userpermissions.class.php 2005-05-21 21:47:40 UTC (rev 2038)
+++ plog/branches/plog-1.1-ben/class/dao/userpermissions.class.php 2005-05-22 15:15:01 UTC (rev 2039)
@@ -1,8 +1,8 @@
<?php
- include_once( PLOG_CLASS_PATH."class/dao/model.class.php" );
+ include_once( PLOG_CLASS_PATH."class/dao/model.class.php" );
include_once( PLOG_CLASS_PATH."class/dao/userpermission.class.php" );
- include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
+ include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
//
// :KLUDGE: This should be done in a better way...
@@ -13,15 +13,15 @@
/**
* Handles user permissions.
- *
- * \ingroup DAO
+ *
+ * \ingroup DAO
*/
- class UserPermissions extends Model
- {
+ class UserPermissions extends Model
+ {
- function UserPermissions()
+ function UserPermissions()
{
- $this->Model();
+ $this->Model();
//print("user constructor<br/>");
}
@@ -39,29 +39,29 @@
{
$perms = Array();
- // check if the user is the owner
+ // check if the user is the owner
$query = "SELECT owner_id FROM ".$this->getPrefix()."blogs WHERE id = '".Db::qstr($blogId)."'";
$result = $this->Execute( $query );
if( $result ) {
- $row = $result->FetchRow();
+ $row = $result->FetchRow();
if( $row["owner_id"] == $userId ) {
- $perm = new UserPermission( $userId, $blogId, PERMISSION_BLOG_OWNER, 0 );
+ $perm = new UserPermission( $userId, $blogId, PERMISSION_BLOG_OWNER, 0 );
array_push( $perms, $perm );
}
}
// we can continue now to check for other permissions, even though BLOG_OWNER level
// is higher than any other
- $query = "SELECT * FROM ".$this->getPrefix()."users_permissions WHERE user_id = '".Db::qstr($userId)."' AND blog_id = '".Db::qstr($blogId)."'";
+ $query = "SELECT * FROM ".$this->getPrefix()."users_permissions WHERE user_id = '".Db::qstr($userId)."' AND blog_id = '".Db::qstr($blogId)."'";
$result = $this->Execute( $query );
//$result = $this->_db->CacheExecute( 60, $query );
if( !$result )
- return false;
+ return false;
while( $row = $result->FetchRow()) {
- array_push( $perms, $this->_fillUserPermissionInformation( $row ));
+ array_push( $perms, $this->_fillUserPermissionInformation( $row ));
}
return $perms;
@@ -72,7 +72,7 @@
*/
function _fillUserPermissionInformation( $row )
{
- $perm = new UserPermission( $row["user_id"], $row["blog_id"], $row["permission_id"], $row["id"] );
+ $perm = new UserPermission( $row["user_id"], $row["blog_id"], $row["permission_id"], $row["id"] );
return $perm;
}
@@ -85,32 +85,32 @@
*/
function isSiteAdmin( $userId )
{
- if( isset($this->cache[$userId])) {
- //print("user cached<br/>");
+ if( isset($this->cache[$userId])) {
+ //print("user cached<br/>");
$result = $this->cache[$userId];
}
else {
- $query = "SELECT * FROM ".$this->getPrefix()."users_permissions WHERE permission_id = 1 AND user_id = '".Db::qstr($userId)."'";
+ $query = "SELECT * FROM ".$this->getPrefix()."users_permissions WHERE permission_id = 1 AND user_id = '".Db::qstr($userId)."'";
- $result = $this->Execute( $query );
+ $result = $this->Execute( $query );
$this->cache[$userId] = $result;
//print("user fetching!<br/>");
}
if( !$result )
- return false;
+ return false;
if( $result->RowCount() == 0 )
- return false;
+ return false;
// let's double check and make completely sure...
$row = $result->FetchRow();
if( $row["user_id"] == $userId )
- return true;
+ return true;
else
- return false;
+ return false;
}
/**
@@ -120,9 +120,9 @@
*/
function setSiteAdmin( $userId )
{
- // first check if the user already has administrator permissions
- if( $this->isSiteAdmin( $userId ))
- return true;
+ // first check if the user already has administrator permissions
+ if( $this->isSiteAdmin( $userId ))
+ return true;
// if not, we can proceed and give them
$query = "INSERT INTO ".$this->getPrefix()."users_permissions (user_id,blog_id,permission_id) VALUES ( $userId, 0, 1 );";
@@ -130,9 +130,9 @@
$result = $this->Execute( $query );
if( !$result )
- return false;
+ return false;
else
- return true;
+ return true;
}
/**
@@ -143,9 +143,9 @@
*/
function revokeSiteAdmin( $userId )
{
- // we don't have to do anything if the user is not an administrator
- if( !$this->isSiteAdmin( $userId ))
- return true;
+ // we don't have to do anything if the user is not an administrator
+ if( !$this->isSiteAdmin( $userId ))
+ return true;
// if he or she is, we can proceed and remove the permission
$query = "DELETE FROM ".$this->getPrefix()."users_permissions WHERE user_id = $userId AND blog_id = 0 AND permission_id = 1;";
@@ -153,9 +153,9 @@
$result = $this->Execute( $query );
if( !$result )
- return false;
+ return false;
else
- return true;
+ return true;
}
/**
@@ -169,10 +169,10 @@
*/
function updateSiteAdmin( $userId, $siteAdmin )
{
- if( $siteAdmin )
- $result = $this->setSiteAdmin( $userId );
+ if( $siteAdmin )
+ $result = $this->setSiteAdmin( $userId );
else
- $result = $this->revokeSiteAdmin( $userId );
+ $result = $this->revokeSiteAdmin( $userId );
return $result;
}
@@ -189,7 +189,7 @@
*/
function grantPermission( $userId, $blogId, $permissionId )
{
- // check if the permission has already been granted
+ // check if the permission has already been granted
$query = "SELECT * FROM ".$this->getPrefix()."users_permissions
WHERE user_id = $userId AND blog_id = $blogId
AND permission_id = $permissionId";
@@ -198,7 +198,7 @@
// the permission has already been granted so there's nothing else to do here
if( $result && $result->RowCount() == 1 )
- return true;
+ return true;
// if not, grant it now
$query = "INSERT INTO ".$this->getPrefix()."users_permissions
@@ -207,9 +207,9 @@
$result = $this->Execute( $query );
if( !$result )
- return false;
+ return false;
else
- return true;
+ return true;
}
/**
@@ -223,7 +223,7 @@
*/
function revokePermission( $userId, $blogId, $permissionId )
{
- // check if the permission has already been removed or doesn't exist
+ // check if the permission has already been removed or doesn't exist
$query = "SELECT * FROM ".$this->getPrefix()."users_permissions
WHERE user_id = $userId AND blog_id = $blogId
AND permission_id = $permissionId";
@@ -231,10 +231,10 @@
$result = $this->Execute( $query );
if( !$result )
- return true;
+ return true;
if( $result->RowCount() == 0 )
- return true;
+ return true;
// if not, grant it now
$query = "DELETE FROM ".$this->getPrefix()."users_permissions
@@ -243,9 +243,9 @@
$result = $this->Execute( $query );
if( !$result )
- return false;
+ return false;
else
- return true;
+ return true;
}
/**
@@ -257,7 +257,7 @@
*/
function revokeBlogPermissions( $blogId )
{
- $query = "DELETE FROM ".$this->getPrefix()."users_permissions
+ $query = "DELETE FROM ".$this->getPrefix()."users_permissions
WHERE blog_id = $blogId";
$result = $this->Execute( $query );
@@ -265,34 +265,34 @@
return $result;
}
- /**
- * updates the list of users that have access to the blog. But this method works so
- * that it first removes all current permissions and then recreates them again
- * based on the given list of users
- *
- * @param blogId
- * @param userIdList An associative array with user ids
- * @return true if successful or false otherwise
- */
- function updateBlogUserPermissions( $blogId, $userList )
- {
- // first of all, remove all the permissions
- $this->revokeBlogPermissions( $blogId );
-
- // make sure that we're dealing with an array
- if( !is_array( $userList )) {
- return false;
- }
-
- // loop through the array and recreate the permissions
- foreach( $userList as $userId ) {
- if( $userId > 0 ) {
- $this->grantPermission( $userId, $blogId, PERMISSION_BLOG_USER );
- }
- }
-
- return true;
- }
+ /**
+ * updates the list of users that have access to the blog. But this method works so
+ * that it first removes all current permissions and then recreates them again
+ * based on the given list of users
+ *
+ * @param blogId
+ * @param userIdList An associative array with user ids
+ * @return true if successful or false otherwise
+ */
+ function updateBlogUserPermissions( $blogId, $userList )
+ {
+ // first of all, remove all the permissions
+ $this->revokeBlogPermissions( $blogId );
+
+ // make sure that we're dealing with an array
+ if( !is_array( $userList )) {
+ return false;
+ }
+
+ // loop through the array and recreate the permissions
+ foreach( $userList as $userId ) {
+ if( $userId > 0 ) {
+ $this->grantPermission( $userId, $blogId, PERMISSION_BLOG_USER );
+ }
+ }
+
+ return true;
+ }
/**
* revokes all the permissions that a user may have
@@ -302,7 +302,7 @@
*/
function revokeUserPermissions( $userId )
{
- $query = "DELETE FROM ".$this->getPrefix()."users_permissions
+ $query = "DELETE FROM ".$this->getPrefix()."users_permissions
WHERE user_id = $userId";
$result = $this->Execute( $query );
@@ -320,7 +320,7 @@
*/
function getBlogUsersPermissions( $blogId )
{
- $query = "SELECT * FROM ".$this->getPrefix()."users_permissions WHERE blog_id = ".$blogId.";";
+ $query = "SELECT * FROM ".$this->getPrefix()."users_permissions WHERE blog_id = ".$blogId.";";
$result = $this->Execute( $query );
if (!$result)
@@ -328,33 +328,33 @@
$perms = array();
while( $row = $result->FetchRow()) {
- array_push( $perms, $this->_fillUserPermissionInformation( $row ));
+ array_push( $perms, $this->_fillUserPermissionInformation( $row ));
}
return $perms;
}
-
- /**
- * returns the usernames of the users who have permissions in a blog
- *
- * @param blogId
- * @retur An array of UserInfo objects
- */
- function getBlogUsers( $blogId )
- {
- $query = "SELECT * FROM ".$this->getPrefix()."users_permissions WHERE blog_id = '".Db::qstr($blogId)."'";
+
+ /**
+ * returns the usernames of the users who have permissions in a blog
+ *
+ * @param blogId
+ * @retur An array of UserInfo objects
+ */
+ function getBlogUsers( $blogId )
+ {
+ $query = "SELECT * FROM ".$this->getPrefix()."users_permissions WHERE blog_id = '".Db::qstr($blogId)."'";
$result = $this->Execute( $query );
if (!$result)
return false;
$blogUsers = array();
- $users = new Users();
+ $users = new Users();
while( $row = $result->FetchRow()) {
- $blogUsers[] = $users->getUserInfoFromId( $row["user_id"] );
+ $blogUsers[] = $users->getUserInfoFromId( $row["user_id"] );
}
- return $blogUsers;
- }
+ return $blogUsers;
+ }
}
-?>
\ No newline at end of file
+?>
More information about the pLog-svn
mailing list