Commit 169f14d2f1fd997a4a402c0d91d98066d40f2978
1 parent
0a295c3e
Exists in
master
and in
112 other branches
Add shared objects (only TimeTables and Catalogs)
Showing
25 changed files
with
1311 additions
and
100 deletions
Show diff stats
generic_data/resources.json
... | ... | @@ -17,7 +17,7 @@ |
17 | 17 | {"nodeType" : "","text" : "Catalogs","id" : "catalog-treeBase", |
18 | 18 | "children" : [ |
19 | 19 | { "nodeType" : "catalog", "text" : "My Catalogs", "id" : "catalog-treeRootNode"}, |
20 | - { "nodeType" : "sharedCatalog", "text" : "Shared Catalogs", "id" : "sharedCatalog-treeRootNode"} | |
20 | + { "nodeType" : "sharedcatalog", "text" : "Shared Catalogs", "id" : "sharedcatalog-treeRootNode"} | |
21 | 21 | ] |
22 | 22 | }, |
23 | 23 | {"nodeType" : "myData","text" : "My Files", "id" : "myData-treeRootNode"} |
... | ... |
js/app/controllers/CatalogModule.js
... | ... | @@ -11,7 +11,8 @@ Ext.define('amdaDesktop.CatalogModule', { |
11 | 11 | extend: 'amdaDesktop.InteractiveModule', |
12 | 12 | |
13 | 13 | requires: [ |
14 | - 'amdaUI.CatalogUI' | |
14 | + 'amdaUI.CatalogUI', | |
15 | + 'amdaUI.ShareObjectUI' | |
15 | 16 | ], |
16 | 17 | |
17 | 18 | contentId : 'catalogUI', |
... | ... | @@ -43,5 +44,54 @@ Ext.define('amdaDesktop.CatalogModule', { |
43 | 44 | }, this); |
44 | 45 | } |
45 | 46 | |
46 | - } | |
47 | + }, | |
48 | + | |
49 | + shareCatalog : function(catObj) { | |
50 | + var win = myDesktopApp.desktop.getWindow('sharecat-win'); | |
51 | + if(!win) | |
52 | + { | |
53 | + var me = this; | |
54 | + var win = myDesktopApp.desktop.createWindow( | |
55 | + { | |
56 | + border: false, | |
57 | + id : 'sharecat-win', | |
58 | + title : 'Share Catalog', | |
59 | + width : 400, | |
60 | + height : 300, | |
61 | + layout : 'fit', | |
62 | + maximizable : false, | |
63 | + items : [ | |
64 | + { | |
65 | + xtype : 'shareobject', | |
66 | + id : 'shareCatUI', | |
67 | + onAfterShareObject : function(folder_id, object_id) { | |
68 | + win.close(); | |
69 | + var explorerTree = Ext.getCmp(amdaUI.ExplorerUI.RESRC_TAB.TREE_ID); | |
70 | + var sharedCatRootNode = explorerTree.getRootNode().findChild('id','sharedcatalog-treeRootNode',true); | |
71 | + amdaModel.InteractiveNode.preloadNodes(sharedCatRootNode, function() { | |
72 | + sharedCatRootNode.expand(); | |
73 | + var folderNode = explorerTree.getRootNode().findChild('id', folder_id, true); | |
74 | + if (!folderNode) | |
75 | + return; | |
76 | + folderNode.removeAll(); | |
77 | + folderNode.set('loaded',false); | |
78 | + amdaModel.InteractiveNode.preloadNodes(folderNode, function() { | |
79 | + folderNode.expand(); | |
80 | + var objectNode = explorerTree.getRootNode().findChild('id',object_id,true); | |
81 | + sharedCatRootNode.myGetOwnerTree().getSelectionModel().select(objectNode); | |
82 | + }); | |
83 | + }); | |
84 | + } | |
85 | + } | |
86 | + ] | |
87 | + }); | |
88 | + } | |
89 | + | |
90 | + var sharePanel = win.down('#shareCatUI'); | |
91 | + if (sharePanel) | |
92 | + sharePanel.setProperties('catalog', catObj); | |
93 | + | |
94 | + win.show(); | |
95 | + } | |
96 | + | |
47 | 97 | }); |
... | ... |
js/app/controllers/ExplorerModule.js
... | ... | @@ -25,6 +25,7 @@ Ext.define('amdaDesktop.ExplorerModule', { |
25 | 25 | 'amdaModel.CatalogNode', |
26 | 26 | 'amdaModel.StatisticsNode', // singleton; not shown in the tree |
27 | 27 | 'amdaModel.sharedTimeTableNode', |
28 | + 'amdaModel.sharedCatalogNode', | |
28 | 29 | 'amdaModel.MyDataParamNode', |
29 | 30 | 'amdaModel.MyDataNode', |
30 | 31 | 'amdaModel.PlotNode', |
... | ... |
js/app/controllers/TimeTableModule.js
... | ... | @@ -16,7 +16,8 @@ Ext.define('amdaDesktop.TimeTableModule', { |
16 | 16 | extend: 'amdaDesktop.InteractiveModule', |
17 | 17 | |
18 | 18 | requires: [ |
19 | - 'amdaUI.TimeTableUI' | |
19 | + 'amdaUI.TimeTableUI', | |
20 | + 'amdaUI.ShareObjectUI' | |
20 | 21 | ], |
21 | 22 | |
22 | 23 | contentId : 'timeTableUi', |
... | ... | @@ -49,6 +50,52 @@ Ext.define('amdaDesktop.TimeTableModule', { |
49 | 50 | /* Reset if form in form ( OperationsTT in TimeTable ) */ |
50 | 51 | this.getUiContent().down('form').getForm().reset(); |
51 | 52 | } |
52 | - } | |
53 | + }, | |
54 | + | |
55 | + shareTT : function(ttObj) { | |
56 | + var win = myDesktopApp.desktop.getWindow('sharett-win'); | |
57 | + if(!win) | |
58 | + { | |
59 | + var me = this; | |
60 | + var win = myDesktopApp.desktop.createWindow( | |
61 | + { | |
62 | + border: false, | |
63 | + id : 'sharett-win', | |
64 | + title : 'Share TimeTable', | |
65 | + width : 400, | |
66 | + height : 300, | |
67 | + layout : 'fit', | |
68 | + maximizable : false, | |
69 | + items : [ | |
70 | + { | |
71 | + xtype : 'shareobject', | |
72 | + id : 'shareTTUI', | |
73 | + onAfterShareObject : function(folder_id, object_id) { | |
74 | + win.close(); | |
75 | + var explorerTree = Ext.getCmp(amdaUI.ExplorerUI.RESRC_TAB.TREE_ID); | |
76 | + var sharedTTRootNode = explorerTree.getRootNode().findChild('id','sharedtimeTable-treeRootNode',true); | |
77 | + amdaModel.InteractiveNode.preloadNodes(sharedTTRootNode, function() { | |
78 | + sharedTTRootNode.expand(); | |
79 | + var folderNode = explorerTree.getRootNode().findChild('id', folder_id, true); | |
80 | + folderNode.removeAll(); | |
81 | + folderNode.set('loaded',false); | |
82 | + amdaModel.InteractiveNode.preloadNodes(folderNode, function() { | |
83 | + folderNode.expand(); | |
84 | + var objectNode = explorerTree.getRootNode().findChild('id',object_id,true); | |
85 | + sharedTTRootNode.myGetOwnerTree().getSelectionModel().select(objectNode); | |
86 | + }); | |
87 | + }); | |
88 | + } | |
89 | + } | |
90 | + ] | |
91 | + }); | |
92 | + } | |
93 | + | |
94 | + var sharePanel = win.down('#shareTTUI'); | |
95 | + if (sharePanel) | |
96 | + sharePanel.setProperties('timeTable', ttObj); | |
97 | + | |
98 | + win.show(); | |
99 | + } | |
53 | 100 | |
54 | 101 | }); |
... | ... |
js/app/models/CatalogNode.js
... | ... | @@ -26,15 +26,12 @@ Ext.define('amdaModel.CatalogNode', { |
26 | 26 | |
27 | 27 | localMenuItems : function() { |
28 | 28 | var menuItems = |
29 | - [/*{ | |
30 | - fnId : 'dire-shareNode', | |
31 | - text : 'Share content', | |
32 | - hidden : true | |
33 | - },{ | |
29 | + [ | |
30 | + { | |
34 | 31 | fnId : 'leaf-shareLeaf', |
35 | 32 | text : 'Share '+this.self.objectName, |
36 | 33 | hidden : true |
37 | - },*/{ | |
34 | + },{ | |
38 | 35 | fnId : 'leaf-download', |
39 | 36 | text : 'Download '+ this.self.objectName, |
40 | 37 | hidden : true |
... | ... | @@ -49,16 +46,13 @@ Ext.define('amdaModel.CatalogNode', { |
49 | 46 | |
50 | 47 | localMultiMenuItems : function() { |
51 | 48 | var menuItems = |
52 | - [/*{ | |
49 | + [{ | |
53 | 50 | fnId : 'mult-shareMulti', |
54 | 51 | text : 'Share selected '+this.self.objectName+'s' |
55 | - },*/{ | |
52 | + },{ | |
56 | 53 | fnId : 'mult-downloadMulti', |
57 | 54 | text : 'Download selected '+this.self.objectName+'s' |
58 | - }/*,{ | |
59 | - fnId : 'mult-operationsMulti', | |
60 | - text : 'Operations' | |
61 | - }*/]; | |
55 | + }]; | |
62 | 56 | |
63 | 57 | return menuItems; |
64 | 58 | }, |
... | ... | @@ -71,6 +65,12 @@ Ext.define('amdaModel.CatalogNode', { |
71 | 65 | alert('NOT IMPLEMENTED YET'); |
72 | 66 | }, |
73 | 67 | |
68 | + shareNode: function(node) { | |
69 | + myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id, true, function (module) { | |
70 | + module.shareCatalog({'name' : node.get('text'), 'id' : node.get('id')}); | |
71 | + }); | |
72 | + }, | |
73 | + | |
74 | 74 | visu : function(contextNode) { |
75 | 75 | |
76 | 76 | var me = this; |
... | ... |
js/app/models/InteractiveNode.js
... | ... | @@ -250,7 +250,7 @@ Ext.define('amdaModel.InteractiveNode', { |
250 | 250 | */ |
251 | 251 | create : function(opt) |
252 | 252 | { |
253 | - if (!this.get('contextNode') || (this.get('contextNode').data.id == 'sharedtimeTable-treeRootNode')) { | |
253 | + if (!this.get('contextNode') || (this.get('contextNode').data.id == 'sharedtimeTable-treeRootNode') || (this.get('contextNode').data.id == 'sharedcatalog-treeRootNode')) { | |
254 | 254 | // set the root node of 'Derived Parameters' tree as contextNode |
255 | 255 | this.set('contextNode',this.getRootNode()); |
256 | 256 | } |
... | ... |
js/app/models/TimeTableNode.js
... | ... | @@ -28,15 +28,12 @@ Ext.define('amdaModel.TimeTableNode', { |
28 | 28 | localMenuItems : function() |
29 | 29 | { |
30 | 30 | var menuItems = |
31 | - [/*{ | |
32 | - fnId : 'dire-shareNode', | |
33 | - text : 'Share content', | |
34 | - hidden : true | |
35 | - },{ | |
31 | + [ | |
32 | + { | |
36 | 33 | fnId : 'leaf-shareLeaf', |
37 | 34 | text : 'Share Time Table', |
38 | 35 | hidden : true |
39 | - },*/{ | |
36 | + },{ | |
40 | 37 | fnId : 'leaf-download', |
41 | 38 | text : 'Download Time Table', |
42 | 39 | hidden : true |
... | ... | @@ -51,10 +48,8 @@ Ext.define('amdaModel.TimeTableNode', { |
51 | 48 | |
52 | 49 | localMultiMenuItems : function() { |
53 | 50 | var menuItems = |
54 | - [/*{ | |
55 | - fnId : 'mult-shareMulti', | |
56 | - text : 'Share selected '+this.self.objectName+'s' | |
57 | - },*/{ | |
51 | + [ | |
52 | + { | |
58 | 53 | fnId : 'mult-downloadMulti', |
59 | 54 | text : 'Download selected '+this.self.objectName+'s' |
60 | 55 | },{ |
... | ... | @@ -89,7 +84,6 @@ Ext.define('amdaModel.TimeTableNode', { |
89 | 84 | |
90 | 85 | switch (fnId) { |
91 | 86 | |
92 | - case 'shareNode': | |
93 | 87 | case 'shareLeaf': |
94 | 88 | this.shareNode(this); |
95 | 89 | break; |
... | ... | @@ -106,10 +100,6 @@ Ext.define('amdaModel.TimeTableNode', { |
106 | 100 | // this.deleteMulti(); |
107 | 101 | // break; |
108 | 102 | |
109 | - case 'shareMulti': | |
110 | - this.shareMulti(); | |
111 | - break; | |
112 | - | |
113 | 103 | case 'downloadMulti': |
114 | 104 | this.downloadMulti(); |
115 | 105 | break; |
... | ... | @@ -148,13 +138,9 @@ Ext.define('amdaModel.TimeTableNode', { |
148 | 138 | }, |
149 | 139 | |
150 | 140 | shareNode: function(node) { |
151 | - alert("NOT IMPLEMENTED YET"); | |
152 | - }, | |
153 | - | |
154 | - shareMulti: function(){ | |
155 | - var selection = this.myGetOwnerTree().getSelectionModel().selected.items; | |
156 | - alert(selection.length+' to share!'); | |
157 | - alert("NOT IMPLEMENTED YET"); | |
141 | + myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.tt.id, true, function (module) { | |
142 | + module.shareTT({'name' : node.get('text'), 'id' : node.get('id')}); | |
143 | + }); | |
158 | 144 | }, |
159 | 145 | |
160 | 146 | downloadMulti: function(){ |
... | ... |
... | ... | @@ -0,0 +1,42 @@ |
1 | +/** | |
2 | + * Project : AMDA-NG4 | |
3 | + * Name : sharedCatalogNode.js | |
4 | + * @class amdaModel.sharedCatalogNode | |
5 | + * @extends amdaModel.InteractiveNode | |
6 | + * @brief Basic Model of Node corresponding to a amda Shared Catalog | |
7 | + * @author | |
8 | + * @version $Id: sharedCatalogNode.js 1916 2013-11-26 10:58:49Z elena $ | |
9 | + */ | |
10 | + | |
11 | +Ext.define('amdaModel.sharedCatalogNode', { | |
12 | + | |
13 | + extend: 'amdaModel.InteractiveNode', | |
14 | + | |
15 | + statics: { | |
16 | + nodeType: 'sharedcatalog', | |
17 | + objectName: 'Catalog' | |
18 | + }, | |
19 | + | |
20 | + constructor : function(config){ | |
21 | + this.callParent(arguments); | |
22 | + this.set('moduleId',myDesktopApp.dynamicModules.catalog.id); | |
23 | + this.set('objectDataModel','amdaModel.Catalog'); | |
24 | + if (this.get('leaf')) this.set('iconCls', 'icon-catalog'); | |
25 | + }, | |
26 | + | |
27 | + localMenuItems : function() { | |
28 | + var menuItems = | |
29 | + [{ | |
30 | + fnId : 'leaf-editLeaf', | |
31 | + text : 'Edit Catalog', | |
32 | + hidden : true | |
33 | + }]; | |
34 | + | |
35 | + return menuItems; | |
36 | + }, | |
37 | + | |
38 | + getAllContextMenuItems: function(){ | |
39 | + | |
40 | + return this.localMenuItems(); | |
41 | + } | |
42 | +}); | |
... | ... |
js/app/stores/ExplorerReader.js
... | ... | @@ -41,6 +41,8 @@ Ext.define('amdaReader.ExplorerReader', { |
41 | 41 | return amdaModel.CatalogNode; |
42 | 42 | case 'sharedtimeTable' : |
43 | 43 | return amdaModel.sharedTimeTableNode; |
44 | + case 'sharedcatalog' : | |
45 | + return amdaModel.sharedCatalogNode; | |
44 | 46 | case 'condition' : |
45 | 47 | return amdaModel.SearchNode; |
46 | 48 | case 'request' : |
... | ... |
js/app/views/CatalogUI.js
... | ... | @@ -209,7 +209,7 @@ Ext.define('amdaUI.CatalogUI', { |
209 | 209 | } |
210 | 210 | else |
211 | 211 | { |
212 | - // var typeTT = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id).linkedNode.data.nodeType; | |
212 | + var typeTT = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id).linkedNode.data.nodeType; | |
213 | 213 | if (this.object.get('id') == '') |
214 | 214 | { |
215 | 215 | |
... | ... | @@ -217,7 +217,7 @@ Ext.define('amdaUI.CatalogUI', { |
217 | 217 | else |
218 | 218 | { |
219 | 219 | //From existing TT file |
220 | - AmdaAction.initTTCacheFromTT(this.object.get('id'), 'catalog', this.onAfterInit, this); | |
220 | + AmdaAction.initTTCacheFromTT(this.object.get('id'), typeTT, this.onAfterInit, this); | |
221 | 221 | } |
222 | 222 | } |
223 | 223 | }, |
... | ... |
js/app/views/ExplorerUI.js
... | ... | @@ -0,0 +1,224 @@ |
1 | +/** | |
2 | + * Project : AMDA-NG | |
3 | + * Name : ShareObjectUI.js | |
4 | + * @class amdaUI.ShareObjectUI | |
5 | + * @extends Ext.form.Panel | |
6 | + * @brief Share object UI definition (View) | |
7 | + * @author Benjamin | |
8 | + * @version $Id: $ | |
9 | + ******************************************************************************** | |
10 | + * FT Id : Date : Name - Description | |
11 | + ******************************************************************************* | |
12 | + */ | |
13 | +Ext.define('amdaUI.ShareObjectUI',{ | |
14 | + extend: 'Ext.form.Panel', | |
15 | + alias: 'widget.shareobject', | |
16 | + | |
17 | + infoTextArea : null, | |
18 | + folderStore : null, | |
19 | + folderCombo : null, | |
20 | + nameField : null, | |
21 | + descriptionTextArea : null, | |
22 | + objectType : 'unknown', | |
23 | + objectProp : null, | |
24 | + onAfterShareObject : null, | |
25 | + | |
26 | + constructor: function(config) { | |
27 | + this.init(config); | |
28 | + this.callParent(arguments); | |
29 | + }, | |
30 | + | |
31 | + setProperties: function(objectType, objProp) { | |
32 | + var typeName = ''; | |
33 | + | |
34 | + switch (objectType) { | |
35 | + case 'timetab' : | |
36 | + typeName = 'TimeTable'; | |
37 | + break; | |
38 | + case 'catalog' : | |
39 | + typeName = 'Catalog'; | |
40 | + break; | |
41 | + default: | |
42 | + typeName = 'Unknown Type'; | |
43 | + } | |
44 | + | |
45 | + this.objectType = objectType; | |
46 | + this.objectProp = objProp; | |
47 | + | |
48 | + var message = 'Do you really want to share "' + objProp.name + '" to the community?'; | |
49 | + message += '\n\nNote: You will not be able to delete or change this object once shared.'; | |
50 | + | |
51 | + this.infoTextArea.setValue(message); | |
52 | + this.nameField.setValue(objProp.name); | |
53 | + | |
54 | + //Update folders list | |
55 | + AmdaAction.getSharedObjectFolders({'type' : this.objectType}, function (result, e) { | |
56 | + var t = e.getTransaction(); | |
57 | + if (e.status) | |
58 | + { | |
59 | + if (result && result.success) | |
60 | + { | |
61 | + this.folderCombo.store.loadData(result.folders, false); | |
62 | + } | |
63 | + else | |
64 | + Ext.Msg.show( { | |
65 | + title : 'Share Object', | |
66 | + msg : 'Cannot get folder list ('+result.message+')', | |
67 | + modal : true, | |
68 | + icon : Ext.Msg.ERROR, | |
69 | + buttons : Ext.Msg.OK | |
70 | + }); | |
71 | + } | |
72 | + else | |
73 | + { | |
74 | + // FAILURE | |
75 | + Ext.Msg.show({title:'Error System', msg: e.message, icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK}); | |
76 | + } | |
77 | + },this); | |
78 | + }, | |
79 | + | |
80 | + init : function(config) { | |
81 | + var me = this; | |
82 | + | |
83 | + //Callback called when a new shared object is added | |
84 | + if (config.onAfterShareObject) | |
85 | + me.onAfterShareObject = config.onAfterShareObject; | |
86 | + | |
87 | + this.infoTextArea = Ext.create('Ext.form.field.TextArea', { | |
88 | + xtype : 'textareafield', | |
89 | + hideLabel : true, | |
90 | + autoScroll : true, | |
91 | + }); | |
92 | + | |
93 | + this.folderStore = Ext.create('Ext.data.Store', { | |
94 | + fields: ['id', 'name'], | |
95 | + data : [], | |
96 | + listeners: { | |
97 | + datachanged : function(store) { | |
98 | + if ((store.getCount() <= 0) || !me.folderCombo) | |
99 | + return; | |
100 | + me.folderCombo.select(store.getAt(0)); | |
101 | + } | |
102 | + } | |
103 | + }); | |
104 | + | |
105 | + this.folderCombo = Ext.create('Ext.form.field.ComboBox', { | |
106 | + fieldLabel: 'Choose Folder', | |
107 | + store: this.folderStore, | |
108 | + queryMode: 'local', | |
109 | + displayField: 'name', | |
110 | + valueField: 'id', | |
111 | + value: 'None', | |
112 | + editable: false, | |
113 | + forceSelection: true | |
114 | + }); | |
115 | + | |
116 | + this.nameField = Ext.create('Ext.form.field.Text', { | |
117 | + fieldLabel: 'Name', | |
118 | + allowBlank: false // requires a non-empty value | |
119 | + }); | |
120 | + | |
121 | + this.descriptionTextArea = Ext.create('Ext.form.field.TextArea', { | |
122 | + xtype : 'textareafield', | |
123 | + fieldLabel: 'Description', | |
124 | + autoScroll : true, | |
125 | + allowBlank : false // requires a non-empty value | |
126 | + }); | |
127 | + | |
128 | + var myConf = { | |
129 | + layout: { | |
130 | + type: 'vbox', | |
131 | + align: 'stretch' | |
132 | + }, | |
133 | + items: [ | |
134 | + this.infoTextArea, | |
135 | + this.folderCombo, | |
136 | + this.nameField, | |
137 | + this.descriptionTextArea | |
138 | + ], | |
139 | + fbar: [ | |
140 | + { | |
141 | + text: 'Share', | |
142 | + scope: this, | |
143 | + handler: function() { | |
144 | + if(!me.isValid()) | |
145 | + return; | |
146 | + | |
147 | + var folder = me.folderCombo.getValue(); | |
148 | + var description = me.descriptionTextArea.getValue(); | |
149 | + var name = me.nameField.getValue(); | |
150 | + | |
151 | + AmdaAction.isSharedObjectNameAlreadyUsed({'type' : me.objectType, 'name' : name}, function (result, e) { | |
152 | + var t = e.getTransaction(); | |
153 | + if (e.status) | |
154 | + { | |
155 | + if (result && result.success) | |
156 | + { | |
157 | + var request_obj = { | |
158 | + 'type' : me.objectType, | |
159 | + 'object' : me.objectProp, | |
160 | + 'folder' : folder, | |
161 | + 'name' : name, | |
162 | + 'description' : description | |
163 | + }; | |
164 | + | |
165 | + if (result.alreadyUsed) | |
166 | + { | |
167 | + Ext.Msg.show( { | |
168 | + title : 'Share Object', | |
169 | + msg : 'Name "' + name + '" already used', | |
170 | + modal : true, | |
171 | + icon : Ext.Msg.ERROR, | |
172 | + buttons : Ext.Msg.OK | |
173 | + }); | |
174 | + return; | |
175 | + } | |
176 | + | |
177 | + AmdaAction.shareObjects(request_obj, function (result, e) { | |
178 | + var t = e.getTransaction(); | |
179 | + if (e.status) | |
180 | + { | |
181 | + if (result && result.success) | |
182 | + { | |
183 | + if (me.onAfterShareObject) | |
184 | + me.onAfterShareObject(result.folder_id, result.object_id); | |
185 | + } | |
186 | + else | |
187 | + Ext.Msg.show( { | |
188 | + title : 'Share Object', | |
189 | + msg : 'Cannot share objects ('+result.message+')', | |
190 | + modal : true, | |
191 | + icon : Ext.Msg.ERROR, | |
192 | + buttons : Ext.Msg.OK | |
193 | + }); | |
194 | + } | |
195 | + else | |
196 | + { | |
197 | + // FAILURE | |
198 | + Ext.Msg.show({title:'Error System', msg: e.message, icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK}); | |
199 | + } | |
200 | + },me); | |
201 | + } | |
202 | + else | |
203 | + Ext.Msg.show( { | |
204 | + title : 'Share Object', | |
205 | + msg : 'Cannot share objects ('+result.message+')', | |
206 | + modal : true, | |
207 | + icon : Ext.Msg.ERROR, | |
208 | + buttons : Ext.Msg.OK | |
209 | + }); | |
210 | + } | |
211 | + else | |
212 | + { | |
213 | + // FAILURE | |
214 | + Ext.Msg.show({title:'Error System', msg: e.message, icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK}); | |
215 | + } | |
216 | + }); | |
217 | + } | |
218 | + } | |
219 | + ] | |
220 | + }; | |
221 | + | |
222 | + Ext.apply (this , Ext.apply (arguments, myConf)); | |
223 | + } | |
224 | +}); | |
0 | 225 | \ No newline at end of file |
... | ... |
php/AmdaUpdate.php
... | ... | @@ -29,11 +29,12 @@ |
29 | 29 | /* |
30 | 30 | * Get Shared TT id SHAREDTT dir doesn't exist |
31 | 31 | */ |
32 | - if (!$updateOnly) { | |
33 | - if (!is_dir(SHAREDPATH)) { | |
32 | + if (!$updateOnly) { | |
33 | + //BRE ToDo SHARED | |
34 | + /*if (!is_dir(SHAREDPATH)) { | |
34 | 35 | system("svn export ".SVN_DDMISSIONSINFO."SHAREDTT ".SHAREDPATH); |
35 | 36 | $amda->fsmodifyr(SHAREDPATH); |
36 | - } | |
37 | + } */ | |
37 | 38 | } |
38 | 39 | |
39 | 40 | |
... | ... |
php/classes/AmdaAction.php
... | ... | @@ -90,8 +90,9 @@ class AmdaAction { |
90 | 90 | switch ($nodeType) |
91 | 91 | { |
92 | 92 | case 'sharedtimeTable': |
93 | - $xmlName = SHAREDPATH.'/WS/Tt.xml'; | |
94 | - break; | |
93 | + case 'sharedcatalog': | |
94 | + $xmlName = SHAREDPATH.'/SharedObjectTree.xml'; | |
95 | + break; | |
95 | 96 | case 'bkgWorks': |
96 | 97 | $xmlName = USERJOBDIR.$this->xmlFiles[$nodeType]; |
97 | 98 | break; |
... | ... | @@ -113,8 +114,8 @@ class AmdaAction { |
113 | 114 | $Dom->load($xmlName); |
114 | 115 | |
115 | 116 | if ($node == "myRemoteSimuData-treeRootNode") |
116 | - $node = "myRemoteData-treeRootNode"; | |
117 | - | |
117 | + $node = "myRemoteData-treeRootNode"; | |
118 | + | |
118 | 119 | $nodeToOpen = $Dom->getElementById($node); |
119 | 120 | $children = $nodeToOpen->childNodes; |
120 | 121 | |
... | ... | @@ -128,7 +129,6 @@ class AmdaAction { |
128 | 129 | $isLeaf = false; |
129 | 130 | break; |
130 | 131 | } |
131 | - | |
132 | 132 | if ($child->tagName == 'folder') $isLeaf = false; |
133 | 133 | |
134 | 134 | //TODO MAKE PROPERLY as function of nodetype !!!! |
... | ... | @@ -181,11 +181,17 @@ class AmdaAction { |
181 | 181 | break; |
182 | 182 | |
183 | 183 | case 'timeTable': |
184 | - case 'sharedtimeTable': | |
185 | 184 | case 'catalog': |
186 | 185 | if ($isLeaf) $info = $child->getAttribute('intervals').' intervals'; |
187 | 186 | break; |
188 | - | |
187 | + case 'sharedtimeTable': | |
188 | + case 'sharedcatalog': | |
189 | + if ($isLeaf) { | |
190 | + $info = '<b>Nb intervals:</b> '.$child->getAttribute('nbIntervals').'<br/>'; | |
191 | + $info .= '<b>Shared by:</b> '.$child->getAttribute('sharedBy').' ('.$child->getAttribute('sharedDate').')<br/>'; | |
192 | + $info .= '<b>Description:</b> '.$child->getAttribute('description'); | |
193 | + } | |
194 | + break; | |
189 | 195 | case 'derivedParam': |
190 | 196 | $info = $child->getAttribute('buildchain'); |
191 | 197 | if ($isLeaf) $isParameter = true; |
... | ... | @@ -615,6 +621,7 @@ class AmdaAction { |
615 | 621 | $objectMgr = new TimeTableMgr(); |
616 | 622 | break; |
617 | 623 | case 'catalog' : |
624 | + case 'sharedcatalog' : | |
618 | 625 | $objectMgr = new CatalogMgr(); |
619 | 626 | break; |
620 | 627 | case 'condition' : |
... | ... | @@ -779,6 +786,7 @@ class AmdaAction { |
779 | 786 | $objectMgr = new TimeTableMgr(); |
780 | 787 | break; |
781 | 788 | case 'catalog' : |
789 | + case 'sharedcatalog' : | |
782 | 790 | $objectMgr = new CatalogMgr(); |
783 | 791 | break; |
784 | 792 | case 'condition' : |
... | ... | @@ -958,7 +966,7 @@ class AmdaAction { |
958 | 966 | |
959 | 967 | public function initTTCacheFromTT($id, $type) |
960 | 968 | { |
961 | - if ($type == 'catalog') $cacheMgr = new CatalogCacheMgr(); | |
969 | + if ($type == 'catalog' || $type == 'sharedcatalog') $cacheMgr = new CatalogCacheMgr(); | |
962 | 970 | else $cacheMgr = new TimeTableCacheMgr(); |
963 | 971 | |
964 | 972 | return $cacheMgr->initFromTT($id, $type); |
... | ... | @@ -966,7 +974,7 @@ class AmdaAction { |
966 | 974 | |
967 | 975 | public function initForChart($id, $name, $isTmpObject, $type) |
968 | 976 | { |
969 | - if ($type == 'catalog') $objMgr = new CatalogMgr(); | |
977 | + if ($type == 'catalog' || $type == 'sharedcatalog') $objMgr = new CatalogMgr(); | |
970 | 978 | |
971 | 979 | return $objMgr->initForChart($id, $name, $isTmpObject, $type); |
972 | 980 | } |
... | ... | @@ -990,7 +998,7 @@ class AmdaAction { |
990 | 998 | |
991 | 999 | public function readTTCacheIntervals($o) |
992 | 1000 | { |
993 | - if ($o->typeTT == 'catalog') $cacheMgr = new CatalogCacheMgr(); | |
1001 | + if ($o->typeTT == 'catalog' || $type == 'sharedcatalog') $cacheMgr = new CatalogCacheMgr(); | |
994 | 1002 | else $cacheMgr = new TimeTableCacheMgr(); |
995 | 1003 | |
996 | 1004 | return $cacheMgr->getIntervals($o->start,$o->limit,$o->sort,$o->filter); |
... | ... | @@ -998,7 +1006,7 @@ class AmdaAction { |
998 | 1006 | |
999 | 1007 | public function readIntervalsForChart($o) |
1000 | 1008 | { |
1001 | - if ($o->typeTT == 'catalog') $objMgr = new CatalogMgr(); | |
1009 | + if ($o->typeTT == 'catalog' || $type == 'sharedcatalog') $objMgr = new CatalogMgr(); | |
1002 | 1010 | |
1003 | 1011 | |
1004 | 1012 | return $objMgr->getIntervalsForChart($o->id, $o->name, $o->fromPlugin, $o->typeTT); |
... | ... | @@ -1304,6 +1312,42 @@ class AmdaAction { |
1304 | 1312 | ); |
1305 | 1313 | return $this->executeRequest($inputobj, FunctionTypeEnumClass::PARAMINFO); |
1306 | 1314 | } |
1315 | + | |
1316 | + public function getSharedObjectFolders($obj) | |
1317 | + { | |
1318 | + $mgr = new SharedObjectsMgr(); | |
1319 | + $folders = $mgr->getFolders($obj->type); | |
1320 | + return array('success' => true, 'folders' => $folders); | |
1321 | + } | |
1322 | + | |
1323 | + public function shareObjects($obj) | |
1324 | + { | |
1325 | + $mgr = new SharedObjectsMgr(); | |
1326 | + switch ($obj->type) { | |
1327 | + case 'timeTable' : | |
1328 | + case 'catalog' : | |
1329 | + $src_object_path = USERTTDIR.$obj->object->id.".xml"; | |
1330 | + break; | |
1331 | + | |
1332 | + default: | |
1333 | + return array('success' => false, 'message' => 'Unknown object type'); | |
1334 | + } | |
1335 | + | |
1336 | + $result = $mgr->add($obj->type, $obj->name, $obj->folder, $src_object_path, $obj->description, $this->user); | |
1337 | + if (!$result['success']) | |
1338 | + return $result; | |
1339 | + | |
1340 | + $mgr->updateTree(); | |
1341 | + return $result; | |
1342 | + } | |
1343 | + | |
1344 | + public function isSharedObjectNameAlreadyUsed($obj) | |
1345 | + { | |
1346 | + $mgr = new SharedObjectsMgr(); | |
1347 | + $alreadyUsed = $mgr->isNameAlreadyUsed($obj->type, $obj->name); | |
1348 | + return array('success' => true, 'alreadyUsed' => $alreadyUsed); | |
1349 | + } | |
1350 | + | |
1307 | 1351 | } |
1308 | 1352 | ?> |
1309 | 1353 | |
... | ... |
php/classes/CatalogMgr.php
... | ... | @@ -6,8 +6,8 @@ |
6 | 6 | |
7 | 7 | class CatalogMgr extends TimeTableMgr { |
8 | 8 | |
9 | - function __construct() { | |
10 | - parent::__construct('Tt.xml'); | |
9 | + function __construct($sharedObject = FALSE) { | |
10 | + parent::__construct('Tt.xml', $sharedObject); | |
11 | 11 | $this->contentRootId = 'catalog-treeRootNode'; |
12 | 12 | $this->contentRootTag = 'catalogList'; |
13 | 13 | $this->attributes = array('name' => '', 'intervals' => ''); // + 'parameters' |
... | ... | @@ -15,7 +15,7 @@ class CatalogMgr extends TimeTableMgr { |
15 | 15 | $this->objTagName = 'catalog'; |
16 | 16 | $this->id_prefix = 'cat_'; // 'tt_' ? |
17 | 17 | |
18 | - if (!file_exists($this->xmlName)) { | |
18 | + if (!$sharedObject && !file_exists($this->xmlName)) { | |
19 | 19 | $this->createDom(); |
20 | 20 | $this->xp = new domxpath($this->contentDom); |
21 | 21 | } |
... | ... | @@ -109,18 +109,20 @@ class CatalogMgr extends TimeTableMgr { |
109 | 109 | |
110 | 110 | public function loadIntervalsFromTT($id, $typeTT, $start = NULL, $limit = NULL) |
111 | 111 | { |
112 | - if ($typeTT == 'sharedcatalog') { | |
113 | - $pathid = SHAREDPATH.'TT/'.$id; | |
112 | + if ($typeTT == 'sharedcatalog') { | |
113 | + //Shared object | |
114 | + $sharedObjMgr = new SharedObjectsMgr(); | |
115 | + $path = $sharedObjMgr->getDataFilePath('catalog', $id); | |
114 | 116 | } |
115 | 117 | else { |
116 | - $pathid = USERTTDIR.$id; | |
118 | + $path = USERTTDIR.$id.'.xml'; | |
117 | 119 | } |
118 | 120 | |
119 | 121 | //load intervals from TT id |
120 | - if (!file_exists($pathid.'.xml')) | |
121 | - return array('success' => false, 'message' => "Cannot find Catalog file ".$id); | |
122 | + if (!file_exists($path)) | |
123 | + return array('success' => false, 'message' => "Cannot find Catalog file ".$typeTT); | |
122 | 124 | |
123 | - $this->objectDom->load($pathid.'.xml'); | |
125 | + $this->objectDom->load($path); | |
124 | 126 | |
125 | 127 | if (!($objToGet = $this->objectDom->getElementById($id))) |
126 | 128 | return array('success' => false, 'message' => NO_SUCH_ID." ".$id); |
... | ... | @@ -325,21 +327,23 @@ class CatalogMgr extends TimeTableMgr { |
325 | 327 | |
326 | 328 | public function getCatalogParamDescription($id, $name, $isTmpObject, $typeTT) |
327 | 329 | { |
328 | - if ($typeTT == 'sharedcatalog') { | |
329 | - $pathid = SHAREDPATH.'TT/'.$id; | |
330 | + if ($typeTT == 'sharedcatalog') { | |
331 | + //Shared object | |
332 | + $sharedObjMgr = new SharedObjectsMgr(); | |
333 | + $path = $sharedObjMgr->getDataFilePath('catalog', $id); | |
330 | 334 | } |
331 | 335 | elseif (!$isTmpObject) { |
332 | - $pathid = USERTTDIR.$id; | |
336 | + $path = USERTTDIR.$id.'.xml'; | |
333 | 337 | } |
334 | 338 | else { |
335 | - $pathid = USERWORKINGDIR.$id.'/'.$name; | |
339 | + $path = USERWORKINGDIR.$id.'/'.$name.'.xml'; | |
336 | 340 | } |
337 | 341 | |
338 | 342 | //load intervals from Catalog id |
339 | - if (!file_exists($pathid.'.xml')) | |
343 | + if (!file_exists($path)) | |
340 | 344 | return array('success' => false, 'message' => "Cannot find Catalog file ".$id); |
341 | 345 | |
342 | - if (!$this->objectDom->load($pathid.'.xml')) | |
346 | + if (!$this->objectDom->load($path)) | |
343 | 347 | return array('success' => false, 'message' => "Cannot load Catalog file ".$id); |
344 | 348 | |
345 | 349 | // if (!($objToGet = $this->objectDom->getElementById($id))) |
... | ... |
... | ... | @@ -0,0 +1,36 @@ |
1 | +<?php | |
2 | +/** | |
3 | + * @class SharedCatalogMgrImpl | |
4 | + * @version | |
5 | + * | |
6 | + */ | |
7 | + | |
8 | +class SharedCatalogMgrImpl extends SharedObjectMgrAbstract { | |
9 | + public static $ROOT_DIR_NAME = "CAT"; | |
10 | + | |
11 | + private $catMgr = NULL; | |
12 | + | |
13 | + function __construct() { | |
14 | + $this->rootdirname = self::$ROOT_DIR_NAME; | |
15 | + $this->catMgr = new CatalogMgr(TRUE); | |
16 | + parent::__construct(); | |
17 | + } | |
18 | + | |
19 | + protected function getDataInfo($object_id) { | |
20 | + $result = $this->catMgr->getObject($object_id, 'sharedcatalog'); | |
21 | + | |
22 | + if (!isset($result) || array_key_exists('error', $result)) | |
23 | + return array(); | |
24 | + | |
25 | + return $result; | |
26 | + } | |
27 | + | |
28 | + protected function addData($src_object_path, $dst_data_path, $newId, $newName) { | |
29 | + $result = $this->catMgr->copyTT($src_object_path, $dst_data_path, $newId, $newName); | |
30 | + if (!$result) | |
31 | + return array('success' => FALSE, 'message' => 'Cannot copy the Catalog'); | |
32 | + return array('success' => TRUE); | |
33 | + } | |
34 | +} | |
35 | + | |
36 | +?> | |
0 | 37 | \ No newline at end of file |
... | ... |
... | ... | @@ -0,0 +1,126 @@ |
1 | +<?php | |
2 | +/** | |
3 | + * @class SharedObjectHeaderFile | |
4 | + * @version | |
5 | + * | |
6 | + */ | |
7 | + | |
8 | +class SharedObjectHeaderFile { | |
9 | + private $doc = null; | |
10 | + private $filePath = ""; | |
11 | + | |
12 | + function __construct($filePath) { | |
13 | + if (!file_exists($filePath)) | |
14 | + $this->createFile($filePath); | |
15 | + $this->loadFile($filePath); | |
16 | + $this->filePath = $filePath; | |
17 | + } | |
18 | + | |
19 | + public function getInfo() { | |
20 | + return array( | |
21 | + "name" => $this->getName(), | |
22 | + "description" => $this->getDescription(), | |
23 | + "sharedBy" => $this->getSharedBy(), | |
24 | + "sharedDate" => $this->getSharedDate() | |
25 | + ); | |
26 | + } | |
27 | + | |
28 | + public function getName() { | |
29 | + return $this->getOneInfo("name"); | |
30 | + } | |
31 | + | |
32 | + public function setName($name) { | |
33 | + $this->setOneInfo("name", $name); | |
34 | + } | |
35 | + | |
36 | + public function getDescription() { | |
37 | + return $this->getOneInfo("description"); | |
38 | + } | |
39 | + | |
40 | + public function setDescription($description) { | |
41 | + $this->setOneInfo("description", $description); | |
42 | + } | |
43 | + | |
44 | + public function getSharedBy() { | |
45 | + return $this->getOneInfo("sharedBy"); | |
46 | + } | |
47 | + | |
48 | + public function setSharedBy($sharedBy) { | |
49 | + $this->setOneInfo("sharedBy", $sharedBy); | |
50 | + } | |
51 | + | |
52 | + public function getSharedDate() { | |
53 | + return $this->getOneInfo("sharedDate"); | |
54 | + } | |
55 | + | |
56 | + public function setSharedDate($sharedDate) { | |
57 | + $this->setOneInfo("sharedDate", $sharedDate); | |
58 | + } | |
59 | + | |
60 | + private function createFile($filePath) { | |
61 | + $this->doc = new DOMDocument("1.0", "UTF-8"); | |
62 | + $this->doc->preserveWhiteSpace = false; | |
63 | + $this->doc->formatOutput = true; | |
64 | + | |
65 | + $rootNode = $this->doc->createElement("shared-header"); | |
66 | + $this->doc->appendChild($rootNode); | |
67 | + | |
68 | + $nameNode = $this->doc->createElement("name"); | |
69 | + $rootNode->appendChild($nameNode); | |
70 | + | |
71 | + $descriptionNode = $this->doc->createElement("description"); | |
72 | + $rootNode->appendChild($descriptionNode); | |
73 | + | |
74 | + $sharedByNode = $this->doc->createElement("sharedBy"); | |
75 | + $rootNode->appendChild($sharedByNode); | |
76 | + | |
77 | + $sharedDateNode = $this->doc->createElement("sharedDate"); | |
78 | + $rootNode->appendChild($sharedDateNode); | |
79 | + | |
80 | + $this->doc->save($filePath); | |
81 | + | |
82 | + chgrp($filePath, APACHE_USER); | |
83 | + chmod($filePath, 0775); | |
84 | + } | |
85 | + | |
86 | + private function loadFile($filePath) { | |
87 | + $this->doc = new DOMDocument("1.0", "UTF-8"); | |
88 | + $this->doc->preserveWhiteSpace = false; | |
89 | + $this->doc->formatOutput = true; | |
90 | + $this->doc->load($filePath); | |
91 | + } | |
92 | + | |
93 | + private function getOneInfo($infoName) { | |
94 | + if (!isset($this->doc)) | |
95 | + return ""; | |
96 | + | |
97 | + $rootNode = $this->doc->documentElement; | |
98 | + if (!isset($rootNode)) | |
99 | + return ""; | |
100 | + | |
101 | + $infoNodes = $rootNode->getElementsByTagName($infoName); | |
102 | + if (count($infoNodes) == 0) | |
103 | + return ""; | |
104 | + | |
105 | + return $infoNodes->item(0)->nodeValue; | |
106 | + } | |
107 | + | |
108 | + private function setOneInfo($infoName, $infoValue) { | |
109 | + if (!isset($this->doc)) | |
110 | + return; | |
111 | + | |
112 | + $rootNode = $this->doc->documentElement; | |
113 | + if (!isset($rootNode)) | |
114 | + return ""; | |
115 | + | |
116 | + $infoNodes = $rootNode->getElementsByTagName($infoName); | |
117 | + if (count($infoNodes) == 0) | |
118 | + return ""; | |
119 | + | |
120 | + $infoNodes->item(0)->nodeValue = $infoValue; | |
121 | + | |
122 | + $this->doc->save($this->filePath); | |
123 | + } | |
124 | +} | |
125 | + | |
126 | +?> | |
... | ... |
... | ... | @@ -0,0 +1,161 @@ |
1 | +<?php | |
2 | +/** | |
3 | + * @class SharedObjectMgrAbstract | |
4 | + * @version | |
5 | + * | |
6 | + */ | |
7 | + | |
8 | +abstract class SharedObjectMgrAbstract { | |
9 | + protected $rootdirname = ""; | |
10 | + | |
11 | + private static $headerdirname = "header"; | |
12 | + | |
13 | + private static $datadirname = "data"; | |
14 | + | |
15 | + function __construct() { | |
16 | + if (!is_dir($this->getRootDirPath())) { | |
17 | + mkdir($this->getRootDirPath()); | |
18 | + chgrp($this->getRootDirPath(), APACHE_USER); | |
19 | + chmod($this->getRootDirPath(), 0775); | |
20 | + } | |
21 | + } | |
22 | + | |
23 | + abstract protected function getDataInfo($object_id); | |
24 | + | |
25 | + abstract protected function addData($src_object_path, $dst_data_path, $newId, $newName); | |
26 | + | |
27 | + public function getDescription($folder_name, $object_id) { | |
28 | + $result = array(); | |
29 | + | |
30 | + $headerFilePath = $this->getHeaderFilePath($folder_name, $object_id); | |
31 | + $headerFile = new SharedObjectHeaderFile($headerFilePath); | |
32 | + | |
33 | + //Get info contained in data file | |
34 | + $result = $this->getDataInfo($object_id); | |
35 | + | |
36 | + //Get info contained in header file | |
37 | + $header_info = $headerFile->getInfo(); | |
38 | + | |
39 | + foreach ($header_info as $key => $value) { | |
40 | + //if (!array_key_exists($key, $result) && empty($value)) | |
41 | + // continue; | |
42 | + $result[$key] = $value; | |
43 | + } | |
44 | + | |
45 | + return $result; | |
46 | + } | |
47 | + | |
48 | + public function add($object_name, $folder_name, $src_object_path, $description, $sharedBy, $newId) { | |
49 | + $dst_folder_path = $this->getFolderDirPath($folder_name); | |
50 | + if (!is_dir($dst_folder_path)) | |
51 | + return array('success' => false, 'message' => 'Cannot get folder path'); | |
52 | + | |
53 | + $dst_header_path = $this->getHeaderDirPath($folder_name); | |
54 | + if (!is_dir($dst_header_path)) { | |
55 | + mkdir($dst_header_path); | |
56 | + chgrp($dst_header_path, APACHE_USER); | |
57 | + chmod($dst_header_path, 0775); | |
58 | + } | |
59 | + | |
60 | + $dst_data_path = $this->getDataDirPath($folder_name); | |
61 | + if (!is_dir($dst_data_path)) { | |
62 | + mkdir($dst_data_path); | |
63 | + chgrp($dst_data_path, APACHE_USER); | |
64 | + chmod($dst_data_path, 0775); | |
65 | + } | |
66 | + | |
67 | + $headerFilePath = $this->getHeaderFilePath($folder_name, $newId); | |
68 | + $headerFile = new SharedObjectHeaderFile($headerFilePath); | |
69 | + | |
70 | + $headerFile->setName($object_name); | |
71 | + $headerFile->setDescription($description); | |
72 | + $headerFile->setSharedBy($sharedBy); | |
73 | + date_default_timezone_set("UTC"); | |
74 | + $headerFile->setSharedDate(date("c")); | |
75 | + | |
76 | + $result = $this->addData($src_object_path, $dst_data_path, $newId, $object_name); | |
77 | + | |
78 | + if (!$result['success']) | |
79 | + return $result; | |
80 | + | |
81 | + return array('success' => TRUE, 'object_id' => $newId); | |
82 | + } | |
83 | + | |
84 | + public function getRootDirPath() { | |
85 | + return SHAREDPATH . "/" . $this->rootdirname; | |
86 | + } | |
87 | + | |
88 | + public function getFolderDirPath($folder_name) { | |
89 | + return $this->getRootDirPath() . "/" . $folder_name; | |
90 | + } | |
91 | + | |
92 | + public function getHeaderDirPath($folder_name) { | |
93 | + return $this->getFolderDirPath($folder_name) . "/" . self::$headerdirname; | |
94 | + } | |
95 | + | |
96 | + public function getDataDirPath($folder_name) { | |
97 | + return $this->getFolderDirPath($folder_name) . "/" . self::$datadirname; | |
98 | + } | |
99 | + | |
100 | + public function getHeaderFilePath($folder_name, $object_id) { | |
101 | + return $this->getHeaderDirPath($folder_name) . "/" . $object_id . ".xml"; | |
102 | + } | |
103 | + | |
104 | + public function getDataFilePath($folder_name, $object_id) { | |
105 | + return $this->getDataDirPath($folder_name) . "/" . $object_id . ".xml"; | |
106 | + } | |
107 | + | |
108 | + public function scanObjects() { | |
109 | + $root_dir = $this->getRootDirPath(); | |
110 | + $folders = $this->scanDir($root_dir, TRUE, FALSE); | |
111 | + $result = array(); | |
112 | + foreach ($folders as $folder_name) { | |
113 | + $header_path = $this->getHeaderDirPath($folder_name); | |
114 | + if (!is_dir($header_path)) { | |
115 | + mkdir($header_path); | |
116 | + chgrp($header_path, APACHE_USER); | |
117 | + chmod($header_path, 0775); | |
118 | + } | |
119 | + $header_files = $this->scanDir($header_path, FALSE, TRUE); | |
120 | + | |
121 | + $data_path = $this->getDataDirPath($folder_name); | |
122 | + if (!is_dir($data_path)) { | |
123 | + mkdir($data_path); | |
124 | + chgrp($data_path, APACHE_USER); | |
125 | + chmod($data_path, 0775); | |
126 | + } | |
127 | + $data_files = $this->scanDir($data_path, FALSE, TRUE); | |
128 | + | |
129 | + foreach ($header_files as $header_file) { | |
130 | + //Check if we have header and data files | |
131 | + if (!in_array($header_file, $data_files)) | |
132 | + continue; | |
133 | + if (!array_key_exists($folder_name, $result)) | |
134 | + $result[$folder_name] = array(); | |
135 | + | |
136 | + $result[$folder_name][] = basename($header_file, ".xml");; | |
137 | + } | |
138 | + //Add empty folders | |
139 | + if (!array_key_exists($folder_name, $result)) | |
140 | + $result[$folder_name] = array(); | |
141 | + } | |
142 | + | |
143 | + return $result; | |
144 | + } | |
145 | + | |
146 | + private function scanDir($dir, $getDirs, $getFiles) { | |
147 | + $dirs = array_diff(scandir($dir), Array( ".", ".." )); | |
148 | + | |
149 | + $result = array(); | |
150 | + foreach($dirs as $d){ | |
151 | + if($getDirs && is_dir($dir."/".$d)) | |
152 | + $result[] = $d; | |
153 | + if($getFiles && !is_dir($dir."/".$d)) | |
154 | + $result[] = $d; | |
155 | + } | |
156 | + | |
157 | + return $result; | |
158 | + } | |
159 | +} | |
160 | + | |
161 | +?> | |
0 | 162 | \ No newline at end of file |
... | ... |
... | ... | @@ -0,0 +1,283 @@ |
1 | +<?php | |
2 | +/** | |
3 | + * @class SharedObjectTreeFile | |
4 | + * @version | |
5 | + * | |
6 | + */ | |
7 | + | |
8 | +class SharedObjectTreeFile { | |
9 | + public static $FILE_NAME = "SharedObjectTree.xml"; | |
10 | + | |
11 | + private $doc = null; | |
12 | + | |
13 | + public static $ROOT_NODE_NAME = "shared"; | |
14 | + public static $LIST_NODE_NAME_SUFFIX = "List"; | |
15 | + | |
16 | + function __construct() { | |
17 | + $this->init(); | |
18 | + } | |
19 | + | |
20 | + public function update($object_type, $object_mgr) { | |
21 | + //Get available objects | |
22 | + $objects = $object_mgr->scanObjects(); | |
23 | + | |
24 | + //Update related folders and objects | |
25 | + $listNode = $this->getObjectListNode($object_type); | |
26 | + | |
27 | + if (!isset($listNode)) | |
28 | + $listNode = $this->createObjectListNode($object_type); | |
29 | + | |
30 | + $lastObjectId = $listNode->getAttribute("lastObjectId"); | |
31 | + | |
32 | + foreach ($objects as $folder_name => $folder_objects) { | |
33 | + $folderNode = $this->getObjectFolderNode($object_type, $folder_name); | |
34 | + | |
35 | + if (!isset($folderNode)) | |
36 | + $folderNode = $this->createObjectFolderNode($object_type, $folder_name); | |
37 | + | |
38 | + foreach ($folder_objects as $object_id) { | |
39 | + $objectNode = $this->getObjectNode($object_type, $folder_name, $object_id); | |
40 | + | |
41 | + if (!isset($objectNode)) | |
42 | + $objectNode = $this->createObjectNode($object_type, $folder_name, $object_id); | |
43 | + | |
44 | + if (!isset($objectNode)) | |
45 | + continue; | |
46 | + | |
47 | + $description = $object_mgr->getDescription($folder_name, $object_id); | |
48 | + | |
49 | + foreach ($description as $key => $value) | |
50 | + $objectNode->setAttribute($key, $value); | |
51 | + } | |
52 | + } | |
53 | + | |
54 | + | |
55 | + //Remove obsolete folders and objects | |
56 | + | |
57 | + $this->doc->save($this->getFilePath()); | |
58 | + | |
59 | + return array('success' => TRUE); | |
60 | + } | |
61 | + | |
62 | + public function reserveNewId($object_type) { | |
63 | + $listNode = $this->getObjectListNode($object_type); | |
64 | + | |
65 | + if (!isset($listNode)) | |
66 | + return NULL; | |
67 | + | |
68 | + $lastObjectId = $listNode->getAttribute("lastObjectId"); | |
69 | + | |
70 | + if ($lastObjectId == "") | |
71 | + $lastObjectId = 'shared' . $object_type . '_0'; | |
72 | + else { | |
73 | + $res = sscanf($lastObjectId , 'shared' . $object_type . '_%d'); | |
74 | + $lastObjectId = 'shared' . $object_type . '_' . ($res[0] + 1); | |
75 | + } | |
76 | + | |
77 | + $listNode->setAttribute("lastObjectId", $lastObjectId); | |
78 | + | |
79 | + $this->doc->save($this->getFilePath()); | |
80 | + | |
81 | + return $lastObjectId; | |
82 | + } | |
83 | + | |
84 | + public function getFolders($object_type) { | |
85 | + $listNode = $this->getObjectListNode($object_type); | |
86 | + | |
87 | + if (!isset($listNode)) | |
88 | + return array(); | |
89 | + | |
90 | + $folderNodes = $listNode->getElementsByTagName("folder"); | |
91 | + | |
92 | + $folders = array(); | |
93 | + foreach ($folderNodes as $folderNode) { | |
94 | + if (empty($folderNode->getAttribute('name')) || empty($folderNode->getAttribute('xml:id'))) | |
95 | + continue; | |
96 | + $folders[] = array('id' => $folderNode->getAttribute('xml:id'), 'name' => $folderNode->getAttribute('name')); | |
97 | + } | |
98 | + | |
99 | + return $folders; | |
100 | + } | |
101 | + | |
102 | + public function isNameAlreadyUsed($object_type, $name) { | |
103 | + $listNode = $this->getObjectListNode($object_type); | |
104 | + | |
105 | + if (!isset($listNode)) | |
106 | + return FALSE; | |
107 | + | |
108 | + $folderNodes = $listNode->getElementsByTagName("folder"); | |
109 | + | |
110 | + foreach ($folderNodes as $folderNode) { | |
111 | + $objectNodes = $folderNode->getElementsByTagName($object_type); | |
112 | + foreach ($objectNodes as $objectNode) { | |
113 | + if ($objectNode->getAttribute('name') == $name) | |
114 | + return TRUE; | |
115 | + } | |
116 | + } | |
117 | + | |
118 | + return FALSE; | |
119 | + } | |
120 | + | |
121 | + public function getFolderNameById($object_type, $folder_id) { | |
122 | + $listNode = $this->getObjectListNode($object_type); | |
123 | + | |
124 | + if (!isset($listNode)) | |
125 | + return ""; | |
126 | + | |
127 | + $folderNodes = $listNode->getElementsByTagName("folder"); | |
128 | + | |
129 | + foreach ($folderNodes as $folderNode) { | |
130 | + if (empty($folderNode->getAttribute('name')) || empty($folderNode->getAttribute('xml:id'))) | |
131 | + continue; | |
132 | + if ($folder_id != $folderNode->getAttribute('xml:id')) | |
133 | + continue; | |
134 | + return $folderNode->getAttribute('name'); | |
135 | + } | |
136 | + | |
137 | + return FALSE; | |
138 | + } | |
139 | + | |
140 | + public function getFolderIdByObjectId($object_type, $object_id) { | |
141 | + $listNode = $this->getObjectListNode($object_type); | |
142 | + | |
143 | + if (!isset($listNode)) | |
144 | + return ""; | |
145 | + | |
146 | + $folderNodes = $listNode->getElementsByTagName("folder"); | |
147 | + | |
148 | + foreach ($folderNodes as $folderNode) { | |
149 | + if (empty($folderNode->getAttribute('name')) || empty($folderNode->getAttribute('xml:id'))) | |
150 | + continue; | |
151 | + | |
152 | + $objectNodes = $folderNode->getElementsByTagName($object_type); | |
153 | + | |
154 | + foreach ($objectNodes as $objectNode) { | |
155 | + if ($objectNode->getAttribute('xml:id') == $object_id) | |
156 | + return $folderNode->getAttribute('xml:id'); | |
157 | + } | |
158 | + } | |
159 | + | |
160 | + return ""; | |
161 | + } | |
162 | + | |
163 | + private function init() { | |
164 | + if (!file_exists($this->getFilePath())) | |
165 | + $this->createFile(); | |
166 | + else | |
167 | + $this->loadFile(); | |
168 | + } | |
169 | + | |
170 | + public function getFilePath() { | |
171 | + | |
172 | + return SHAREDPATH . "/" . self::$FILE_NAME; | |
173 | + } | |
174 | + | |
175 | + private function createFile() { | |
176 | + $this->doc = new DOMDocument("1.0", "UTF-8"); | |
177 | + $this->doc->preserveWhiteSpace = false; | |
178 | + $this->doc->formatOutput = true; | |
179 | + | |
180 | + $xmlNode = $this->doc->createElement("shared"); | |
181 | + $this->doc->appendChild($xmlNode); | |
182 | + | |
183 | + $this->doc->save($this->getFilePath()); | |
184 | + chgrp($this->getFilePath(), APACHE_USER); | |
185 | + chmod($this->getFilePath(), 0775); | |
186 | + } | |
187 | + | |
188 | + private function loadFile() { | |
189 | + $this->doc = new DOMDocument("1.0", "UTF-8"); | |
190 | + $this->doc->preserveWhiteSpace = false; | |
191 | + $this->doc->formatOutput = true; | |
192 | + | |
193 | + $this->doc->load($this->getFilePath()); | |
194 | + } | |
195 | + | |
196 | + private function getObjectListNode($object_type) { | |
197 | + $nodeName = $object_type . "List"; | |
198 | + $listNodes = $this->doc->documentElement->getElementsByTagName($nodeName); | |
199 | + | |
200 | + if (count($listNodes) == 0) | |
201 | + return NULL; | |
202 | + | |
203 | + return $listNodes->item(0); | |
204 | + } | |
205 | + | |
206 | + private function createObjectListNode($object_type) { | |
207 | + $nodeName = $object_type . "List"; | |
208 | + | |
209 | + $listNode = $this->doc->createElement($nodeName); | |
210 | + $listNode->setAttribute("xml:id", "shared" . $object_type . "-treeRootNode"); | |
211 | + $this->doc->documentElement->appendChild($listNode); | |
212 | + $this->doc->save($this->getFilePath()); | |
213 | + return $listNode; | |
214 | + } | |
215 | + | |
216 | + private function getObjectFolderNode($object_type, $folder_name) { | |
217 | + $listNode = $this->getObjectListNode($object_type); | |
218 | + if (!isset($listNode)) | |
219 | + return NULL; | |
220 | + | |
221 | + $folderNodes = $listNode->getElementsByTagName("folder"); | |
222 | + | |
223 | + foreach ($folderNodes as $folderNode) { | |
224 | + if ($folderNode->getAttribute('name') == $folder_name) | |
225 | + return $folderNode; | |
226 | + } | |
227 | + | |
228 | + return NULL; | |
229 | + } | |
230 | + | |
231 | + private function createObjectFolderNode($object_type, $folder_name) { | |
232 | + $listNode = $this->getObjectListNode($object_type); | |
233 | + if (!isset($listNode)) | |
234 | + return NULL; | |
235 | + | |
236 | + $folderNode = $this->doc->createElement("folder"); | |
237 | + $folderNode->setAttribute("xml:id", $folder_name . '_' . $object_type); | |
238 | + $folderNode->setAttribute("name", $folder_name); | |
239 | + | |
240 | + $listNode->appendChild($folderNode); | |
241 | + $this->doc->save($this->getFilePath()); | |
242 | + return $folderNode; | |
243 | + } | |
244 | + | |
245 | + private function getObjectNode($object_type, $folder_name, $object_id) { | |
246 | + $folderNode = $this->getObjectFolderNode($object_type, $folder_name); | |
247 | + | |
248 | + if (!isset($folderNode)) | |
249 | + return NULL; | |
250 | + | |
251 | + $objectNodes = $folderNode->getElementsByTagName($object_type); | |
252 | + | |
253 | + foreach ($objectNodes as $objectNode) { | |
254 | + if ($objectNode->getAttribute('xml:id') == $object_id) | |
255 | + return $objectNode; | |
256 | + } | |
257 | + | |
258 | + return NULL; | |
259 | + } | |
260 | + | |
261 | + private function createObjectNode($object_type, $folder_name, $object_id) { | |
262 | + $listNode = $this->getObjectListNode($object_type); | |
263 | + | |
264 | + if (!isset($listNode)) | |
265 | + return NULL; | |
266 | + | |
267 | + $folderNode = $this->getObjectFolderNode($object_type, $folder_name); | |
268 | + | |
269 | + if (!isset($folderNode)) | |
270 | + return NULL; | |
271 | + | |
272 | + $objectNode = $this->doc->createElement($object_type); | |
273 | + $objectNode->setAttribute("xml:id", $object_id); | |
274 | + | |
275 | + $folderNode->appendChild($objectNode); | |
276 | + | |
277 | + $this->doc->save($this->getFilePath()); | |
278 | + | |
279 | + return $objectNode; | |
280 | + } | |
281 | +} | |
282 | + | |
283 | +?> | |
0 | 284 | \ No newline at end of file |
... | ... |
... | ... | @@ -0,0 +1,99 @@ |
1 | +<?php | |
2 | +/** | |
3 | + * @class SharedObjectsMgr | |
4 | + * @version | |
5 | + * | |
6 | + */ | |
7 | + | |
8 | +class SharedObjectsMgr { | |
9 | + private $sharedObjectsMgr = array(); | |
10 | + | |
11 | + private $treeFile = null; | |
12 | + | |
13 | + function __construct() { | |
14 | + $this->init(); | |
15 | + } | |
16 | + | |
17 | + public function updateTree() { | |
18 | + $sucess = TRUE; | |
19 | + $message = ""; | |
20 | + foreach ($this->sharedObjectsMgr as $key => $mgr) { | |
21 | + if (!isset($mgr)) | |
22 | + continue; | |
23 | + $result = $this->treeFile->update($key, $mgr); | |
24 | + $sucess &= $result['success']; | |
25 | + if (!$result['success']) { | |
26 | + if (!empty($message)) | |
27 | + $message .= "; "; | |
28 | + $message .= $result['message']; | |
29 | + } | |
30 | + } | |
31 | + | |
32 | + return array('success' => $sucess, 'message' => $message); | |
33 | + } | |
34 | + | |
35 | + public function add($object_type, $object_name, $folder_id, $src_object_path, $description, $sharedBy) { | |
36 | + if (!array_key_exists($object_type, $this->sharedObjectsMgr) || !isset($this->sharedObjectsMgr[$object_type])) | |
37 | + return array('success' => FALSE, 'message' => 'Unknown type'); | |
38 | + | |
39 | + $folder_name = $this->treeFile->getFolderNameById($object_type, $folder_id); | |
40 | + | |
41 | + if (empty($folder_name)) | |
42 | + return array('success' => FALSE, 'message' => 'Cannot retrieve folder'); | |
43 | + | |
44 | + $newId = $this->treeFile->reserveNewId($object_type); | |
45 | + | |
46 | + $result = $this->sharedObjectsMgr[$object_type]->add($object_name, $folder_name, $src_object_path, $description, $sharedBy, $newId); | |
47 | + | |
48 | + if ($result['success']) | |
49 | + $result['folder_id'] = $folder_id; | |
50 | + | |
51 | + return $result; | |
52 | + } | |
53 | + | |
54 | + public function getFolders($object_type) { | |
55 | + if (!array_key_exists($object_type, $this->sharedObjectsMgr) || !isset($this->sharedObjectsMgr[$object_type])) | |
56 | + return array(); | |
57 | + | |
58 | + return $this->treeFile->getFolders($object_type); | |
59 | + } | |
60 | + | |
61 | + public function isNameAlreadyUsed($object_type, $name) { | |
62 | + if (!array_key_exists($object_type, $this->sharedObjectsMgr) || !isset($this->sharedObjectsMgr[$object_type])) | |
63 | + return FALSE; | |
64 | + | |
65 | + return $this->treeFile->isNameAlreadyUsed($object_type, $name); | |
66 | + } | |
67 | + | |
68 | + public function getDataFilePath($object_type, $object_id) { | |
69 | + if (!array_key_exists($object_type, $this->sharedObjectsMgr) || !isset($this->sharedObjectsMgr[$object_type])) | |
70 | + return ""; | |
71 | + | |
72 | + $folder_id = $this->treeFile->getFolderIdByObjectId($object_type, $object_id); | |
73 | + | |
74 | + $folder_name = $this->treeFile->getFolderNameById($object_type, $folder_id); | |
75 | + | |
76 | + if (empty($folder_name)) | |
77 | + return ""; | |
78 | + | |
79 | + return $this->sharedObjectsMgr[$object_type]->getDataFilePath($folder_name, $object_id); | |
80 | + } | |
81 | + | |
82 | + public function getTreeFilePath() { | |
83 | + return $this->treeFile->getFilePath(); | |
84 | + } | |
85 | + | |
86 | + private function init() { | |
87 | + if (!is_dir(SHAREDPATH)) { | |
88 | + mkdir(SHAREDPATH); | |
89 | + chgrp(SHAREDPATH, APACHE_USER); | |
90 | + chmod(SHAREDPATH, 0775); | |
91 | + } | |
92 | + | |
93 | + $this->treeFile = new SharedObjectTreeFile(); | |
94 | + $this->sharedObjectsMgr["timeTable"] = new SharedTimeTableMgrImpl(); | |
95 | + $this->sharedObjectsMgr["catalog"] = new SharedCatalogMgrImpl(); | |
96 | + } | |
97 | +} | |
98 | + | |
99 | +?> | |
0 | 100 | \ No newline at end of file |
... | ... |
... | ... | @@ -0,0 +1,36 @@ |
1 | +<?php | |
2 | +/** | |
3 | + * @class SharedTimeTableMgrImpl | |
4 | + * @version | |
5 | + * | |
6 | + */ | |
7 | + | |
8 | +class SharedTimeTableMgrImpl extends SharedObjectMgrAbstract { | |
9 | + public static $ROOT_DIR_NAME = "TT"; | |
10 | + | |
11 | + private $ttMgr = NULL; | |
12 | + | |
13 | + function __construct() { | |
14 | + $this->rootdirname = self::$ROOT_DIR_NAME; | |
15 | + $this->ttMgr = new TimeTableMgr("", TRUE); | |
16 | + parent::__construct(); | |
17 | + } | |
18 | + | |
19 | + protected function getDataInfo($object_id) { | |
20 | + $result = $this->ttMgr->getObject($object_id, 'sharedtimeTable'); | |
21 | + | |
22 | + if (!isset($result) || array_key_exists('error', $result)) | |
23 | + return array(); | |
24 | + | |
25 | + return $result; | |
26 | + } | |
27 | + | |
28 | + protected function addData($src_object_path, $dst_data_path, $newId, $newName) { | |
29 | + $result = $this->ttMgr->copyTT($src_object_path, $dst_data_path, $newId, $newName); | |
30 | + if (!$result) | |
31 | + return array('success' => FALSE, 'message' => 'Cannot copy the TimeTable'); | |
32 | + return array('success' => TRUE); | |
33 | + } | |
34 | +} | |
35 | + | |
36 | +?> | |
0 | 37 | \ No newline at end of file |
... | ... |
php/classes/TimeTableMgr.php
... | ... | @@ -22,7 +22,7 @@ function timeFormat($myString) |
22 | 22 | |
23 | 23 | class TimeTableMgr extends AmdaObjectMgr |
24 | 24 | { |
25 | - function __construct($user) | |
25 | + function __construct($user, $sharedObject = FALSE) | |
26 | 26 | { |
27 | 27 | parent::__construct('Tt.xml'); |
28 | 28 | $this->contentRootId = 'timeTable-treeRootNode'; |
... | ... | @@ -32,7 +32,7 @@ class TimeTableMgr extends AmdaObjectMgr |
32 | 32 | $this->objTagName = 'timetab'; |
33 | 33 | $this->id_prefix = 'tt_'; |
34 | 34 | |
35 | - if (!file_exists($this->xmlName)) { | |
35 | + if (!$sharedObject && !file_exists($this->xmlName)) { | |
36 | 36 | $this->createDom(); |
37 | 37 | $this->xp = new domxpath($this->contentDom); |
38 | 38 | } |
... | ... | @@ -287,16 +287,17 @@ class TimeTableMgr extends AmdaObjectMgr |
287 | 287 | */ |
288 | 288 | |
289 | 289 | function getObject($id, $nodeType) { |
290 | - | |
291 | - if (substr($nodeType,0,6) == 'shared') { | |
292 | - $pathid = SHAREDPATH.'TT/'.$id; | |
290 | + if (substr($nodeType,0,6) == 'shared') { | |
291 | + //Shared object | |
292 | + $sharedObjMgr = new SharedObjectsMgr(); | |
293 | + $path = $sharedObjMgr->getDataFilePath(str_replace('shared', '', $nodeType), $id); | |
293 | 294 | } |
294 | 295 | else { |
295 | - $pathid = USERTTDIR.$id; | |
296 | + $path = USERTTDIR.$id.'.xml'; | |
296 | 297 | } |
297 | 298 | |
298 | - if (!file_exists($pathid.'.xml')) return array('error' => NO_OBJECT_FILE); | |
299 | - $this->objectDom -> load($pathid.'.xml'); | |
299 | + if (!file_exists($path)) return array('error' => NO_OBJECT_FILE); | |
300 | + $this->objectDom -> load($path); | |
300 | 301 | if (!($objToGet = $this->objectDom->getElementById($id))) return array('error' => NO_SUCH_ID); |
301 | 302 | $attributesToReturn['id'] = $objToGet->getAttribute('xml:id'); |
302 | 303 | $attributes = $objToGet -> childNodes; |
... | ... | @@ -384,19 +385,21 @@ class TimeTableMgr extends AmdaObjectMgr |
384 | 385 | } |
385 | 386 | |
386 | 387 | public function loadIntervalsFromTT($id,$typeTT,$start = NULL, $limit = NULL) |
387 | - { | |
388 | + { | |
388 | 389 | |
389 | - if ($typeTT == 'sharedtimeTable') { | |
390 | - $pathid = SHAREDPATH.'TT/'.$id; | |
391 | - } | |
392 | - else { | |
393 | - $pathid = USERTTDIR.$id; | |
394 | - } | |
390 | + if ($typeTT == 'sharedtimeTable') { | |
391 | + //Shared object | |
392 | + $sharedObjMgr = new SharedObjectsMgr(); | |
393 | + $path = $sharedObjMgr->getDataFilePath('timeTable', $id); | |
394 | + } | |
395 | + else { | |
396 | + $path = USERTTDIR.$id.'.xml'; | |
397 | + } | |
395 | 398 | |
396 | 399 | //load intervals from TT id |
397 | - if (!file_exists($pathid.'.xml')) | |
400 | + if (!file_exists($path)) | |
398 | 401 | return array('success' => false, 'message' => "Cannot find TT file ".$id); |
399 | - $this->objectDom -> load($pathid.'.xml'); | |
402 | + $this->objectDom -> load($path); | |
400 | 403 | if (!($objToGet = $this->objectDom->getElementById($id))) |
401 | 404 | return array('success' => false, 'message' => NO_SUCH_ID." ".$id); |
402 | 405 | |
... | ... | @@ -446,15 +449,15 @@ class TimeTableMgr extends AmdaObjectMgr |
446 | 449 | |
447 | 450 | public function saveIntervals($id,$intervals,$action) |
448 | 451 | { |
449 | - if (substr($id,0,6) == 'shared') { | |
450 | - $pathid = SHAREDPATH.'TT/'.$id; | |
451 | - } | |
452 | + if (substr($id,0,6) == 'shared') { | |
453 | + return array('success' => false, 'message' => "Cannot save shared TimeTable"); | |
454 | + } | |
452 | 455 | else { |
453 | - $pathid = USERTTDIR.$id; | |
454 | - } | |
455 | - if (!file_exists($pathid.'.xml')) | |
456 | + $path = USERTTDIR.$id.'.xml'; | |
457 | + } | |
458 | + if (!file_exists($path)) | |
456 | 459 | return array('success' => false, 'message' => "Cannot find TT file ".$id); |
457 | - $this->objectDom -> load($pathid.'.xml'); | |
460 | + $this->objectDom -> load($path); | |
458 | 461 | |
459 | 462 | if (!($objToGet = $this->objectDom->getElementById($id))) |
460 | 463 | return array('success' => false, 'message' => NO_SUCH_ID." ".$id); |
... | ... | @@ -769,6 +772,49 @@ class TimeTableMgr extends AmdaObjectMgr |
769 | 772 | |
770 | 773 | return array('valid' => false, 'error' => 'Space character is not allowed'); |
771 | 774 | } |
775 | + | |
776 | + public function copyTT($src_path, $dst_path, $newId, $newName) { | |
777 | + if (!file_exists($src_path)) | |
778 | + return FALSE; | |
779 | + | |
780 | + if (!is_dir($dst_path)) | |
781 | + return FALSE; | |
782 | + | |
783 | + $dom = new DomDocument('1.0'); | |
784 | + $dom->formatOutput = true; | |
785 | + | |
786 | + if (!$dom->load($src_path)) | |
787 | + return FALSE; | |
788 | + | |
789 | + $timeTableNodes = $dom->getElementsByTagName('timetable'); | |
790 | + if (count($timeTableNodes) <= 0) | |
791 | + return FALSE; | |
792 | + | |
793 | + $timeTableNode = $timeTableNodes->item(0); | |
794 | + | |
795 | + $timeTableNode->setAttribute('xml:id', $newId); | |
796 | + | |
797 | + $nameNodes = $timeTableNode->getElementsByTagName('name'); | |
798 | + | |
799 | + if (count($nameNodes) <= 0) { | |
800 | + //create name node (normally never append) | |
801 | + $nameNode = $dom->createElement('name'); | |
802 | + $timeTableNode->appendChild($nameNode); | |
803 | + } | |
804 | + else | |
805 | + $nameNode = $nameNodes->item(0); | |
806 | + | |
807 | + $nameNode->nodeValue = $newName; | |
808 | + | |
809 | + $dst_file_path = $dst_path."/".$newId.".xml"; | |
810 | + if ($dom->save($dst_file_path) === FALSE) | |
811 | + return FALSE; | |
812 | + | |
813 | + chgrp($dst_file_path, APACHE_USER); | |
814 | + chmod($dst_file_path, 0775); | |
815 | + | |
816 | + return TRUE; | |
817 | + } | |
772 | 818 | |
773 | 819 | } |
774 | 820 | ?> |
... | ... |
php/classes/WebServer.php
... | ... | @@ -222,8 +222,10 @@ class WebServer |
222 | 222 | $ttListWSresult = $this->resultMgr->getResOutputName(__FUNCTION__,$this->userID); |
223 | 223 | |
224 | 224 | $dom = new DOMDocument("1.0"); |
225 | - if ($this->userID == 'impex') | |
226 | - $loadDom = $dom->load(SHAREDPATH.'WS/Tt.xml'); | |
225 | + if ($this->userID == 'impex') { | |
226 | + $sharedObjMgr = new SharedObjectsMgr(); | |
227 | + $loadDom = $dom->load($sharedObjMgr->getTreeFilePath()); | |
228 | + } | |
227 | 229 | else |
228 | 230 | $loadDom = $dom->load(USERPATH.$this->userID.'/WS/Tt.xml'); |
229 | 231 | |
... | ... | @@ -267,8 +269,10 @@ class WebServer |
267 | 269 | $vars = $res['vars']; |
268 | 270 | $ttID = $vars['ttID']; |
269 | 271 | |
270 | - if ($this->userID == 'impex') | |
271 | - $ttSrc = SHAREDPATH.'TT/'.$ttID.'.xml'; | |
272 | + if ($this->userID == 'impex') { | |
273 | + $sharedObjMgr = new SharedObjectsMgr(); | |
274 | + $ttSrc = $sharedObjMgr->getDataFilePath('timeTable', $ttID); | |
275 | + } | |
272 | 276 | else |
273 | 277 | $ttSrc = USERPATH.$this->userID.'/TT/'.$ttID.'.xml'; |
274 | 278 | |
... | ... |
php/config.php
... | ... | @@ -146,7 +146,7 @@ define('targetsSimu',HELPPATH.'simu/TargetsSimu.xml'); |
146 | 146 | define('USERPATH', BASE_PATH.'data/'); |
147 | 147 | |
148 | 148 | // Shared dir |
149 | -define('SHAREDPATH', USERPATH.'SHAREDTT/'); | |
149 | +define('SHAREDPATH', BASE_PATH.'shared_data/'); | |
150 | 150 | |
151 | 151 | // Web Services result directory |
152 | 152 | define('WSRESULT', USERPATH.'WSRESULT/'); |
... | ... | @@ -371,6 +371,15 @@ $API = array( |
371 | 371 | ), |
372 | 372 | 'getParamInfo'=>array( |
373 | 373 | 'len'=>1 |
374 | + ), | |
375 | + 'getSharedObjectFolders' => array( | |
376 | + 'len'=>1 | |
377 | + ), | |
378 | + 'shareObjects' => array( | |
379 | + 'len'=>1 | |
380 | + ), | |
381 | + 'isSharedObjectNameAlreadyUsed' => array( | |
382 | + 'len'=>1 | |
374 | 383 | ) |
375 | 384 | ) |
376 | 385 | ) |
... | ... |