1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: cInclude('includes', 'functions.file.php');
19:
20: 21: 22: 23: 24: 25:
26: class cApiFileInformationCollection extends ItemCollection {
27:
28: public function __construct() {
29: global $cfg;
30: parent::__construct($cfg['tab']['file_information'], 'idsfi');
31: $this->_setItemClass('cApiFileInformation');
32: }
33:
34: 35: 36: 37: 38: 39: 40: 41:
42: public function create($typeContent, $filename, $description = '') {
43: $client = cRegistry::getClientId();
44: $auth = cRegistry::getAuth();
45: $item = new cApiFileInformation();
46: $item->loadByMany(array(
47: 'idclient' => $client,
48: 'type' => $typeContent,
49: 'filename' => $filename
50: ));
51: if (!$item->isLoaded()) {
52: $item = parent::createNewItem();
53:
54: $item->set('idclient', $client);
55: $item->set('type', $typeContent);
56: $item->set('filename', $filename);
57: $item->set('created', date('Y-m-d H:i:s'));
58: $item->set('lastmodified', date('Y-m-d H:i:s'));
59: $item->set('author', $auth->auth['uid']);
60: $item->set('modifiedby', $auth->auth['uid']);
61: $item->set('description', $description);
62: $item->store();
63:
64: return $item;
65: } else {
66: return $this->updateFile($filename, $typeContent, $description);
67: }
68: }
69:
70: 71: 72: 73: 74: 75: 76: 77: 78: 79:
80: public function updateFile($filename, $typeContent, $description = '', $newFilename = '', $author = '') {
81: $auth = cRegistry::getAuth();
82: $client = cRegistry::getClientId();
83: $item = new cApiFileInformation();
84: $item->loadByMany(array(
85: 'idclient' => $client,
86: 'type' => $typeContent,
87: 'filename' => $filename
88: ));
89: $id = $item->get('idsfi');
90: if ($item->isLoaded()) {
91: $item->set('idsfi', $id);
92: $item->set('lastmodified', date('Y-m-d H:i:s'));
93: $item->set('description', $description);
94: $item->set('modifiedby', $auth->auth['uid']);
95: if (!empty($newFilename)) {
96: $item->set('filename', $newFilename);
97: }
98: if (!empty($author)) {
99: $item->set('author', $author);
100: }
101: $item->store();
102: }
103:
104: return $item;
105: }
106:
107: 108: 109: 110: 111: 112: 113:
114: public function removeFileInformation(array $values) {
115: $item = new cApiFileInformation();
116: $item->loadByMany($values);
117: $idsfi = $item->get('idsfi');
118: return $this->delete($idsfi);
119: }
120:
121: 122: 123: 124: 125: 126: 127:
128: public function getFileInformation($filename, $type) {
129: $client = cRegistry::getClientId();
130: $fileInformation = array();
131: $item = new cApiFileInformation();
132: $item->loadByMany(array(
133: 'idclient' => $client,
134: 'type' => $type,
135: 'filename' => $filename
136: ));
137: if ($item->isLoaded()) {
138: $fileInformation['idsfi'] = $item->get('idsfi');
139: $fileInformation['created'] = $item->get('created');
140: $fileInformation['lastmodified'] = $item->get('lastmodified');
141: $fileInformation['author'] = cSecurity::unFilter($item->get('author'));
142: $fileInformation['modifiedby'] = $item->get('modifiedby');
143: $fileInformation['description'] = cSecurity::unFilter($item->get('description'));
144: }
145: return $fileInformation;
146: }
147:
148: }
149:
150: 151: 152: 153: 154: 155:
156: class cApiFileInformation extends Item {
157:
158: public function __construct($id = false) {
159: global $cfg;
160: parent::__construct($cfg['tab']['file_information'], 'idsfi');
161: if ($id !== false) {
162: $this->loadByPrimaryKey($id);
163: }
164: }
165:
166: }
167: