~ubuntu-branches/ubuntu/utopic/moodle/utopic

« back to all changes in this revision

Viewing changes to course/renderer.php

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2014-05-12 16:10:38 UTC
  • mfrom: (36.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20140512161038-puyqf65k4e0s8ytz
Tags: 2.6.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
328
328
     *
329
329
     * @see course_get_cm_edit_actions()
330
330
     *
331
 
     * @param array $actions array of action_link or pix_icon objects
 
331
     * @param action_link[] $actions Array of action_link objects
 
332
     * @param cm_info $mod The module we are displaying actions for.
 
333
     * @param array $displayoptions additional display options:
 
334
     *     ownerselector => A JS/CSS selector that can be used to find an cm node.
 
335
     *         If specified the owning node will be given the class 'action-menu-shown' when the action
 
336
     *         menu is being displayed.
 
337
     *     constraintselector => A JS/CSS selector that can be used to find the parent node for which to constrain
 
338
     *         the action menu to when it is being displayed.
 
339
     *     donotenhance => If set to true the action menu that gets displayed won't be enhanced by JS.
332
340
     * @return string
333
341
     */
334
 
    public function course_section_cm_edit_actions($actions) {
335
 
        $output = html_writer::start_tag('span', array('class' => 'commands'));
 
342
    public function course_section_cm_edit_actions($actions, cm_info $mod = null, $displayoptions = array()) {
 
343
        global $CFG;
 
344
 
 
345
        if (empty($actions)) {
 
346
            return '';
 
347
        }
 
348
 
 
349
        if (isset($displayoptions['ownerselector'])) {
 
350
            $ownerselector = $displayoptions['ownerselector'];
 
351
        } else if ($mod) {
 
352
            $ownerselector = '#module-'.$mod->id;
 
353
        } else {
 
354
            debugging('You should upgrade your call to '.__FUNCTION__.' and provide $mod', DEBUG_DEVELOPER);
 
355
            $ownerselector = 'li.activity';
 
356
        }
 
357
 
 
358
        if (isset($displayoptions['constraintselector'])) {
 
359
            $constraint = $displayoptions['constraintselector'];
 
360
        } else {
 
361
            $constraint = '.course-content';
 
362
        }
 
363
 
 
364
        $menu = new action_menu();
 
365
        $menu->set_owner_selector($ownerselector);
 
366
        $menu->set_constraint($constraint);
 
367
        $menu->set_alignment(action_menu::TR, action_menu::BR);
 
368
        $menu->set_menu_trigger(get_string('edit'));
 
369
        if (isset($CFG->modeditingmenu) && !$CFG->modeditingmenu || !empty($displayoptions['donotenhance'])) {
 
370
            $menu->do_not_enhance();
 
371
 
 
372
            // Swap the left/right icons.
 
373
            // Normally we have have right, then left but this does not
 
374
            // make sense when modactionmenu is disabled.
 
375
            $moveright = null;
 
376
            $_actions = array();
 
377
            foreach ($actions as $key => $value) {
 
378
                if ($key === 'moveright') {
 
379
 
 
380
                    // Save moveright for later.
 
381
                    $moveright = $value;
 
382
                } else if ($moveright) {
 
383
 
 
384
                    // This assumes that the order was moveright, moveleft.
 
385
                    // If we have a moveright, then we should place it immediately after the current value.
 
386
                    $_actions[$key] = $value;
 
387
                    $_actions['moveright'] = $moveright;
 
388
 
 
389
                    // Clear the value to prevent it being used multiple times.
 
390
                    $moveright = null;
 
391
                } else {
 
392
 
 
393
                    $_actions[$key] = $value;
 
394
                }
 
395
            }
 
396
            $actions = $_actions;
 
397
            unset($_actions);
 
398
        }
336
399
        foreach ($actions as $action) {
337
 
            if ($action instanceof renderable) {
338
 
                $output .= $this->output->render($action);
339
 
            } else {
340
 
                $output .= $action;
 
400
            if ($action instanceof action_menu_link) {
 
401
                $action->add_class('cm-edit-action');
341
402
            }
 
403
            $menu->add($action);
342
404
        }
343
 
        $output .= html_writer::end_tag('span');
344
 
        return $output;
 
405
        $menu->attributes['class'] .= ' section-cm-edit-actions commands';
 
406
 
 
407
        // Prioritise the menu ahead of all other actions.
 
408
        $menu->prioritise = true;
 
409
 
 
410
        return $this->render($menu);
345
411
    }
346
412
 
347
413
    /**
543
609
        }
544
610
        $completion = $completioninfo->is_enabled($mod);
545
611
        if ($completion == COMPLETION_TRACKING_NONE) {
 
612
            if ($this->page->user_is_editing()) {
 
613
                $output .= html_writer::span(' ', 'filler');
 
614
            }
546
615
            return $output;
547
616
        }
548
617
 
578
647
        if ($completionicon) {
579
648
            $formattedname = $mod->get_formatted_name();
580
649
            $imgalt = get_string('completion-alt-' . $completionicon, 'completion', $formattedname);
581
 
            if ($completion == COMPLETION_TRACKING_MANUAL && !$this->page->user_is_editing()) {
 
650
 
 
651
            if ($this->page->user_is_editing()) {
 
652
                // When editing, the icon is just an image.
 
653
                $completionpixicon = new pix_icon('i/completion-'.$completionicon, $imgalt, '',
 
654
                        array('title' => $imgalt, 'class' => 'iconsmall'));
 
655
                $output .= html_writer::tag('span', $this->output->render($completionpixicon),
 
656
                        array('class' => 'autocompletion'));
 
657
            } else if ($completion == COMPLETION_TRACKING_MANUAL) {
582
658
                $imgtitle = get_string('completion-title-' . $completionicon, 'completion', $formattedname);
583
659
                $newstate =
584
660
                    $completiondata->completionstate == COMPLETION_COMPLETE
614
690
                $output .= html_writer::end_tag('div');
615
691
                $output .= html_writer::end_tag('form');
616
692
            } else {
617
 
                // In auto mode, or when editing, the icon is just an image
 
693
                // In auto mode, the icon is just an image.
618
694
                $completionpixicon = new pix_icon('i/completion-'.$completionicon, $imgalt, '',
619
695
                        array('title' => $imgalt));
620
696
                $output .= html_writer::tag('span', $this->output->render($completionpixicon),
678
754
        // Avoid unnecessary duplication: if e.g. a forum name already
679
755
        // includes the word forum (or Forum, etc) then it is unhelpful
680
756
        // to include that in the accessible description that is added.
681
 
        if (false !== strpos(textlib::strtolower($instancename),
682
 
                textlib::strtolower($altname))) {
 
757
        if (false !== strpos(core_text::strtolower($instancename),
 
758
                core_text::strtolower($altname))) {
683
759
            $altname = '';
684
760
        }
685
761
        // File type after name, for alphabetic lists (screen reader).
783
859
            }
784
860
        } else {
785
861
            // No link, so display only content.
786
 
            $output = html_writer::tag('div', $accesstext . $content, array('class' => $textclasses));
 
862
            $output = html_writer::tag('div', $accesstext . $content,
 
863
                    array('class' => 'contentwithoutlink ' . $textclasses));
787
864
        }
788
865
        return $output;
789
866
    }
831
908
    }
832
909
 
833
910
    /**
 
911
     * Renders HTML to display one course module for display within a section.
 
912
     *
 
913
     * This function calls:
 
914
     * {@link core_course_renderer::course_section_cm()}
 
915
     *
 
916
     * @param stdClass $course
 
917
     * @param completion_info $completioninfo
 
918
     * @param cm_info $mod
 
919
     * @param int|null $sectionreturn
 
920
     * @param array $displayoptions
 
921
     * @return String
 
922
     */
 
923
    public function course_section_cm_list_item($course, &$completioninfo, cm_info $mod, $sectionreturn, $displayoptions = array()) {
 
924
        $output = '';
 
925
        if ($modulehtml = $this->course_section_cm($course, $completioninfo, $mod, $sectionreturn, $displayoptions)) {
 
926
            $modclasses = 'activity ' . $mod->modname . ' modtype_' . $mod->modname . ' ' . $mod->get_extra_classes();
 
927
            $output .= html_writer::tag('li', $modulehtml, array('class' => $modclasses, 'id' => 'module-' . $mod->id));
 
928
        }
 
929
        return $output;
 
930
    }
 
931
 
 
932
    /**
834
933
     * Renders HTML to display one course module in a course section
835
934
     *
836
935
     * This includes link, content, availability, completion info and additional information
877
976
                $indentclasses .= ' mod-indent-huge';
878
977
            }
879
978
        }
880
 
        $output .= html_writer::start_tag('div', array('class' => $indentclasses));
881
 
 
882
 
        // Start the div for the activity title, excluding the edit icons.
883
 
        $output .= html_writer::start_tag('div', array('class' => 'activityinstance'));
 
979
 
 
980
        $output .= html_writer::start_tag('div');
 
981
 
 
982
        if ($this->page->user_is_editing()) {
 
983
            $output .= course_get_cm_move($mod, $sectionreturn);
 
984
        }
 
985
 
 
986
        $output .= html_writer::start_tag('div', array('class' => 'mod-indent-outer'));
 
987
 
 
988
        // This div is used to indent the content.
 
989
        $output .= html_writer::div('', $indentclasses);
 
990
 
 
991
        // Start a wrapper for the actual content to keep the indentation consistent
 
992
        $output .= html_writer::start_tag('div');
884
993
 
885
994
        // Display the link to the module (or do nothing if module has no url)
886
 
        $output .= $this->course_section_cm_name($mod, $displayoptions);
887
 
 
888
 
        // Module can put text after the link (e.g. forum unread)
889
 
        $output .= $mod->get_after_link();
890
 
 
891
 
        // Closing the tag which contains everything but edit icons. Content part of the module should not be part of this.
892
 
        $output .= html_writer::end_tag('div'); // .activityinstance
 
995
        $cmname = $this->course_section_cm_name($mod, $displayoptions);
 
996
 
 
997
        if (!empty($cmname)) {
 
998
            // Start the div for the activity title, excluding the edit icons.
 
999
            $output .= html_writer::start_tag('div', array('class' => 'activityinstance'));
 
1000
            $output .= $cmname;
 
1001
 
 
1002
 
 
1003
            if ($this->page->user_is_editing()) {
 
1004
                $output .= ' ' . course_get_cm_rename_action($mod, $sectionreturn);
 
1005
            }
 
1006
 
 
1007
            // Module can put text after the link (e.g. forum unread)
 
1008
            $output .= $mod->get_after_link();
 
1009
 
 
1010
            // Closing the tag which contains everything but edit icons. Content part of the module should not be part of this.
 
1011
            $output .= html_writer::end_tag('div'); // .activityinstance
 
1012
        }
893
1013
 
894
1014
        // If there is content but NO link (eg label), then display the
895
1015
        // content here (BEFORE any icons). In this case cons must be
903
1023
            $output .= $contentpart;
904
1024
        }
905
1025
 
 
1026
        $modicons = '';
906
1027
        if ($this->page->user_is_editing()) {
907
1028
            $editactions = course_get_cm_edit_actions($mod, $mod->indent, $sectionreturn);
908
 
            $output .= ' '. $this->course_section_cm_edit_actions($editactions);
909
 
            $output .= $mod->get_after_edit_icons();
910
 
        }
911
 
 
912
 
        $output .= $this->course_section_cm_completion($course, $completioninfo, $mod, $displayoptions);
 
1029
            $modicons .= ' '. $this->course_section_cm_edit_actions($editactions, $mod, $displayoptions);
 
1030
            $modicons .= $mod->get_after_edit_icons();
 
1031
        }
 
1032
 
 
1033
        $modicons .= $this->course_section_cm_completion($course, $completioninfo, $mod, $displayoptions);
 
1034
 
 
1035
        if (!empty($modicons)) {
 
1036
            $output .= html_writer::span($modicons, 'actions');
 
1037
        }
913
1038
 
914
1039
        // If there is content AND a link, then display the content here
915
1040
        // (AFTER any icons). Otherwise it was displayed before
921
1046
        $output .= $this->course_section_cm_availability($mod, $displayoptions);
922
1047
 
923
1048
        $output .= html_writer::end_tag('div'); // $indentclasses
 
1049
 
 
1050
        // End of indentation div.
 
1051
        $output .= html_writer::end_tag('div');
 
1052
 
 
1053
        $output .= html_writer::end_tag('div');
924
1054
        return $output;
925
1055
    }
926
1056
 
966
1096
                    continue;
967
1097
                }
968
1098
 
969
 
                if ($modulehtml = $this->course_section_cm($course,
 
1099
                if ($modulehtml = $this->course_section_cm_list_item($course,
970
1100
                        $completioninfo, $mod, $sectionreturn, $displayoptions)) {
971
1101
                    $moduleshtml[$modnumber] = $modulehtml;
972
1102
                }
973
1103
            }
974
1104
        }
975
1105
 
 
1106
        $sectionoutput = '';
976
1107
        if (!empty($moduleshtml) || $ismoving) {
977
 
 
978
 
            $output .= html_writer::start_tag('ul', array('class' => 'section img-text'));
979
 
 
980
1108
            foreach ($moduleshtml as $modnumber => $modulehtml) {
981
1109
                if ($ismoving) {
982
1110
                    $movingurl = new moodle_url('/course/mod.php', array('moveto' => $modnumber, 'sesskey' => sesskey()));
983
 
                    $output .= html_writer::tag('li', html_writer::link($movingurl, $this->output->render($movingpix)),
 
1111
                    $sectionoutput .= html_writer::tag('li', html_writer::link($movingurl, $this->output->render($movingpix)),
984
1112
                            array('class' => 'movehere', 'title' => $strmovefull));
985
1113
                }
986
1114
 
987
 
                $mod = $modinfo->cms[$modnumber];
988
 
                $modclasses = 'activity '. $mod->modname. ' modtype_'.$mod->modname. ' '. $mod->get_extra_classes();
989
 
                $output .= html_writer::start_tag('li', array('class' => $modclasses, 'id' => 'module-'. $mod->id));
990
 
                $output .= $modulehtml;
991
 
                $output .= html_writer::end_tag('li');
 
1115
                $sectionoutput .= $modulehtml;
992
1116
            }
993
1117
 
994
1118
            if ($ismoving) {
995
1119
                $movingurl = new moodle_url('/course/mod.php', array('movetosection' => $section->id, 'sesskey' => sesskey()));
996
 
                $output .= html_writer::tag('li', html_writer::link($movingurl, $this->output->render($movingpix)),
 
1120
                $sectionoutput .= html_writer::tag('li', html_writer::link($movingurl, $this->output->render($movingpix)),
997
1121
                        array('class' => 'movehere', 'title' => $strmovefull));
998
1122
            }
999
 
 
1000
 
            $output .= html_writer::end_tag('ul'); // .section
1001
1123
        }
1002
1124
 
 
1125
        // Always output the section module list.
 
1126
        $output .= html_writer::tag('ul', $sectionoutput, array('class' => 'section img-text'));
 
1127
 
1003
1128
        return $output;
1004
1129
    }
1005
1130
 
1079
1204
        $classes = trim('coursebox clearfix '. $additionalclasses);
1080
1205
        if ($chelper->get_show_courses() >= self::COURSECAT_SHOW_COURSES_EXPANDED) {
1081
1206
            $nametag = 'h3';
1082
 
            $classes .= ' expanded';
1083
1207
        } else {
1084
1208
            $classes .= ' collapsed';
1085
1209
            $nametag = 'div';
1097
1221
        // course name
1098
1222
        $coursename = $chelper->get_course_formatted_name($course);
1099
1223
        $coursenamelink = html_writer::link(new moodle_url('/course/view.php', array('id' => $course->id)),
1100
 
                $coursename, array('class' => $course->visible ? '' : 'dimmed'));
1101
 
        $content .= html_writer::tag($nametag, $coursenamelink, array('class' => 'name'));
1102
 
 
 
1224
                                            $coursename, array('class' => $course->visible ? '' : 'dimmed'));
 
1225
        $content .= html_writer::tag($nametag, $coursenamelink, array('class' => 'coursename'));
1103
1226
        // If we display course in collapsed form but the course has summary or course contacts, display the link to the info page.
1104
1227
        $content .= html_writer::start_tag('div', array('class' => 'moreinfo'));
1105
1228
        if ($chelper->get_show_courses() < self::COURSECAT_SHOW_COURSES_EXPANDED) {
1383
1506
    protected function coursecat_include_js() {
1384
1507
        global $CFG;
1385
1508
        static $jsloaded = false;
1386
 
        if (!$jsloaded && $CFG->enableajax) {
 
1509
        if (!$jsloaded) {
1387
1510
            // We must only load this module once.
1388
1511
            $this->page->requires->yui_module('moodle-course-categoryexpander',
1389
1512
                    'Y.Moodle.course.categoryexpander.init');
1463
1586
                $classes[] = 'with_children';
1464
1587
                $classes[] = 'collapsed';
1465
1588
            }
1466
 
            // Make sure JS file to expand category content is included.
1467
 
            $this->coursecat_include_js();
1468
1589
        } else {
1469
1590
            // load category content
1470
1591
            $categorycontent = $this->coursecat_category_content($chelper, $coursecat, $depth);
1471
1592
            $classes[] = 'loaded';
1472
1593
            if (!empty($categorycontent)) {
1473
1594
                $classes[] = 'with_children';
1474
 
                $classes[] = 'expanded';
1475
1595
            }
1476
1596
        }
 
1597
 
 
1598
        // Make sure JS file to expand category content is included.
 
1599
        $this->coursecat_include_js();
 
1600
 
1477
1601
        $content = html_writer::start_tag('div', array(
1478
1602
            'class' => join(' ', $classes),
1479
1603
            'data-categoryid' => $coursecat->id,
1493
1617
                    array('title' => get_string('numberofcourses'), 'class' => 'numberofcourse'));
1494
1618
        }
1495
1619
        $content .= html_writer::start_tag('div', array('class' => 'info'));
1496
 
        $content .= html_writer::tag(($depth > 1) ? 'h4' : 'h3', $categoryname, array('class' => 'name'));
 
1620
 
 
1621
        $content .= html_writer::tag(($depth > 1) ? 'h4' : 'h3', $categoryname, array('class' => 'categoryname'));
1497
1622
        $content .= html_writer::end_tag('div'); // .info
1498
1623
 
1499
1624
        // add category content to the output
1564
1689
        if (!$coursecat->id) {
1565
1690
            if (can_edit_in_category()) {
1566
1691
                // add 'Manage' button instead of course search form
1567
 
                $managebutton = $this->single_button(new moodle_url('/course/manage.php'),
1568
 
                                get_string('managecourses'), 'get');
 
1692
                $managebutton = $this->single_button(new moodle_url('/course/management.php'), get_string('managecourses'), 'get');
1569
1693
                $this->page->set_button($managebutton);
1570
1694
            }
1571
1695
            if (coursecat::count_all() == 1) {
1969
2093
        $chelper->set_attributes(array('class' => 'frontpage-course-list-all'));
1970
2094
        $courses = coursecat::get(0)->get_courses($chelper->get_courses_display_options());
1971
2095
        $totalcount = coursecat::get(0)->get_courses_count($chelper->get_courses_display_options());
1972
 
        if (!$totalcount && has_capability('moodle/course:create', context_system::instance())) {
 
2096
        if (!$totalcount && !$this->page->user_is_editing() && has_capability('moodle/course:create', context_system::instance())) {
1973
2097
            // Print link to create a new course, for the 1st available category.
1974
 
            $output = $this->container_start('buttons');
1975
 
            $url = new moodle_url('/course/edit.php', array('category' => $CFG->defaultrequestcategory, 'returnto' => 'topcat'));
1976
 
            $output .= $this->single_button($url, get_string('addnewcourse'), 'get');
1977
 
            $output .= $this->container_end('buttons');
1978
 
            return $output;
 
2098
            return $this->add_new_course_button();
1979
2099
        }
1980
2100
        return $this->coursecat_courses($chelper, $courses, $totalcount);
1981
2101
    }
1982
2102
 
1983
2103
    /**
 
2104
     * Returns HTML to the "add new course" button for the page
 
2105
     *
 
2106
     * @return string
 
2107
     */
 
2108
    public function add_new_course_button() {
 
2109
        global $CFG;
 
2110
        // Print link to create a new course, for the 1st available category.
 
2111
        $output = $this->container_start('buttons');
 
2112
        $url = new moodle_url('/course/edit.php', array('category' => $CFG->defaultrequestcategory, 'returnto' => 'topcat'));
 
2113
        $output .= $this->single_button($url, get_string('addnewcourse'), 'get');
 
2114
        $output .= $this->container_end('buttons');
 
2115
        return $output;
 
2116
    }
 
2117
 
 
2118
    /**
1984
2119
     * Returns HTML to print tree with course categories and courses for the frontpage
1985
2120
     *
1986
2121
     * @return string