ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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.

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

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.
+ 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 112 of file class.ilECSCmsTreeSynchronizer.php.

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

Referenced by sync().

113  {
114  if ($this->default_settings['tree_update'] == false) {
115  $GLOBALS['ilLog']->write(__METHOD__ . ': Tree update disabled for tree with id ' . $this->getTree()->getTreeId());
116  return false;
117  }
118 
119  // Start recursion
120  include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingAssignment.php';
121  $mapping = new ilECSNodeMappingAssignment(
122  $this->getServer()->getServerId(),
123  $this->mid,
124  $this->tree_id,
125  $a_root_obj_id
126  );
127  $a_root_ref_id = $mapping->getRefId();
128  if ($a_root_ref_id) {
129  $this->handleTreeUpdate($a_root_ref_id, $a_root_obj_id);
130  }
131  }
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
handleTreeUpdate($a_parent_ref_id, $a_tnode_id)
Handle tree update (recursively)
+ 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, and array.

Referenced by sync().

62  {
64  }
Create styles array
The data for the language used.
+ 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.

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 checkTreeUpdates(), 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 138 of file class.ilECSCmsTreeSynchronizer.php.

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

Referenced by checkTreeUpdates().

139  {
140  global $tree;
141 
142  // Check if node is already imported at location "parent_ref_id"
143  // If not => move it
144  $cms_data = new ilECSCmsData($a_tnode_id);
145 
146  include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
147  $import_obj_id = ilECSImport::lookupObjIdByContentId(
148  $this->getServer()->getServerId(),
149  $this->mid,
150  $cms_data->getCmsId()
151  );
152  if (!$import_obj_id) {
153  $GLOBALS['ilLog']->write(__METHOD__ . ': cms tree node not imported. tnode_id: ' . $a_tnode_id);
154  return false;
155  }
156 
157  $GLOBALS['ilLog']->write(__METHOD__ . ' parent ref:' . $a_parent_ref_id . ' tnode:' . $a_tnode_id);
158  $ref_ids = ilObject::_getAllReferences($import_obj_id);
159  $import_ref_id = end($ref_ids);
160  $import_ref_id_parent = $tree->getParentId($import_ref_id);
161 
162  if ($a_parent_ref_id != $import_ref_id_parent) {
163  // move node
164  $GLOBALS['ilLog']->write(__METHOD__ . ': Moving node ' . $a_parent_ref_id . ' to ' . $import_ref_id);
165  $tree->moveTree($import_ref_id, $a_parent_ref_id);
166  }
167 
168  // iterate through childs
169  $childs = $this->getTree()->getChilds($a_tnode_id);
170  foreach ((array) $childs as $node) {
171  $this->handleTreeUpdate($import_ref_id, $node['child']);
172  }
173  return true;
174  }
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
static lookupObjIdByContentId($a_server_id, $a_mid, $a_content_id, $a_sub_id=null)
Lookup obj_id by content id.
static _getAllReferences($a_id)
get all reference ids of object
Create styles array
The data for the language used.
handleTreeUpdate($a_parent_ref_id, $a_tnode_id)
Handle tree update (recursively)
+ 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.

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

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  $GLOBALS['ilLog']->write(__METHOD__ . ': No directory allocation settings. Aborting');
93  return true;
94  }
95 
96  // lookup obj id of root node
97  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsData.php';
98 
99  $root_obj_id = ilECSCmsTree::lookupRootId($this->tree_id);
100  $this->syncNode($root_obj_id, 0);
101 
102  // Tree structure is up to date, now check node movements
103  $this->checkTreeUpdates($root_obj_id);
104  return true;
105  }
static lookupRootId($a_tree_id)
lookup root id
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
checkTreeUpdates($a_root_obj_id)
Start tree update check.
getDefaultSettings()
Get default settings.
syncNode($tree_obj_id, $parent_id, $a_mapped=false)
Sync node.
static lookupSettings($a_server_id, $a_mid, $a_tree_id, $a_node_id)
Lookup Settings.
+ Here is the call graph for this function:

◆ syncCategory()

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

Sync category.

Parameters
ilECSNodeMappingAssignment$ass

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

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

Referenced by syncNode().

221  {
222  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsData.php';
223  $data = new ilECSCmsData($ass->getCSId());
224 
225  // Check if node is imported => create
226  // perform title update
227  // perform position update
228  include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
230  $this->getServer()->getServerId(),
231  $this->mid,
232  $data->getCmsId()
233  );
234  if ($obj_id) {
235  $refs = ilObject::_getAllReferences($obj_id);
236  $ref_id = end($refs);
237 
238 
239  $cat = ilObjectFactory::getInstanceByRefId($ref_id, false);
240  if (($cat instanceof ilObject) and $this->default_settings['title_update']) {
241  $GLOBALS['ilLog']->write(__METHOD__ . ': Updating cms category ');
242  $GLOBALS['ilLog']->write(__METHOD__ . ': Title is ' . $data->getTitle());
243  $cat->deleteTranslation($GLOBALS['lng']->getDefaultLanguage());
244  $cat->addTranslation(
245  $data->getTitle(),
246  $cat->getLongDescription(),
247  $GLOBALS['lng']->getDefaultLanguage(),
248  1
249  );
250  $cat->setTitle($data->getTitle());
251  $cat->update();
252  } else {
253  $GLOBALS['ilLog']->write(__METHOD__ . ': Updating cms category -> nothing to do');
254  }
255  return $ref_id;
256  } elseif ($this->getGlobalSettings()->isEmptyContainerCreationEnabled()) {
257  $GLOBALS['ilLog']->write(__METHOD__ . ': Creating new cms category');
258 
259  // Create category
260  include_once './Modules/Category/classes/class.ilObjCategory.php';
261  $cat = new ilObjCategory();
262  $cat->setOwner(SYSTEM_USER_ID);
263  $cat->setTitle($data->getTitle());
264  $cat->create(); // true for upload
265  $cat->createReference();
266  $cat->putInTree($parent_id);
267  $cat->setPermissions($parent_id);
268  $cat->deleteTranslation($GLOBALS['lng']->getDEfaultLanguage());
269  $cat->addTranslation(
270  $data->getTitle(),
271  $cat->getLongDescription(),
272  $GLOBALS['lng']->getDefaultLanguage(),
273  1
274  );
275 
276  // set imported
277  $import = new ilECSImport(
278  $this->getServer()->getServerId(),
279  $cat->getId()
280  );
281  $import->setMID($this->mid);
282  $import->setContentId($data->getCmsId());
283  $import->setImported(true);
284  $import->save();
285 
286  return $cat->getRefId();
287  } else {
288  $GLOBALS['ilLog']->write(__METHOD__ . ': Creation of empty containers is disabled.');
289  return 0;
290  }
291  }
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
static lookupObjIdByContentId($a_server_id, $a_mid, $a_content_id, $a_sub_id=null)
Lookup obj_id by content id.
static _getAllReferences($a_id)
get all reference ids of object
Storage of ECS imported objects.
Class ilObjCategory.
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
setMID($a_mid)
set mid
+ 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 181 of file class.ilECSCmsTreeSynchronizer.php.

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

Referenced by sync().

182  {
183  $childs = $this->getTree()->getChilds($tree_obj_id);
184 
185  $assignment = new ilECSNodeMappingAssignment(
186  $this->getServer()->getServerId(),
187  $this->mid,
188  $this->tree_id,
189  $tree_obj_id
190  );
191 
192  if ($assignment->getRefId()) {
193  $parent_id = $assignment->getRefId();
194  }
195 
196  // information for deeper levels
197  if ($assignment->isMapped()) {
198  $a_mapped = true;
199  }
200 
201  if ($a_mapped) {
202  $parent_id = $this->syncCategory($assignment, $parent_id);
203  }
204 
205  // this is not necessary
206  #if($parent_id)
207  {
208  // iterate through childs
209  foreach ($childs as $node) {
210  $this->syncNode($node['child'], $parent_id, $a_mapped);
211  }
212  }
213  return true;
214  }
syncCategory(ilECSNodeMappingAssignment $ass, $parent_id)
Sync category.
syncNode($tree_obj_id, $parent_id, $a_mapped=false)
Sync node.
+ 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: