diff options
author | cweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f> | 2009-09-22 06:12:25 +0000 |
---|---|---|
committer | cweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f> | 2009-09-22 06:12:25 +0000 |
commit | 724d9fa421dad542a9ea74f14cd8b43ec44e22d3 (patch) | |
tree | 3cb1ea7ce0aac5f4e0c99a884c7de63984721ceb /services/bookmarkservice.php | |
parent | f05dad73e062f5efbc5579f0ac60df8a8e8ff970 (diff) | |
download | semanticscuttle-724d9fa421dad542a9ea74f14cd8b43ec44e22d3.tar.gz semanticscuttle-724d9fa421dad542a9ea74f14cd8b43ec44e22d3.tar.bz2 |
Fix bug #2674961: editAllowed optimization - make less queries for each bookmark
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@366 b3834d28-1941-0410-a4f8-b48e95affb8f
Diffstat (limited to 'services/bookmarkservice.php')
-rw-r--r-- | services/bookmarkservice.php | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/services/bookmarkservice.php b/services/bookmarkservice.php index 6a50df5..f119593 100644 --- a/services/bookmarkservice.php +++ b/services/bookmarkservice.php @@ -97,22 +97,38 @@ class BookmarkService { return $this->db->sql_fetchfield(0, 0); } - function editAllowed($bookmark) { - if (!is_numeric($bookmark) && (!is_array($bookmark) || !is_numeric($bookmark['bId']))) - return false; + /** + * Check if a bookmark may be edited by the current user + * + * @param integer|array $bookmark Bookmark uId or bookmark array + * + * @return boolean True if allowed + */ + function editAllowed($bookmark) + { + if (!is_numeric($bookmark) && (!is_array($bookmark) + || !is_numeric($bookmark['bId'])) + ) { + return false; + } - if (!is_array($bookmark)) - if (!($bookmark = $this->getBookmark($bookmark))) - return false; + if (!is_array($bookmark) + && !($bookmark = $this->getBookmark($bookmark)) + ) { + return false; + } - $userservice = & ServiceFactory :: getServiceInstance('UserService'); - $userid = $userservice->getCurrentUserId(); - if(!is_numeric($userid)) - return false; // useful for few servers configuration (see brunaud bugs) - if ($GLOBALS['adminsCanModifyBookmarksFromOtherUsers'] && $userservice->isAdmin($userid) && !$userservice->isAdmin($bookmark['uId'])) - return true; - else - return ($bookmark['uId'] == $userid); + $userservice = & ServiceFactory::getServiceInstance('UserService'); + $user = $userservice->getCurrentUser(); + + //user has to be either admin, or owner + if ($GLOBALS['adminsCanModifyBookmarksFromOtherUsers'] + && $userservice->isAdmin($user) + ) { + return true; + } else { + return ($bookmark['uId'] == $user['uId']); + } } function bookmarkExists($address = false, $uid = NULL) { |