1: <?php
2:
3: /**
4: * This file contains the file collection 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: * File collection
19: *
20: * @package Core
21: * @subpackage GenericDB_Model
22: */
23: class cApiFileCollection 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']['files'], 'idfile');
32: $this->_setItemClass('cApiFile');
33:
34: // set the join partners so that joins can be used via link() method
35: $this->_setJoinPartner('cApiAreaCollection');
36: }
37:
38: /**
39: * Creates a file item entry
40: *
41: * @param string $area
42: * @param string $filename
43: * @param string $filetype [optional]
44: *
45: * @return cApiFile
46: *
47: * @throws cDbException
48: * @throws cException
49: * @throws cInvalidArgumentException
50: */
51: public function create($area, $filename, $filetype = 'main') {
52: $item = $this->createNewItem();
53:
54: if (is_string($area)) {
55: $c = new cApiArea();
56: $c->loadBy('name', $area);
57:
58: if ($c->isLoaded()) {
59: $area = $c->get('idarea');
60: } else {
61: $area = 0;
62: cWarning(__FILE__, __LINE__, "Could not resolve area [$area] passed to method [create], assuming 0");
63: }
64: }
65:
66: $item->set('idarea', $area);
67: $item->set('filename', $filename);
68:
69: if ($filetype != 'main') {
70: $item->set('filetype', 'inc');
71: } else {
72: $item->set('filetype', 'main');
73: }
74:
75: $item->store();
76:
77: return $item;
78: }
79: }
80:
81: /**
82: * File item
83: *
84: * @package Core
85: * @subpackage GenericDB_Model
86: */
87: class cApiFile extends Item {
88: /**
89: * Constructor to create an instance of this class.
90: *
91: * @param mixed $mId [optional]
92: * Specifies the ID of item to load
93: *
94: * @throws cDbException
95: * @throws cException
96: */
97: public function __construct($mId = false) {
98: global $cfg;
99: parent::__construct($cfg['tab']['files'], 'idfile');
100: $this->setFilters(array(
101: 'addslashes'
102: ), array(
103: 'stripslashes'
104: ));
105: if ($mId !== false) {
106: $this->loadByPrimaryKey($mId);
107: }
108: }
109: }
110: