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