/**
  * Sync category
  * @param ilECSNodeMappingAssignment $ass
  */
 protected function syncCategory(ilECSNodeMappingAssignment $ass, $parent_id)
 {
     include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsData.php';
     $data = new ilECSCmsData($ass->getCSId());
     // Check if node is imported => create
     // perform title update
     // perform position update
     include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
     $obj_id = ilECSImport::lookupObjIdByContentId($this->getServer()->getServerId(), $this->mid, $data->getCmsId());
     if ($obj_id) {
         $refs = ilObject::_getAllReferences($obj_id);
         $ref_id = end($refs);
         $cat = ilObjectFactory::getInstanceByRefId($ref_id, false);
         if ($cat instanceof ilObject and $this->default_settings['title_update']) {
             $GLOBALS['ilLog']->write(__METHOD__ . ': Updating cms category ');
             $GLOBALS['ilLog']->write(__METHOD__ . ': Title is ' . $data->getTitle());
             $cat->deleteTranslation($GLOBALS['lng']->getDefaultLanguage());
             $cat->addTranslation($data->getTitle(), $cat->getLongDescription(), $GLOBALS['lng']->getDefaultLanguage(), 1);
             $cat->setTitle($data->getTitle());
             $cat->update();
         } else {
             $GLOBALS['ilLog']->write(__METHOD__ . ': Updating cms category -> nothing to do');
         }
         return $ref_id;
     } elseif ($this->getGlobalSettings()->isEmptyContainerCreationEnabled()) {
         $GLOBALS['ilLog']->write(__METHOD__ . ': Creating new cms category');
         // Create category
         include_once './Modules/Category/classes/class.ilObjCategory.php';
         $cat = new ilObjCategory();
         $cat->setTitle($data->getTitle());
         $cat->create();
         // true for upload
         $cat->createReference();
         $cat->putInTree($parent_id);
         $cat->setPermissions($parent_id);
         $cat->deleteTranslation($GLOBALS['lng']->getDEfaultLanguage());
         $cat->addTranslation($data->getTitle(), $cat->getLongDescription(), $GLOBALS['lng']->getDefaultLanguage(), 1);
         // set imported
         $import = new ilECSImport($this->getServer()->getServerId(), $cat->getId());
         $import->setMID($this->mid);
         $import->setContentId($data->getCmsId());
         $import->setImported(true);
         $import->save();
         return $cat->getRefId();
     } else {
         $GLOBALS['ilLog']->write(__METHOD__ . ': Creation of empty containers is disabled.');
         return 0;
     }
 }
 /**
  * Sync node to top
  * @param type $tree_id
  * @param type $parent_id
  * @return int obj_id of container
  */
 protected function syncNodeToTop($tree_id, $cms_id)
 {
     $obj_id = $this->getImportId($cms_id);
     if ($obj_id) {
         // node already imported
         return $obj_id;
     }
     $tobj_id = ilECSCmsData::lookupObjId($this->getServer()->getServerId(), $this->getMid(), $tree_id, $cms_id);
     // node is not imported
     $GLOBALS['ilLog']->write(__METHOD__ . ': ecs node with id ' . $cms_id . ' is not imported for mid ' . $this->getMid() . ' tree_id ' . $tree_id);
     // check for mapping: if mapping is available create category
     include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingAssignment.php';
     $ass = new ilECSNodeMappingAssignment($this->getServer()->getServerId(), $this->getMid(), $tree_id, $tobj_id);
     if ($ass->isMapped()) {
         $GLOBALS['ilLog']->write(__METHOD__ . ': node is mapped');
         return $this->syncCategory($tobj_id, $ass->getRefId());
     }
     // Start recursion to top
     include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTree.php';
     $tree = new ilECSCmsTree($tree_id);
     $parent_tobj_id = $tree->getParentId($tobj_id);
     if ($parent_tobj_id) {
         $cms_ids = ilECSCmsData::lookupCmsIds(array($parent_tobj_id));
         $obj_id = $this->syncNodeToTop($tree_id, $cms_ids[0]);
     }
     if ($obj_id) {
         $refs = ilObject::_getAllReferences($obj_id);
         $ref_id = end($refs);
         return $this->syncCategory($tobj_id, $ref_id);
     }
     return 0;
 }
 /**
  * Do mapping
  */
 protected function dMap()
 {
     if (!$_POST['lnodes']) {
         ilUtil::sendFailure($this->lng->txt('select_one'), true);
         $this->ctrl->redirect($this, 'dEditTree');
     }
     $ref_id = end($_POST['lnodes']);
     include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingAssignments.php';
     ilECSNodeMappingAssignments::deleteDisconnectableMappings($this->getServer()->getServerId(), $this->getMid(), (int) $_REQUEST['tid'], $ref_id);
     $nodes = (array) $_POST['rnodes'];
     $nodes = (array) array_reverse($nodes);
     include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingAssignment.php';
     include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingAssignments.php';
     include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTree.php';
     foreach ($nodes as $cms_id) {
         $assignment = new ilECSNodeMappingAssignment($this->getServer()->getServerId(), $this->getMid(), (int) $_REQUEST['tid'], (int) $cms_id);
         $assignment->setRefId($ref_id);
         $assignment->setObjId(ilObject::_lookupObjId($ref_id));
         $assignment->enablePositionUpdate(false);
         $assignment->enableTreeUpdate(false);
         $assignment->enableTitleUpdate(ilECSNodeMappingAssignments::lookupDefaultTitleUpdate($this->getServer()->getServerId(), $this->getMid(), (int) $_REQUEST['tid']));
         $assignment->update();
         // Delete subitems mappings for cms subtree
         $cmsTree = new ilECSCmsTree((int) $_REQUEST['tid']);
         $childs = $cmsTree->getSubTreeIds($cms_id);
         ilECSNodeMappingAssignments::deleteMappingsByCsId($this->getServer()->getServerId(), $this->getMid(), (int) $_REQUEST['tid'], $childs);
     }
     ilECSCmsData::updateStatus($this->getServer()->getServerId(), $this->getMid(), (int) $_REQUEST['tid']);
     // Save parameter cid
     $this->ctrl->setParameter($this, 'lid', (int) $ref_id);
     ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
     $this->ctrl->redirect($this, 'dEditTree');
 }
Exemplo n.º 4
0
 /**
  * Delete
  */
 public function delete()
 {
     global $ilDB;
     // --- cascading delete
     include_once 'Services/WebServices/ECS/classes/Tree/class.ilECSCmsData.php';
     ilECSCmsData::deleteByServerId($this->getServerId());
     include_once 'Services/WebServices/ECS/classes/class.ilECSCommunityCache.php';
     ilECSCommunityCache::deleteByServerId($this->getServerId());
     include_once 'Services/WebServices/ECS/classes/class.ilECSDataMappingSetting.php';
     ilECSDataMappingSetting::deleteByServerId($this->getServerId());
     include_once 'Services/WebServices/ECS/classes/class.ilECSEventQueueReader.php';
     ilECSEventQueueReader::deleteByServerId($this->getServerId());
     include_once 'Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingAssignment.php';
     ilECSNodeMappingAssignment::deleteByServerId($this->getServerId());
     include_once 'Services/WebServices/ECS/classes/class.ilECSParticipantSetting.php';
     ilECSParticipantSetting::deleteByServerId($this->getServerId());
     include_once 'Services/WebServices/ECS/classes/class.ilECSExport.php';
     ilECSExport::deleteByServerId($this->getServerId());
     // resetting server id to flag items in imported list
     include_once 'Services/WebServices/ECS/classes/class.ilECSImport.php';
     ilECSImport::resetServerId($this->getServerId());
     $ilDB->manipulate('DELETE FROM ecs_server ' . 'WHERE server_id = ' . $ilDB->quote($this->getServerId(), 'integer'));
     $this->server_id = NULL;
     return true;
 }