ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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['ilLog']->write(__METHOD__.': Begin read');
36  try
37  {
38  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSDirectoryTreeConnector.php';
39  $dir_reader = new ilECSDirectoryTreeConnector(
40  ilECSSetting::getInstanceByServerId($this->server_id)
41  );
42  $trees = $dir_reader->getDirectoryTrees();
43  $GLOBALS['ilLog']->write(__METHOD__.' '.print_r($trees,true));
44  if($trees instanceof ilECSUriList)
45  {
46  foreach((array) $trees->getLinkIds() as $tree_id)
47  {
48  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsData.php';
49  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTree.php';
50 
51  if(!ilECSCmsData::treeExists($this->server_id, $this->mid, $tree_id))
52  {
53  $result = $dir_reader->getDirectoryTree($tree_id);
54  $this->storeTree($tree_id, $result->getResult());
55  }
56  }
57  }
58  }
59  catch(ilECSConnectorException $e)
60  {
61  throw $e;
62  }
63  }
64 
65  protected function storeTree($tree_id, $a_nodes)
66  {
67  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsData.php';
68  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTree.php';
69 
70  $tree = new ilECSCmsTree($tree_id);
71 
72 
73  $cms_tree = $a_nodes;
74 
75  $data = new ilECSCmsData();
76  $data->setServerId($this->server_id);
77  $data->setMid($this->mid);
78  $data->setCmsId($cms_tree->rootID);
79  $data->setTreeId($tree_id);
80  $data->setTitle($node->directoryTitle);
81  $data->setTerm($node->term);
82  $data->save();
83 
84  $tree->insertRootNode($tree_id, $data->getObjId());
85  $tree->setRootId($data->getObjId());
86 
87 
88  foreach((array) $cms_tree->nodes as $node)
89  {
90  // Add data entry
91  $data = new ilECSCmsData();
92  $data->setServerId($this->server_id);
93  $data->setMid($this->mid);
94  $data->setCmsId($node->id);
95  $data->setTreeId($tree_id);
96  $data->setTitle($node->title);
97  $data->setTerm($node->term);
98  $data->save();
99 
100  // add to tree
101  if($node->parent->id)
102  {
103  $parent_id = ilECSCmsData::lookupObjId(
104  $this->server_id,
105  $this->mid,
106  $tree_id,
107  (int) $node->parent->id
108  );
109  $tree->insertNode($data->getObjId(), $parent_id);
110  }
111  }
112  }
113 }
114 ?>