Esempio n. 1
0
 /**
  * Get the Id of the active user.
  * The active user is the user who is logged on in this session.
  *
  * @return int the id of the current user
  */
 function getActiveUserId() {
 if (isset($this->_activeUser)) {
     return (int) $this->_activeUser->getId();
 } else {
     $session =& $this->getSession();
     return (int) $session->getUserId();
 }
 }
Esempio n. 2
0
/**
 * Find admin user and set as active user
 * @param bool $fallback (optional) whether we should try to fall back if the
 *             API to load the admin user object fails
 * @return GalleryStatus a status code
 */
function selectAdminUser($fallback = false)
{
    global $gallery;
    list($ret, $siteAdminGroupId) = GalleryCoreApi::getPluginParameter('module', 'core', 'id.adminGroup');
    if ($ret) {
        return $ret;
    }
    list($ret, $adminUserInfo) = GalleryCoreApi::fetchUsersForGroup($siteAdminGroupId, 1);
    if ($ret) {
        return $ret;
    }
    if (empty($adminUserInfo)) {
        return GalleryCoreApi::error(ERROR_MISSING_VALUE);
    }
    /* Fetch the first admin from list */
    list($userId, $userName) = each($adminUserInfo);
    list($ret, $adminUser) = GalleryCoreApi::loadEntitiesById($userId, 'GalleryUser');
    if ($ret) {
        if ($fallback) {
            /* Initialize a GalleryUser with the id of a real admin */
            $gallery->debug('Unable to load admin user. Using in-memory user object as fallback');
            GalleryCoreApi::requireOnce('modules/core/classes/GalleryUser.class');
            $adminUser = new GalleryUser();
            $adminUser->setId((int) $userId);
            $adminUser->setUserName($userName);
        } else {
            return $ret;
        }
    }
    $gallery->setActiveUser($adminUser);
    $session =& $gallery->getSession();
    $session->put('isUpgrade', true);
    return null;
}