/**
  * Will use the csv file submitted by the instructor to create all of the assessments
  *   Note that it does clear all existing data in the assessment related tables first
  *
  */
 public function upload_assessments()
 {
     global $course, $DB;
     $files = $this->get_draft_files('uploaded_assessments');
     if (!empty($files)) {
         $file = reset($files);
         $content = $file->get_content();
         $all_rows = explode("\n", $content);
         $courseid = get_course_id();
         // Need to delete everything related to course assessments, and each assessment
         foreach ($this->_customdata['assessments'] as $assessment) {
             $this->delete_all_relations_to_assessment($assessment->id);
         }
         $DB->delete_records('courseassessment', array('courseid' => $courseid));
         foreach ($all_rows as $row) {
             if ($row != "") {
                 $this->parse_and_save_assessment_row($row, $courseid);
             }
         }
     }
 }
 /**
  * Will use the csv file submitted by the instructor to create all of the sessions
  *   Note that it does clear all existing data in the session related tables first
  *
  */
 public function upload_sessions()
 {
     global $course, $DB;
     $files = $this->get_draft_files('uploaded_sessions');
     if (!empty($files)) {
         $file = reset($files);
         $content = $file->get_content();
         $all_rows = explode("\n", $content);
         $courseid = get_course_id();
         // Need to delete everything related to course sessions, and each session
         foreach ($this->_customdata['sessions'] as $session) {
             $this->delete_all_relations_to_session($session->id);
         }
         $DB->delete_records('coursesession', array('courseid' => $courseid));
         foreach ($all_rows as $row) {
             // Skip rows that are blank
             if ($row != "") {
                 $this->parse_and_save_session_row($row, $courseid);
             }
         }
     }
 }
<?php

global $PAGE, $CFG, $DB;
require_once '../../config.php';
require_once 'lib.php';
// Check that they can access.
require_login();
// TODO: Get permissions working.
$courseId = get_course_id();
$context = context_course::instance($courseId);
// require_capability('local/metadata:ins_view', $context);
require_once $CFG->dirroot . '/local/metadata/session_form.php';
// Define global variable for DB result
$course = $DB->get_record('course', array('id' => $courseId), '*', MUST_EXIST);
$session_page = optional_param('page', 0, PARAM_INT);
// Set up page information
$PAGE->set_context($context);
$PAGE->set_pagelayout('standard');
$PAGE->set_title(get_string('ins_pluginname', 'local_metadata'));
$heading = sprintf(get_string('instructor_heading', 'local_metadata'), $course->shortname, $course->fullname);
$PAGE->set_heading($heading);
// Create urls
$general_url = create_insview_url('general', $courseId);
$assessment_url = create_insview_url('assessment', $courseId);
$session_url = create_insview_url('session', $courseId);
$syllabus_url = create_insview_url('syllabus', $courseId);
$session_url->param('page', $session_page);
$PAGE->set_url($session_url);
$PAGE->requires->css('/local/metadata/insview_style.css');
$PAGE->requires->css('/local/metadata/session_element_style.css');
// Create form
Beispiel #4
0
/**
* grabs the table named $table and returns it as an array. 
* @param string $table Name of the table that you need returned. 
* @return array containing the required table
*/
function get_table_data_for_course($table)
{
    global $DB;
    $courseId = get_course_id();
    return $DB->get_records($table, array('courseid' => $courseId));
}
 /**
  * Save all of the given tuples to the database
  *      For new elements, will update their ['id'] with the index they are inserted into
  *
  * Can include extra fields that will not be saved in the 
  *
  * @param array $tuples array of tuples to be updated in the database, or inserted into it.
  *
  */
 function saveTuplesToDB(&$tuples)
 {
     global $DB;
     foreach ($tuples as &$tuple) {
         // Two different cases for each tuple
         if ($this->isInDatabase($tuple)) {
             // Already exists in the database
             $DB->update_record($this->tableName, $tuple);
         } else {
             // Need to add to database
             $courseIdArray = array('courseid' => get_course_id());
             $inserted = array_merge($tuple, $courseIdArray);
             $tuple['id'] = $DB->insert_record($this->tableName, $inserted);
         }
     }
 }
function course_num_students($course = '', $link = false)
{
    if ($course == '') {
        $course = get_course_id();
    }
    if ($link) {
        $before = '<a href="' . admin_url("course.php?action=view-students&course=" . $course) . '"' . ' title="' . __("Danh sách sinh viên của khóa học này") . '">';
        $after = '</a>';
    }
    echo $before . get_course_num_students($course) . $after;
}
function course_list_select($current = 0, $input_name, $input_id)
{
    echo "<select name=\"{$input_name}\" id=\"{$input_id}\">";
    $all_courses = _get_courses();
    foreach ($all_courses as $course) {
        setup_coursedata($course);
        echo '<option ' . is_selected(get_course_id() == $current) . ' value="' . get_course_id() . '">' . get_course_name() . '</option>';
    }
    echo "</select>";
}