PrintQueueAction
<?php require_once "autoload.php";
class PrintQueueAction extends SourcesAction
{
public function __construct($model)
{
parent::__construct($model);
$this->path = array("./USER/PRINTS/");
$this->view = new PrintQueueView($this);
}
public function edit()
{
$am = ApplicationManager::getInstance();
return $am->notify("EDIT_PRINTS", null);
}
public function loadActions()
{
if($this->actionMode == true)
{
$cm = ContentManager::getInstance();
$result = $cm->getResources(array("./ACTIONS/PRINT/","./ACTIONS/EDIT/"),$this->actionCollection);
$result = ($result & $cm->getChildResources(array("./ACTIONS/EDIT/"), $this->actionCollection));
if (!$result)
{
return false;
}
return true;
}
}
/*
public function action($ids)
{
$ret = false;
$id = reset($ids);
$am = ApplicationManager::getInstance();
switch ($id)
{
case "./ACTIONS/PRINT/":
echo "PrintQueueAction.print";
break;
case "./ACTIONS/EDIT/
break;
case "./ACTIONS/EDIT/ROTATE90/";
echo "PrintQueueAction.rotate90";
break;
default:
echo "PrintQueueAction.unknown";
break;
}
}*/
}
?>
SourcesAction
<?php require_once "autoload.php";
class SourcesAction extends ExploreAction
{
protected $actionCollection;
public function __construct($model)
{
parent::__construct($model);
$pm = PersistenceManager::getInstance();
$this->actionMode = $pm->load("ACTION_MODE");
$this->path = $model["path"];
$this->selectionKey = "./USER/SOURCE_SELECTION/";
$this->checkedIds = $model["checkedIds"];
$this->view = new SourcesView($this);
}
public function view()
{
$this->loadActions();
parent::view();
}
public function loadActions()
{
$cm = ContentManager::getInstance();
$result = $cm->getChildResources(array("./USER/ACTIONS/"), $this->actionCollection);
if (!$result)
{
$am = ApplicationManager::getInstance();
$am->notify("AUTHENTICATE", null);
return false;
}
return true;
}
public function editActions()
{
$am = ApplicationManager::getInstance();
return $am->notify("EDIT_ACTIONS", null);
}
public function action($ids)
{
$ret = false;
$id = reset($ids);
$am = ApplicationManager::getInstance();
switch ($id)
{
case "./ACTIONS/SHARE/":
$model["checkedIds"] = $this->checkedIds;
$ret = $am->notify("SHARE", $model);
break;
case "./ACTIONS/QUEUEPRINT/":
$pm = PersistenceManager::getInstance();
$list = $pm->load("./USER/PRINTS/");
foreach ($this->checkedIds as $checkedId)
{
$list[] = $checkedId;
}
$pm->save("./USER/PRINTS/", array_unique($list));
$ret = $am->notify("SELF", $this->getModel());
break;
case "./ACTIONS/VIEW/":
$ret = $this->detail($this->checkedIds);
break;
case "./ACTIONS/EDIT/":
$ret = $am->notify("EDIT_PRINTS",$this->getModel());
default:
echo "SourcesAction.action";
break;
}
return $ret;
}
public function toggleActionMode()
{
$this->actionMode = !$this->actionMode;
$pm = PersistenceManager::getInstance();
$pm->save("ACTION_MODE",$this->actionMode);
$am = ApplicationManager::getInstance();
return $am->notify("SELF",null);
}
}
?>
ExploreAction
<?php require_once "autoload.php";
class ExploreAction extends ViewAction
{
/*The path is the current directory the user has navigated to. The view populates data based on
where we have pathed to.*/
protected $path;
/*The selectionKey represents objects that have already been selected by the user. For example
if a user adds a target to his "mobile albums," this target is stored in ./USER/TARGET_SELECTION.
Setting the selectionKey to ./USER/TARGET_SELECTION will notify the view that the user has already selected
the "mobile albums" target.*/
protected $selectionKey;
/*checkedIds represents objects that the user has selected in previous paths. */
protected $checkedIds;
protected $resourceCollection;
/*selectedId represents a focused item. Used by the singleImageAction/view to select one image.*/
protected $selectedId;
public function __construct($model)
{
parent::__construct($model);
$this->checkedIds = $model["checkedIds"];
$this->path = $model["path"];
}
/* Equivalent to clicking a source. Details handles how we procede from the current state.
In this explore context, we execute SAME.
*/
public function detail($ids)
{
$this->path = $ids;
$am = ApplicationManager::getInstance();
return $am->notify("SAME", $this->getModel());
}
public function navigateDetail($ids)
{
$model["path"] = $ids;
$model["selectedId"] = $this->selectedId;
$am = ApplicationManager::getInstance();
return $am->notify("NAVIGATE",$model);
}
public function imageDetail($ids)
{
$tm = TransactionManager::getInstance();
$top = $tm->top();
//echo print_r($ids,true);
$topModel = $top->get("model");
$this->path = $topModel["path"];
//echo "here".print_r($top->get("businessAction"),true);
//$newModel["path"] = $this->path;
//needs bound checking on size of $ids array
// echo "here".print_r($top->get("model"),true);
$this->selectedId = $ids[0];
//when i echo, the stack doesnt grow... seems weird
//INFOUT($model["selectedId"]."Model selectedId");
$am = ApplicationManager::getInstance();
return $am->notify("VIEW_IMAGE", $this->getModel());
}
public function getModel()
{
// echo("Expensive getModel() call used");
if($this->path)
$model["path"] = $this->path;
if($this->selectionKey)
$model["selectionKey"] = $this->selectionKey;
// $model["checkedIds"] = $this->checkedIds;
// if($this->resourceCollection)
// $model["resourceCollection"] = $this->resourceCollection;
if($this->selectedId)
$model["selectedId"] = $this->selectedId;
return $model;
}
public function view()
{
if ($this->load())
return parent::view();
return false;
}
public function load()
{
$cm = ContentManager::getInstance();
$result = $cm->getChildResources($this->path, $this->resourceCollection);
if (!$result)
{
$am = ApplicationManager::getInstance();
$am->notify("AUTHENTICATE", null);
return false;
}
$pm = PersistenceManager::getInstance();
$selectedResourceIds = $pm->load($this->selectionKey);
if (!$selectedResourceIds)
$selectedResourceIds = array();
foreach ($this->resourceCollection as $resource)
{
$resource->set("selected", in_array($resource->get("id"), $selectedResourceIds));
$index = array_search($resource->get("id"), $selectedResourceIds);
if ($index === false)
continue;
unset($selectedResourceIds[$index]);
}
$pm->save($this->selectionKey, $selectedResourceIds);
return true;
}
public function save()
{
$pm = PersistenceManager::getInstance();
$selectedResourceIds = $pm->load($this->selectionKey);
if (!$selectedResourceIds)
$selectedResourceIds = array();
if (!$this->checkedIds)
{
$this->checkedIds = array();
}
$selectedResourceIds = array_unique(array_merge($selectedResourceIds, $this->checkedIds));
$pm->save($this->selectionKey, $selectedResourceIds);
return true;
}
public function back()
{
//$this->save();
$am = ApplicationManager::getInstance();
$am->notify("BACK", null);
}
public function cancel()
{
echo "ExploreAction.cancel - not fully implemented";
//$this->save();
$am = ApplicationManager::getInstance();
$am->notify("CANCEL", null);
}
public function done()
{
$am = ApplicationManager::getInstance();
$am->notify("DONE", null);
}
}
?>
ViewAction
<?php require_once "autoload.php";
abstract class ViewAction extends RouterAction
{
protected $view;
public abstract function save();
public function execute()
{
$this->save();
if (!$this->method)
$this->method = "view";
parent::execute();
}
public abstract function getModel();
public function view()
{
$ret = false;
do
{
$err = get_class($this)." - ViewAction:start - ";
if (!$this->view)
{
ERROUT($err."no view defined for this action");
break;
}
if (!$this->view->compose())
{
ERROUT($err."view ".get_class($this->view)." failed to compose");
break;
}
$pm = PersistenceManager::getInstance();
$pm->commit();
if (!$this->view->render())
{
ERROUT($err."view ".get_class($this->view)." failed to render");
break;
}
$ret = true;
} while (false);
return $ret;
}
}
?>
RouterAction
<?php require_once "autoload.php";
abstract class RouterAction extends Action
{
protected $method;
protected $methodName;
protected $args;
public function __construct($model)
{
parent::__construct($model);
do
{
$this->method = $model["method"];
if (!$this->method)
{
break;
}
} while (false);
}
public function execute()
{
$ret = false;
do
{
if (!$this->method)
{
ERROUT(get_class($this).":execute - Method not provided.");
break;
}
$this->methodName = $this->method;
if (is_array($this->method))
{
$this->methodName = reset(array_keys($this->method));
}
if (!is_string($this->methodName))
{
ERROUT(get_class($this)." - RouterAction:__construct - Method name incorrect format.");
break;
}
preg_match("/^([^\(]+)(\((.*)\))?/", $this->methodName, $params);
if ($params[1] != null)
{
$this->methodName = $params[1];
$this->args = preg_split("/,/", $params[3]);
foreach (array_keys($this->args) as $key)
{
preg_match("/{(.*)}/", $this->args[$key], $tokens);
if (!$tokens)
continue;
$this->args[$key] = preg_split("/;/", $tokens[1]);
}
}
$ret = call_user_func_array(array($this, $this->methodName), $this->args);
} while (false);
return $ret;
}
}
?>
Action
<?php require_once "autoload.php";
abstract class Action extends Bean
{
protected $action;
public function __construct($model)
{
parent::__construct();
//$this->map_to_vars($model);
}
public abstract function execute();
}
?>
Bean
<?php include_once "autoload.php";
abstract class Bean
{
public function set($field, &$value) { $this->$field = $value; }
public function &get($field) { return $this->$field; }
public function __construct()
{
}
public function map_to_vars(&$map)
{
foreach (array_keys(get_object_vars($this)) as $key)
{
$this->$key = $map[$key];
}
}
}
?>