IHMSharedObjectsClass.php 1.67 KB
<?php

/**
 * @class IHMSharedObjectsClass
 * @brief Shared objects helper
 * @details
 */
class IHMSharedObjectsClass {
	/*
	 * @brief Constructor
	*/
	function __construct()
	{
	}
	
	public static function getPath($object_type, $object_id) {
		$objectDir = "";
		switch ($object_type) {
			case 'timeTable' :
				$objectDir = "TT";
				break;
			case 'catalog' :
				$objectDir = "CAT";
				break;
			default:
				return array('success' => false, 'message' => 'Unknown shared object type');
		}
		
		$treeFilePath = IHMConfigClass::getSharedTreeFilePath();
		
		if (!file_exists($treeFilePath))
			return array('success' => false, 'message' => 'Cannot retrieve shared objects file');
		
		$dom = new DomDocument("1.0");
		if (!$dom->load($treeFilePath))
			return array('success' => false, 'message' => 'Cannot load shared objects file');
		
		$objectRootNodeId = 'shared'.$object_type.'-treeRootNode';
		
		$objectRootNode = $dom->getElementById($objectRootNodeId);
		
		if (!isset($objectRootNode))
			return array('success' => false, 'message' => 'Cannot retrieve shared objects root node');
		
		$folderNodes = $objectRootNode->getElementsByTagName("folder");
		
		foreach ($folderNodes as $folderNode) {
			$objectNodes = $folderNode->getElementsByTagName($object_type);
			
			foreach ($objectNodes as $objectNode) {
				if ($objectNode->getAttribute('xml:id') == $object_id) {
					switch ($object_type) {
						
					}
					return array('success' => true, 'path' => IHMConfigClass::getSharedPath().$objectDir."/".$folderNode->getAttribute('name').'/data/'.$object_id.".xml");
				}
			}
		}
		
		return array('success' => false, 'message' => 'Cannot retrieve shared object with id '.$object_id);
	}
}

?>