Blame view

php/classes/AliasMgr.php 3.28 KB
16035364   Benjamin Renard   First commit
1
2
3
4
<?php
/**
 * @class AliasMgr
 * @version $Id: AliasMgr.php 899 2012-05-02 14:08:28Z benjamin $
16035364   Benjamin Renard   First commit
5
6
 */

05ebfb1e   Elena.Budnik   alias, first commit
7
class AliasMgr extends AmdaObjectMgr {
16035364   Benjamin Renard   First commit
8

05ebfb1e   Elena.Budnik   alias, first commit
9
10
11
12
13
14
15
16
17
	function __construct() {
		parent::__construct('Alias.xml');
		$this->contentRootId = 'alias-treeRootNode';
		$this->contentRootTag = 'aliasList';
		$this->attributes = array('name' => '', 'param' => '');
		$this->objTagName = 'alias';
		if (!file_exists($this->xmlName)) {
			$this->createDom();
			$this->xp = new domxpath($this->contentDom);
16035364   Benjamin Renard   First commit
18
19
20
21
		}
	}

	protected function createDom() {
05ebfb1e   Elena.Budnik   alias, first commit
22
		$rootElement = $this->contentDom->createElement($this->contentRootTag);
16035364   Benjamin Renard   First commit
23
		$rootElement->setAttribute('xml:id', $this->contentRootId);
05ebfb1e   Elena.Budnik   alias, first commit
24
		$this->contentDom->appendChild($rootElement);
16035364   Benjamin Renard   First commit
25
		$this->contentDom->save($this->xmlName);
05ebfb1e   Elena.Budnik   alias, first commit
26
	}
16035364   Benjamin Renard   First commit
27
	
05ebfb1e   Elena.Budnik   alias, first commit
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
	/*
	* Add Alias in Alias.xml
	*/      
	protected function addAlias($obj) {
		$objList = $this->contentDom->getElementById($this->contentRootId); 		
		$newObj = $this->contentDom->createElement($this->objTagName);
		$newObj->setAttribute('xml:id',$this->id);
		$obj_arr = (array)$obj;
		foreach ($this->attributes as $key => $value) {
			if ($key == 'name') $newObj->setAttribute($key, $obj_arr[$key]);
		}
		
		if (count($obj_arr['component_info']) > 0) {
			foreach ($obj_arr['component_info'] as $key => $value) {
				$newObj->setAttribute($key, $value);
			}
		}
		
		$objList -> appendChild($newObj);       
16035364   Benjamin Renard   First commit
47

05ebfb1e   Elena.Budnik   alias, first commit
48
49
		$this->saveContent() ;
	}
16035364   Benjamin Renard   First commit
50
51
52
      
	/*
	 *   Create Alias
05ebfb1e   Elena.Budnik   alias, first commit
53
	 */      
16035364   Benjamin Renard   First commit
54
55
    protected function createParameter($obj)   {	
		$this->id = $obj->param;
05ebfb1e   Elena.Budnik   alias, first commit
56
		$this->addAlias($obj);
16035364   Benjamin Renard   First commit
57
58
		return "OK";
	}
05ebfb1e   Elena.Budnik   alias, first commit
59
	
16035364   Benjamin Renard   First commit
60
61
62
63
	/*****************************************************************
	 *                           PUBLIC FUNCTIONS
	 *****************************************************************/

05ebfb1e   Elena.Budnik   alias, first commit
64
65
	public function getList() {
		$AliasList = $this->contentDom->getElementsByTagName('alias');
16035364   Benjamin Renard   First commit
66

05ebfb1e   Elena.Budnik   alias, first commit
67
68
		return $AliasList;
	}
16035364   Benjamin Renard   First commit
69

05ebfb1e   Elena.Budnik   alias, first commit
70
	public function substrParamAlias($chain, $paramName, $aliasName) {
16035364   Benjamin Renard   First commit
71

05ebfb1e   Elena.Budnik   alias, first commit
72
73
74
75
76
77
78
79
80
81
82
		$aliasName="#".$aliasName;
		$pos = strpos($chain, $paramName);
		while ( $pos !== FALSE ) {
			$pos = $pos+strlen($paramName);
			if (preg_match('/[-+*,^<>&|=\/\[\]\(\)\ ]/', $chain[$pos]) || $chain[$pos] === '') {
					$chain = substr_replace($chain, $aliasName,$pos-strlen($paramName),strlen($paramName));
			}
			$pos = strpos($chain, $paramName, $pos);
		}
		return $chain;
	}
16035364   Benjamin Renard   First commit
83

05ebfb1e   Elena.Budnik   alias, first commit
84
	public function substrAliasParam($chain, $paramName, $aliasName) {
16035364   Benjamin Renard   First commit
85

05ebfb1e   Elena.Budnik   alias, first commit
86
87
88
89
90
91
92
93
94
95
96
		$aliasName="#".$aliasName;
		$pos = strpos($chain, $aliasName);
		while ( $pos !== FALSE ) {
			$pos = $pos+strlen($aliasName);
			if (preg_match('/[-+*,^<>&|=\/\[\]\(\)\ ]/', $chain[$pos]) || $chain[$pos] === '') {
					$chain = substr_replace($chain, $paramName,$pos-strlen($aliasName),strlen($aliasName));
			}
			$pos = strpos($chain, $aliasName, $pos);
		}
		return $chain;
	}
16035364   Benjamin Renard   First commit
97
98
99
100
101
102
103
    
  	protected function deleteParameter($id){
		
	}
	
	/*
	 *   Get Object into Edit
05ebfb1e   Elena.Budnik   alias, first commit
104
	 */
16035364   Benjamin Renard   First commit
105
106
107
108
109
110
111
112
	public function getObject($id) {
		if (!($obj = $this->objectExistsById($id))) return "NO_SUCH_ID";
		$attributesToReturn['id'] = $obj->getAttribute('xml:id');
		$attributesToReturn['name'] = $obj->getAttribute('name');
		return  $attributesToReturn;
	}

	/*
05ebfb1e   Elena.Budnik   alias, first commit
113
114
	*   Get alias of parameter
	*/
16035364   Benjamin Renard   First commit
115
116
117
118
119
120
121
122
	public function getAlias($id) {
		$alias = "";
		if (($obj = $this->objectExistsById($id))) 
			if ($obj->hasAttribute('name'))
				$alias = $obj->getAttribute('name');
			
		return $alias;
	}
05ebfb1e   Elena.Budnik   alias, first commit
123
}