/**
  * Init (read) current mappings
  */
 protected function initMappings()
 {
     include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseMappingRule.php';
     $mappings = array();
     foreach (ilECSCourseMappingRule::getRuleRefIds($this->getSid(), $this->getMid()) as $ref_id) {
         $mappings[$ref_id] = array();
     }
     foreach ($mappings as $ref_id => $tmp) {
         $this->mappings[$ref_id] = $GLOBALS['tree']->getPathId($ref_id, 1);
     }
     return true;
 }
 /**
  * Sync attribute mapping
  * @param type $a_content_id
  * @param type $course
  */
 protected function doAttributeMapping($a_content_id, $course)
 {
     // Check if course is already created
     $course_id = $course->lectureID;
     $obj_id = $this->getImportId($course_id);
     if ($obj_id) {
         // do update
         $GLOBALS['ilLog']->write(__METHOD__ . ' Performing update of already imported course.');
         $refs = ilObject::_getAllReferences($obj_id);
         $ref = end($refs);
         return $this->doSync($a_content_id, $course, ilObject::_lookupObjId($GLOBALS['tree']->getParentId($ref)));
     }
     // Get all rules
     $matching_rule = 0;
     include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseMappingRule.php';
     foreach (ilECSCourseMappingRule::getRuleRefIds($this->getServer()->getServerId(), $this->getMid()) as $ref_id) {
         if (ilECSCourseMappingRule::isMatching($course, $this->getServer()->getServerId(), $this->getMid(), $ref_id)) {
             $matching_rule = $ref_id;
         }
     }
     if (!$matching_rule) {
         // Put course in default category
         $GLOBALS['ilLog']->write(__METHOD__ . ': No matching attribute mapping rule found.');
         $GLOBALS['ilLog']->write(__METHOD__ . ': Using course default category');
         return $this->doSync($a_content_id, $course, ilObject::_lookupObjId($this->getMapping()->getDefaultCourseCategory()));
     }
     // map according mapping rules
     $parent_ref = ilECSCourseMappingRule::doMappings($course, $this->getServer()->getServerId(), $this->getMid(), $ref_id);
     $this->doSync($a_content_id, $course, ilObject::_lookupObjId($parent_ref));
     return true;
 }
 protected function cDeleteRulesOfNode()
 {
     $current_node = (int) $_REQUEST['lnodes'];
     include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseMappingRule.php';
     $rules = ilECSCourseMappingRule::getRulesOfRefId($this->getServer()->getServerId(), $this->getMid(), $current_node);
     foreach ($rules as $rid) {
         $rule = new ilECSCourseMappingRule($rid);
         $rule->delete();
     }
     ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
     $this->ctrl->redirect($this, 'cInitOverview');
 }
 /**
  * 
  * @param type $course
  * @param type $a_sid
  * @param type $a_mid
  * @param type $a_ref_id
  */
 public static function doMappings($course, $a_sid, $a_mid, $a_ref_id)
 {
     global $ilDB;
     $query = 'SELECT rid FROM ecs_cmap_rule ' . 'WHERE sid = ' . $ilDB->quote($a_sid, 'integer') . ' ' . 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' . 'AND ref_id = ' . $ilDB->quote($a_ref_id, 'integer') . ' ' . 'ORDER BY rid';
     $res = $ilDB->query($query);
     $first = true;
     while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
         $rule = new ilECSCourseMappingRule($row->rid);
         if ($first) {
             $parent_ref = $rule->getRefId();
         }
         $parent_ref = $rule->doMapping($course, $parent_ref);
         $first = false;
     }
     return $parent_ref;
 }