1: <?php
2:
3: /**
4: * This file contains the frame file and item class.
5: *
6: * @package Core
7: * @subpackage GenericDB_Model
8: * @author Timo Hummel
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: * Frame file collection
19: *
20: * @package Core
21: * @subpackage GenericDB_Model
22: */
23: class cApiFrameFileCollection 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']['framefiles'], 'idframefile');
32: $this->_setItemClass('cApiFrameFile');
33:
34: // set the join partners so that joins can be used via link() method
35: $this->_setJoinPartner('cApiAreaCollection');
36: $this->_setJoinPartner('cApiFileCollection');
37: }
38:
39: /**
40: * Creates a frame file item
41: *
42: * @param string $area
43: * @param int $idframe
44: * @param int $idfile
45: *
46: * @return cApiFrameFile
47: *
48: * @throws cDbException
49: * @throws cException
50: * @throws cInvalidArgumentException
51: */
52: public function create($area, $idframe, $idfile) {
53: $item = $this->createNewItem();
54:
55: if (is_string($area)) {
56: $c = new cApiArea();
57: $c->loadBy('name', $area);
58:
59: if ($c->isLoaded()) {
60: $area = $c->get('idarea');
61: } else {
62: $area = 0;
63: cWarning(__FILE__, __LINE__, "Could not resolve area [$area] passed to method [create], assuming 0");
64: }
65: }
66:
67: $item->set('idarea', $area);
68: $item->set('idfile', $idfile);
69: $item->set('idframe', $idframe);
70:
71: $item->store();
72:
73: return $item;
74: }
75: }
76:
77: /**
78: * Frame file item
79: *
80: * @package Core
81: * @subpackage GenericDB_Model
82: */
83: class cApiFrameFile extends Item {
84: /**
85: * Constructor to create an instance of this class.
86: *
87: * @param mixed $mId [optional]
88: * Specifies the ID of item to load
89: *
90: * @throws cDbException
91: * @throws cException
92: */
93: public function __construct($mId = false) {
94: global $cfg;
95: parent::__construct($cfg['tab']['framefiles'], 'idframefile');
96: $this->setFilters(array(
97: 'addslashes'
98: ), array(
99: 'stripslashes'
100: ));
101: if ($mId !== false) {
102: $this->loadByPrimaryKey($mId);
103: }
104: }
105:
106: /**
107: * Userdefined setter for framefile fields.
108: *
109: * @param string $name
110: * @param mixed $value
111: * @param bool $bSafe [optional]
112: * Flag to run defined inFilter on passed value
113: * @return bool
114: */
115: public function setField($name, $value, $bSafe = true) {
116: switch ($name) {
117: case 'idarea':
118: $value = (int) $value;
119: break;
120: case 'idfile':
121: $value = (int) $value;
122: break;
123: case 'idframe':
124: $value = (int) $value;
125: break;
126: }
127:
128: return parent::setField($name, $value, $bSafe);
129: }
130:
131: }
132: