<?php

class TableColumn {



	public $ctrl;
    public $hidden = false;
    public $canHide = false;
    public $width = 'auto';
	public $sortable = null;
	public $renderer = null;



	public function buildCell(Table $table, TableRow $row, $record, $field, $i) {
		$out = $record[$field];
		if ($this->renderer) {
			$out = ActionService::execAction($this->renderer, array($table, $row, $record, $field, $i));
		}

		if ($out instanceof TableCell) {
			$row->add($out);
		} else {
			$tc = new TableCell();
			$tc->addText($out);
			$row->add($tc);
		}
	}



	public function buildHeader(Table $table, $field) {
		$th = new TableCell();
		$th->asHead = TRUE;
		$th->addText($this->text ? $this->text : '&nbsp;');

		if ($this->hidden) {
			;
		}

		if ($this->canHide) {
			;
		}

		if ($this->width) {
			$th->width = $this->width;
		}

		if ($this->sortable) {
			$a = $this->ctrl . '/orderBy';
			$descending = new Image();
			$descending->image = 'var/img/arrow-down.png';
			$descending->text = 'Descending';
			$descending->addListener(new ClickListener(new Action($a, array("'$field'", '1'))));
			$th->add($descending);
			$ascending = new Image();
			$ascending->image = 'var/img/arrow-up.png';
			$ascending->text = 'Ascending';
			$ascending->addListener(new ClickListener(new Action($a, array("'$field'", '0'))));
			$th->add($ascending);
		}

		return $th;
	}



} // class TableColumn

?>