コード例 #1
0
 /**
  * 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;
     }
 }
コード例 #2
0
 /**	
  * Creates a dav collection as a child of this object.
  *
  * @param	string		the name of the collection.
  * @return	ilObjectDAV	returns the created collection, or null if creation failed.
  */
 function createCollection($name)
 {
     global $lng, $tree;
     $this->lng =& $lng;
     $newObj = new ilObjCategory(0);
     $newObj->setType($this->getILIASCollectionType());
     $newObj->setTitle($name);
     //$newObj->setDescription('');
     $newObj->create();
     $newObj->createReference();
     $newObj->setPermissions($this->getRefId());
     $newObj->putInTree($this->getRefID());
     $newObj->addTranslation($name, '', $lng->getLangKey(), 1);
     return new ilObjCategoryDAV($newObj->getRefId(), $newObj);
 }
コード例 #3
0
 /**
  * Generate Categories
  *
  * @param
  * @return
  */
 function generateCategories($a_start = 1, $a_end = 500, $a_sub_cats_per_cat = 10, $a_title_base = "Category", $a_node = "", $a_init_cnt = true, $a_depth = 1)
 {
     global $tree;
     include_once "./Modules/Category/classes/class.ilObjCategory.php";
     if ($a_init_cnt) {
         $this->item_cnt = $a_start;
         $this->max_depth = ceil(log($a_end - $a_start, $a_sub_cats_per_cat));
     }
     if ($a_depth > $this->max_depth) {
         return;
     }
     if ($a_node == "") {
         $a_node = $tree->getRootId();
         $this->log("Creating Categories");
     }
     $sub_cat_cnt = 0;
     $sub_cats = array();
     while ($sub_cat_cnt < $a_sub_cats_per_cat && $this->item_cnt <= $a_end) {
         if ($this->item_cnt <= $a_end) {
             $this->log($a_title_base . " " . $this->item_cnt);
             $new_cat = new ilObjCategory();
             $new_cat->setTitle($a_title_base . " " . $this->item_cnt);
             $new_cat->create();
             $new_cat->createReference();
             $new_cat->putInTree($a_node);
             $new_cat->setPermissions($a_node);
             $sub_cats[] = $new_cat;
             $sub_cat_cnt++;
             $this->item_cnt++;
         }
     }
     foreach ($sub_cats as $sub_cat) {
         $this->generateCategories($this->item_cnt, $a_end, $a_sub_cats_per_cat, $a_title_base, $sub_cat->getRefId(), false, $a_depth + 1);
     }
 }
コード例 #4
0
 /**
  * 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();
 }
コード例 #5
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;
 }