2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* This is a form decorator (a class that wraps around a form) providing us with some functions
|
|
|
|
* to display it in a Tabular style.
|
2008-01-09 05:18:36 +01:00
|
|
|
* @package forms
|
|
|
|
* @subpackage transformations
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2008-08-06 08:54:59 +02:00
|
|
|
class TabularStyle extends ViewableData {
|
2007-07-19 12:40:28 +02:00
|
|
|
protected $form;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represent the given form in a tabular style
|
|
|
|
* @param form The form to decorate.
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function __construct($form) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$this->form = $form;
|
2008-08-06 08:54:59 +02:00
|
|
|
$this->failover = $form;
|
|
|
|
parent::__construct();
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Return a representation of this form as a table row
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function AsTableRow() {
|
2007-07-19 12:40:28 +02:00
|
|
|
return "<tr class=\"addrow\">{$this->CellFields()}<td class=\"actions\">{$this->CellActions()}</td></tr>";
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function CellFields() {
|
2007-07-19 12:40:28 +02:00
|
|
|
$result = "";
|
|
|
|
$hiddenFields = '';
|
|
|
|
foreach($this->form->Fields() as $field) {
|
|
|
|
if(!$field->is_a('HiddenField')) {
|
|
|
|
$result .= "<td>" . $field->Field() . "</td>";
|
|
|
|
} else {
|
|
|
|
$hiddenFields .= $field->Field();
|
|
|
|
}
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
// Add hidden fields in the last cell
|
|
|
|
$result = substr($result,0,-5) . $hiddenFields . substr($result,-5);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function CellActions() {
|
2007-07-19 12:40:28 +02:00
|
|
|
$actions = "";
|
2008-08-06 08:54:59 +02:00
|
|
|
foreach($this->form->Actions() as $action) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$actions .= $action->Field();
|
|
|
|
}
|
|
|
|
return $actions;
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This is the 'wrapper' aspect of the code
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function __call($func, $args) {
|
2007-07-19 12:40:28 +02:00
|
|
|
return call_user_func_array(array(&$this->form, $func), $args);
|
|
|
|
}
|
2012-09-19 12:07:39 +02:00
|
|
|
public function __get($field) {
|
2007-07-19 12:40:28 +02:00
|
|
|
return $this->form->$field;
|
|
|
|
}
|
2012-09-19 12:07:39 +02:00
|
|
|
public function __set($field, $val) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$this->form->$field = $val;
|
|
|
|
}
|
|
|
|
}
|