|
|
|
|
File: [Development] / advokit-installer-bak / BaseAction.class.php
(download)
/
(as text)
Revision: 1.3, Thu Jul 8 12:58:55 2004 UTC (6 years, 2 months ago) by travislow Branch: MAIN CVS Tags: r1-1-1-alpha-00, r1-1-0-alpha-00, r0-9-5, r0-9-0, r-0-8-5, r-0-8-2, r-0-8-1, r-0-8-0, HEAD Changes since 1.2: +22 -4 lines adding license. |
<?
# ======================================================================
# AdvoKit -- a campaign managment tool
# Copyright (C) 2004 OrchidSuites, Inc. (info@orchidsuites.net)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the AFFERO GENERAL PUBLIC LICENSE
# as published by Affero, Inc.; either version 1
# 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
# AFFERO GENERAL PUBLIC LICENSE for more details.
#
# You should have received a copy of the AFFERO GENERAL PUBLIC LICENSE
# along with this program; if not, write to Affero, Inc. at
# 510 Third Street - Suite 225, San Francisco, CA 94107, USA
# or visit <http://www.affero.org>.
# ======================================================================
# ======================================================================
# Base Action class. Your own actions should extend this one.
# ======================================================================
class BaseAction
{
# Convenient wrapper for request-related information,
# db object, user object, and other stuff.
var $context = NULL;
# TRUE => this was just posted.
var $repost = NULL;
# TRUE => okay to repost.
var $okaytorepost = TRUE;
# Id of current logged in user.
var $person_id;
#.................................................. BaseAction
#
# Constructor. Pass in the context for the current
# request. If this action exists in the session,
# and is not timed out, then restore any state information.
#
# Subclass should call this constructor, then make
# any desired modifications to state information.
#
function BaseAction( &$context )
{
$this->context =& $context;
$this->context->logger->debug( __FILE__, "Creating instance of action ".$this->getName()."..." );
$this->displayinfo = array();
$this->context->logger->debug( __FILE__, "...instance of ".$this->getName()." created" );
$id = md5( serialize( $context->request->getParms() ) );
if( $_SESSION[$this->getName()] == $id )
{
$this->repost = TRUE;
}
else
{
$_SESSION[$this->getName()] = $id;
}
$this->person_id = $context->user->getId();
}
#.................................................. getName
#
# Return the name of this action, which is generally
# the same as the php filename. That is, action FooBar
# will be loaded from file FooBar.class.php.
#
# Subclasses should DEFINITELY override this function.
#
function getName()
{
return "BaseAction";
}
#.................................................. perform
#
# Perform this action.
#
function perform()
{
if( $this->repost && !$this->okaytorepost )
{
$this->setMessage( $this->getName().": Ignoring repost of previously posted information." );
$this->context->logger->debug( __FILE__, $this->getName().": Ignoring repost of previously posted information." );
$this->setDisplay( $this->context->ustate->getValue( $this->person_id, 0, '', '', "lastdisplay" ) );
$this->context->request->setParms( $this->context->ustate->getData( $this->person_id, 0, '', '', "lastparms" ) );
}
else
{
$this->context->logger->debug( __FILE__, "Performing action ".$this->getName()."..." );
$this->doPerform( $this->context->request );
$returndisplay = $this->context->request->get( "returndisplay" );
if( $returndisplay )
{
$this->setDisplay( $returndisplay );
}
$returnid = $this->context->request->get( "returnid" );
if( $returnid )
{
$this->context->request->set( "id", $returnid );
}
$this->context->logger->debug( __FILE__, "...".$this->getName()." performed." );
}
}
#.................................................. doPerform
#
# Really perform this action.
#
# Override this in the subclass. Any values you wish
# to display should be placed in $this->displayinfo.
#
function doPerform( &$request )
{
}
#.................................................. setDisplay
#
# Set the next display name in the context.
#
function setDisplay( $displayname )
{
$this->context->displayname = $displayname;
}
#.................................................. redisplay
#
# Redisplay whatever was displayed previously.
#
function redisplay()
{
$this->context->request->set( "redisplay", 1 );
}
#.................................................. setMessage
#
# Set the message in the context.
#
function setMessage( $message )
{
$this->context->message = $message;
}
#.................................................. appendMessage
#
# Append the message to the message the context.
#
function appendMessage( $message )
{
$this->context->message .= " ".$message;
}
#.................................................. set
#
# Set the value in the context, if $key has
# an interesting value.
#
function set( $key, $value )
{
if( isset( $key ) && $key != "" )
{
$this->context->set( $key, $value );
}
}
#.................................................. nullify
#
# Unset the value in the context, if $key has
# an interesting value.
#
function nullify( $key )
{
$this->context->nullify( $key );
}
#.................................................. setNonEmpty
#
# Set the value in the context, if both $key
# and $value have interesting values.
#
function setNonEmpty( $key, $value )
{
if( isset( $key ) && $key != "" && isset( $value ) && $value != "" )
{
$this->context->set( $key, $value );
}
}
#.................................................. get
#
# Get the value from the context, if it exists.
#
function get( $key )
{
return $context->get( $key );
}
}
?>
| cvsadmin@voter2voter.org | CVS Snapshots (updated daily) |