* @package Wombat */ // WBClass::load('Airclip'); /** * FAQ Access * * @version 0.1.0 * @package Wombat */ class WBDatasource_FAQ extends WBStdClass implements WBDatasource_Callback { const TABLE_FAQ = 'faq'; const TABLE_FAQTYPE = 'faqtype'; /** * Table Access * @var WBDatasource_Table */ private $table; /** * Current Limit per Page / Fetch * @var int */ private $limit = 10; /** * Current Base Clause * @var array */ private $clause = array( array( 'field' => 'enabled', 'value' => 1 ) ); /** * Constructor * * @param array */ public function __construct($parameter = array()) { if (empty($parameter['table'])) { $parameter['table'] = WBClass::create('WBDatasource_Table', $parameter); } $this->table = $parameter['table']; } /** * Set Fetch Limit * * @param int */ public function setLimit($limit) { $this->limit = $limit; } /** * Get Base Clause * * @return array */ public function getClause() { return $this->clause; } /** * Set Base Clause * * @param array */ public function setClause($clause) { $this->clause = $clause; } /** * Get List Of Records For Type(s) * * Fetch FAQ items and return then * * @param array list of types * @return array */ public function get4Type($type = array('public')) { if (!is_array($type)) { $type = array($type); } if ('public' == $type[0]) { $type = $this->getPublicTypeId(); } $clause = $this->clause; $clause[] = array( 'field' => $this->table->getIdentifier(self::TABLE_FAQTYPE, true), 'relation' => 'in', 'value' => $type ); $option = array( 'limit' => $this->limit, 'order' => array( 'field' => 'changed', 'asc' => 0 ), 'callback' => $this ); return $this->table->get(self::TABLE_FAQ, null, null, $clause, $option); } /** * Get Ids of Public Types * * @return array */ private function getPublicTypeId() { $clause = array(); $clause[] = array( 'field' => 'requireuser', 'relation' => 'in', 'value' => array('anybody', 'anonymous') ); return $this->table->getIds(self::TABLE_FAQTYPE, null, $clause); } /** * Callback When Receive Whole Entry * * @param string $src name of source * @param string $key * @param array $data loaded data * @return bool true on success */ public function onDatasourceGet($src, $key, &$data) { if (self::TABLE_FAQ != $src) { return true; } $data['question_url'] = urlencode(str_replace(array('?', '/'), array('', '_'), $data['question'])); } }