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: * Constructor to create an instance of this class.
26: *
27: * @throws cInvalidArgumentException
28: */
29: public function __construct() {
30: global $cfg;
31: parent::__construct($cfg['tab']['keywords'], 'idkeyword');
32: $this->_setItemClass('cApiKeyword');
33: }
34:
35: /**
36: * @todo params w/ defaults should be relocated
37: *
38: * @param string $keyword
39: * @param string $exp [optional]
40: * @param string $auto
41: * @param string $self [optional]
42: * @param int $idlang
43: *
44: * @return cApiKeyword
45: * @throws cDbException
46: * @throws cException
47: * @throws cInvalidArgumentException
48: */
49: public function create($keyword, $exp = '', $auto, $self = '', $idlang) {
50: $item = $this->createNewItem();
51:
52: $item->set('keyword', $keyword);
53: $item->set('exp', $exp);
54: $item->set('auto', $auto);
55: $item->set('self', $self);
56: $item->set('idlang', $idlang);
57:
58: $item->store();
59:
60: return $item;
61: }
62:
63: }
64:
65: /**
66: * Keyword item
67: *
68: * @package Core
69: * @subpackage GenericDB_Model
70: */
71: class cApiKeyword extends Item
72: {
73: /**
74: * Constructor to create an instance of this class.
75: *
76: * @param mixed $mId [optional]
77: * Specifies the ID of item to load
78: *
79: * @throws cDbException
80: * @throws cException
81: */
82: public function __construct($mId = false) {
83: global $cfg;
84: parent::__construct($cfg['tab']['keywords'], 'idkeyword');
85: $this->setFilters(array(
86: 'addslashes'
87: ), array(
88: 'stripslashes'
89: ));
90: if ($mId !== false) {
91: $this->loadByPrimaryKey($mId);
92: }
93: }
94:
95: /**
96: * Userdefined setter for keyword fields.
97: *
98: * @param string $name
99: * @param mixed $value
100: * @param bool $bSafe [optional]
101: * Flag to run defined inFilter on passed value
102: * @return bool
103: */
104: public function setField($name, $value, $bSafe = true) {
105: switch ($name) {
106: case 'idlang':
107: $value = (int) $value;
108: break;
109: }
110:
111: return parent::setField($name, $value, $bSafe);
112: }
113:
114: }
115: