コード例 #1
0
ファイル: lib.php プロジェクト: numbas/moodle
/**
* $prevstateoverrides = true will set the visibility of the course module
* to what is defined in visibleold. This enables us to remember the current
* visibility when making a whole section hidden, so that when we toggle
* that section back to visible, we are able to return the visibility of
* the course module back to what it was originally.
*/
function set_coursemodule_visible($id, $visible, $prevstateoverrides = false)
{
    global $DB, $CFG;
    require_once $CFG->libdir . '/gradelib.php';
    if (!($cm = $DB->get_record('course_modules', array('id' => $id)))) {
        return false;
    }
    if (!($modulename = $DB->get_field('modules', 'name', array('id' => $cm->module)))) {
        return false;
    }
    if ($events = $DB->get_records('event', array('instance' => $cm->instance, 'modulename' => $modulename))) {
        foreach ($events as $event) {
            if ($visible) {
                show_event($event);
            } else {
                hide_event($event);
            }
        }
    }
    // hide the associated grade items so the teacher doesn't also have to go to the gradebook and hide them there
    $grade_items = grade_item::fetch_all(array('itemtype' => 'mod', 'itemmodule' => $modulename, 'iteminstance' => $cm->instance, 'courseid' => $cm->course));
    if ($grade_items) {
        foreach ($grade_items as $grade_item) {
            $grade_item->set_hidden(!$visible);
        }
    }
    if ($prevstateoverrides) {
        if ($visible == '0') {
            // Remember the current visible state so we can toggle this back.
            $DB->set_field('course_modules', 'visibleold', $cm->visible, array('id' => $id));
        } else {
            // Get the previous saved visible states.
            return $DB->set_field('course_modules', 'visible', $cm->visibleold, array('id' => $id));
        }
    }
    return $DB->set_field("course_modules", "visible", $visible, array("id" => $id));
}
コード例 #2
0
ファイル: lib.php プロジェクト: Jtgadbois/Pedadida
/**
 * Set the visibility of a module and inherent properties.
 *
 * From 2.4 the parameter $prevstateoverrides has been removed, the logic it triggered
 * has been moved to {@link set_section_visible()} which was the only place from which
 * the parameter was used.
 *
 * @param int $id of the module
 * @param int $visible state of the module
 * @return bool false when the module was not found, true otherwise
 */
function set_coursemodule_visible($id, $visible)
{
    global $DB, $CFG;
    require_once $CFG->libdir . '/gradelib.php';
    // Trigger developer's attention when using the previously removed argument.
    if (func_num_args() > 2) {
        debugging('Wrong number of arguments passed to set_coursemodule_visible(), $prevstateoverrides
            has been removed.', DEBUG_DEVELOPER);
    }
    if (!($cm = $DB->get_record('course_modules', array('id' => $id)))) {
        return false;
    }
    // Create events and propagate visibility to associated grade items if the value has changed.
    // Only do this if it's changed to avoid accidently overwriting manual showing/hiding of student grades.
    if ($cm->visible == $visible) {
        return true;
    }
    if (!($modulename = $DB->get_field('modules', 'name', array('id' => $cm->module)))) {
        return false;
    }
    if ($events = $DB->get_records('event', array('instance' => $cm->instance, 'modulename' => $modulename))) {
        foreach ($events as $event) {
            if ($visible) {
                show_event($event);
            } else {
                hide_event($event);
            }
        }
    }
    // Hide the associated grade items so the teacher doesn't also have to go to the gradebook and hide them there.
    $grade_items = grade_item::fetch_all(array('itemtype' => 'mod', 'itemmodule' => $modulename, 'iteminstance' => $cm->instance, 'courseid' => $cm->course));
    if ($grade_items) {
        foreach ($grade_items as $grade_item) {
            $grade_item->set_hidden(!$visible);
        }
    }
    // Updating visible and visibleold to keep them in sync. Only changing a section visibility will
    // affect visibleold to allow for an original visibility restore. See set_section_visible().
    $cminfo = new stdClass();
    $cminfo->id = $id;
    $cminfo->visible = $visible;
    $cminfo->visibleold = $visible;
    $DB->update_record('course_modules', $cminfo);
    rebuild_course_cache($cm->course, true);
    return true;
}
コード例 #3
0
ファイル: lib.php プロジェクト: ncsu-delta/moodle
/**
* $prevstateoverrides = true will set the visibility of the course module
* to what is defined in visibleold. This enables us to remember the current
* visibility when making a whole section hidden, so that when we toggle
* that section back to visible, we are able to return the visibility of
* the course module back to what it was originally.
*/
function set_coursemodule_visible($id, $visible, $prevstateoverrides=false) {
    global $DB, $CFG;
    require_once($CFG->libdir.'/gradelib.php');

    if (!$cm = $DB->get_record('course_modules', array('id'=>$id))) {
        return false;
    }

    // Create events and propagate visibility to associated grade items if the value has changed.
    // Only do this if it's changed to avoid accidently overwriting manual showing/hiding of student grades.
    if ($cm->visible == $visible) {
        return true;
    }

    if (!$modulename = $DB->get_field('modules', 'name', array('id'=>$cm->module))) {
        return false;
    }
    if ($events = $DB->get_records('event', array('instance'=>$cm->instance, 'modulename'=>$modulename))) {
        foreach($events as $event) {
            if ($visible) {
                show_event($event);
            } else {
                hide_event($event);
            }
        }
    }

    // Hide the associated grade items so the teacher doesn't also have to go to the gradebook and hide them there.
    $grade_items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$modulename, 'iteminstance'=>$cm->instance, 'courseid'=>$cm->course));
    if ($grade_items) {
        foreach ($grade_items as $grade_item) {
            $grade_item->set_hidden(!$visible);
        }
    }

    $cminfo = new stdClass();
    $cminfo->id = $id;
    $cminfo->visible = $visible;

    if ($prevstateoverrides) {
        // If we making whole section visiblility change..
        if ($visible == 0) {
            // Retain previous visibility state.
            $cminfo->visibleold = $cm->visible;
        } else {
            // Restore previous visibility state.
            $cminfo->visible = $cm->visibleold;
        }
    } else {
        $cminfo->visibleold = $visible;
    }
    return $DB->update_record('course_modules', $cminfo);
}
コード例 #4
0
/**
* $prevstateoverrides = true will set the visibility of the course module
* to what is defined in visibleold. This enables us to remember the current
* visibility when making a whole section hidden, so that when we toggle
* that section back to visible, we are able to return the visibility of
* the course module back to what it was originally.
*/
function set_coursemodule_visible($id, $visible, $prevstateoverrides = false)
{
    if (!($cm = get_record('course_modules', 'id', $id))) {
        return false;
    }
    if (!($modulename = get_field('modules', 'name', 'id', $cm->module))) {
        return false;
    }
    if ($events = get_records_select('event', "instance = '{$cm->instance}' AND modulename = '{$modulename}'")) {
        foreach ($events as $event) {
            if ($visible) {
                show_event($event);
            } else {
                hide_event($event);
            }
        }
    }
    if ($prevstateoverrides) {
        if ($visible == '0') {
            // Remember the current visible state so we can toggle this back.
            set_field('course_modules', 'visibleold', $cm->visible, 'id', $id);
        } else {
            // Get the previous saved visible states.
            return set_field('course_modules', 'visible', $cm->visibleold, 'id', $id);
        }
    }
    return set_field("course_modules", "visible", $visible, "id", $id);
}
コード例 #5
0
ファイル: lib.php プロジェクト: nicolasconnault/moodle2.0
/**
* $prevstateoverrides = true will set the visibility of the course module
* to what is defined in visibleold. This enables us to remember the current
* visibility when making a whole section hidden, so that when we toggle
* that section back to visible, we are able to return the visibility of
* the course module back to what it was originally.
*/
function set_coursemodule_visible($id, $visible, $prevstateoverrides = false)
{
    global $DB;
    if (!($cm = $DB->get_record('course_modules', array('id' => $id)))) {
        return false;
    }
    if (!($modulename = $DB->get_field('modules', 'name', array('id' => $cm->module)))) {
        return false;
    }
    if ($events = $DB->get_records('event', array('instance' => $cm->instance, 'modulename' => $modulename))) {
        foreach ($events as $event) {
            if ($visible) {
                show_event($event);
            } else {
                hide_event($event);
            }
        }
    }
    if ($prevstateoverrides) {
        if ($visible == '0') {
            // Remember the current visible state so we can toggle this back.
            $DB->set_field('course_modules', 'visibleold', $cm->visible, array('id' => $id));
        } else {
            // Get the previous saved visible states.
            return $DB->set_field('course_modules', 'visible', $cm->visibleold, array('id' => $id));
        }
    }
    return $DB->set_field("course_modules", "visible", $visible, array("id" => $id));
}