/** * 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 cm_info::get_after_link()} * {@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 // 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 (!$mod->uservisible && (empty($mod->showavailability) || 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; if ($this->page->user_is_editing()) { $output .= ' ' . course_get_cm_rename_action($mod, $sectionreturn); } // Module can put text after the link (e.g. forum unread) $output .= $mod->get_after_link(); // 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->get_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->get_after_edit_icons(); } $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; }
/** * 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; }