Blame view

php/classes/SharedObjectsMgr.php 4.22 KB
169f14d2   Benjamin Renard   Add shared object...
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
<?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);
	}
87effbfd   Benjamin Renard   Fix typo
34

0ab5efd0   Benjamin Renard   Keep TT or catalo...
35
	public function add($object_type, $object_name, $folder_id, $src_object_path, $description, $sharedBy, $forceId = "") {
169f14d2   Benjamin Renard   Add shared object...
36
37
38
39
40
41
42
43
		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');
		
0ab5efd0   Benjamin Renard   Keep TT or catalo...
44
		$id = empty($forceId) ? $this->treeFile->reserveNewId($object_type) : $forceId;
169f14d2   Benjamin Renard   Add shared object...
45
		
87effbfd   Benjamin Renard   Fix typo
46
		$result = $this->sharedObjectsMgr[$object_type]->add($object_name, $folder_name, $src_object_path, $description, $sharedBy, $id);
169f14d2   Benjamin Renard   Add shared object...
47
48
49
50
51
52
		
		if ($result['success'])
			$result['folder_id'] = $folder_id;
		
		return $result;
	}
952d9101   Benjamin Renard   Add function to u...
53
54
55
56
57
58
59
60
61
62
63
64

	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);

0ab5efd0   Benjamin Renard   Keep TT or catalo...
65
		$id = "";
952d9101   Benjamin Renard   Add function to u...
66
67
68
		if (!empty($objects)) {
			//delete old objects
			foreach ($objects as $object_id) {
0ab5efd0   Benjamin Renard   Keep TT or catalo...
69
				$id = $object_id;
952d9101   Benjamin Renard   Add function to u...
70
71
				$result = $this->treeFile->deleteObjectByObjectId($object_type, $folder_name, $object_id);
				$result = $this->sharedObjectsMgr[$object_type]->delete($folder_name, $object_id);
0ab5efd0   Benjamin Renard   Keep TT or catalo...
72
				break;
952d9101   Benjamin Renard   Add function to u...
73
74
75
76
			}
		}

		//add new object
0ab5efd0   Benjamin Renard   Keep TT or catalo...
77
		return $this->add($object_type, $object_name, $folder_id, $src_object_path, $description, $sharedBy, $id);
952d9101   Benjamin Renard   Add function to u...
78
	}
169f14d2   Benjamin Renard   Add shared object...
79
80
81
82
83
84
85
	
	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);
	}
c1c7a99c   Benjamin Renard   Add new functions...
86
87
88
89
90
91
92
93
94
95
96
97

	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();
	}
169f14d2   Benjamin Renard   Add shared object...
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
	
	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();
	}
}

c1c7a99c   Benjamin Renard   Add new functions...
137
?>