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:     /**
26:      * Constructor to create an instance of this class.
27:      */
28:     public function __construct() {
29:         global $cfg;
30:         parent::__construct($cfg['tab']['meta_type'], 'idmetatype');
31:         $this->_setItemClass('cApiMetaType');
32:     }
33: 
34:     /**
35:      * Creates a meta type entry.
36:      *
37:      * @param string $metatype
38:      * @param string $fieldtype
39:      * @param int $maxlength
40:      * @param string $fieldname
41:      * @return cApiMetaType
42:      */
43:     public function create($metatype, $fieldtype, $maxlength, $fieldname) {
44:         $oItem = $this->createNewItem();
45: 
46:         $oItem->set('metatype', $metatype);
47:         $oItem->set('fieldtype', $fieldtype);
48:         $oItem->set('maxlength', $maxlength);
49:         $oItem->set('fieldname', $fieldname);
50:         $oItem->store();
51: 
52:         return $oItem;
53:     }
54: 
55: }
56: 
57: /**
58:  * Metatype item
59:  *
60:  * @package Core
61:  * @subpackage GenericDB_Model
62:  */
63: class cApiMetaType extends Item {
64: 
65:     /**
66:      * Constructor to create an instance of this class.
67:      *
68:      * @param mixed $mId
69:      *         Specifies the ID of item to load
70:      */
71:     public function __construct($mId = false) {
72:         global $cfg;
73:         parent::__construct($cfg['tab']['meta_type'], 'idmetatype');
74:         $this->setFilters(array(), array());
75:         if ($mId !== false) {
76:             $this->loadByPrimaryKey($mId);
77:         }
78:     }
79: 
80:     /**
81:      * Userdefined setter for article language fields.
82:      *
83:      * @param string $name
84:      * @param mixed $value
85:      * @param bool $bSafe [optional]
86:      *         Flag to run defined inFilter on passed value
87:      * @return bool
88:      */
89:     public function setField($name, $value, $bSafe = true) {
90:         if ('maxlength' == $name) {
91:             $value = (int) $value;
92:         }
93: 
94:         return parent::setField($name, $value, $bSafe);
95:     }
96: 
97: }
98: