示例#1
0
文件: lib.php 项目: rushi963/moodle
/**
 * For a given course section, marks it visible or hidden,
 * and does the same for every activity in that section
 *
 * @param int $courseid course id
 * @param int $sectionnumber The section number to adjust
 * @param int $visibility The new visibility
 * @return array A list of resources which were hidden in the section
 */
function set_section_visible($courseid, $sectionnumber, $visibility)
{
    global $DB;
    $resourcestotoggle = array();
    if ($section = $DB->get_record("course_sections", array("course" => $courseid, "section" => $sectionnumber))) {
        course_update_section($courseid, $section, array('visible' => $visibility));
        // Determine which modules are visible for AJAX update
        $modules = !empty($section->sequence) ? explode(',', $section->sequence) : array();
        if (!empty($modules)) {
            list($insql, $params) = $DB->get_in_or_equal($modules);
            $select = 'id ' . $insql . ' AND visible = ?';
            array_push($params, $visibility);
            if (!$visibility) {
                $select .= ' AND visibleold = 1';
            }
            $resourcestotoggle = $DB->get_fieldset_select('course_modules', 'id', $select, $params);
        }
    }
    return $resourcestotoggle;
}
示例#2
0
 /**
  * Updates the value in the database and modifies this object respectively.
  *
  * ALWAYS check user permissions before performing an update! Throw exceptions if permissions are not sufficient
  * or value is not legit.
  *
  * @param stdClass $section
  * @param string $itemtype
  * @param mixed $newvalue
  * @return \core\output\inplace_editable
  */
 public function inplace_editable_update_section_name($section, $itemtype, $newvalue)
 {
     if ($itemtype === 'sectionname' || $itemtype === 'sectionnamenl') {
         $context = context_course::instance($section->course);
         external_api::validate_context($context);
         require_capability('moodle/course:update', $context);
         $newtitle = clean_param($newvalue, PARAM_TEXT);
         if (strval($section->name) !== strval($newtitle)) {
             course_update_section($section->course, $section, array('name' => $newtitle));
         }
         return $this->inplace_editable_render_section_name($section, $itemtype === 'sectionname', true);
     }
 }
示例#3
0
if ($mform->is_cancelled()) {
    // Form cancelled, return to course.
    redirect(course_get_url($course, $section, array('sr' => $sectionreturn)));
} else {
    if ($data = $mform->get_data()) {
        // Data submitted and validated, update and return to course.
        // For consistency, we set the availability field to 'null' if it is empty.
        if (!empty($CFG->enableavailability)) {
            // Renamed field.
            $data->availability = $data->availabilityconditionsjson;
            unset($data->availabilityconditionsjson);
            if ($data->availability === '') {
                $data->availability = null;
            }
        }
        course_update_section($course, $section, $data);
        $PAGE->navigation->clear_cache();
        redirect(course_get_url($course, $section, array('sr' => $sectionreturn)));
    }
}
// The edit form is displayed for the first time or if there was validation error on the previous step.
$sectionname = get_section_name($course, $sectionnum);
$stredit = get_string('edita', '', " {$sectionname}");
$strsummaryof = get_string('summaryof', '', " {$sectionname}");
$PAGE->set_title($stredit);
$PAGE->set_heading($course->fullname);
$PAGE->navbar->add($stredit);
echo $OUTPUT->header();
echo $OUTPUT->heading($strsummaryof);
$mform->display();
echo $OUTPUT->footer();