1: <?php
2:
3: /**
4: * This file contains the keyword collection and item class.
5: *
6: * @package Core
7: * @subpackage GenericDB_Model
8: * @author Frederic Schneider
9: * @copyright four for business AG <www.4fb.de>
10: * @license http://www.contenido.org/license/LIZENZ.txt
11: * @link http://www.4fb.de
12: * @link http://www.contenido.org
13: */
14:
15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
16:
17: /**
18: * Keyword collection
19: *
20: * @package Core
21: * @subpackage GenericDB_Model
22: */
23: class cApiKeywordCollection extends ItemCollection {
24:
25: /**
26: * Constructor to create an instance of this class.
27: */
28: public function __construct() {
29: global $cfg;
30: parent::__construct($cfg['tab']['keywords'], 'idkeyword');
31: $this->_setItemClass('cApiKeyword');
32: }
33:
34: /**
35: * @todo params w/ defaults should be relocated
36: * @param string $keyword
37: * @param string $exp [optional]
38: * @param string $auto
39: * @param string $self [optional]
40: * @param int $idlang
41: * @return cApiKeyword
42: */
43: public function create($keyword, $exp = '', $auto, $self = '', $idlang) {
44: $item = $this->createNewItem();
45:
46: $item->set('keyword', $keyword);
47: $item->set('exp', $exp);
48: $item->set('auto', $auto);
49: $item->set('self', $self);
50: $item->set('idlang', $idlang);
51:
52: $item->store();
53:
54: return $item;
55: }
56:
57: }
58:
59: /**
60: * Keyword item
61: *
62: * @package Core
63: * @subpackage GenericDB_Model
64: */
65: class cApiKeyword extends Item {
66:
67: /**
68: * Constructor to create an instance of this class.
69: *
70: * @param mixed $mId [optional]
71: * Specifies the ID of item to load
72: */
73: public function __construct($mId = false) {
74: global $cfg;
75: parent::__construct($cfg['tab']['keywords'], 'idkeyword');
76: $this->setFilters(array(
77: 'addslashes'
78: ), array(
79: 'stripslashes'
80: ));
81: if ($mId !== false) {
82: $this->loadByPrimaryKey($mId);
83: }
84: }
85:
86: /**
87: * Userdefined setter for keyword fields.
88: *
89: * @param string $name
90: * @param mixed $value
91: * @param bool $bSafe [optional]
92: * Flag to run defined inFilter on passed value
93: * @return bool
94: */
95: public function setField($name, $value, $bSafe = true) {
96: switch ($name) {
97: case 'idlang':
98: $value = (int) $value;
99: break;
100: }
101:
102: return parent::setField($name, $value, $bSafe);
103: }
104:
105: }
106: