* @license PHP License * @package WB * @subpackage base */ WBClass::load('WBWxml_Dialog'); /** * Wxml Dialog Module * * Table * * @version 0.1.0 * @package WB * @subpackage base */ class WBWxml_Dialog_Tablesheet extends WBWxml_Dialog { /** * @var WBDatasource_Table_Sheet */ private $ds; /** * Construtor */ public function __construct() { parent::__construct(); $this->ds = WBClass::create('WBDatasource_Table_Sheet'); } private function getDefaultRows() { $rows = array(); $rows[] = array( array( 'rowno' => 0, 'columnno' => 0, 'body' => '', 'class' => '' ), array( 'rowno' => 0, 'columnno' => 1, 'body' => '', 'class' => '' ) ); $rows[] = array( array( 'rowno' => 1, 'columnno' => 0, 'body' => '', 'class' => '' ), array( 'rowno' => 1, 'columnno' => 1, 'body' => '', 'class' => '' ) ); return $rows; } /** * Start dialog using default values * */ public function start() { $this->value = trim($this->value); if (empty($this->value)) { $this->selectTable(); return; } $this->submit(); } /** * Select existing table * * @todo make use of pager */ private function selectTable() { $pager = $this->ds->getPager(); $info = $pager->browse($this->req->get('goto', '__first')); $list = $pager->get(); $this->loadTemplates('tablesheet_list'); $this->tmpl->addGlobalVars($info, 'pager_'); $this->tmpl->addRows('list_entry', $list); } /** * Submit function * * Default implementation: process form */ public function submit($values = array()) { $this->setValue($this->req->get('val')); if (!$this->req->get('save', false) && '__new' != $this->value) { $values = $this->ds->get($this->value); // copy table? if ('copytable' == $this->req->get('tableaction')) { $values['title'] .= ' - Kopie'; $this->setValue('__new'); $this->req->set('val', '__new'); } } $rows = $this->ds->getRows(); if (empty($rows)) { $rows = $this->getDefaultRows(); } $this->loadTemplates('table'); foreach ($rows as $r) { $this->tmpl->addVars('table_row', $r[0]); $this->tmpl->addRows('table_cell', $r); $this->tmpl->parseTemplate('table_row', 'a'); $this->tmpl->clearTemplate('table_cell'); } parent::submit($values); } /** * Form "Tablesheet" validated * * @param patForms $forn * @param array $values * @return bool always true - display valid-template */ protected function onTablesheetValid($forn, $values) { if (empty($this->value)) { $this->value = '__new'; } $this->setValue($this->ds->set($this->value, $values)); /** @var $hdl WBMarkup_Handler_Wxml2Xml */ $hdl = WBClass::create( 'WBMarkup_Handler_Wxml2Xml' ); /** @var $scan WBMarkup_Scanner */ $scan = WBClass::create( 'WBMarkup_Scanner' ); $scan->setHandler($hdl); $rows = $this->req->get('row'); $save = array(); foreach ($rows as $r) { $s = array(); foreach ($r as $v) { $scan->scan($v); $s[] = array( 'class' => '', 'body' => $hdl->getParsedContent() ); } $save[] = $s; } $this->ds->setRows($this->value, $save); $this->tmpl->addGlobalVars($values); return true; } }