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