<?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
//
// +----------------------------------------------------------------------+
// | ezSqliteAdmin V0.1 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2004, Wenlong Wu <hide@address.com> |
// | Homepage http://www.phpsalon.com |
// | License GNU Lesser General Public License (LGPL) |
// +----------------------------------------------------------------------+
// | This library is free software; you can redistribute it and/or |
// | modify it under the terms of the GNU Lesser General Public |
// | License as published by the Free Software Foundation; either |
// | version 2.1 of the License, or (at your option) any later version. |
// +----------------------------------------------------------------------+
// | Authors: Wenlong Wu <hide@address.com> |
// +----------------------------------------------------------------------+
//
// $Id: MainDataView.php,v 1.3 2004/09/18 09:30:02 wenlong Exp $
//
require_once('MainDataModel.php');
/**
* MainDataView
*
* @package ezSqliteAdmin
* @version $Revision: 1.3 $
* @author Wenlong Wu <hide@address.com>
* @homepage http://www.phpsalon.com
* @copyright Copyright (c) 2004, Wenlong Wu
* @license http://opensource.org/licenses/lgpl-license.php
* @access public
*/
class MainDataView extends AView implements IView {
/**
* contains MainDataModel class
*
* @access private
* @var object
*/
private $model = null;
/**
* Constructor
*/
public function __construct() {
$this->model = MainDataModel::getInstance();
}
/**
* build list header
*
* @access public
* @return string
*/
private function buildListHead() {
$fields = $this->model->getFields();
$count = count($fields);
$xul = '<listcols>';
$xul .= str_repeat('<listcol />', $count);
$xul .= '</listcols>';
$xul .= '<listhead allowevents="true">';
foreach ($fields as $field) {
$xul .= '<listheader label="'. $field['name'] .'" />';
}
$xul .= '</listhead>';
return $xul;
}
/**
* build list item
*
* @access public
* @return string
*/
private function buildListItem() {
$values = $this->model->getValues();
$xul = '';
foreach ($values as $row) {
//print_r($row);
$xul .= '<listitem>';
foreach ($row as $item) {
$xul .= '<listcell label="'. $item .'" />';
}
$xul .= '</listitem>';
}
return $xul;
}
/**
* Prepare XUL for output
*
* @access public
* @return string XUL
*/
public function render() {
$record_isfirst = $this->model->isFirstPage() ? ' disabled="true"' : '';
$record_islast = $this->model->isLastPage() ? ' disabled="true"' : '';
$record_hasprev = $this->model->hasPrevPage() ? '' : ' disabled="true"';
$record_hasnext = $this->model->hasNextPage() ? '' : ' disabled="true"';
$xul = <<<EOD
<!--
<popupset>
<popup id="datamenu">
<menuitem label="Add record"/>
<menuitem label="Edit record"/>
<menuitem label="Delete record"/>
</popup>
</popupset>
-->
<hbox>
<!--<toolbar id="dataBrowserToolbar">-->
<toolbarbutton image="images/record_first.png" $record_isfirst />
<toolbarbutton image="images/record_prev.png" $record_hasprev />
<toolbarbutton image="images/record_next.png" $record_hasnext />
<toolbarbutton image="images/record_last.png" $record_islast />
<toolbarseparator/>
<toolbarbutton image="images/apply.png" onclick="parent.addLogMessage('test');"/>
<toolbarbutton image="images/cancel.png" />
<!--</toolbar>-->
</hbox>
<listbox flex="1" context="datamenu">
EOD;
if (!$this->model->isEmpty()) {
$xul .= $this->buildListHead();
$xul .= $this->buildListItem();
}
$xul .= '</listbox>';
return $xul;
}
}
?>