Diverting the table used in a course/view.php

Diverting the table used in a course/view.php

by Rangga Wiratno -
Number of replies: 0

Hi, my course have a condition where a section of the course won't be visible for certain users during certain times.

In order to do this, I have created a seperate table where the user's id, user's participated courses's id, course's section and visible value is stored. It is then joined into a view which combines this new table with the course_sections table.

The structure of the view is the same as course_sections with an added column of user's id. The value of the visible column is taken from the new table instead so by adding a parameter where the view's user's id column is the same as $USER->id, if a user is not allowed to view a section of the course, it won't effect other users of the course.

I have been trying to do this but I couldn't divert the table used, I want it to use the view instead of the course_sections table if the user doesn't have the user_allowed_editing capability. How can I do this?

Here are the changes of what I've done so far in the course/view.php :

require_login($course);

//Create a view of filtered sections
if (!$PAGE->user_allowed_editing()) {
echo "Cannot edit";
if ($sectionid) {
$section = $DB->get_field('v_course_sections', 'section', array('id' => $sectionid, 'course' => $course->id, 'npm' => $USER->id), MUST_EXIST);
}
if ($section) {
$urlparams['section'] = $section;
}
}else{
echo "Can edit";
if ($sectionid) {
$section = $DB->get_field('course_sections', 'section', array('id' => $sectionid, 'course' => $course->id), MUST_EXIST);
}
$PAGE->set_url('/course/view.php', $urlparams); // Defined here to avoid notices on errors etc

if ($section) {
$urlparams['section'] = $section;
}
}

And one more thing, will using a view effect the performance of my server? If it does, how can I make a dynamic table in mysql?

Thanks in advance

Moodle 2.3, Windows XP SP3

Average of ratings: -