Exemplo n.º 1
0
/**
 * Obtains shared data that is used in print_section when displaying a
 * course-module entry.
 *
 * Calls format_text or format_string as appropriate, and obtains the correct icon.
 *
 * This data is also used in other areas of the code.
 * @param cm_info $cm Course-module data (must come from get_fast_modinfo)
 * @param object $course Moodle course object
 * @return array An array with the following values in this order:
 *   $content (optional extra content for after link),
 *   $instancename (text of link)
 */
function get_print_section_cm_text(cm_info $cm, $course)
{
    global $OUTPUT;
    // Get course context
    $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
    // Get content from modinfo if specified. Content displays either
    // in addition to the standard link (below), or replaces it if
    // the link is turned off by setting ->url to null.
    if (($content = $cm->get_content()) !== '') {
        $labelformatoptions = new stdClass();
        $labelformatoptions->noclean = true;
        $labelformatoptions->overflowdiv = true;
        $labelformatoptions->context = $coursecontext;
        $content = format_text($content, FORMAT_HTML, $labelformatoptions);
    } else {
        $content = '';
    }
    $stringoptions = new stdClass();
    $stringoptions->context = $coursecontext;
    $instancename = format_string($cm->name, true, $stringoptions);
    return array($content, $instancename);
}
Exemplo n.º 2
0
/**
 * Obtains shared data that is used in print_section when displaying a
 * course-module entry.
 *
 * Calls format_text or format_string as appropriate, and obtains the correct icon.
 *
 * This data is also used in other areas of the code.
 * @param cm_info $cm Course-module data (must come from get_fast_modinfo)
 * @param object $course Moodle course object
 * @return array An array with the following values in this order:
 *   $content (optional extra content for after link),
 *   $instancename (text of link)
 */
function get_print_section_cm_text(cm_info $cm, $course)
{
    global $OUTPUT;
    // Get content from modinfo if specified. Content displays either
    // in addition to the standard link (below), or replaces it if
    // the link is turned off by setting ->url to null.
    if (($content = $cm->get_content()) !== '') {
        // Improve filter performance by preloading filter setttings for all
        // activities on the course (this does nothing if called multiple
        // times)
        filter_preload_activities($cm->get_modinfo());
        // Get module context
        $modulecontext = get_context_instance(CONTEXT_MODULE, $cm->id);
        $labelformatoptions = new stdClass();
        $labelformatoptions->noclean = true;
        $labelformatoptions->overflowdiv = true;
        $labelformatoptions->context = $modulecontext;
        $content = format_text($content, FORMAT_HTML, $labelformatoptions);
    } else {
        $content = '';
    }
    // Get course context
    $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
    $stringoptions = new stdClass();
    $stringoptions->context = $coursecontext;
    $instancename = format_string($cm->name, true, $stringoptions);
    return array($content, $instancename);
}
Exemplo n.º 3
0
 /**
  * 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;
 }