<?php
/*
Views.php, provides classes for working with multiple views
Copyright (C) 2005 Arend van Beelen, Auton Rijnsburg
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.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
For any questions, comments or whatever, you may mail me at: hide@address.com
*/
require_once('GUI.php');
require_once('Locale.php');
require_once('Login.php');
require_once('Widgets.php');
require_once('Windows.php');
/**
* @brief A container for multiple views
*
* This is a special container which can be used to group views. The container
* will then take care of displaying the correct view.
*
* A view container will use a request variable which equals the ID of the
* container to determine which view to display. Once a view is set, this view
* is remembered in a session variable. If the request variable 'button' is set
* to i18n('Cancel'), the view container will look for another request variable
* named "{$id}_cancel" and change its view to the value of this variable if
* this variable is set.
*
* @since Aukyla 1.1
*/
class ViewContainer extends Container
{
/**
* Constructor.
*
* Creates a new view container.
*
* @param parent Container to add this view container to.
* @param id ID of the view container. This is also the request
* variable this container will use to detect which view
* to display.
*/
public function __construct(Container $parent, $id = 'view')
{
parent::__construct($parent);
if(Config::request("{$id}_cancel") != '' &&
Config::request('button') == i18n('Cancel'))
{
$this->view = Config::request("{$id}_cancel");
Login::setSessionVariable($id, $this->view);
}
elseif(Config::request($id) != '')
{
$this->view = Config::request($id);
Login::setSessionVariable($id, $this->view);
}
else
{
$this->view = Login::sessionVariable($id);
}
}
/**
* Returns which view is requested for this container.
*
* @return The ID of the requested view.
*/
public function view()
{
return $this->view;
}
/**
* Overwrites the requested view by setting a new view to be shown.
*
* @param view The ID of the view which should be shown.
*/
public function setView($view)
{
$this->view = $view;
}
public function show()
{
$windowManager = WindowManager::instance();
$defaultView = null;
foreach($this->children as $child)
{
if($child->id() == $this->view)
{
$child->show();
return;
}
if($child->id() == 'default')
{
$defaultView = $child;
}
}
if($defaultView == null)
{
new Paragraph($this, i18n('The requested view could not be found.'));
parent::show();
}
else
{
$defaultView->show();
}
}
protected $children;
private $view;
}
/**
* @brief A view.
*
* Views are used for different interfaces within a window. By switching views,
* you switch to another interface. Use a view in combination with a
* ViewContainer which will take care of showing the correct view.
*
* @since Aukyla 1.1
*/
class View extends Container
{
/**
* Constructor.
*
* Creates a new View.
*
* @param parent ViewContainer to add this view to.
* @param id ID of this view. If ommitted, this view becomes the default
* view.
*/
public function __construct(ViewContainer $parent, $id = 'default')
{
parent::__construct($parent, $id);
}
}
?>