ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilECSCmsTreeSynchronizer Class Reference

Description of class. More...

+ Collaboration diagram for ilECSCmsTreeSynchronizer:

Public Member Functions

 __construct (ilECSSetting $server, $mid, $tree_id)
 Constructor. More...
 
 getServer ()
 Get server. More...
 
 getTree ()
 
 getDefaultSettings ()
 Get default settings. More...
 
 getGlobalSettings ()
 get global settings More...
 
 sync ()
 Synchronize tree. More...
 

Protected Member Functions

 checkTreeUpdates ($a_root_obj_id)
 Start tree update check. More...
 
 handleTreeUpdate ($a_parent_ref_id, $a_tnode_id)
 Handle tree update (recursively) More...
 
 syncNode ($tree_obj_id, $parent_id, $a_mapped=false)
 Sync node. More...
 
 syncCategory (ilECSNodeMappingAssignment $ass, $parent_id)
 Sync category. More...
 

Private Attributes

 $server = null
 
 $mid = null
 
 $tree_id = null
 
 $tree = null
 
 $default_settings = array()
 
 $global_settings = null
 

Detailed Description

Description of class.

Author
Stefan Meyer smeye.nosp@m.r.il.nosp@m.ias@g.nosp@m.mx.d.nosp@m.e

Definition at line 15 of file class.ilECSCmsTreeSynchronizer.php.

Constructor & Destructor Documentation

◆ __construct()

ilECSCmsTreeSynchronizer::__construct ( ilECSSetting  $server,
  $mid,
  $tree_id 
)

Constructor.

Definition at line 29 of file class.ilECSCmsTreeSynchronizer.php.

30 {
31 $this->server = $server;
32 $this->mid = $mid;
33 $this->tree = new ilECSCmsTree($tree_id);
34 $this->tree_id = $tree_id;
35
36 include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingSettings.php';
37 $this->global_settings = ilECSNodeMappingSettings::getInstanceByServerMid($this->getServer()->getServerId(),$this->mid);
38 }
static getInstanceByServerMid($a_server_id, $a_mid)
Get instance.

References $mid, $server, $tree_id, ilECSNodeMappingSettings\getInstanceByServerMid(), and getServer().

+ Here is the call graph for this function:

Member Function Documentation

◆ checkTreeUpdates()

ilECSCmsTreeSynchronizer::checkTreeUpdates (   $a_root_obj_id)
protected

Start tree update check.

Parameters
type$a_root_obj_id
Returns
bool

Definition at line 113 of file class.ilECSCmsTreeSynchronizer.php.

114 {
115 if($this->default_settings['tree_update'] == false)
116 {
117 $GLOBALS['ilLog']->write(__METHOD__.': Tree update disabled for tree with id '. $this->getTree()->getTreeId());
118 return false;
119 }
120
121 // Start recursion
122 include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingAssignment.php';
123 $mapping = new ilECSNodeMappingAssignment(
124 $this->getServer()->getServerId(),
125 $this->mid,
126 $this->tree_id,
127 $a_root_obj_id
128 );
129 $a_root_ref_id = $mapping->getRefId();
130 if($a_root_ref_id)
131 {
132 $this->handleTreeUpdate($a_root_ref_id, $a_root_obj_id);
133 }
134 }
handleTreeUpdate($a_parent_ref_id, $a_tnode_id)
Handle tree update (recursively)
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276

References $GLOBALS, getServer(), and handleTreeUpdate().

Referenced by sync().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDefaultSettings()

ilECSCmsTreeSynchronizer::getDefaultSettings ( )

Get default settings.

Returns
type

Definition at line 61 of file class.ilECSCmsTreeSynchronizer.php.

References $default_settings.

Referenced by sync().

+ Here is the caller graph for this function:

◆ getGlobalSettings()

ilECSCmsTreeSynchronizer::getGlobalSettings ( )

get global settings

Returns
ilECSNodeMappingSettings

Definition at line 70 of file class.ilECSCmsTreeSynchronizer.php.

References $global_settings.

Referenced by syncCategory().

+ Here is the caller graph for this function:

◆ getServer()

ilECSCmsTreeSynchronizer::getServer ( )

Get server.

Returns
ilECSSetting

Definition at line 44 of file class.ilECSCmsTreeSynchronizer.php.

45 {
46 return $this->server;
47 }

References $server.

Referenced by __construct(), checkTreeUpdates(), handleTreeUpdate(), sync(), syncCategory(), and syncNode().

+ Here is the caller graph for this function:

◆ getTree()

ilECSCmsTreeSynchronizer::getTree ( )
Returns
ilECSCmsTree

Definition at line 52 of file class.ilECSCmsTreeSynchronizer.php.

References $tree.

Referenced by handleTreeUpdate(), and syncNode().

+ Here is the caller graph for this function:

◆ handleTreeUpdate()

ilECSCmsTreeSynchronizer::handleTreeUpdate (   $a_parent_ref_id,
  $a_tnode_id 
)
protected

Handle tree update (recursively)

Parameters
type$a_parent_ref_id
type$tnode_id

Definition at line 141 of file class.ilECSCmsTreeSynchronizer.php.

142 {
143 global $tree;
144
145 // Check if node is already imported at location "parent_ref_id"
146 // If not => move it
147 $cms_data = new ilECSCmsData($a_tnode_id);
148
149 include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
151 $this->getServer()->getServerId(),
152 $this->mid,
153 $cms_data->getCmsId());
154 if(!$import_obj_id)
155 {
156 $GLOBALS['ilLog']->write(__METHOD__.': cms tree node not imported. tnode_id: '. $a_tnode_id);
157 return false;
158 }
159
160 $GLOBALS['ilLog']->write(__METHOD__.' parent ref:'.$a_parent_ref_id.' tnode:'. $a_tnode_id);
161 $ref_ids = ilObject::_getAllReferences($import_obj_id);
162 $import_ref_id = end($ref_ids);
163 $import_ref_id_parent = $tree->getParentId($import_ref_id);
164
165 if($a_parent_ref_id != $import_ref_id_parent)
166 {
167 // move node
168 $GLOBALS['ilLog']->write(__METHOD__.': Moving node '.$a_parent_ref_id.' to '.$import_ref_id);
169 $tree->moveTree($import_ref_id,$a_parent_ref_id);
170 }
171
172 // iterate through childs
173 $childs = $this->getTree()->getChilds($a_tnode_id);
174 foreach((array) $childs as $node)
175 {
176 $this->handleTreeUpdate($import_ref_id, $node['child']);
177 }
178 return true;
179 }
static lookupObjIdByContentId($a_server_id, $a_mid, $a_content_id, $a_sub_id='')
Lookup obj_id by content id.
static _getAllReferences($a_id)
get all reference ids of object

References $GLOBALS, $tree, ilObject\_getAllReferences(), getServer(), getTree(), handleTreeUpdate(), and ilECSImport\lookupObjIdByContentId().

Referenced by checkTreeUpdates(), and handleTreeUpdate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sync()

ilECSCmsTreeSynchronizer::sync ( )

Synchronize tree.

Returns
boolean

Definition at line 80 of file class.ilECSCmsTreeSynchronizer.php.

81 {
82 include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingAssignments.php';
83 $this->default_settings = ilECSNodeMappingAssignments::lookupSettings(
84 $this->getServer()->getServerId(),
85 $this->mid,
86 $this->tree_id,
87 0
88 );
89
90 // return if setting is false => no configuration done
91 if(!$this->getDefaultSettings())
92 {
93 $GLOBALS['ilLog']->write(__METHOD__.': No directory allocation settings. Aborting');
94 return true;
95 }
96
97 // lookup obj id of root node
98 include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsData.php';
99
100 $root_obj_id = ilECSCmsTree::lookupRootId($this->tree_id);
101 $this->syncNode($root_obj_id,0);
102
103 // Tree structure is up to date, now check node movements
104 $this->checkTreeUpdates($root_obj_id);
105 return true;
106 }
checkTreeUpdates($a_root_obj_id)
Start tree update check.
syncNode($tree_obj_id, $parent_id, $a_mapped=false)
Sync node.
static lookupRootId($a_tree_id)
lookup root id
static lookupSettings($a_server_id, $a_mid, $a_tree_id, $a_node_id)
Lookup Settings.

References $GLOBALS, checkTreeUpdates(), getDefaultSettings(), getServer(), ilECSCmsTree\lookupRootId(), ilECSNodeMappingAssignments\lookupSettings(), and syncNode().

+ Here is the call graph for this function:

◆ syncCategory()

ilECSCmsTreeSynchronizer::syncCategory ( ilECSNodeMappingAssignment  $ass,
  $parent_id 
)
protected

Sync category.

Parameters
ilECSNodeMappingAssignment$ass

Definition at line 228 of file class.ilECSCmsTreeSynchronizer.php.

229 {
230 include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsData.php';
231 $data = new ilECSCmsData($ass->getCSId());
232
233 // Check if node is imported => create
234 // perform title update
235 // perform position update
236 include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
238 $this->getServer()->getServerId(),
239 $this->mid,
240 $data->getCmsId());
241 if($obj_id)
242 {
243 $refs = ilObject::_getAllReferences($obj_id);
244 $ref_id = end($refs);
245
246
248 if(($cat instanceof ilObject) and $this->default_settings['title_update'])
249 {
250 $GLOBALS['ilLog']->write(__METHOD__.': Updating cms category ');
251 $GLOBALS['ilLog']->write(__METHOD__.': Title is '. $data->getTitle());
252 $cat->deleteTranslation($GLOBALS['lng']->getDefaultLanguage());
253 $cat->addTranslation(
254 $data->getTitle(),
255 $cat->getLongDescription(),
256 $GLOBALS['lng']->getDefaultLanguage(),
257 1
258 );
259 $cat->setTitle($data->getTitle());
260 $cat->update();
261 }
262 else
263 {
264 $GLOBALS['ilLog']->write(__METHOD__.': Updating cms category -> nothing to do');
265 }
266 return $ref_id;
267 }
268 elseif($this->getGlobalSettings()->isEmptyContainerCreationEnabled())
269 {
270 $GLOBALS['ilLog']->write(__METHOD__.': Creating new cms category');
271
272 // Create category
273 include_once './Modules/Category/classes/class.ilObjCategory.php';
274 $cat = new ilObjCategory();
275 $cat->setTitle($data->getTitle());
276 $cat->create(); // true for upload
277 $cat->createReference();
278 $cat->putInTree($parent_id);
279 $cat->setPermissions($parent_id);
280 $cat->deleteTranslation($GLOBALS['lng']->getDEfaultLanguage());
281 $cat->addTranslation(
282 $data->getTitle(),
283 $cat->getLongDescription(),
284 $GLOBALS['lng']->getDefaultLanguage(),
285 1
286 );
287
288 // set imported
289 $import = new ilECSImport(
290 $this->getServer()->getServerId(),
291 $cat->getId()
292 );
293 $import->setMID($this->mid);
294 $import->setContentId($data->getCmsId());
295 $import->setImported(true);
296 $import->save();
297
298 return $cat->getRefId();
299 }
300 else
301 {
302 $GLOBALS['ilLog']->write(__METHOD__.': Creation of empty containers is disabled.');
303 return 0;
304 }
305 }
Storage of ECS imported objects.
Class ilObjCategory.
getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
Class ilObject Basic functions for all objects.
$data
$ref_id
Definition: sahs_server.php:39

References $data, $GLOBALS, $ref_id, ilObject\_getAllReferences(), ilECSNodeMappingAssignment\getCSId(), getGlobalSettings(), ilObjectFactory\getInstanceByRefId(), getServer(), and ilECSImport\lookupObjIdByContentId().

Referenced by syncNode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ syncNode()

ilECSCmsTreeSynchronizer::syncNode (   $tree_obj_id,
  $parent_id,
  $a_mapped = false 
)
protected

Sync node.

Parameters
type$cs_id
type$setting

Definition at line 186 of file class.ilECSCmsTreeSynchronizer.php.

187 {
188 $childs = $this->getTree()->getChilds($tree_obj_id);
189
190 $assignment = new ilECSNodeMappingAssignment(
191 $this->getServer()->getServerId(),
192 $this->mid,
193 $this->tree_id,
194 $tree_obj_id);
195
196 if($assignment->getRefId())
197 {
198 $parent_id = $assignment->getRefId();
199 }
200
201 // information for deeper levels
202 if($assignment->isMapped())
203 {
204 $a_mapped = true;
205 }
206
207 if($a_mapped)
208 {
209 $parent_id = $this->syncCategory($assignment,$parent_id);
210 }
211
212 // this is not necessary
213 #if($parent_id)
214 {
215 // iterate through childs
216 foreach($childs as $node)
217 {
218 $this->syncNode($node['child'],$parent_id,$a_mapped);
219 }
220 }
221 return true;
222 }
syncCategory(ilECSNodeMappingAssignment $ass, $parent_id)
Sync category.

References getServer(), getTree(), syncCategory(), and syncNode().

Referenced by sync(), and syncNode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $default_settings

ilECSCmsTreeSynchronizer::$default_settings = array()
private

Definition at line 22 of file class.ilECSCmsTreeSynchronizer.php.

Referenced by getDefaultSettings().

◆ $global_settings

ilECSCmsTreeSynchronizer::$global_settings = null
private

Definition at line 23 of file class.ilECSCmsTreeSynchronizer.php.

Referenced by getGlobalSettings().

◆ $mid

ilECSCmsTreeSynchronizer::$mid = null
private

Definition at line 18 of file class.ilECSCmsTreeSynchronizer.php.

Referenced by __construct().

◆ $server

ilECSCmsTreeSynchronizer::$server = null
private

Definition at line 17 of file class.ilECSCmsTreeSynchronizer.php.

Referenced by __construct(), and getServer().

◆ $tree

ilECSCmsTreeSynchronizer::$tree = null
private

Definition at line 20 of file class.ilECSCmsTreeSynchronizer.php.

Referenced by getTree(), and handleTreeUpdate().

◆ $tree_id

ilECSCmsTreeSynchronizer::$tree_id = null
private

Definition at line 19 of file class.ilECSCmsTreeSynchronizer.php.

Referenced by __construct().


The documentation for this class was generated from the following file: