function addCourse($sid, $target_id, $crs_xml)
 {
     $this->initAuth($sid);
     $this->initIlias();
     if (!$this->__checkSession($sid)) {
         return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
     }
     if (!is_numeric($target_id)) {
         return $this->__raiseError('No valid target id given. Please choose an existing reference id of an ILIAS category', 'Client');
     }
     global $rbacsystem;
     if (!($target_obj =& ilObjectFactory::getInstanceByRefId($target_id, false))) {
         return $this->__raiseError('No valid target given.', 'Client');
     }
     if (ilObject::_isInTrash($target_id)) {
         return $this->__raiseError("Parent with ID {$target_id} has been deleted.", 'CLIENT_OBJECT_DELETED');
     }
     if (!$rbacsystem->checkAccess('create', $target_id, 'crs')) {
         return $this->__raiseError('Check access failed. No permission to create courses', 'Server');
     }
     // Start import
     include_once "Modules/Course/classes/class.ilObjCourse.php";
     $newObj = new ilObjCourse();
     $newObj->setType('crs');
     $newObj->setTitle('dummy');
     $newObj->setDescription("");
     $newObj->create(true);
     // true for upload
     $newObj->createReference();
     $newObj->putInTree($target_id);
     $newObj->setPermissions($target_id);
     include_once 'Modules/Course/classes/class.ilCourseXMLParser.php';
     $xml_parser = new ilCourseXMLParser($newObj);
     $xml_parser->setXMLContent($crs_xml);
     $xml_parser->startParsing();
     return $newObj->getRefId() ? $newObj->getRefId() : "0";
 }
예제 #2
0
 /**
  * Generate courses
  *
  * @param
  * @return
  */
 function generateCourses($a_start = 1, $a_end = 500, $a_course_per_cat = 10, $a_title_base = "Course")
 {
     global $tree;
     include_once "./Modules/Course/classes/class.ilObjCourse.php";
     $this->log("Creating Courses");
     $a_current = $a_start;
     // how many categories do we need?
     $needed_cats = ceil(($a_end - $a_start + 1) / $a_course_per_cat);
     // get all categories and sort them by depth
     $nodes = $tree->getFilteredSubTree($tree->getRootId(), array("adm", "crs", "fold", "grp"));
     $nodes = ilUtil::sortArray($nodes, "depth", "desc");
     foreach ($nodes as $node) {
         if ($node["type"] == "cat" && $a_current <= $a_end) {
             for ($i = 1; $i <= $a_course_per_cat; $i++) {
                 if ($a_current <= $a_end) {
                     $this->log($a_title_base . " " . $a_current);
                     $new_crs = new ilObjCourse();
                     $new_crs->setTitle($a_title_base . " " . $a_current);
                     $new_crs->create();
                     $new_crs->createReference();
                     $new_crs->putInTree($node["child"]);
                     $new_crs->setPermissions($node["child"]);
                     $a_current++;
                 }
             }
         }
     }
 }