summaryrefslogtreecommitdiff
path: root/modules/user/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'modules/user/helpers')
-rw-r--r--modules/user/helpers/user.php38
-rw-r--r--modules/user/helpers/user_event.php27
2 files changed, 60 insertions, 5 deletions
diff --git a/modules/user/helpers/user.php b/modules/user/helpers/user.php
index a04542d3..1667afd1 100644
--- a/modules/user/helpers/user.php
+++ b/modules/user/helpers/user.php
@@ -57,11 +57,38 @@ class user_Core {
}
/**
+ * Make sure that we have a session and group_ids cached in the session.
+ */
+ public static function load_user() {
+ $session = Session::instance();
+ if (!($user = $session->get("user"))) {
+ $session->set("user", $user = user::guest());
+ }
+
+ if (!$session->get("group_ids")) {
+ $ids = array();
+ foreach ($user->groups as $group) {
+ $ids[] = $group->id;
+ }
+ $session->set("group_ids", $ids);
+ }
+ }
+
+ /**
+ * Return the array of group ids this user belongs to
+ *
+ * @return array
+ */
+ public static function group_ids() {
+ return Session::instance()->get("group_ids", array(1));
+ }
+
+ /**
* Return the active user. If there's no active user, return the guest user.
*
* @return User_Model
*/
- static function active() {
+ public static function active() {
return Session::instance()->get("user", self::guest());
}
@@ -72,7 +99,7 @@ class user_Core {
*
* @return User_Model
*/
- static function guest() {
+ public static function guest() {
return model_cache::get("user", 1);
}
@@ -81,8 +108,9 @@ class user_Core {
*
* @return User_Model
*/
- static function set_active($user) {
- return Session::instance()->set("user", $user);
+ public static function set_active($user) {
+ Session::instance()->set("user", $user);
+ self::load_user();
}
/**
@@ -93,7 +121,7 @@ class user_Core {
* @param string $password
* @return User_Model
*/
- static function create($name, $display_name, $password) {
+ public static function create($name, $display_name, $password) {
$user = ORM::factory("user")->where("name", $name)->find();
if ($user->loaded) {
throw new Exception("@todo USER_ALREADY_EXISTS $name");
diff --git a/modules/user/helpers/user_event.php b/modules/user/helpers/user_event.php
new file mode 100644
index 00000000..2d1ce171
--- /dev/null
+++ b/modules/user/helpers/user_event.php
@@ -0,0 +1,27 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2008 Bharat Mediratta
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+class user_event_Core {
+ /**
+ * Initialization.
+ */
+ public static function gallery_ready() {
+ user::load_user();
+ }
+}