* @license PHP License * @package WB * @subpackage content */ /** * Load classes */ WBClass::load('WBContent' , 'WBContent_ITS' , 'WBITS'); /** * Content component: ITS_Ticket * * @version 1.0.0 * @package WB * @subpackage content */ class WBContent_ITS_Ticket extends WBContent_ITS { /** * Parameter list * @var array */ protected $config = array( 'captcha' => 'auto', 'action' => 'add', 'requiredgroup' => '', 'obscureid' => '', 'namespace' => '', 'titlebubbleformat' => 'Support Ticket: %s', 'titlebubblenotfound' => 'Support Ticket' ); /** * run * * run component * * @return array parameter list */ public function run() { unset($this->config['__path']); $this->tmpl->addGlobalVars($this->config, 'CONFIG_'); if (!$this->isUserInGroup($this->config['requiredgroup'])) { $this->loadTemplates('anon'); return $this->config; } switch ($this->config['action']) { case 'list': $this->listTicket(); break; case 'add': $this->processForm('edit'); break; case 'upload': $this->processForm('upload'); break; default: $this->displayTickets(); break; } return $this->config; } /** * List my tickets * * List tickets where this use account set as customer */ private function listTicket() { $pager = $this->its->getPager(WBITS::PAGER_TYPE_USER); $this->tmpl->addGlobalVars($pager->browse($this->config['goto']), 'pager_'); $this->loadTemplates('list'); $this->tmpl->addRows('list_entry', $pager->get()); } /** * Add Uploaded File to Ticket * * @param patForms $form * @param array $values */ protected function onUploadValid($form, $values) { $this->ticket = WBClass::create('WBITS_Ticket'); $this->ticket->loadByObscureId($this->config['obscureid']); $data = $this->ticket->getData(); $data['ticketmedia'][] = $values['file']; $save = array( 'ticketmedia' => $data['ticketmedia'] ); // save comment with file if (isset($values['filenote'])) { $save['comment'] = $values['filenote']; } $this->ticket->save($save); return true; } /** * Save ticket data * * Add new ticket * * @param patForms $form * @param array $values * @return bool always true */ protected function onEditValid($form, $values) { if ($this->user->isAuthenticated()) { $values['customeruid'] = $this->user->getId(); } // remove captcha, if set if (isset($values['captcha'])) { unset($values['captcha']); } // generate title from blurb if (!isset($values['title'])) { $blurb = $values['blurb']; $blurb = str_replace('

', "

\n", $blurb); $blurb = strip_tags($blurb); $blurb = str_replace(' ', ' ', $blurb); $blurb = trim($blurb); $blurb = array_map('trim', explode("\n", $blurb)); foreach ($blurb as $title) { $title = trim($title); if (5 > strlen($title)) { continue; } $values['title'] = $title; break; } } $this->ticket = WBClass::create('WBITS_Ticket'); $this->ticket->save($values); return true; } /** * List tickets * * Get pager and fill template with list */ private function displayTickets() { $this->loadTemplates('display'); $this->ticket = $this->its->loadByObscureId($this->config['obscureid']); $oid = $this->ticket->getObscureId(); if (empty($oid)) { $this->bubbles['title'] = $this->config['titlebubblenotfound']; return; } $data = $this->ticket->getData(); $this->bubbles['title'] = sprintf($this->config['titlebubbleformat'], $data['title']); $tmplData = array(); foreach ($data as $key => $value) { if (is_scalar($value)) { $tmplData[$key] = $value; continue; } foreach($value as $k => $v) { if (is_scalar($v)) { $tmplData[$key . '_' . $k] = $v; } } } $this->tmpl->addGlobalVars($tmplData); $this->tmpl->addGlobalVar('obscureid', $oid); $this->tmpl->addGlobalVar('id', $this->ticket->getId()); } /** * Fetch list of form elements * * Use different file regardless of actual form name. * * @param string name of form * @return array $elements */ protected function getFormElementList($name) { $list = parent::getFormElementList($name); if (!in_array($name, array('edit', 'upload'))) { return $list; } $this->injectElement4Captcha($list, $this->user->isAuthenticated(), $this->config['captcha']); if ('edit' != $name) { return $list; } // copy default values from user data if ($this->user->isAuthenticated()) { $userData = $this->user->getData(); // name if (isset($list['customername'])) { $list['customername']['attributes']['default'] = $userData['forename'] . ' ' . $userData['surname']; } // e-mail if (isset($list['customeremailurlid'])) { $list['customeremailurlid']['attributes']['default'] = $userData['email']; } // generic copy of user data if form element's name starts with "customer" foreach ($list as $key => &$value) { // those fields are done before if (in_array($key, array('customername', 'customeremailurlid'))) { continue; } if ( 0 != strncmp($key, 'customer', 8)) { continue; } $suffix = substr($key, 8); if (isset($userData[$suffix])) { $value['attributes']['default'] = $userData[$suffix]; } } } return $list; } }