Blame view

framework/forms/TabularStyle.php 1.51 KB
0084d336   Administrator   Importers CRUD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
  <?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.
   * @package forms
   * @subpackage transformations
   */
  class TabularStyle extends ViewableData {
  	protected $form;
  
  	/**
  	 * Represent the given form in a tabular style
  	 * @param form The form to decorate.
  	 */
  	public function __construct($form) {
  		$this->form = $form;
  		$this->failover = $form;
  		parent::__construct();
  	}
  	
  	/**
  	 * Return a representation of this form as a table row
  	 */
  	public function AsTableRow() {
  		return "<tr class=\"addrow\">{$this->CellFields()}<td class=\"actions\">{$this->CellActions()}</td></tr>";
  	}
  	
  	public function CellFields() {
  		$result = "";
  		$hiddenFields = '';
  		foreach($this->form->Fields() as $field) {
  			if(!$field->is_a('HiddenField')) {
  				$result .= "<td>" . $field->Field() . "</td>";
  			} else {
  				$hiddenFields .= $field->Field();
  			}
  		}
  		
  		// Add hidden fields in the last cell
  		$result = substr($result,0,-5) . $hiddenFields . substr($result,-5);
  		
  		return $result;
  	}
  
  	public function CellActions() {
  		$actions = "";
  		foreach($this->form->Actions() as $action) {
  			$actions .= $action->Field();
  		}
  		return $actions;
  	}
  	
  	
  
  	/**
  	 * This is the 'wrapper' aspect of the code
  	 */
  	public function __call($func, $args) {
  		return call_user_func_array(array(&$this->form, $func), $args);
  	}
  	public function __get($field) {
  		return $this->form->$field;
  	}
  	public function __set($field, $val) {
  		$this->form->$field = $val;
  	}
  }