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
	function __construct() {
		parent::__construct('Alias.xml');
		$this->contentRootId = 'alias-treeRootNode';
		$this->contentRootTag = 'aliasList';
bafc2a52   Elena.Budnik   icon Cls for alias
13
		$this->attributes = array('name' => '', 'param' => '', 'iconCls' => '');
05ebfb1e   Elena.Budnik   alias, first commit
14
15
16
17
		$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
	/*
	* Add Alias in Alias.xml
	*/      
	protected function addAlias($obj) {
1c1db276   Elena.Budnik   iconCls
32

05ebfb1e   Elena.Budnik   alias, first commit
33
34
35
36
37
		$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) {
1c1db276   Elena.Budnik   iconCls
38
			$newObj->setAttribute($key, $obj_arr[$key]);
05ebfb1e   Elena.Budnik   alias, first commit
39
40
41
42
43
44
45
46
47
		}
		
		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
48

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

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

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

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

05ebfb1e   Elena.Budnik   alias, first commit
73
74
75
76
77
78
79
80
81
82
83
		$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
84

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

05ebfb1e   Elena.Budnik   alias, first commit
87
88
89
90
91
92
93
94
95
96
97
		$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
98
99
100
101
102
103
104
    
  	protected function deleteParameter($id){
		
	}
	
	/*
	 *   Get Object into Edit
05ebfb1e   Elena.Budnik   alias, first commit
105
	 */
16035364   Benjamin Renard   First commit
106
107
108
109
110
111
112
113
	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
114
115
	*   Get alias of parameter
	*/
16035364   Benjamin Renard   First commit
116
117
118
119
120
121
122
123
	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
124
}