1: <?php
2:
3: /**
4: * This file contains the meta type collection and item class.
5: *
6: * @package Core
7: * @subpackage GenericDB_Model
8: * @author Murat Purc <murat@purc.de>
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: * Metatype collection
19: *
20: * @package Core
21: * @subpackage GenericDB_Model
22: */
23: class cApiMetaTypeCollection 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']['meta_type'], 'idmetatype');
32: $this->_setItemClass('cApiMetaType');
33: }
34:
35: /**
36: * Creates a meta type entry.
37: *
38: * @param string $metatype
39: * @param string $fieldtype
40: * @param int $maxlength
41: * @param string $fieldname
42: *
43: * @return cApiMetaType
44: * @throws cDbException
45: * @throws cException
46: * @throws cInvalidArgumentException
47: */
48: public function create($metatype, $fieldtype, $maxlength, $fieldname) {
49: $oItem = $this->createNewItem();
50:
51: $oItem->set('metatype', $metatype);
52: $oItem->set('fieldtype', $fieldtype);
53: $oItem->set('maxlength', $maxlength);
54: $oItem->set('fieldname', $fieldname);
55: $oItem->store();
56:
57: return $oItem;
58: }
59:
60: }
61:
62: /**
63: * Metatype item
64: *
65: * @package Core
66: * @subpackage GenericDB_Model
67: */
68: class cApiMetaType extends Item
69: {
70: /**
71: * Constructor to create an instance of this class.
72: *
73: * @param mixed $mId
74: * Specifies the ID of item to load
75: *
76: * @throws cDbException
77: * @throws cException
78: */
79: public function __construct($mId = false) {
80: global $cfg;
81: parent::__construct($cfg['tab']['meta_type'], 'idmetatype');
82: $this->setFilters(array(), array());
83: if ($mId !== false) {
84: $this->loadByPrimaryKey($mId);
85: }
86: }
87:
88: /**
89: * Userdefined setter for article language fields.
90: *
91: * @param string $name
92: * @param mixed $value
93: * @param bool $bSafe [optional]
94: * Flag to run defined inFilter on passed value
95: * @return bool
96: */
97: public function setField($name, $value, $bSafe = true) {
98: if ('maxlength' == $name) {
99: $value = (int) $value;
100: }
101:
102: return parent::setField($name, $value, $bSafe);
103: }
104:
105: }
106: