~ubuntu-branches/ubuntu/maverick/gallery2/maverick

« back to all changes in this revision

Viewing changes to modules/core/classes/helpers/GalleryPermissionHelper_simple.class

  • Committer: Bazaar Package Importer
  • Author(s): Michael C. Schultheiss
  • Date: 2007-09-10 20:22:19 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070910202219-0jsuntvqge4ade6b
Tags: 2.2.3-2
Add Slovak translation of Debconf templates.  (Thanks to 
Ivan Masá.  Closes: #441671)

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 * @package GalleryCore
24
24
 * @subpackage Helpers
25
25
 * @author Bharat Mediratta <bharat@menalto.com>
26
 
 * @version $Revision: 15754 $
 
26
 * @version $Revision: 16471 $
27
27
 * @static
28
28
 */
29
29
class GalleryPermissionHelper_simple {
34
34
    function fetchAccessListIds($permission, $userId, $sessionPermissions=true) {
35
35
        global $gallery;
36
36
 
37
 
        $cacheKey = 'GalleryPermissionHelper::fetchAccessListIds(' .
38
 
            "$permission, $userId, $sessionPermissions)";
 
37
        $sessionPermissions = (int)$sessionPermissions;
 
38
        $cacheKey = 'GalleryPermissionHelper::fetchAccessListIds('
 
39
            . "$permission,$userId,$sessionPermissions)";
39
40
        if (!GalleryDataCache::containsKey($cacheKey)) {
40
41
            list ($ret, $groupIds) = GalleryCoreApi::fetchGroupsForUser($userId);
41
42
            if ($ret) {
191
192
    /**
192
193
     * @see GalleryCoreApi::studyPermissions
193
194
     */
194
 
    function studyPermissions($itemIds, $userId=null) {
 
195
    function studyPermissions($itemIds, $userId=null, $sessionPermissions=true) {
195
196
        list ($ret, $permissionsTable) =
196
 
            GalleryCoreApi::fetchPermissionsForItems($itemIds, $userId);
 
197
            GalleryCoreApi::fetchPermissionsForItems($itemIds, $userId, $sessionPermissions);
197
198
        if ($ret) {
198
199
            return $ret;
199
200
        }
204
205
    /**
205
206
     * @see GalleryCoreApi::fetchPermissionsForItems
206
207
     */
207
 
    function fetchPermissionsForItems($itemIds, $userId=null) {
 
208
    function fetchPermissionsForItems($itemIds, $userId=null, $sessionPermissions=true) {
208
209
        global $gallery;
209
210
 
210
211
        if (!is_array($itemIds) || empty($itemIds)) {
217
218
        if (is_null($userId)) {
218
219
            $userId = $gallery->getActiveUserId(); /* default user id */
219
220
        }
 
221
        $sessionPermissions = (int)$sessionPermissions;
220
222
 
221
223
        /* Check the cache */
222
224
        $permTable = array();
223
225
        foreach ($itemIds as $idx => $itemId) {
224
 
            $cacheKey = "GalleryPermissionHelper::getPermissions($itemId,$userId)";
 
226
            $cacheKey =
 
227
                "GalleryPermissionHelper::getPermissions($itemId,$userId,$sessionPermissions)";
225
228
            if (GalleryDataCache::containsKey($cacheKey)) {
226
229
                $permTable[$itemId] = GalleryDataCache::get($cacheKey);
227
230
                unset($itemIds[$idx]);
241
244
            return array($ret, null);
242
245
        }
243
246
        $groupIds = array_keys($groupIds);
244
 
        if ($userId == $gallery->getActiveUserId()) {
 
247
        if ($sessionPermissions && $userId == $gallery->getActiveUserId()) {
245
248
            /* Session based permissions */
246
249
            $session =& $gallery->getSession();
247
250
            $sessionEntityIds = $session->get(GALLERY_PERMISSION_SESSION_KEY);
317
320
            }
318
321
 
319
322
            /* Cache the permissions in memory. */
320
 
            $cacheKey = "GalleryPermissionHelper::getPermissions($itemId,$userId)";
 
323
            $cacheKey =
 
324
                "GalleryPermissionHelper::getPermissions($itemId,$userId,$sessionPermissions)";
321
325
            GalleryDataCache::put($cacheKey, $permTable[$itemId]);
322
326
        }
323
327
 
420
424
    /**
421
425
     * @see GalleryCoreApi::getPermissions
422
426
     */
423
 
    function getPermissions($itemId, $userId=null) {
 
427
    function getPermissions($itemId, $userId=null, $sessionPermissions=true) {
424
428
        global $gallery;
425
429
 
426
430
        if (!isset($userId)) {
427
431
            $userId = $gallery->getActiveUserId();
428
432
        }
 
433
        $sessionPermissions = (int)$sessionPermissions;
429
434
 
430
 
        $cacheKey = "GalleryPermissionHelper::getPermissions($itemId,$userId)";
 
435
        $cacheKey =
 
436
            "GalleryPermissionHelper::getPermissions($itemId,$userId,$sessionPermissions)";
431
437
        if (GalleryDataCache::containsKey($cacheKey)) {
432
438
            $permissions = GalleryDataCache::get($cacheKey);
433
439
        } else {
434
 
            list ($ret, $permissionsTable) =
435
 
                GalleryCoreApi::fetchPermissionsForItems(array($itemId), $userId);
 
440
            list ($ret, $permissionsTable) = GalleryCoreApi::fetchPermissionsForItems(
 
441
                array($itemId), $userId, $sessionPermissions);
436
442
            if ($ret) {
437
443
                return array($ret, null);
438
444
            }