/** * Import the aicc object (as a result from the parse_config_files function) into the database structure * @param string Unique course code * @return bool Returns -1 on error */ function import_aicc($course_code) { if ($this->debug > 0) { error_log('New LP - In aicc::import_aicc(' . $course_code . ')', 0); } //get table names $new_lp = 'lp'; $new_lp_item = 'lp_item'; //The previous method wasn't safe to get the database name, so do it manually with the course_code $sql = "SELECT * FROM " . Database::get_main_table(TABLE_MAIN_COURSE) . " WHERE code='{$course_code}'"; $res = Database::query($sql, __FILE__, __LINE__); if (Database::num_rows($res) < 1) { error_log('New LP - Database for ' . $course_code . ' not found ' . __FILE__ . ' ' . __LINE__, 0); return -1; } $row = Database::fetch_array($res); $dbname = Database::get_course_table_prefix() . $row['db_name'] . Database::get_database_glue(); $new_lp = Database::get_course_table(TABLE_LP_MAIN); $new_lp_item = Database::get_course_table(TABLE_LP_ITEM); $get_max = "SELECT MAX(display_order) FROM {$new_lp}"; $res_max = Database::query($get_max); if (Database::num_rows($res_max) < 1) { $dsp = 1; } else { $row = Database::fetch_array($res_max); $dsp = $row[0] + 1; } $this->config_encoding = "ISO-8859-1"; $sql = "INSERT INTO {$new_lp} " . "(lp_type, name, ref, description, " . "path, force_commit, default_view_mod, default_encoding, " . "js_lib, content_maker,display_order)" . "VALUES " . "(3,'" . $this->course_title . "', '" . $this->course_id . "','" . $this->course_description . "'," . "'" . $this->subdir . "', 0, 'embedded', '" . $this->config_encoding . "'," . "'aicc_api.php','" . $this->course_creator . "',{$dsp})"; if ($this->debug > 2) { error_log('New LP - In import_aicc(), inserting path: ' . $sql, 0); } $res = Database::query($sql); $lp_id = Database::insert_id(); $this->lp_id = $lp_id; api_item_property_update(api_get_course_info($course_code), TOOL_LEARNPATH, $this->lp_id, 'LearnpathAdded', api_get_user_id()); api_item_property_update(api_get_course_info($course_code), TOOL_LEARNPATH, $this->lp_id, 'visible', api_get_user_id()); $previous = 0; foreach ($this->aulist as $identifier => $dummy) { $oAu =& $this->aulist[$identifier]; //echo "Item ".$oAu->identifier; $field_add = ''; $value_add = ''; if (!empty($oAu->masteryscore)) { $field_add = 'mastery_score, '; $value_add = $oAu->masteryscore . ','; } $title = $oAu->identifier; if (is_object($this->deslist[$identifier])) { $title = $this->deslist[$identifier]->title; } $path = $oAu->path; //$max_score = $oAu->max_score //TODO check if special constraint exists for this item //$min_score = $oAu->min_score //TODO check if special constraint exists for this item $parent = 0; //TODO deal with parent $previous = 0; $prereq = $oAu->prereq_string; $parameters = $oAu->parameters; //$previous = (!empty($this->au_order_list_new_id[x])?$this->au_order_list_new_id[x]:0); //TODO deal with previous $sql_item = "INSERT INTO {$new_lp_item} " . "(lp_id,item_type,ref,title," . "path,parameters, min_score,max_score, {$field_add}" . "parent_item_id,previous_item_id,next_item_id," . "prerequisite,display_order) " . "VALUES " . "({$lp_id}, 'au','" . $oAu->identifier . "','" . $title . "'," . "'{$path}','{$parameters}',0,100, {$value_add}" . "{$parent}, {$previous}, 0, " . "'{$prereq}', 0" . ")"; $res_item = Database::query($sql_item); if ($this->debug > 1) { error_log('New LP - In aicc::import_aicc() - inserting item : ' . $sql_item . ' : ' . mysql_error(), 0); } $item_id = Database::insert_id(); //now update previous item to change next_item_id if ($previous != 0) { $upd = "UPDATE {$new_lp_item} SET next_item_id = {$item_id} WHERE id = {$previous}"; $upd_res = Database::query($upd); //update previous item id } $previous = $item_id; } }