Esempio n. 1
0
 /**
  * Read trees from ecs
  *
  * @throws ilECSConnectorException
  */
 public function read()
 {
     $GLOBALS['ilLog']->write(__METHOD__ . ': Begin read');
     try {
         include_once './Services/WebServices/ECS/classes/Tree/class.ilECSDirectoryTreeConnector.php';
         $dir_reader = new ilECSDirectoryTreeConnector(ilECSSetting::getInstanceByServerId($this->server_id));
         $trees = $dir_reader->getDirectoryTrees();
         $GLOBALS['ilLog']->write(__METHOD__ . ' ' . print_r($trees, true));
         if ($trees instanceof ilECSUriList) {
             foreach ((array) $trees->getLinkIds() as $tree_id) {
                 include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsData.php';
                 include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTree.php';
                 if (!ilECSCmsData::treeExists($this->server_id, $this->mid, $tree_id)) {
                     $result = $dir_reader->getDirectoryTree($tree_id);
                     $this->storeTree($tree_id, $result->getResult());
                 }
             }
         }
     } catch (ilECSConnectorException $e) {
         throw $e;
     }
 }
 /**
  * Handle update
  * @param ilECSSetting $server
  * @param type $a_content_id
  */
 public function handleUpdate(ilECSSetting $server, $a_content_id)
 {
     // 1)  Mark all nodes as deleted
     // 2a) Delete cms tree
     // 2)  Add cms tree table entries
     // 2)  Replace the cms data table entries
     // 3)  Insert deleted tree nodes in tree
     // 4)  Sync tree
     try {
         include_once './Services/WebServices/ECS/classes/Tree/class.ilECSDirectoryTreeConnector.php';
         $dir_reader = new ilECSDirectoryTreeConnector($this->getServer());
         $res = $dir_reader->getDirectoryTree($a_content_id);
         $nodes = $res->getResult();
     } catch (ilECSConnectorException $e) {
         $GLOBALS['ilLog']->write(__METHOD__ . ': Tree creation failed  with mesage ' . $e->getMessage());
         return false;
     }
     // read old tree structure
     include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTree.php';
     $tree = new ilECSCmsTree($a_content_id);
     $root_node = $tree->getNodeData(ilECSCmsTree::lookupRootId($a_content_id));
     $old_nodes = array();
     if ($root_node['child']) {
         $old_nodes = $tree->getSubTree($root_node, true);
     }
     //$GLOBALS['ilLog']->write(__METHOD__.': OLD TREE DATA ........'.print_r($old_nodes,true));
     // Delete old cms tree
     ilECSCmsTree::deleteByTreeId($a_content_id);
     // Mark all nodes in cms data as deleted
     include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsData.php';
     ilECSCmsData::writeAllDeleted($this->getServer()->getServerId(), $this->mid, $a_content_id, true);
     // Check for update or new entry
     $cms_tree = $nodes;
     $data_obj_id = ilECSCmsData::lookupObjId($this->getServer()->getServerId(), $this->mid, $a_content_id, $cms_tree->rootID);
     $data = new ilECSCmsData($data_obj_id);
     $data->setServerId($server->getServerId());
     $data->setMid($this->mid);
     $data->setCmsId($cms_tree->rootID);
     $data->setTreeId($a_content_id);
     $data->setTitle($cms_tree->directoryTreeTitle);
     $data->setTerm($cms_tree->term);
     if ($data_obj_id) {
         $data->setDeleted(false);
         $data->update();
     } else {
         $data->save();
     }
     $tree->insertRootNode($a_content_id, $data->getObjId());
     $tree->setRootId($data->getObjId());
     foreach ((array) $cms_tree->nodes as $node) {
         $data_obj_id = ilECSCmsData::lookupObjId($this->getServer()->getServerId(), $this->mid, $a_content_id, $node->id);
         // update data entry
         $data = new ilECSCmsData($data_obj_id);
         $data->setTitle($node->title);
         $data->setTerm($node->term);
         $data->setDeleted(false);
         if ($data_obj_id) {
             $data->update();
         } else {
             $data->setCmsId($node->id);
             $data->setMid($this->mid);
             $data->setServerId($this->getServer()->getServerId());
             $data->setTreeId($a_content_id);
             $data->setDeleted(false);
             $data->save();
             $data_obj_id = $data->getObjId();
         }
         // add to tree
         $parent_id = ilECSCmsData::lookupObjId($this->getServer()->getServerId(), $this->mid, $a_content_id, (int) $node->parent->id);
         $tree->insertNode($data->getObjId(), $parent_id);
     }
     // Insert deleted nodes in tree
     $deleted = ilECSCmsData::findDeletedNodes($this->getServer()->getServerId(), $this->mid, $a_content_id);
     foreach ((array) $deleted as $obj_id) {
         $parent = 0;
         foreach ((array) $old_nodes as $tmp_id => $node) {
             if ($node['child'] == $obj_id) {
                 $parent = $node['parent'];
                 break;
             }
         }
         if ($tree->isInTree($parent) and $parent) {
             $tree->insertNode($obj_id, $parent);
         }
     }
     // Sync tree
     include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTreeSynchronizer.php';
     $sync = new ilECSCmsTreeSynchronizer($this->getServer(), $this->mid, $a_content_id);
     $sync->sync();
     return true;
 }