* @license PHP License * @package WB * @subpackage content */ /** * Load classes */ // WBClass::load('WBContent'); /** * Wombat Incident Ticket System * * @version 1.0.0 * @package WB * @subpackage content */ class WBITS extends WBStdClass { /** * Table name */ const TABLE_TICKET = 'ticket'; const PAGER_TYPE_ALL = 'pager_all'; const PAGER_TYPE_USER = 'pager_user'; const PAGER_TYPE_COMPANY = 'pager_company'; /** * table * @var WBDatasource_Table_ITS */ protected $table; /** * @var WBFormProcessor_Filter */ private $filter; /** * Current configurateion */ static private $config = array(); /** * Current selected namespace, or empty for dynamic selection * @param string */ private $selectedNamespace = ''; /** * Constructor * */ public function __construct($parameter) { $parameter = array_merge(array( 'tmpl' => null, 'tmplDir' => null, 'req' => null, 'formConfigDir' => null ), $parameter); $this->filter = WBClass::create('WBFormProcessor_Filter'); $this->filter->setRequest($parameter['req']); $this->filter->setTemplate($parameter['tmpl'], $parameter['tmplDir']); $this->filter->setFormConfigDir($parameter['formConfigDir']); $this->table = WBClass::create('WBDatasource_Table_ITS'); $this->table->switchTranslation(false); } /** * Get ITS config * * Load from its/config.xml. Merge config with default values * Configuration parameter: * - obscurelength: length of obscure code for new tickets, recommended: min 2, max 5 * - namespace: default namespace * - namespaces: configuration of all available namespaces * * @todo strip max length * @return array */ static public function getConfig() { // load only once if (!empty(self::$config)) { return self::$config; } // load general config self::$config = array( 'obscurelength' => 3, 'namespace' => 'default', 'namespaces' => array() ); $config = WBClass::create('WBConfig'); if ($config->load('its/config', true)) { self::$config = array_merge(self::$config, $config->get('ticket', array())); } return self::$config; } /** * Use Namespace * * @todo strip max length * @param string */ public function useNamespace($ns = '') { if (empty($ns)) { $this->selectedNamespace = ''; return; } self::getConfig(); if (isset(self::$config['namespaces'][$ns])) { $this->selectedNamespace = $ns; return; } $this->selectedNamespace = self::$config['namespace']; } /** * Initlialize filter options * * Render and process filter form. * * @param array $searchfields * @return array template variables */ public function initFilter($searchfields = array()) { $searchfields = array_merge(array('title', 'blurb'), $searchfields); return $this->filter->buildClause($searchfields); } /** * Get ticket pager * * @return WBDatasource_Pager */ public function getPager($type = self::PAGER_TYPE_ALL) { $clause = $this->filter->getClause(); // force namespace? if (!empty($this->selectedNamespace)) { $clause[] = array( 'field' => 'namespace', 'value' => $this->selectedNamespace ); } switch ($type) { case self::PAGER_TYPE_ALL: break; default: case self::PAGER_TYPE_USER: $clause[] = array( 'field' => 'customeruid', 'value' => WBUser_Auth::getCurrent()->getId() ); break; } $id = __CLASS__ . ':' . self::TABLE_TICKET; $options = array( 'limit' => 10, 'callback' => WBClass::create('WBITS_DatasourceCallback') ); return $this->table->getPager($id, self::TABLE_TICKET, null, $clause, $options); } /** * Load ticket by obscureid id * * @param string $obscureid * @return WBITS_Ticket */ public function loadByObscureId($obscureid = null) { $parameter = array( 'table' => $this->table ); $ticket = WBClass::create('WBITS_Ticket', $parameter); if (empty($obscureid)) { return $ticket; } return $ticket->loadByObscureId($obscureid); } }