/** * Set the visibility of a module and inherent properties. * * Note: Do not forget to trigger the event \core\event\course_module_updated as it needs * to be triggered manually, refer to {@link \core\event\course_module_updated::create_from_cm()}. * * 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'; require_once $CFG->dirroot . '/calendar/lib.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) { $event = new calendar_event($event); $event->toggle_visibility(true); } else { $event = new calendar_event($event); $event->toggle_visibility(false); } } } // 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); // Hide the associated grade items so the teacher doesn't also have to go to the gradebook and hide them there. // Note that this must be done after updating the row in course_modules, in case // the modules grade_item_update function needs to access $cm->visible. if (plugin_supports('mod', $modulename, FEATURE_CONTROLS_GRADE_VISIBILITY) && component_callback_exists('mod_' . $modulename, 'grade_item_update')) { $instance = $DB->get_record($modulename, array('id' => $cm->instance), '*', MUST_EXIST); component_callback('mod_' . $modulename, 'grade_item_update', array($instance)); } else { $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); } } } rebuild_course_cache($cm->course, true); return true; }
/** * Call this function to unhide an event in the calendar table * the event will be identified by the id field of the $event object. * * @param object $event An object representing an event from the calendar table. The event will be identified by the id field. * @return true */ function show_event($event) { global $CFG; require_once($CFG->dirroot.'/calendar/lib.php'); $event = new calendar_event($event); return $event->toggle_visibility(true); }
/** * Call this function to unhide an event in the calendar table * the event will be identified by the id field of the $event object. * * @param object $event An object representing an event from the calendar table. The event will be identified by the id field. * @return true * @deprecated please use calendar_event->toggle_visibility(true) instead. * @todo final deprecation of this function in MDL-40607 */ function show_event($event) { global $CFG; require_once $CFG->dirroot . '/calendar/lib.php'; debugging('show_event() is deprecated, please use calendar_event->toggle_visibility(true) instead.', DEBUG_DEVELOPER); $event = new calendar_event($event); return $event->toggle_visibility(true); }