* @license PHP License * @package WB * @subpackage content */ /** * Load classes */ WBClass::load('WBContent' , 'WBITS'); /** * Content component: ITS_Editor * * @version 1.1.0 * @package WB * @subpackage content */ class WBContent_ITS_Editor extends WBContent { /** * Parameter list * - action either "edit", "add", "list" * - requiredgroup (tableeditor) * - requiredgroupmanager (tableadmin) * - searchfields (array()) list of columns that are allowed to search in using LIKE * @var array */ protected $config = array( 'action' => 'list', 'requiredgroup' => 'its-staff', 'requiredgroupmanager' => 'its-master', 'goto' => '1', 'searchfields' => array('title', 'blurb') ); /** * Backend * @var WBITS */ private $its; /** * Current ticket * @var WBITS_Ticket */ private $ticket; /** * 2nd constructor * * Called after configuration was done */ protected function init() { $parameter = array( 'tmpl' => $this->tmpl, 'tmplDir' => $this->config['tmplDir'], 'req' => $this->req, 'formConfigDir' => $this->getFormConfigDir() ); $this->its = WBClass::create('WBITS', $parameter); } /** * run * * run component * * @return array parameter list */ public function run() { if (!$this->isUserInGroup($this->config['requiredgroup'])) { $this->loadTemplates('anon'); return $this->config; } $this->its->initFilter($this->config['searchfields']); switch ($this->config['action']) { case 'edit': case 'add': if (!$this->editTicket()) { break; } default: case 'list': $this->listTickets(); break; } return $this->config; } /** * Show form to edit ticket * * @return bool true if ticket was saved, false to display form */ private function editTicket() { $save = $this->req->get('save', ''); $this->ticket = $this->its->loadByObscureId($this->req->get('obscureid', '')); // normal edit stuff $this->tmpl->addGlobalVar('obscureid', $this->ticket->getObscureId()); $this->tmpl->addGlobalVar('id', $this->ticket->getId()); $ret = $this->processForm('edit', $this->ticket->getData()); if (is_bool($ret)) { return $ret; } return false; } /** * Save ticket data * * Update ticket data * * @param patForms $form * @param array $values * @return bool always false */ public function onEditValid($form, $values) { $this->ticket->save($values); return false; } /** * List tickets * * Get pager and fill template with list */ private function listTickets() { $pager = $this->its->getPager(); $this->tmpl->addGlobalVars($pager->browse($this->config['goto']), 'pager_'); $this->loadTemplates('list'); $this->tmpl->addRows('list_entry', $pager->get()); } /** * receive output * * fetch output of this content component * * @return string */ public function getString() { return $this->tmpl->getParsedTemplate('snippet'); } /** * location of form config * * Return sub directory where form element definitions are located * * @return string folder */ protected function getFormConfigDir() { return strtolower($this->config['tmplDir']); } }