ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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['DIC']['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  }
handleTreeUpdate($a_parent_ref_id, $a_tnode_id)
Handle tree update (recursively)
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
+ 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.

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 $DIC, $GLOBALS, $tree, ilObject\_getAllReferences(), getServer(), getTree(), and ilECSImport\lookupObjIdByContentId().

Referenced by checkTreeUpdates().

139  {
140  global $DIC;
141 
142  $tree = $DIC['tree'];
143 
144  // Check if node is already imported at location "parent_ref_id"
145  // If not => move it
146  $cms_data = new ilECSCmsData($a_tnode_id);
147 
148  include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
149  $import_obj_id = ilECSImport::lookupObjIdByContentId(
150  $this->getServer()->getServerId(),
151  $this->mid,
152  $cms_data->getCmsId()
153  );
154  if (!$import_obj_id) {
155  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': cms tree node not imported. tnode_id: ' . $a_tnode_id);
156  return false;
157  }
158 
159  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ' parent ref:' . $a_parent_ref_id . ' tnode:' . $a_tnode_id);
160  $ref_ids = ilObject::_getAllReferences($import_obj_id);
161  $import_ref_id = end($ref_ids);
162  $import_ref_id_parent = $tree->getParentId($import_ref_id);
163 
164  if ($a_parent_ref_id != $import_ref_id_parent) {
165  // move node
166  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': Moving node ' . $a_parent_ref_id . ' to ' . $import_ref_id);
167  $tree->moveTree($import_ref_id, $a_parent_ref_id);
168  }
169 
170  // iterate through childs
171  $childs = $this->getTree()->getChilds($a_tnode_id);
172  foreach ((array) $childs as $node) {
173  $this->handleTreeUpdate($import_ref_id, $node['child']);
174  }
175  return true;
176  }
global $DIC
Definition: saml.php:7
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
handleTreeUpdate($a_parent_ref_id, $a_tnode_id)
Handle tree update (recursively)
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
+ 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['DIC']['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
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.
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
+ Here is the call graph for this function:

◆ syncCategory()

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

Sync category.

Parameters
ilECSNodeMappingAssignment$ass

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

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

Referenced by syncNode().

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

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

Referenced by sync().

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