Blame view

php/classes/SharedObjectsMgr.php 3.19 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
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
<?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) {
		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');
		
		$newId = $this->treeFile->reserveNewId($object_type);
		
		$result = $this->sharedObjectsMgr[$object_type]->add($object_name, $folder_name, $src_object_path, $description, $sharedBy, $newId);
		
		if ($result['success'])
			$result['folder_id'] = $folder_id;
		
		return $result;
	}
	
	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...
60
61
62
63
64
65
66
67
68
69
70
71

	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...
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
	
	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...
111
?>