* @license PHP License * @package WB * @subpackage content */ /** * Load base class */ WBClass::load('WBContent'); /** * Content component: Guestbook * * @version 0.1.1 * @package WB * @subpackage content */ class WBContent_Guestbook extends WBContent { /** * my parameter list * @var array */ protected $config = array( 'requiredgroup' => '', 'process' => 'list', 'goto' => '0', 'limit' => 20 ); /** * table * @var WBDatasource_Table */ protected $table; /** * id of current guestbook article * @var string */ protected $id = '__new'; /** * constructor * * Start table object */ public function __construct() { parent::__construct(); $this->table = WBClass::create('WBDatasource_Table'); } /** * run * * run component * * @return array parameter list */ public function run() { // display list is default if (!in_array($this->config['process'], array('edit', 'add', 'rm'))) { $this->loadTemplates('list'); $this->show(); return $this->config; } // load article $entry = array(array()); $this->id = $this->req->get('id', '__new'); if ($this->config['process'] == 'add') { $this->id = '__new'; } // administrators may delete other's guestbook entries but not edit them $foreign = $this->user->getId(); if ($this->config['process'] == 'rm' && $this->isUserInGroup('admin')) { $foreign = null; } // load entry if($this->id != '__new') { $entry = $this->table->get('guestbook', $this->id, $foreign); } if (count($entry) != 1) { $entry = array(array()); $this->id = '__new'; } $entry = $entry[0]; $this->tmpl->addGlobalVar('id', $this->id); $this->tmpl->addGlobalVars($entry); if ($this->config['process'] == 'rm' && $this->id != '__new') { if ($this->req->get('force', 'no') != 'yes') { $this->loadTemplates('rm'); return $this->config; } $this->table->delete('guestbook', $this->id, $foreign); $this->loadTemplates('rmDeleted'); return $this->config; } $this->processForm('edit', $entry); return $this->config; } /** * auxilliary function to show load and display guestbook pager * * */ protected function show() { $clause = array(); $options = array(); if ($this->config['limit']) { $options['limit'] = $this->config['limit']; } // initialize guestbook pager $pager = $this->table->getPager($this->part . __CLASS__, 'guestbook', null, $clause, $options); $pinfo = $pager->browse($this->config['goto']); $list = $pager->get(); $this->tmpl->addGlobalVars($pinfo, 'pager_'); $this->tmpl->addRows('list_entry', $list); } /** * receive output * * fetch output of this content component * * @return string */ public function getString() { return $this->tmpl->getParsedTemplate( 'snippet' ); } /** * Save guestbook entry * * save record in guestbook * * @param patForms $form * @param array $values */ public function onEditValid($form, $values) { $values['uid'] = $this->user->getId(); $this->table->save('guestbook', $this->id, $values); return true; } /** * location of form config * * Return sub directory where form element definitions are located * * @return string folder */ protected function getFormConfigDir() { return 'guestbook'; } } ?>