ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilECSCmsTreeSynchronizer Class Reference
+ Collaboration diagram for ilECSCmsTreeSynchronizer:

Public Member Functions

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

Protected Member Functions

 checkTreeUpdates (int $a_root_obj_id)
 Start tree update check. More...
 
 handleTreeUpdate (int $a_parent_ref_id, int $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

ilLogger $logger
 
ilLanguage $lng
 
ilTree $tree
 
ilECSSetting $server = null
 
int $mid
 
int $tree_id
 
ilECSCmsTree $ecs_tree = null
 
array $default_settings = array()
 
ilECSNodeMappingSettings $global_settings = null
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

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

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

References $DIC, $mid, $server, $tree_id, ilECSNodeMappingSettings\getInstanceByServerMid(), ILIAS\Repository\lng(), and ILIAS\Repository\logger().

40  {
41  global $DIC;
42 
43  $this->logger = $DIC->logger()->wsrv();
44  $this->lng = $DIC->language();
45  $this->tree = $DIC->repositoryTree();
46 
47 
48  $this->server = $server;
49  $this->mid = $mid;
50  $this->ecs_tree = new ilECSCmsTree($tree_id);
51  $this->tree_id = $tree_id;
52 
53  $this->global_settings = ilECSNodeMappingSettings::getInstanceByServerMid($this->server->getServerId(), $this->mid);
54  }
static getInstanceByServerMid(int $a_server_id, int $a_mid)
Get instance.
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

Member Function Documentation

◆ checkTreeUpdates()

ilECSCmsTreeSynchronizer::checkTreeUpdates ( int  $a_root_obj_id)
protected

Start tree update check.

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

References $mid, $tree_id, ilECSNodeMappingAssignment\getRefId(), handleTreeUpdate(), and ILIAS\Repository\logger().

Referenced by sync().

116  : void
117  {
118  if ($this->default_settings['tree_update'] === false) {
119  $this->logger->info('Tree update disabled for tree with id ' . $this->ecs_tree->getTreeId());
120  return;
121  }
122 
123  // Start recursion
124  $mapping = new ilECSNodeMappingAssignment(
125  $this->server->getServerId(),
126  $this->mid,
128  $a_root_obj_id
129  );
130  $a_root_ref_id = $mapping->getRefId();
131  if ($a_root_ref_id) {
132  $this->handleTreeUpdate($a_root_ref_id, $a_root_obj_id);
133  }
134  }
handleTreeUpdate(int $a_parent_ref_id, int $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.

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

References $default_settings.

Referenced by sync().

72  : array
73  {
75  }
+ Here is the caller graph for this function:

◆ getECSTree()

ilECSCmsTreeSynchronizer::getECSTree ( )

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

References $ecs_tree.

◆ getGlobalSettings()

ilECSCmsTreeSynchronizer::getGlobalSettings ( )

get global settings

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

References $global_settings.

◆ getServer()

ilECSCmsTreeSynchronizer::getServer ( )

Get server.

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

References $server.

◆ handleTreeUpdate()

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

Handle tree update (recursively)

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

References $mid, ilObject\_getAllReferences(), ilECSImportManager\getInstance(), ILIAS\Repository\int(), and ILIAS\Repository\logger().

Referenced by checkTreeUpdates().

139  : bool
140  {
141  // Check if node is already imported at location "parent_ref_id"
142  // If not => move it
143  $cms_data = new ilECSCmsData($a_tnode_id);
144 
145  $import_obj_id = ilECSImportManager::getInstance()->lookupObjIdByContentId(
146  $this->server->getServerId(),
147  $this->mid,
148  //TODO fix this cast
149  (int) $cms_data->getCmsId()
150  );
151  if (!$import_obj_id) {
152  $this->logger->error('cms tree node not imported. tnode_id: ' . $a_tnode_id);
153  return false;
154  }
155 
156  $this->logger->info(' parent ref:' . $a_parent_ref_id . ' tnode:' . $a_tnode_id);
157  $ref_ids = ilObject::_getAllReferences($import_obj_id);
158  $import_ref_id = end($ref_ids);
159  $import_ref_id_parent = $this->tree->getParentId($import_ref_id);
160 
161  if ($a_parent_ref_id !== $import_ref_id_parent) {
162  // move node
163  $this->logger->info('Moving node ' . $a_parent_ref_id . ' to ' . $import_ref_id);
164  $this->tree->moveTree($import_ref_id, $a_parent_ref_id);
165  }
166 
167  // iterate through childs
168  $childs = $this->ecs_tree->getChilds($a_tnode_id);
169  foreach ($childs as $node) {
170  $this->handleTreeUpdate($import_ref_id, $node['child']);
171  }
172  return true;
173  }
static _getAllReferences(int $id)
get all reference ids for object ID
static getInstance()
Get the singleton instance of this ilECSImportManager.
handleTreeUpdate(int $a_parent_ref_id, int $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.

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

References $mid, $tree_id, checkTreeUpdates(), getDefaultSettings(), ILIAS\Repository\logger(), ilECSCmsTree\lookupRootId(), ilECSNodeMappingAssignments\lookupSettings(), and syncNode().

88  : bool
89  {
90  $this->default_settings = ilECSNodeMappingAssignments::lookupSettings(
91  $this->server->getServerId(),
92  $this->mid,
94  0
95  );
96 
97  // return if setting is false => no configuration done
98  if (!$this->getDefaultSettings()) {
99  $this->logger->info('No directory allocation settings. Aborting');
100  return true;
101  }
102 
103  // lookup obj id of root node
104 
105  $root_obj_id = ilECSCmsTree::lookupRootId($this->tree_id);
106  $this->syncNode($root_obj_id, 0);
107 
108  // Tree structure is up to date, now check node movements
109  $this->checkTreeUpdates($root_obj_id);
110  return true;
111  }
static lookupRootId($a_tree_id)
lookup root id
static lookupSettings(int $a_server_id, int $a_mid, int $a_tree_id, int $a_node_id)
Lookup Settings.
getDefaultSettings()
Get default settings.
checkTreeUpdates(int $a_root_obj_id)
Start tree update check.
syncNode($tree_obj_id, $parent_id, $a_mapped=false)
Sync node.
+ Here is the call graph for this function:

◆ syncCategory()

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

Sync category.

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

References $data, $mid, $ref_id, ilObject\_getAllReferences(), ilECSNodeMappingAssignment\getCSId(), ilECSImportManager\getInstance(), ilObjectFactory\getInstanceByRefId(), ILIAS\Repository\int(), ILIAS\Repository\lng(), ILIAS\Repository\logger(), ilECSImport\setMID(), and SYSTEM_USER_ID.

Referenced by syncNode().

217  {
218  $data = new ilECSCmsData($ass->getCSId());
219 
220  // Check if node is imported => create
221  // perform title update
222  // perform position update
223  $obj_id = ilECSImportManager::getInstance()->lookupObjIdByContentId(
224  $this->server->getServerId(),
225  $this->mid,
226  //TODO fix this cast
227  (int) $data->getCmsId()
228  );
229  if ($obj_id) {
230  $refs = ilObject::_getAllReferences($obj_id);
231  $ref_id = end($refs);
232 
233 
235  if (($cat instanceof ilObject) && $this->default_settings['title_update']) {
236  $this->logger->info('Updating cms category ');
237  $this->logger->info('Title is ' . $data->getTitle());
238  $cat->deleteTranslation($this->lng->getDefaultLanguage());
239  $cat->addTranslation(
240  $data->getTitle(),
241  $cat->getLongDescription(),
242  $this->lng->getDefaultLanguage(),
243  $this->lng->getDefaultLanguage()
244  );
245  $cat->setTitle($data->getTitle());
246  $cat->update();
247  } else {
248  $this->logger->info('Updating cms category -> nothing to do');
249  }
250  return $ref_id;
251  }
252 
253  if ($this->global_settings->isEmptyContainerCreationEnabled()) {
254  $this->logger->info('Creating new cms category');
255 
256  // Create category
257  $cat = new ilObjCategory();
258  $cat->setOwner(SYSTEM_USER_ID);
259  $cat->setTitle($data->getTitle());
260  $cat->create(); // true for upload
261  $cat->createReference();
262  $cat->putInTree($parent_id);
263  $cat->setPermissions($parent_id);
264  $cat->deleteTranslation($this->lng->getDEfaultLanguage());
265  $cat->addTranslation(
266  $data->getTitle(),
267  $cat->getLongDescription(),
268  $this->lng->getDefaultLanguage(),
269  $this->lng->getDefaultLanguage()
270  );
271 
272  // set imported
273  $import = new ilECSImport(
274  $this->server->getServerId(),
275  $cat->getId()
276  );
277  $import->setMID($this->mid);
278  $import->setContentId($data->getCmsId());
279  $import->setImported(true);
280  $import->save();
281 
282  return $cat->getRefId();
283  }
284 
285  $this->logger->info('Creation of empty containers is disabled.');
286  return 0;
287  }
const SYSTEM_USER_ID
This file contains constants for PHPStan analyis, see: https://phpstan.org/config-reference#constants...
Definition: constants.php:26
static _getAllReferences(int $id)
get all reference ids for object ID
static getInstance()
Get the singleton instance of this ilECSImportManager.
$ref_id
Definition: ltiauth.php:67
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
Storage of ECS imported objects.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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.

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

References $mid, $tree_id, ilECSNodeMappingAssignment\getRefId(), and syncCategory().

Referenced by sync().

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

array ilECSCmsTreeSynchronizer::$default_settings = array()
private

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

Referenced by getDefaultSettings().

◆ $ecs_tree

ilECSCmsTree ilECSCmsTreeSynchronizer::$ecs_tree = null
private

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

Referenced by getECSTree().

◆ $global_settings

ilECSNodeMappingSettings ilECSCmsTreeSynchronizer::$global_settings = null
private

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

Referenced by getGlobalSettings().

◆ $lng

ilLanguage ilECSCmsTreeSynchronizer::$lng
private

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

◆ $logger

ilLogger ilECSCmsTreeSynchronizer::$logger
private

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

◆ $mid

int ilECSCmsTreeSynchronizer::$mid
private

◆ $server

ilECSSetting ilECSCmsTreeSynchronizer::$server = null
private

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

Referenced by __construct(), and getServer().

◆ $tree

ilTree ilECSCmsTreeSynchronizer::$tree
private

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

◆ $tree_id

int ilECSCmsTreeSynchronizer::$tree_id
private

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

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


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