/** * Sync category * @param type $tobj_id * @param type $parent_ref_id */ protected function syncCategory($tobj_id, $parent_ref_id) { include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsData.php'; $data = new ilECSCmsData($tobj_id); 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_ref_id); $cat->setPermissions($parent_ref_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->getMid()); $import->setContentId($data->getCmsId()); $import->setImported(true); $import->save(); return $cat->getId(); }
/** * 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; } }
/** * Do mapping * @param type $course * @param type $parent_ref */ public function doMapping($course, $parent_ref) { global $tree; if (!$this->isSubdirCreationEnabled()) { return $parent_ref; } include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSMappingUtils.php'; $value = ilECSMappingUtils::getCourseValueByMappingAttribute($course, $this->getAttribute()); $childs = $tree->getChildsByType($parent_ref, 'cat'); $existing_ref = 0; foreach ((array) $childs as $child) { if (strcmp($child['title'], $value) === 0) { $existing_ref = $child['child']; break; } } if (!$existing_ref) { // Create category include_once './Modules/Category/classes/class.ilObjCategory.php'; $cat = new ilObjCategory(); $cat->setTitle($value); $cat->create(); $cat->createReference(); $cat->putInTree($parent_ref); $cat->setPermissions($parent_ref); $cat->deleteTranslation($GLOBALS['lng']->getDefaultLanguage()); $cat->addTranslation($value, $cat->getLongDescription(), $GLOBALS['lng']->getDefaultLanguage(), 1); return $cat->getRefId(); } return $existing_ref; }