SharedObjectsMgr.php
4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
/**
* @class SharedObjectsMgr
* @version
*
*/
class SharedObjectsMgr {
private $sharedObjectsMgr = array();
private $treeFile = null;
function __construct() {
$this->init();
}
public function updateTree() {
$sucess = TRUE;
$message = "";
foreach ($this->sharedObjectsMgr as $key => $mgr) {
if (!isset($mgr))
continue;
$result = $this->treeFile->update($key, $mgr);
$sucess &= $result['success'];
if (!$result['success']) {
if (!empty($message))
$message .= "; ";
$message .= $result['message'];
}
}
return array('success' => $sucess, 'message' => $message);
}
public function add($object_type, $object_name, $folder_id, $src_object_path, $description, $sharedBy, $forceId = "") {
if (!array_key_exists($object_type, $this->sharedObjectsMgr) || !isset($this->sharedObjectsMgr[$object_type]))
return array('success' => FALSE, 'message' => 'Unknown type');
$folder_name = $this->treeFile->getFolderNameById($object_type, $folder_id);
if (empty($folder_name))
return array('success' => FALSE, 'message' => 'Cannot retrieve folder');
$id = empty($forceId) ? $this->treeFile->reserveNewId($object_type) : $forceId;
$result = $this->sharedObjectsMgr[$object_type]->add($object_name, $folder_name, $src_object_path, $description, $sharedBy, $id);
if ($result['success'])
$result['folder_id'] = $folder_id;
return $result;
}
public function update($object_type, $object_name, $folder_id, $src_object_path, $description, $sharedBy) {
if (!array_key_exists($object_type, $this->sharedObjectsMgr) || !isset($this->sharedObjectsMgr[$object_type]))
return array('success' => FALSE, 'message' => 'Unknown type');
$folder_name = $this->treeFile->getFolderNameById($object_type, $folder_id);
if (empty($folder_name))
return array('success' => FALSE, 'message' => 'Cannot retrieve folder');
$objects = $this->treeFile->getObjectsByName($object_type, $folder_name, $object_name);
$id = "";
if (!empty($objects)) {
//delete old objects
foreach ($objects as $object_id) {
$id = $object_id;
$result = $this->treeFile->deleteObjectByObjectId($object_type, $folder_name, $object_id);
$result = $this->sharedObjectsMgr[$object_type]->delete($folder_name, $object_id);
break;
}
}
//add new object
return $this->add($object_type, $object_name, $folder_id, $src_object_path, $description, $sharedBy, $id);
}
public function getFolders($object_type) {
if (!array_key_exists($object_type, $this->sharedObjectsMgr) || !isset($this->sharedObjectsMgr[$object_type]))
return array();
return $this->treeFile->getFolders($object_type);
}
public function createFolder($object_type, $folder_name) {
if (!array_key_exists($object_type, $this->sharedObjectsMgr) || !isset($this->sharedObjectsMgr[$object_type])) {
return array('success' => FALSE, 'message' => 'Unknown type');
}
if (!$this->sharedObjectsMgr[$object_type]->createFolder($folder_name)) {
return array('success' => FALSE, 'message' => 'Cannot create folder '.$folder_name);
}
return $this->updateTree();
}
public function isNameAlreadyUsed($object_type, $name) {
if (!array_key_exists($object_type, $this->sharedObjectsMgr) || !isset($this->sharedObjectsMgr[$object_type]))
return FALSE;
return $this->treeFile->isNameAlreadyUsed($object_type, $name);
}
public function getDataFilePath($object_type, $object_id) {
if (!array_key_exists($object_type, $this->sharedObjectsMgr) || !isset($this->sharedObjectsMgr[$object_type]))
return "";
$folder_id = $this->treeFile->getFolderIdByObjectId($object_type, $object_id);
$folder_name = $this->treeFile->getFolderNameById($object_type, $folder_id);
if (empty($folder_name))
return "";
return $this->sharedObjectsMgr[$object_type]->getDataFilePath($folder_name, $object_id);
}
public function getTreeFilePath() {
return $this->treeFile->getFilePath();
}
private function init() {
if (!is_dir(SHAREDPATH)) {
mkdir(SHAREDPATH);
chgrp(SHAREDPATH, APACHE_USER);
chmod(SHAREDPATH, 0775);
}
$this->treeFile = new SharedObjectTreeFile();
$this->sharedObjectsMgr["timeTable"] = new SharedTimeTableMgrImpl();
$this->sharedObjectsMgr["catalog"] = new SharedCatalogMgrImpl();
}
}
?>