1
0
This repository has been archived on 2021-04-26. You can view files and clone it, but cannot push or open issues or pull requests.
gallery3-contrib/modules/user_homes/helpers/user_homes_event.php

164 lines
4.8 KiB
PHP
Raw Normal View History

2009-07-24 23:11:02 +00:00
<?php defined("SYSPATH") or die("No direct script access.");
2009-08-03 03:36:03 +00:00
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2009 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_homes_event_Core {
/**
2009-08-03 03:36:03 +00:00
* Called when a user logs in. This will setup the session with the
* user home if it exists on the database. This means when the page
* is refreshed after logging in the direction can occur.
*/
static function user_login($user) {
$home = ORM::factory("user_home")->where("id", $user->id)->find();
2009-08-03 03:36:03 +00:00
if ($home->loaded && $home->home != 0) {
Session::instance()->set("redirect_home", $home->home);
}
}
/**
* called after a log in occurs and when the first gallery is loaded.
* if the home variable exists on the session then a redirect will
* occur to that home and the variable removed from the session to
*/
static function gallery_ready() {
$session = Session::instance();
$home = $session->get("redirect_home");
if ($home) {
2009-08-03 03:36:03 +00:00
// Remove from session to ensure redirect does not occur again
$session->set("redirect_home",null);
url::redirect("albums/$home");
}
}
/**
2009-08-03 03:36:03 +00:00
* Called just before a user is deleted. This will remove the user from
* the user_homes directory.
*/
static function user_before_delete($user) {
ORM::factory("user_home")
2009-08-03 03:36:03 +00:00
->where("id", $user->id)
->delete_all();
}
/**
2009-08-03 03:36:03 +00:00
* Called when admin is adding a user
*/
static function user_add_form_admin($user, $form) {
$form->add_user->dropdown("user_home")
2009-08-03 03:36:03 +00:00
->label(t("Home Gallery"))
->options(self::createGalleryArray())
->selected(0);
}
/**
2009-08-03 03:36:03 +00:00
* Called after a user has been added
*/
static function user_add_form_admin_completed($user, $form) {
$home = ORM::factory("user_home")->where("id", $user->id)->find();
2009-08-03 03:36:03 +00:00
$home->id = $user->id;
$home->home = $form->add_user->user_home->value;
$home->save();
}
/**
2009-08-03 03:36:03 +00:00
* Called when admin is editing a user
*/
static function user_edit_form_admin($user, $form) {
$home = ORM::factory("user_home")->where("id", $user->id)->find();
2009-08-03 03:36:03 +00:00
if ($home->loaded) {
$selected = $home->home;
} else {
$selected = 0;
}
$form->edit_user->dropdown("user_home")
2009-08-03 03:36:03 +00:00
->label(t("Home Gallery"))
->options(self::createGalleryArray())
->selected($selected);
}
/**
2009-08-03 03:36:03 +00:00
* Called after a user had been edited by the admin
*/
static function user_edit_form_admin_completed($user, $form) {
$home = ORM::factory("user_home")->where("id", $user->id)->find();
2009-08-03 03:36:03 +00:00
$home->id = $user->id;
$home->home = $form->edit_user->user_home->value;
$home->save();
}
/**
2009-08-03 03:36:03 +00:00
* Called when user is editing their own form
*/
static function user_edit_form($user, $form) {
$home = ORM::factory("user_home")->where("id", $user->id)->find();
2009-08-03 03:36:03 +00:00
if ($home->loaded) {
$selected = $home->home;
} else {
$selected = 0;
}
$form->edit_user->dropdown("user_home")
2009-08-03 03:36:03 +00:00
->label(t("Home Gallery"))
->options(self::createGalleryArray())
->selected($selected);
}
/**
2009-08-03 03:36:03 +00:00
* Called after a user had been edited by the user
*/
static function user_edit_form_completed($user, $form) {
$home = ORM::factory("user_home")->where("id", $user->id)->find();
2009-08-03 03:36:03 +00:00
$home->id = $user->id;
$home->home = $form->edit_user->user_home->value;
$home->save();
}
/**
2009-08-03 03:36:03 +00:00
* Creates an array of galleries
*/
static function createGalleryArray() {
$array[0] = "none";
$root = ORM::factory("item", 1);
self::tree($root, "", $array);
return $array;
}
/**
* recursive function to build array for drop down list
*/
static function tree($parent, $dashes, &$array) {
if ($parent->id == "1") {
$array[$parent->id] = "home";
} else {
$array[$parent->id] = "$dashes $parent->name";
}
$albums = ORM::factory("item")
2009-08-03 03:36:03 +00:00
->where(array("parent_id" => $parent->id, "type" => "album"))
->orderby(array("title" => "ASC"))
->find_all();
foreach ($albums as $album) {
self::tree($album, "-$dashes", $array);
}
return;
}
2009-07-24 23:11:02 +00:00
}