/**
* The required files
*/
require_once(HTML_BASE_COMMON_PATH.'/Html.php');
require_once(HTML_TABLE_COMPONENT_PATH.'/TableHeader.php');
require_once(HTML_TABLE_COMPONENT_PATH.'/Table.php');
if (defined('HTML_DB_LOGIN_VIEW_PATH')) {
require_once(HTML_DB_LOGIN_VIEW_PATH.'/ViewLogin.php');
}
if (defined('HTML_DB_BASKET_VIEW_PATH')) {
require_once(HTML_DB_BASKET_VIEW_PATH.'/ViewBasket.php');
}
if (defined('HTML_DB_CUSTOMER_VIEW_PATH')) {
require_once(HTML_DB_CUSTOMER_VIEW_PATH.'/ViewCustomerList.php');
}
if (defined('HTML_DB_SEARCH_VIEW_PATH')) {
require_once(HTML_DB_SEARCH_VIEW_PATH.'/ViewSearchForm.php');
require_once(HTML_DB_SEARCH_VIEW_PATH.'/ViewSearchList.php');
}
require_once(HTML_MVC_VIEW_PATH.'/ViewList.php');
require_once(HTML_MVC_VIEW_PATH.'/ViewPlain.php');
require_once(HTML_MVC_VIEW_PATH.'/ViewDetail.php');
require_once(HTML_MVC_VIEW_PATH.'/ViewSimple.php');
require_once(HTML_MVC_VIEW_PATH.'/ViewForm.php');
require_once(HTML_MVC_VIEW_PATH.'/ViewBusinessCard.php');
require_once(HTML_MVC_VIEW_PATH.'/ViewInfo.php');
if (defined('HTML_SAX_VIEW_PATH')) {
require_once(HTML_SAX_VIEW_PATH.'/ViewXmlReader.php');
}
require_once(HTML_DTO_UTIL_PATH.'/DataReader.php');
if (defined('HTML_LOG_UTIL_PATH')) {
require_once(HTML_LOG_UTIL_PATH.'/Log.php');
}
/**
* The Grid object is respponsible for all the different views like a form. a list or a basket view
* It Generates the html for a Grid through the layout parameter
* <code>
* Usage:
* $command = new Command();
* $sql = "SELECT * FROM table WHERE ID=1"
* $datareader = $command->newDataReader($sql);
* Or
* $datareader = DatareaderFactory::newDatareader($sql);
*
* // Create the view
* $layout = GRID_LAYOUT_VIEW_DETAIL;
* $text = 'The text header to use';
* $grid = new Grid($datareader, $layout, $text);
* print $grid->getHtml();
* Or
* Grid::display($datareader, $layout, $text);
* Or
* // Get the view as an object
* $grid = new Grid($datareader, $layout, $text);
* $view = $grid->newView();
* print $view->getHtml();
*
*
* Generates a complete grid interface
* +--------------------------------
* | Text header
* +--------------------------------
* | head1 | head2 | head3 | etc
* +--------------------------------
* | dat_1 | dat_2 | dat_3 | etc
* +--------------------------------
* </code>
* @package mvc
*/
class Grid extends Html {
/**
* @var DataReader $datareader The Data Reader object to use
*/
var $datareader = '';
/**
* @var String $layout The layout to use
*/
var $layout = '';
/**
* @var String $text The text header to use
*/
var $text = '';
/**
* Constructor
* @param DataReader $datareader The Data Reader object
* @param String $layout The layout to use
* @param String $text The text header to use
*/
function Grid($datareader='',$layout='', $text='') {
$this->Html();
$this->layout = $layout!=''?$layout:GRID_LAYOUT_VIEW_PLAIN;
$this->datareader = $datareader!=''?$datareader:new DataReader();
if (!is_a($this->datareader,DATA_READER_CLASS_NAME)) {
$msg = $this->getClassName().'->sanityCheck(), Wrong object, expected: '.CLASS_NAME_DATA_READER.' found: '.$this->datareade;
if (defined('HTML_LOG_UTIL_PATH')) {
Log::fatal(__FILE__,__LINE__,$msg);
$html = $this->getMsg(LOG_LEVEL_FATAL, $msg);
} else {
die('File: '.__FILE__."<br />\r\nLine: ".__LINE__."<br />\r\n".$msg);
}
}
$this->text = $text;
}
/**
* Return the data as a new ViewSearcForm object
* @return object The requested view object
*/
function newViewSearchForm() {
return new ViewSearchForm($this->datareader,$this->text);
}
/**
* Return the data as a new ViewSearchList object
* @return object The requested view object
*/
function newViewSearchList() {
return new ViewSearchList($this->datareader,$this->text);
}
/**
* Return the data as a new ViewList object
* @return object The requested view object
*/
function newViewList() {
return new ViewList($this->datareader,$this->text);
}
/**
* Return the data as a new ViewForm object
* @return object The requested view object
*/
function newViewForm() {
return new ViewForm($this->datareader,$this->text);
}
/**
* Return the data as a new ViewLogin object
* @return object The requested view object
*/
function newViewLogin() {
if (defined('HTML_DB_LOGIN_VIEW_PATH')) {
return new ViewLogin($this->datareader,$this->text);
} else {
return new Raw("<!-- ".$this->getClassName()."->newViewLogin() is disabled because of HTML_DB_LOGIN_VIEW_PATH -->\r\n");
}
}
/**
* Return the data as a new ViewDetail object
* @return object The requested view object
*/
function newViewDetail() {
return new ViewDetail($this->datareader,$this->text);
}
/**
* Return the data as a new ViewSimple object
* @return object The requested view object
*/
function newViewSimple() {
return new ViewSimple($this->datareader,$this->text);
}
/**
* Return the data as html a new ViewBasket object
* @return object The requested view object
*/
function newViewBasket() {
if (defined('HTML_DB_BASKET_VIEW_PATH')) {
return new ViewBasket($this->datareader,$this->text);
} else {
return new Raw("<!-- ".$this->getClassName()."->newViewBasket() is disabled because of HTML_DB_BASKET_VIEW_PATH -->\r\n");
}
}
/**
* Return the data as a new ViewCustomerList object
* @return object The requested view object
*/
function newViewCustomerList() {
if (defined('HTML_DB_CUSTOMER_VIEW_PATH')) {
return new ViewCustomerList($this->datareader,$this->text);
} else {
return new Raw("<!-- ".$this->getClassName()."->newViewCustomerList() is disabled because of HTML_DB_CUSTOMER_VIEW_PATH -->\r\n");
}
}
/**
* Return the data as a new ViewPlain object
* @return object The requested view object
*/
function newViewPlain() {
return new ViewPlain($this->datareader,$this->text);
}
/**
* Return the data as a new ViewBusinessCard object
* @return object The requested view object
*/
function newViewBusinessCard() {
return new ViewBusinessCard($this->datareader,$this->text);
}
/**
* Return the data as a new ViewInfo object
* @return object The requested view object
*/
function newViewInfo() {
return new ViewInfo($this->datareader,$this->text);
}
/**
* Return the data as new ViewXMLReader data object
* @return object The requested view object
*/
function newViewXmlReader() {
if (defined('HTML_SAX_VIEW_PATH')) {
return new ViewXmlReader($this->datareader,$this->text);
} else {
return new Raw("<!-- ".$this->getClassName()."->newViewXmlReader() is disabled because of HTML_SAX_VIEW_PATH -->\r\n");
}
}
/**
* Return the view as a new View object
* <code>
* Usage:
* $grid = new Grid($datareader, $layout, $text);
* $view = $grid->newView();
* print $view->getHtml();
* </code>
* @return object The requested view object
*/
function newView() {
$view = new Raw();
switch ($this->layout) {
case GRID_LAYOUT_VIEW_SEARCH_FORM:
$view = $this->newViewSearchForm();
break;
case GRID_LAYOUT_VIEW_SEARCH_LIST:
$view = $this->newViewSearchList();
break;
case GRID_LAYOUT_VIEW_LIST:
$view = $this->newViewList();
break;
case GRID_LAYOUT_VIEW_FORM:
$view = $this->newViewForm();
break;
case GRID_LAYOUT_VIEW_LOGIN:
$view = $this->newViewLogin();
break;
case GRID_LAYOUT_VIEW_DETAIL:
$view = $this->newViewDetail();
break;
case GRID_LAYOUT_VIEW_SIMPLE:
$view = $this->newViewSimple();
break;
case GRID_LAYOUT_VIEW_BASKET:
$view = $this->newViewBasket();
break;
case GRID_LAYOUT_VIEW_CUSTOMER_LIST:
$view = $this->newViewCustomerList();
break;
case GRID_LAYOUT_VIEW_XML_READER:
$view = $this->newViewXmlReader();
break;
case GRID_LAYOUT_VIEW_PLAIN:
$view = $this->newViewPlain();
break;
case GRID_LAYOUT_VIEW_BUSINESS_CARD:
$view = $this->newViewBusinessCard();
break;
case GRID_LAYOUT_VIEW_INFO:
$view = $this->newViewInfo();
break;
default:
die($this->getClassName().", Unknown GRID_LAYOUT_VIEW_xxx, found=".strtoupper(dechex($this->layout)));
break;
}
return $view;
}
/**
* Return the html
* @return String The html
*/
function getHtml() {
$html = $this->html;
$view = $this->newView();
$html .= $view->getHtml();
return $html;
}
/**
* Display html
* <code>
* Usage:
* Grid::display($datareader,$layout,$text);
* </code>
* @static
* @param DataReader $datareader The Data Reader object
* @param String $layout The layout to use
* @param String $text The text header to use
*/
function display($datareader,$layout='',$text='') {
$html = new Grid($datareader,$layout,$text);
$html->addHtml();
}
}
?>