ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilECSTreeReader.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
11 {
12  private $server_id;
13  private $mid;
14 
20  public function __construct($server_id, $mid)
21  {
22  $this->server_id = $server_id;
23  $this->mid = $mid;
24  }
25 
26 
27 
33  public function read()
34  {
35  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': Begin read');
36  try {
37  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSDirectoryTreeConnector.php';
38  $dir_reader = new ilECSDirectoryTreeConnector(
39  ilECSSetting::getInstanceByServerId($this->server_id)
40  );
41  $trees = $dir_reader->getDirectoryTrees();
42  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ' ' . print_r($trees, true));
43  if ($trees instanceof ilECSUriList) {
44  foreach ((array) $trees->getLinkIds() as $tree_id) {
45  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsData.php';
46  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTree.php';
47 
48  if (!ilECSCmsData::treeExists($this->server_id, $this->mid, $tree_id)) {
49  $result = $dir_reader->getDirectoryTree($tree_id);
50  $this->storeTree($tree_id, $result->getResult());
51  }
52  }
53  }
54  } catch (ilECSConnectorException $e) {
55  throw $e;
56  }
57  }
58 
59  protected function storeTree($tree_id, $a_nodes)
60  {
61  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsData.php';
62  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTree.php';
63 
64  $tree = new ilECSCmsTree($tree_id);
65 
66 
67  $cms_tree = $a_nodes;
68 
69  $data = new ilECSCmsData();
70  $data->setServerId($this->server_id);
71  $data->setMid($this->mid);
72  $data->setCmsId($cms_tree->rootID);
73  $data->setTreeId($tree_id);
74  $data->setTitle($node->directoryTitle);
75  $data->setTerm($node->term);
76  $data->save();
77 
78  $tree->insertRootNode($tree_id, $data->getObjId());
79  $tree->setRootId($data->getObjId());
80 
81 
82  foreach ((array) $cms_tree->nodes as $node) {
83  // Add data entry
84  $data = new ilECSCmsData();
85  $data->setServerId($this->server_id);
86  $data->setMid($this->mid);
87  $data->setCmsId($node->id);
88  $data->setTreeId($tree_id);
89  $data->setTitle($node->title);
90  $data->setTerm($node->term);
91  $data->save();
92 
93  // add to tree
94  if ($node->parent->id) {
95  $parent_id = ilECSCmsData::lookupObjId(
96  $this->server_id,
97  $this->mid,
98  $tree_id,
99  (int) $node->parent->id
100  );
101  $tree->insertNode($data->getObjId(), $parent_id);
102  }
103  }
104  }
105 }
static getInstanceByServerId($a_server_id)
Get singleton instance per server.
static treeExists($a_server_id, $a_mid, $a_tree_id)
$result
static lookupObjId($a_server_id, $a_mid, $a_tree_id, $cms_id)
read()
Read trees from ecs.
Presentation of ecs uril (http://...campusconnect/courselinks)
Reads and store cms tree in database.
__construct($server_id, $mid)
Constructor.
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
$data
Definition: bench.php:6
storeTree($tree_id, $a_nodes)