1: <?php
2: /**
3: * XOOPS kernel class
4: *
5: * You may not change or alter any portion of this comment or credits
6: * of supporting developers from this source code or any supporting source code
7: * which is considered copyrighted (c) material of the original comment or credit authors.
8: * This program is distributed in the hope that it will be useful,
9: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11: *
12: * @copyright XOOPS Project (http://xoops.org)
13: * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
14: * @package kernel
15: * @since 2.0.0
16: * @author Kazumi Ono (AKA onokazu) http://www.myweb.ne.jp/, http://jp.xoops.org/
17: * @version $Id$
18: */
19:
20: namespace Xoops\Core\Kernel\Handlers;
21:
22: use Xoops\Core\Database\Connection;
23: use Xoops\Core\Kernel\CriteriaElement;
24: use Xoops\Core\Kernel\XoopsPersistableObjectHandler;
25:
26: /**
27: * XOOPS tplset handler class.
28: * This class is responsible for providing data access mechanisms to the data source
29: * of XOOPS tplset class objects.
30: *
31: * @category Xoops\Core\Kernel\Handlers\XoopsTplSetHandler
32: * @package Xoops\Core\Kernel
33: * @author Kazumi Ono <onokazu@xoops.org>
34: * @copyright 2000-2015 XOOPS Project (http://xoops.org)
35: * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
36: * @link http://xoops.org
37: */
38: class XoopsTplSetHandler extends XoopsPersistableObjectHandler
39: {
40:
41: /**
42: * Constructor
43: *
44: * @param Connection|null $db database
45: */
46: public function __construct(Connection $db = null)
47: {
48: parent::__construct(
49: $db,
50: 'system_tplset',
51: '\Xoops\Core\Kernel\Handlers\XoopsTplSet',
52: 'tplset_id',
53: 'tplset_name'
54: );
55: }
56:
57: /**
58: * getByName
59: *
60: * @param string $tplset_name of the block to retrieve
61: *
62: * @return XoopsTplSet|false reference to the tplsets
63: */
64: public function getByName($tplset_name)
65: {
66: $qb = $this->db2->createXoopsQueryBuilder();
67: $eb = $qb->expr();
68:
69: $tplset = false;
70: $tplset_name = trim($tplset_name);
71: if ($tplset_name != '') {
72: $qb->select('*')
73: ->fromPrefix('system_tplset', null)
74: ->where($eb->eq('tplset_name', ':tplsetname'))
75: ->setParameter(':tplsetname', $tplset_name, \PDO::PARAM_STR);
76: $result = $qb->execute();
77: if (!$result) {
78: return false;
79: }
80: $allrows = $result->fetchAll();
81: if (count($allrows) == 1) {
82: $tplset = new XoopsTplSet();
83: $tplset->assignVars(reset($allrows));
84: }
85: }
86: return $tplset;
87: }
88:
89: /**
90: * get a list of tplsets matching certain conditions
91: *
92: * @param CriteriaElement|null $criteria conditions to match
93: *
94: * @return array array of tplsets matching the conditions
95: **/
96: public function getNameList(CriteriaElement $criteria = null)
97: {
98: $ret = array();
99: $tplsets = $this->getObjects($criteria, true);
100: foreach (array_keys($tplsets) as $i) {
101: $ret[$tplsets[$i]->getVar('tplset_name')] = $tplsets[$i]->getVar('tplset_name');
102: }
103: return $ret;
104: }
105: }
106: