示例#1
0
/**
 * Produces the editing buttons for a module
 *
 * Deprecated. Please use:
 * $courserenderer = $PAGE->get_renderer('core', 'course');
 * $actions = course_get_cm_edit_actions($mod, $indent, $section);
 * return ' ' . $courserenderer->course_section_cm_edit_actions($actions);
 *
 * @deprecated since 2.5
 * @see course_get_cm_edit_actions()
 * @see core_course_renderer->course_section_cm_edit_actions()
 *
 * @param stdClass $mod The module to produce editing buttons for
 * @param bool $absolute_ignored (argument ignored) - all links are absolute
 * @param bool $moveselect (argument ignored)
 * @param int $indent The current indenting
 * @param int $section The section to link back to
 * @return string XHTML for the editing buttons
 */
function make_editing_buttons(stdClass $mod, $absolute_ignored = true, $moveselect = true, $indent = -1, $section = null)
{
    global $PAGE;
    debugging('Function make_editing_buttons() is deprecated, please see PHPdocs in ' . 'lib/deprecatedlib.php on how to replace it', DEBUG_DEVELOPER);
    if (!$mod instanceof cm_info) {
        $modinfo = get_fast_modinfo($mod->course);
        $mod = $modinfo->get_cm($mod->id);
    }
    $actions = course_get_cm_edit_actions($mod, $indent, $section);
    $courserenderer = $PAGE->get_renderer('core', 'course');
    // The space added before the <span> is a ugly hack but required to set the CSS property white-space: nowrap
    // and having it to work without attaching the preceding text along with it. Hopefully the refactoring of
    // the course page HTML will allow this to be removed.
    return ' ' . $courserenderer->course_section_cm_edit_actions($actions);
}
 /**
  * Parent class version of this function simply returns NULL This should be implemented by the derived class to return the content object.
  *
  * @return object The content object
  */
 public function get_content()
 {
     global $USER, $CFG, $DB, $OUTPUT;
     if ($this->content !== null) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->items = array();
     $this->content->icons = array();
     $this->content->footer = '';
     if (empty($this->instance)) {
         if (!isset($this->content)) {
             $this->content = new stdClass();
         }
         return $this->content;
     }
     if (!isset($this->config->title)) {
         if (!isset($this->config)) {
             $this->config = new stdClass();
         }
         $this->config->title = '';
     }
     $course = $this->page->course;
     require_once $CFG->dirroot . '/course/lib.php';
     $context = context_course::instance($course->id);
     $isediting = $this->page->user_is_editing() && has_capability('moodle/course:manageactivities', $context);
     // Create a new section for this block (if necessary).
     if (empty($this->config->section)) {
         require_once $CFG->dirroot . '/blocks/side_bar/locallib.php';
         if (null == ($section = block_side_bar_create_section($course))) {
             return $this->content;
         }
         $this->config->section = $section->section;
         $this->config->section_id = $section->id;
         parent::instance_config_commit();
     } else {
         if (empty($this->config->section_id)) {
             $params = array('course' => $course->id, 'section' => $this->config->section);
             $section = $DB->get_record('course_sections', $params);
             $this->config->section_id = $section->id;
             parent::instance_config_commit();
         } else {
             $section = $DB->get_record('course_sections', array('id' => $this->config->section_id));
             if (empty($section)) {
                 require_once $CFG->dirroot . '/blocks/side_bar/locallib.php';
                 if (null == ($section = block_side_bar_create_section($course))) {
                     return $this->content;
                 }
                 $this->config->section = $section->section;
                 $this->config->section_id = $section->id;
                 parent::instance_config_commit();
             }
         }
         // Double check that the section number hasn't been modified by something else.
         // Fixes problem found by Charlotte Owen when moving 'center column' course sections.
         if ($section->section != $this->config->section) {
             $section->section = $this->config->section;
             $DB->update_record('course_sections', $section);
         }
     }
     // extra fast view mode
     $modinfo = get_fast_modinfo($course);
     if (!$isediting) {
         if (!empty($modinfo->sections[$this->config->section])) {
             $options = array('overflowdiv' => true);
             foreach ($modinfo->sections[$this->config->section] as $cmid) {
                 $cm = $modinfo->cms[$cmid];
                 if (!$cm->uservisible) {
                     continue;
                 }
                 $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
                 $instancename = $cm->get_formatted_name();
                 if (!($url = $cm->url)) {
                     $this->content->items[] = $content;
                     $this->content->icons[] = '';
                 } else {
                     $linkcss = $cm->visible ? '' : ' class="dimmed" ';
                     // Accessibility: incidental image - should be empty Alt text
                     $icon = '<img src="' . $cm->get_icon_url() . '" class="icon" alt="" />&nbsp;';
                     $this->content->items[] = '<a title="' . $cm->modplural . '" ' . $linkcss . ' ' . $cm->extra . ' href="' . $url . '">' . $icon . $instancename . '</a>';
                 }
             }
         }
         return $this->content;
     }
     // slow & hacky editing mode
     $courserenderer = $this->page->get_renderer('core', 'course');
     $ismoving = ismoving($course->id);
     if (!($cs = $DB->get_record('course_sections', array('section' => $this->config->section, 'course' => $course->id)))) {
         debugging('Could not get course section record for section ' . $this->config->section, DEBUG_DEVELOPER);
         return $this->content;
     }
     $modinfo = get_fast_modinfo($course);
     $section = $modinfo->get_section_info($this->config->section);
     $modnames = get_module_types_names();
     $groupbuttons = $course->groupmode;
     $groupbuttonslink = !$course->groupmodeforce;
     if ($ismoving) {
         $strmovehere = get_string('movehere');
         $strmovefull = strip_tags(get_string('movefull', '', "'{$USER->activitycopyname}'"));
         $strcancel = get_string('cancel');
         $stractivityclipboard = $USER->activitycopyname;
     } else {
         $strmove = get_string('move');
     }
     // Casting $course->modinfo to string prevents one notice when the field is null
     $editbuttons = '';
     if ($ismoving) {
         $this->content->icons[] = '<img src="' . $OUTPUT->pix_url('t/move') . '" class="iconsmall" alt="" />';
         $this->content->items[] = $USER->activitycopyname . '&nbsp;(<a href="' . $CFG->wwwroot . '/course/mod.php?cancelcopy=true&amp;sesskey=' . sesskey() . '">' . $strcancel . '</a>)';
     }
     if (!empty($modinfo->sections[$this->config->section])) {
         $options = array('overflowdiv' => true);
         foreach ($modinfo->sections[$this->config->section] as $modnumber) {
             $mod = $modinfo->cms[$modnumber];
             if (!$mod->uservisible) {
                 continue;
             }
             if (!$ismoving) {
                 $actions = course_get_cm_edit_actions($mod, -1);
                 // Prepend list of actions with the 'move' action.
                 $actions = array('move' => new action_menu_link_primary(new moodle_url('/course/mod.php', array('sesskey' => sesskey(), 'copy' => $mod->id)), new pix_icon('t/move', $strmove, 'moodle', array('class' => 'iconsmall', 'title' => '')), $strmove)) + $actions;
                 $editactions = $courserenderer->course_section_cm_edit_actions($actions, $mod, array('donotenhance' => true));
                 $editbuttons = html_writer::tag('div', $editactions, array('class' => 'buttons'));
             } else {
                 $editbuttons = '';
             }
             if ($mod->visible || has_capability('moodle/course:viewhiddenactivities', $context)) {
                 if ($ismoving) {
                     if ($mod->id == $USER->activitycopy) {
                         continue;
                     }
                     $this->content->items[] = '<a title="' . $strmovefull . '" href="' . $CFG->wwwroot . '/course/mod.php' . '?moveto=' . $mod->id . '&amp;sesskey=' . sesskey() . '"><img style="height:16px; width:80px; border:0px"' . ' src="' . $OUTPUT->pix_url('movehere') . '" alt="' . $strmovehere . '" /></a>';
                     $this->content->icons[] = '';
                 }
                 $content = $mod->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
                 $instancename = $mod->get_formatted_name();
                 $linkcss = $mod->visible ? '' : ' class="dimmed" ';
                 if (!($url = $mod->url)) {
                     $this->content->items[] = $content . $editbuttons;
                     $this->content->icons[] = '';
                 } else {
                     // Accessibility: incidental image - should be empty Alt text
                     $icon = '<img src="' . $mod->get_icon_url() . '" class="icon" alt="" />&nbsp;';
                     $this->content->items[] = '<a title="' . $mod->modfullname . '" ' . $linkcss . ' ' . $mod->extra . ' href="' . $url . '">' . $icon . $instancename . '</a>' . $editbuttons;
                 }
             }
         }
     }
     if ($ismoving) {
         $this->content->items[] = '<a title="' . $strmovefull . '" href="' . $CFG->wwwroot . '/course/mod.php?' . 'movetosection=' . $section->id . '&amp;sesskey=' . sesskey() . '"><img style="height' . ':16px; width:80px; border:0px" src="' . $OUTPUT->pix_url('movehere') . '" alt="' . $strmovehere . '" /></a>';
         $this->content->icons[] = '';
     }
     $this->content->footer = $courserenderer->course_section_add_cm_control($course, $this->config->section, null, array('inblock' => true));
     // Replace modchooser with dropdown
     $this->content->footer = str_replace('hiddenifjs addresourcedropdown', 'visibleifjs addresourcedropdown', $this->content->footer);
     $this->content->footer = str_replace('visibleifjs addresourcemodchooser', 'hiddenifjs addresourcemodchooser', $this->content->footer);
     return $this->content;
 }
 function get_content()
 {
     global $USER, $CFG, $DB, $OUTPUT;
     if ($this->content !== NULL) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->items = array();
     $this->content->icons = array();
     $this->content->footer = '';
     if (empty($this->instance)) {
         return $this->content;
     }
     $course = $this->page->course;
     require_once $CFG->dirroot . '/course/lib.php';
     $context = context_course::instance($course->id);
     $isediting = $this->page->user_is_editing() && has_capability('moodle/course:manageactivities', $context);
     /// extra fast view mode
     if (!$isediting) {
         $modinfo = get_fast_modinfo($course);
         if (!empty($modinfo->sections[0])) {
             foreach ($modinfo->sections[0] as $cmid) {
                 $cm = $modinfo->cms[$cmid];
                 if (!$cm->uservisible) {
                     continue;
                 }
                 if ($cm->indent > 0) {
                     $indent = '<div class="mod-indent mod-indent-' . $cm->indent . '"></div>';
                 } else {
                     $indent = '';
                 }
                 if (!empty($cm->url)) {
                     $attrs = array();
                     $attrs['title'] = $cm->modfullname;
                     $attrs['class'] = $cm->extraclasses . ' activity-action';
                     if ($cm->onclick) {
                         $attrs['id'] = html_writer::random_id('onclick');
                         $OUTPUT->add_action_handler(new component_action('click', $cm->onclick), $attrs['id']);
                     }
                     if (!$cm->visible) {
                         $attrs['class'] .= ' dimmed';
                     }
                     $icon = '<img src="' . $cm->get_icon_url() . '" class="icon" alt="" />';
                     $content = html_writer::link($cm->url, $icon . $cm->get_formatted_name(), $attrs);
                 } else {
                     $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
                 }
                 $this->content->items[] = $indent . html_writer::div($content, 'main-menu-content');
             }
         }
         return $this->content;
     }
     // Slow & hacky editing mode.
     /** @var core_course_renderer $courserenderer */
     $courserenderer = $this->page->get_renderer('core', 'course');
     $ismoving = ismoving($course->id);
     course_create_sections_if_missing($course, 0);
     $modinfo = get_fast_modinfo($course);
     $section = $modinfo->get_section_info(0);
     if ($ismoving) {
         $strmovehere = get_string('movehere');
         $strmovefull = strip_tags(get_string('movefull', '', "'{$USER->activitycopyname}'"));
         $strcancel = get_string('cancel');
         $stractivityclipboard = $USER->activitycopyname;
     } else {
         $strmove = get_string('move');
     }
     $editbuttons = '';
     if ($ismoving) {
         $this->content->icons[] = '<img src="' . $OUTPUT->pix_url('t/move') . '" class="iconsmall" alt="" />';
         $this->content->items[] = $USER->activitycopyname . '&nbsp;(<a href="' . $CFG->wwwroot . '/course/mod.php?cancelcopy=true&amp;sesskey=' . sesskey() . '">' . $strcancel . '</a>)';
     }
     if (!empty($modinfo->sections[0])) {
         $options = array('overflowdiv' => true);
         foreach ($modinfo->sections[0] as $modnumber) {
             $mod = $modinfo->cms[$modnumber];
             if (!$mod->uservisible) {
                 continue;
             }
             if (!$ismoving) {
                 $actions = course_get_cm_edit_actions($mod, $mod->indent);
                 // Prepend list of actions with the 'move' action.
                 $actions = array('move' => new action_menu_link_primary(new moodle_url('/course/mod.php', array('sesskey' => sesskey(), 'copy' => $mod->id)), new pix_icon('t/move', $strmove, 'moodle', array('class' => 'iconsmall', 'title' => '')), $strmove)) + $actions;
                 $editbuttons = html_writer::tag('div', $courserenderer->course_section_cm_edit_actions($actions, $mod, array('donotenhance' => true)), array('class' => 'buttons'));
             } else {
                 $editbuttons = '';
             }
             if ($mod->visible || has_capability('moodle/course:viewhiddenactivities', $mod->context)) {
                 if ($ismoving) {
                     if ($mod->id == $USER->activitycopy) {
                         continue;
                     }
                     $this->content->items[] = '<a title="' . $strmovefull . '" href="' . $CFG->wwwroot . '/course/mod.php?moveto=' . $mod->id . '&amp;sesskey=' . sesskey() . '">' . '<img style="height:16px; width:80px; border:0px" src="' . $OUTPUT->pix_url('movehere') . '" alt="' . $strmovehere . '" /></a>';
                     $this->content->icons[] = '';
                 }
                 if ($mod->indent > 0) {
                     $indent = '<div class="mod-indent mod-indent-' . $mod->indent . '"></div>';
                 } else {
                     $indent = '';
                 }
                 $url = $mod->url;
                 if (!$url) {
                     $content = $mod->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
                 } else {
                     //Accessibility: incidental image - should be empty Alt text
                     $attrs = array();
                     $attrs['title'] = $mod->modfullname;
                     $attrs['class'] = $mod->extraclasses . ' activity-action';
                     if ($mod->onclick) {
                         $attrs['id'] = html_writer::random_id('onclick');
                         $OUTPUT->add_action_handler(new component_action('click', $mod->onclick), $attrs['id']);
                     }
                     if (!$mod->visible) {
                         $attrs['class'] .= ' dimmed';
                     }
                     $icon = '<img src="' . $mod->get_icon_url() . '" class="icon" alt="" />';
                     $content = html_writer::link($url, $icon . $mod->get_formatted_name(), $attrs);
                 }
                 $this->content->items[] = $indent . html_writer::div($content . $editbuttons, 'main-menu-content');
             }
         }
     }
     if ($ismoving) {
         $this->content->items[] = '<a title="' . $strmovefull . '" href="' . $CFG->wwwroot . '/course/mod.php?movetosection=' . $section->id . '&amp;sesskey=' . sesskey() . '">' . '<img style="height:16px; width:80px; border:0px" src="' . $OUTPUT->pix_url('movehere') . '" alt="' . $strmovehere . '" /></a>';
         $this->content->icons[] = '';
     }
     $this->content->footer = $courserenderer->course_section_add_cm_control($course, 0, null, array('inblock' => true));
     return $this->content;
 }
示例#4
0
 /**
  * Renders HTML to display one course module in a course section
  *
  * This includes link, content, availability, completion info and additional information
  * that module type wants to display (i.e. number of unread forum posts)
  *
  * This function calls:
  * {@link core_course_renderer::course_section_cm_name()}
  * {@link core_course_renderer::course_section_cm_text()}
  * {@link core_course_renderer::course_section_cm_availability()}
  * {@link core_course_renderer::course_section_cm_completion()}
  * {@link course_get_cm_edit_actions()}
  * {@link core_course_renderer::course_section_cm_edit_actions()}
  *
  * @param stdClass $course
  * @param completion_info $completioninfo
  * @param cm_info $mod
  * @param int|null $sectionreturn
  * @param array $displayoptions
  * @return string
  */
 public function course_section_cm($course, &$completioninfo, cm_info $mod, $sectionreturn, $displayoptions = array())
 {
     $output = '';
     // We return empty string (because course module will not be displayed at all)
     // if:
     // 1) The activity is not visible to users
     // and
     // 2) The 'availableinfo' is empty, i.e. the activity was
     //     hidden in a way that leaves no info, such as using the
     //     eye icon.
     if (!$mod->uservisible && empty($mod->availableinfo)) {
         return $output;
     }
     $indentclasses = 'mod-indent';
     if (!empty($mod->indent)) {
         $indentclasses .= ' mod-indent-' . $mod->indent;
         if ($mod->indent > 15) {
             $indentclasses .= ' mod-indent-huge';
         }
     }
     $output .= html_writer::start_tag('div');
     if ($this->page->user_is_editing()) {
         $output .= course_get_cm_move($mod, $sectionreturn);
     }
     $output .= html_writer::start_tag('div', array('class' => 'mod-indent-outer'));
     // This div is used to indent the content.
     $output .= html_writer::div('', $indentclasses);
     // Start a wrapper for the actual content to keep the indentation consistent
     $output .= html_writer::start_tag('div');
     // Display the link to the module (or do nothing if module has no url)
     $cmname = $this->course_section_cm_name($mod, $displayoptions);
     if (!empty($cmname)) {
         // Start the div for the activity title, excluding the edit icons.
         $output .= html_writer::start_tag('div', array('class' => 'activityinstance'));
         $output .= $cmname;
         // Module can put text after the link (e.g. forum unread)
         $output .= $mod->afterlink;
         // Closing the tag which contains everything but edit icons. Content part of the module should not be part of this.
         $output .= html_writer::end_tag('div');
         // .activityinstance
     }
     // If there is content but NO link (eg label), then display the
     // content here (BEFORE any icons). In this case cons must be
     // displayed after the content so that it makes more sense visually
     // and for accessibility reasons, e.g. if you have a one-line label
     // it should work similarly (at least in terms of ordering) to an
     // activity.
     $contentpart = $this->course_section_cm_text($mod, $displayoptions);
     $url = $mod->url;
     if (empty($url)) {
         $output .= $contentpart;
     }
     $modicons = '';
     if ($this->page->user_is_editing()) {
         $editactions = course_get_cm_edit_actions($mod, $mod->indent, $sectionreturn);
         $modicons .= ' ' . $this->course_section_cm_edit_actions($editactions, $mod, $displayoptions);
         $modicons .= $mod->afterediticons;
     }
     $modicons .= $this->course_section_cm_completion($course, $completioninfo, $mod, $displayoptions);
     if (!empty($modicons)) {
         $output .= html_writer::span($modicons, 'actions');
     }
     // If there is content AND a link, then display the content here
     // (AFTER any icons). Otherwise it was displayed before
     if (!empty($url)) {
         $output .= $contentpart;
     }
     // show availability info (if module is not available)
     $output .= $this->course_section_cm_availability($mod, $displayoptions);
     $output .= html_writer::end_tag('div');
     // $indentclasses
     // End of indentation div.
     $output .= html_writer::end_tag('div');
     $output .= html_writer::end_tag('div');
     return $output;
 }
 /**
  * Send the details of the newly created activity back to the client browser
  *
  * @param cm_info $mod details of the mod just created
  */
 protected function send_response($mod)
 {
     global $OUTPUT, $PAGE;
     $courserenderer = $PAGE->get_renderer('core', 'course');
     $resp = new stdClass();
     $resp->error = self::ERROR_OK;
     $resp->icon = $mod->get_icon_url()->out();
     $resp->name = $mod->name;
     if ($mod->has_view()) {
         $resp->link = $mod->get_url()->out();
     } else {
         $resp->link = null;
     }
     $resp->content = $mod->get_content();
     $resp->elementid = 'module-' . $mod->id;
     $actions = course_get_cm_edit_actions($mod, 0, $mod->sectionnum);
     $resp->commands = ' ' . $courserenderer->course_section_cm_edit_actions($actions);
     $resp->onclick = $mod->get_on_click();
     $resp->visible = $mod->visible;
     // if using groupings, then display grouping name
     if (!empty($mod->groupingid) && has_capability('moodle/course:managegroups', $this->context)) {
         $groupings = groups_get_all_groupings($this->course->id);
         $resp->groupingname = format_string($groupings[$mod->groupingid]->name);
     }
     echo $OUTPUT->header();
     echo json_encode($resp);
     die;
 }
 function get_content()
 {
     global $USER, $CFG, $DB, $OUTPUT;
     if ($this->content !== NULL) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->items = array();
     $this->content->icons = array();
     $this->content->footer = '';
     if (empty($this->instance)) {
         return $this->content;
     }
     $course = $this->page->course;
     require_once $CFG->dirroot . '/course/lib.php';
     $context = context_course::instance($course->id);
     $isediting = $this->page->user_is_editing() && has_capability('moodle/course:manageactivities', $context);
     $modinfo = get_fast_modinfo($course);
     /// extra fast view mode
     if (!$isediting) {
         if (!empty($modinfo->sections[0])) {
             $options = array('overflowdiv' => true);
             foreach ($modinfo->sections[0] as $cmid) {
                 $cm = $modinfo->cms[$cmid];
                 if (!$cm->uservisible) {
                     continue;
                 }
                 $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
                 $instancename = $cm->get_formatted_name();
                 if (!($url = $cm->get_url())) {
                     $this->content->items[] = $content;
                     $this->content->icons[] = '';
                 } else {
                     $linkcss = $cm->visible ? '' : ' class="dimmed" ';
                     //Accessibility: incidental image - should be empty Alt text
                     $icon = '<img src="' . $cm->get_icon_url() . '" class="icon" alt="" />&nbsp;';
                     $this->content->items[] = '<a title="' . $cm->modplural . '" ' . $linkcss . ' ' . $cm->extra . ' href="' . $url . '">' . $icon . $instancename . '</a>';
                 }
             }
         }
         return $this->content;
     }
     // Slow & hacky editing mode.
     /** @var core_course_renderer $courserenderer */
     $courserenderer = $this->page->get_renderer('core', 'course');
     $ismoving = ismoving($course->id);
     $modinfo = get_fast_modinfo($course);
     $section = $modinfo->get_section_info(0);
     if ($ismoving) {
         $strmovehere = get_string('movehere');
         $strmovefull = strip_tags(get_string('movefull', '', "'{$USER->activitycopyname}'"));
         $strcancel = get_string('cancel');
         $stractivityclipboard = $USER->activitycopyname;
     }
     $editbuttons = '';
     if ($ismoving) {
         $this->content->icons[] = '&nbsp;<img align="bottom" src="' . $OUTPUT->pix_url('t/move') . '" class="iconsmall" alt="" />';
         $this->content->items[] = $USER->activitycopyname . '&nbsp;(<a href="' . $CFG->wwwroot . '/course/mod.php?cancelcopy=true&amp;sesskey=' . sesskey() . '">' . $strcancel . '</a>)';
     }
     if (!empty($modinfo->sections[0])) {
         $options = array('overflowdiv' => true);
         foreach ($modinfo->sections[0] as $modnumber) {
             $mod = $modinfo->cms[$modnumber];
             if (!$mod->uservisible) {
                 continue;
             }
             if (!$ismoving) {
                 $actions = course_get_cm_edit_actions($mod, -1);
                 $editbuttons = '<br />' . $courserenderer->course_section_cm_edit_actions($actions, $mod);
             } else {
                 $editbuttons = '';
             }
             if ($mod->visible || has_capability('moodle/course:viewhiddenactivities', $context)) {
                 if ($ismoving) {
                     if ($mod->id == $USER->activitycopy) {
                         continue;
                     }
                     $this->content->items[] = '<a title="' . $strmovefull . '" href="' . $CFG->wwwroot . '/course/mod.php?moveto=' . $mod->id . '&amp;sesskey=' . sesskey() . '">' . '<img style="height:16px; width:80px; border:0px" src="' . $OUTPUT->pix_url('movehere') . '" alt="' . $strmovehere . '" /></a>';
                     $this->content->icons[] = '';
                 }
                 $content = $mod->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
                 $instancename = $mod->get_formatted_name();
                 $linkcss = $mod->visible ? '' : ' class="dimmed" ';
                 if (!($url = $mod->get_url())) {
                     $this->content->items[] = $content . $editbuttons;
                     $this->content->icons[] = '';
                 } else {
                     //Accessibility: incidental image - should be empty Alt text
                     $icon = '<img src="' . $mod->get_icon_url() . '" class="icon" alt="" />&nbsp;';
                     $this->content->items[] = '<a title="' . $mod->modfullname . '" ' . $linkcss . ' ' . $mod->extra . ' href="' . $url . '">' . $icon . $instancename . '</a>' . $editbuttons;
                 }
             }
         }
     }
     if ($ismoving) {
         $this->content->items[] = '<a title="' . $strmovefull . '" href="' . $CFG->wwwroot . '/course/mod.php?movetosection=' . $section->id . '&amp;sesskey=' . sesskey() . '">' . '<img style="height:16px; width:80px; border:0px" src="' . $OUTPUT->pix_url('movehere') . '" alt="' . $strmovehere . '" /></a>';
         $this->content->icons[] = '';
     }
     $this->content->footer = $courserenderer->course_section_add_cm_control($course, 0, null, array('inblock' => true));
     return $this->content;
 }
 /**
  * Wrapper around course_get_cm_edit_actions
  *
  * @param cm_info $mod The module
  * @param int $sr The section to link back to (used for creating the links)
  * @return array Of action_link or pix_icon objects
  */
 protected function course_get_cm_edit_actions(cm_info $mod, $sr = null)
 {
     $actions = course_get_cm_edit_actions($mod, -1, $sr);
     $actions = array_filter($actions, function ($action) {
         return !$action instanceof action_menu_filler;
     });
     $rename = course_get_cm_rename_action($mod, $mod->indent, $sr);
     $edittitle = get_string('edittitle');
     $rename = str_replace('</a>', "{$edittitle}</a>", $rename);
     $actions['edit-rename'] = $rename;
     return $actions;
 }
 function get_content()
 {
     global $USER, $CFG, $DB, $OUTPUT;
     if ($this->content !== NULL) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->items = array();
     $this->content->icons = array();
     $this->content->footer = '';
     if (empty($this->instance)) {
         return $this->content;
     }
     $course = $this->page->course;
     $courserenderer = $this->page->get_renderer('core', 'course');
     require_once $CFG->dirroot . '/course/lib.php';
     $context = context_course::instance($course->id);
     $isediting = $this->page->user_is_editing() && has_capability('moodle/course:manageactivities', $context);
     $modinfo = get_fast_modinfo($course);
     /// extra fast view mode
     if (!$isediting) {
         if (!empty($modinfo->sections[0])) {
             foreach ($modinfo->sections[0] as $cmid) {
                 $cm = $modinfo->cms[$cmid];
                 if (!$cm->uservisible) {
                     continue;
                 }
                 if (!$cm->url) {
                     $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
                     $this->content->items[] = $content;
                     $this->content->icons[] = '';
                 } else {
                     $this->content->items[] = html_writer::div($courserenderer->course_section_cm_name($cm), 'activity');
                 }
             }
         }
         return $this->content;
     }
     // Slow & hacky editing mode.
     $ismoving = ismoving($course->id);
     $section = $modinfo->get_section_info(0);
     if ($ismoving) {
         $strmovehere = get_string('movehere');
         $strmovefull = strip_tags(get_string('movefull', '', "'{$USER->activitycopyname}'"));
         $strcancel = get_string('cancel');
     } else {
         $strmove = get_string('move');
     }
     if ($ismoving) {
         $this->content->icons[] = '&nbsp;<img align="bottom" src="' . $OUTPUT->pix_url('t/move') . '" class="iconsmall" alt="" />';
         $this->content->items[] = $USER->activitycopyname . '&nbsp;(<a href="' . $CFG->wwwroot . '/course/mod.php?cancelcopy=true&amp;sesskey=' . sesskey() . '">' . $strcancel . '</a>)';
     }
     if (!empty($modinfo->sections[0])) {
         foreach ($modinfo->sections[0] as $modnumber) {
             $mod = $modinfo->cms[$modnumber];
             if (!$mod->uservisible) {
                 continue;
             }
             if (!$ismoving) {
                 $actions = course_get_cm_edit_actions($mod, -1);
                 // Prepend list of actions with the 'move' action.
                 $actions = array('move' => new action_menu_link_primary(new moodle_url('/course/mod.php', array('sesskey' => sesskey(), 'copy' => $mod->id)), new pix_icon('t/move', $strmove, 'moodle', array('class' => 'iconsmall', 'title' => '')), $strmove)) + $actions;
                 $editbuttons = html_writer::tag('div', $courserenderer->course_section_cm_edit_actions($actions, $mod, array('donotenhance' => true)), array('class' => 'buttons'));
             } else {
                 $editbuttons = '';
             }
             if ($mod->visible || has_capability('moodle/course:viewhiddenactivities', $mod->context)) {
                 if ($ismoving) {
                     if ($mod->id == $USER->activitycopy) {
                         continue;
                     }
                     $this->content->items[] = '<a title="' . $strmovefull . '" href="' . $CFG->wwwroot . '/course/mod.php?moveto=' . $mod->id . '&amp;sesskey=' . sesskey() . '">' . '<img style="height:16px; width:80px; border:0px" src="' . $OUTPUT->pix_url('movehere') . '" alt="' . $strmovehere . '" /></a>';
                     $this->content->icons[] = '';
                 }
                 if (!$mod->url) {
                     $content = $mod->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
                     $this->content->items[] = $content . $editbuttons;
                     $this->content->icons[] = '';
                 } else {
                     $this->content->items[] = html_writer::div($courserenderer->course_section_cm_name($mod), 'activity') . $editbuttons;
                 }
             }
         }
     }
     if ($ismoving) {
         $this->content->items[] = '<a title="' . $strmovefull . '" href="' . $CFG->wwwroot . '/course/mod.php?movetosection=' . $section->id . '&amp;sesskey=' . sesskey() . '">' . '<img style="height:16px; width:80px; border:0px" src="' . $OUTPUT->pix_url('movehere') . '" alt="' . $strmovehere . '" /></a>';
         $this->content->icons[] = '';
     }
     $this->content->footer = $courserenderer->course_section_add_cm_control($course, 0, null, array('inblock' => true));
     return $this->content;
 }
 /**
  * Prints a section full of activity modules
  */
 function print_section_fn($course, $section, $mods, $modnamesused, $absolute = false, $width = "100%", $hidecompletion = false, $resubmission = false)
 {
     global $CFG, $USER, $DB, $PAGE, $OUTPUT;
     static $initialised;
     static $groupbuttons;
     static $groupbuttonslink;
     static $isediting;
     static $ismoving;
     static $strmovehere;
     static $strmovefull;
     static $strunreadpostsone;
     static $groupings;
     static $modulenames;
     // oncampus
     $selected_week = $section->__get('section');
     if (!($oc_chapter = $this->get_chapter_for_lection($selected_week))) {
         echo $selected_week . "Fehler beim Laden des Kapitels";
         return;
     }
     if (!has_capability('moodle/course:update', $this->context) and $oc_chapter['enabled'] == 'false') {
         echo '<div class="inactive-chapter">' . $oc_chapter['name'] . ' - Dieses Kapitel ist noch nicht freigegeben!</div>';
         return;
     }
     if (!has_capability('moodle/course:update', $this->context) and $oc_chapter['enabled'] == 'hidden') {
         echo '<div class="inactive-chapter">' . $oc_chapter['name'] . ' - Du besitzt nicht die Rechte um dieses Kapitel zu sehen!</div>';
         return;
     }
     // oncampus ende
     if (!isset($initialised)) {
         $groupbuttons = ($course->groupmode or !$course->groupmodeforce);
         $groupbuttonslink = !$course->groupmodeforce;
         $isediting = $PAGE->user_is_editing();
         $ismoving = $isediting && ismoving($course->id);
         if ($ismoving) {
             $strmovehere = get_string("movehere");
             $strmovefull = strip_tags(get_string("movefull", "", "'{$USER->activitycopyname}'"));
         }
         $modulenames = array();
         $initialised = true;
     }
     $modinfo = get_fast_modinfo($course);
     $completioninfo = new completion_info($course);
     //Accessibility: replace table with list <ul>, but don't output empty list.
     if (!empty($section->sequence)) {
         // Fix bug #5027, don't want style=\"width:$width\".
         echo "<ul class=\"section img-text\">\n";
         $sectionmods = explode(",", $section->sequence);
         foreach ($sectionmods as $modnumber) {
             if (empty($mods[$modnumber])) {
                 continue;
             }
             /**
              * @var cm_info
              */
             $mod = $mods[$modnumber];
             if ($ismoving and $mod->id == $USER->activitycopy) {
                 // do not display moving mod
                 continue;
             }
             if (isset($modinfo->cms[$modnumber])) {
                 // We can continue (because it will not be displayed at all)
                 // if:
                 // 1) The activity is not visible to users
                 // and
                 // 2a) The 'showavailability' option is not set (if that is set,
                 //     we need to display the activity so we can show
                 //     availability info)
                 // or
                 // 2b) The 'availableinfo' is empty, i.e. the activity was
                 //     hidden in a way that leaves no info, such as using the
                 //     eye icon.
                 if (!$modinfo->cms[$modnumber]->uservisible && (empty($modinfo->cms[$modnumber]->showavailability) || empty($modinfo->cms[$modnumber]->availableinfo))) {
                     // visibility shortcut
                     continue;
                 }
             } else {
                 if (!file_exists("{$CFG->dirroot}/mod/{$mod->modname}/lib.php")) {
                     // module not installed
                     continue;
                 }
                 if (!coursemodule_visible_for_user($mod) && empty($mod->showavailability)) {
                     // full visibility check
                     continue;
                 }
             }
             if (!isset($modulenames[$mod->modname])) {
                 $modulenames[$mod->modname] = get_string('modulename', $mod->modname);
             }
             $modulename = $modulenames[$mod->modname];
             // In some cases the activity is visible to user, but it is
             // dimmed. This is done if viewhiddenactivities is true and if:
             // 1. the activity is not visible, or
             // 2. the activity has dates set which do not include current, or
             // 3. the activity has any other conditions set (regardless of whether
             //    current user meets them)
             $canviewhidden = has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $mod->id));
             $accessiblebutdim = false;
             if ($canviewhidden) {
                 $accessiblebutdim = !$mod->visible;
                 if (!empty($CFG->enableavailability)) {
                     $accessiblebutdim = $accessiblebutdim || $mod->availablefrom > time() || $mod->availableuntil && $mod->availableuntil < time() || count($mod->conditionsgrade) > 0 || count($mod->conditionscompletion) > 0;
                 }
             }
             $liclasses = array();
             $liclasses[] = 'activity';
             $liclasses[] = $mod->modname;
             $liclasses[] = 'modtype_' . $mod->modname;
             $extraclasses = $mod->get_extra_classes();
             if ($extraclasses) {
                 $liclasses = array_merge($liclasses, explode(' ', $extraclasses));
             }
             echo html_writer::start_tag('li', array('class' => join(' ', $liclasses), 'id' => 'module-' . $modnumber));
             if ($ismoving) {
                 echo '<a title="' . $strmovefull . '"' . ' href="' . $CFG->wwwroot . '/course/mod.php?moveto=' . $mod->id . '&amp;sesskey=' . sesskey() . '">' . '<img class="movetarget" src="' . $OUTPUT->pix_url('movehere') . '" ' . ' alt="' . $strmovehere . '" /></a><br />
                  ';
             }
             $classes = array('mod-indent');
             if (!empty($mod->indent)) {
                 $classes[] = 'mod-indent-' . $mod->indent;
                 if ($mod->indent > 15) {
                     $classes[] = 'mod-indent-huge';
                 }
             }
             echo html_writer::start_tag('div', array('class' => join(' ', $classes)));
             // Get data about this course-module
             list($content, $instancename) = array($modinfo->cms[$modnumber]->get_formatted_content(array('overflowdiv' => true, 'noclean' => true)), $modinfo->cms[$modnumber]->get_formatted_name());
             //=get_print_section_cm_text($modinfo->cms[$modnumber], $course);
             //Accessibility: for files get description via icon, this is very ugly hack!
             $altname = '';
             $altname = $mod->modfullname;
             if (!empty($customicon)) {
                 $archetype = plugin_supports('mod', $mod->modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
                 if ($archetype == MOD_ARCHETYPE_RESOURCE) {
                     $mimetype = mimeinfo_from_icon('type', $customicon);
                     $altname = get_mimetype_description($mimetype);
                 }
             }
             // Avoid unnecessary duplication: if e.g. a forum name already
             // includes the word forum (or Forum, etc) then it is unhelpful
             // to include that in the accessible description that is added.
             if (false !== strpos(textlib::strtolower($instancename), textlib::strtolower($altname))) {
                 $altname = '';
             }
             // File type after name, for alphabetic lists (screen reader).
             if ($altname) {
                 $altname = get_accesshide(' ' . $altname);
             }
             // We may be displaying this just in order to show information
             // about visibility, without the actual link
             $contentpart = '';
             if ($mod->uservisible) {
                 // Nope - in this case the link is fully working for user
                 $linkclasses = '';
                 $textclasses = '';
                 if ($accessiblebutdim) {
                     $linkclasses .= ' dimmed';
                     $textclasses .= ' dimmed_text';
                     $accesstext = '<span class="accesshide">' . get_string('hiddenfromstudents') . ': </span>';
                 } else {
                     $accesstext = '';
                 }
                 if ($linkclasses) {
                     $linkcss = 'class="' . trim($linkclasses) . '" ';
                 } else {
                     $linkcss = '';
                 }
                 if ($textclasses) {
                     $textcss = 'class="' . trim($textclasses) . '" ';
                 } else {
                     $textcss = '';
                 }
                 // Get on-click attribute value if specified
                 $onclick = $mod->get_on_click();
                 if ($onclick) {
                     $onclick = ' onclick="' . $onclick . '"';
                 }
                 if ($url = $mod->get_url()) {
                     // Display link itself
                     echo '<a ' . $linkcss . $mod->extra . $onclick . ' href="' . $url . '"><img src="' . $mod->get_icon_url() . '" class="activityicon" alt="' . $modulename . '" /> ' . $accesstext . '<span class="instancename">' . $instancename . $altname . '</span></a>';
                     // If specified, display extra content after link
                     if ($content) {
                         $contentpart = '<div class="contentafterlink' . trim($textclasses) . '">' . $content . '</div>';
                     }
                 } else {
                     // No link, so display only content
                     $contentpart = '<div ' . $textcss . $mod->extra . '>' . $accesstext . $content . '</div>';
                 }
                 if (!empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
                     if (!isset($groupings)) {
                         $groupings = groups_get_all_groupings($course->id);
                     }
                     echo " <span class=\"groupinglabel\">(" . format_string($groupings[$mod->groupingid]->name) . ')</span>';
                 }
             } else {
                 $textclasses = $extraclasses;
                 $textclasses .= ' dimmed_text';
                 if ($textclasses) {
                     $textcss = 'class="' . trim($textclasses) . '" ';
                 } else {
                     $textcss = '';
                 }
                 $accesstext = '<span class="accesshide">' . get_string('notavailableyet', 'condition') . ': </span>';
                 if ($url = $mod->get_url()) {
                     // Display greyed-out text of link
                     echo '<div ' . $textcss . $mod->extra . ' >' . '<img src="' . $mod->get_icon_url() . '" class="activityicon" alt="' . $modulename . '" /> <span>' . $instancename . $altname . '</span></div>';
                     // Do not display content after link when it is greyed out like this.
                 } else {
                     // No link, so display only content (also greyed)
                     $contentpart = '<div ' . $textcss . $mod->extra . '>' . $accesstext . $content . '</div>';
                 }
             }
             // Module can put text after the link (e.g. forum unread)
             echo $mod->get_after_link();
             // If there is content but NO link (eg label), then display the
             // content here (BEFORE any icons). In this case cons must be
             // displayed after the content so that it makes more sense visually
             // and for accessibility reasons, e.g. if you have a one-line label
             // it should work similarly (at least in terms of ordering) to an
             // activity.
             if (empty($url)) {
                 echo $contentpart;
             }
             if ($isediting) {
                 if ($groupbuttons and plugin_supports('mod', $mod->modname, FEATURE_GROUPS, 0)) {
                     if (!($mod->groupmodelink = $groupbuttonslink)) {
                         $mod->groupmode = $course->groupmode;
                     }
                 } else {
                     $mod->groupmode = false;
                 }
                 echo '&nbsp;&nbsp;';
                 //echo make_editing_buttons($mod, $absolute, true, $mod->indent, $section->section);
                 if (!$mod instanceof cm_info) {
                     $modinfo = get_fast_modinfo($mod->course);
                     $mod = $modinfo->get_cm($mod->id);
                 }
                 $actions = course_get_cm_edit_actions($mod, $mod->indent, $section->section);
                 $courserenderer = $PAGE->get_renderer('core', 'course');
                 // The space added before the <span> is a ugly hack but required to set the CSS property white-space: nowrap
                 // and having it to work without attaching the preceding text along with it. Hopefully the refactoring of
                 // the course page HTML will allow this to be removed.
                 echo ' ' . $courserenderer->course_section_cm_edit_actions($actions);
                 echo $mod->get_after_edit_icons();
             }
             // Completion
             require_once 'modulelib.php';
             $completion = $hidecompletion ? COMPLETION_TRACKING_NONE : $completioninfo->is_enabled($mod);
             if ($completion != COMPLETION_TRACKING_NONE && isloggedin() && !isguestuser() && $mod->uservisible) {
                 $completiondata = $completioninfo->get_data($mod, true);
                 $completionicon = '';
                 if ($isediting) {
                     switch ($completion) {
                         case COMPLETION_TRACKING_MANUAL:
                             $completionicon = 'manual-enabled';
                             break;
                         case COMPLETION_TRACKING_AUTOMATIC:
                             $completionicon = 'auto-enabled';
                             break;
                         default:
                             // wtf
                     }
                 } else {
                     if (is_siteadmin() || !has_capability('mod/assignment:submit', get_context_instance(CONTEXT_COURSE, $course->id))) {
                         switch ($completion) {
                             case COMPLETION_TRACKING_MANUAL:
                                 $completionicon = 'manual-enabled';
                                 break;
                             case COMPLETION_TRACKING_AUTOMATIC:
                                 $completionicon = 'auto-enabled';
                                 break;
                             default:
                                 // wtf
                         }
                     } else {
                         if ($completion == COMPLETION_TRACKING_MANUAL) {
                             switch ($completiondata->completionstate) {
                                 case COMPLETION_INCOMPLETE:
                                     $completionicon = 'manual-n';
                                     break;
                                 case COMPLETION_COMPLETE:
                                     $completionicon = 'manual-y';
                                     break;
                             }
                         } else {
                             // Automatic
                             if (($mod->modname == 'assignment' || $mod->modname == 'assign') && isset($mod->completiongradeitemnumber)) {
                                 $act_compl = is_saved_or_submitted($mod, $USER->id, $resubmission);
                                 if ($act_compl == 'submitted') {
                                     // $completiondata->completionstate = COMPLETION_WAITFORGRADE_FN;
                                 } else {
                                     if ($act_compl == 'waitinggrade') {
                                         $completiondata->completionstate = COMPLETION_WAITFORGRADE_FN;
                                     } else {
                                         if ($act_compl == 'saved') {
                                             $completiondata->completionstate = COMPLETION_SAVED_FN;
                                         }
                                     }
                                 }
                             }
                             switch ($completiondata->completionstate) {
                                 case COMPLETION_INCOMPLETE:
                                     $completionicon = 'auto-n';
                                     break;
                                 case COMPLETION_COMPLETE:
                                     $completionicon = 'auto-y';
                                     break;
                                 case COMPLETION_COMPLETE_PASS:
                                     $completionicon = 'auto-pass';
                                     break;
                                 case COMPLETION_COMPLETE_FAIL:
                                     $completionicon = 'auto-fail';
                                     break;
                                 case COMPLETION_WAITFORGRADE_FN:
                                     $completionicon = 'submitted';
                                     break;
                                 case COMPLETION_SAVED_FN:
                                     $completionicon = 'saved';
                                     break;
                             }
                         }
                     }
                 }
                 if ($completionicon) {
                     $imgsrc = '' . $CFG->wwwroot . '/course/format/' . $this->course->format . '/pix/completion-' . $completionicon . '.gif';
                     $imgalt = s(get_string('completion-alt-' . $completionicon, 'format_octabs'));
                     if ($completion == COMPLETION_TRACKING_MANUAL && !$isediting && has_capability('mod/assignment:submit', get_context_instance(CONTEXT_COURSE, $course->id)) && !is_primary_admin($USER->id)) {
                         $imgtitle = s(get_string('completion-title-' . $completionicon, 'format_octabs'));
                         $newstate = $completiondata->completionstate == COMPLETION_COMPLETE ? COMPLETION_INCOMPLETE : COMPLETION_COMPLETE;
                         // In manual mode the icon is a toggle form...
                         // If this completion state is used by the
                         // conditional activities system, we need to turn
                         // off the JS.i
                         /* oncampus 
                         			if (!empty($CFG->enableavailability) &&
                                                         condition_info::completion_value_used_as_condition($course, $mod)) {
                                                     $extraclass = ' preventjs';
                                                 } else {
                                                     $extraclass = '';
                                                 }
                                                 echo "
                                                         <form class='togglecompletion$extraclass' method='post' action='" . $CFG->wwwroot . "/course/togglecompletion.php'><div>
                                                         <input type='hidden' name='id' value='{$mod->id}' />
                                                         <input type='hidden' name='sesskey' value='" . sesskey() . "' />
                                                         <input type='hidden' name='completionstate' value='$newstate' />
                                                         <input type='image' src='$imgsrc' alt='$imgalt' title='$imgtitle' />
                                                         </div></form>"; 
                         			*/
                     } else {
                         // In auto mode, or when editing, the icon is just an image
                         /* echo "<span class='autocompletion'>";
                            echo "<img src='$imgsrc' alt='$imgalt' title='$imgalt' /></span>"; */
                     }
                 }
             }
             // If there is content AND a link, then display the content here
             // (AFTER any icons). Otherwise it was displayed before
             if (!empty($url)) {
                 echo $contentpart;
             }
             // Show availability information (for someone who isn't allowed to
             // see the activity itself, or for staff)
             if (!$mod->uservisible) {
                 echo '<div class="availabilityinfo">' . $mod->availableinfo . '</div>';
             } else {
                 if ($canviewhidden && !empty($CFG->enableavailability)) {
                     $ci = new condition_info($mod);
                     $fullinfo = $ci->get_full_information();
                     if ($fullinfo) {
                         echo '<div class="availabilityinfo">' . get_string($mod->showavailability ? 'userrestriction_visible' : 'userrestriction_hidden', 'condition', $fullinfo) . '</div>';
                     }
                 }
             }
             echo html_writer::end_tag('div');
             echo html_writer::end_tag('li') . "\n";
         }
     } elseif ($ismoving) {
         echo "<ul class=\"section\">\n";
     }
     if ($ismoving) {
         echo '<li><a title="' . $strmovefull . '"' . ' href="' . $CFG->wwwroot . '/course/mod.php?movetosection=' . $section->id . '&amp;sesskey=' . sesskey() . '">' . '<img class="movetarget" src="' . $OUTPUT->pix_url('movehere') . '" ' . ' alt="' . $strmovehere . '" /></a></li>
          ';
     }
     if (!empty($section->sequence) || $ismoving) {
         echo "</ul><!--class='section'-->\n\n";
     }
 }