329
329
* @see course_get_cm_edit_actions()
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.
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()) {
345
if (empty($actions)) {
349
if (isset($displayoptions['ownerselector'])) {
350
$ownerselector = $displayoptions['ownerselector'];
352
$ownerselector = '#module-'.$mod->id;
354
debugging('You should upgrade your call to '.__FUNCTION__.' and provide $mod', DEBUG_DEVELOPER);
355
$ownerselector = 'li.activity';
358
if (isset($displayoptions['constraintselector'])) {
359
$constraint = $displayoptions['constraintselector'];
361
$constraint = '.course-content';
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();
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.
377
foreach ($actions as $key => $value) {
378
if ($key === 'moveright') {
380
// Save moveright for later.
382
} else if ($moveright) {
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;
389
// Clear the value to prevent it being used multiple times.
393
$_actions[$key] = $value;
396
$actions = $_actions;
336
399
foreach ($actions as $action) {
337
if ($action instanceof renderable) {
338
$output .= $this->output->render($action);
400
if ($action instanceof action_menu_link) {
401
$action->add_class('cm-edit-action');
343
$output .= html_writer::end_tag('span');
405
$menu->attributes['class'] .= ' section-cm-edit-actions commands';
407
// Prioritise the menu ahead of all other actions.
408
$menu->prioritise = true;
410
return $this->render($menu);
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()) {
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);
584
660
$completiondata->completionstate == COMPLETION_COMPLETE
614
690
$output .= html_writer::end_tag('div');
615
691
$output .= html_writer::end_tag('form');
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))) {
685
761
// File type after name, for alphabetic lists (screen reader).
911
* Renders HTML to display one course module for display within a section.
913
* This function calls:
914
* {@link core_course_renderer::course_section_cm()}
916
* @param stdClass $course
917
* @param completion_info $completioninfo
918
* @param cm_info $mod
919
* @param int|null $sectionreturn
920
* @param array $displayoptions
923
public function course_section_cm_list_item($course, &$completioninfo, cm_info $mod, $sectionreturn, $displayoptions = array()) {
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));
834
933
* Renders HTML to display one course module in a course section
836
935
* This includes link, content, availability, completion info and additional information
877
976
$indentclasses .= ' mod-indent-huge';
880
$output .= html_writer::start_tag('div', array('class' => $indentclasses));
882
// Start the div for the activity title, excluding the edit icons.
883
$output .= html_writer::start_tag('div', array('class' => 'activityinstance'));
980
$output .= html_writer::start_tag('div');
982
if ($this->page->user_is_editing()) {
983
$output .= course_get_cm_move($mod, $sectionreturn);
986
$output .= html_writer::start_tag('div', array('class' => 'mod-indent-outer'));
988
// This div is used to indent the content.
989
$output .= html_writer::div('', $indentclasses);
991
// Start a wrapper for the actual content to keep the indentation consistent
992
$output .= html_writer::start_tag('div');
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);
888
// Module can put text after the link (e.g. forum unread)
889
$output .= $mod->get_after_link();
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);
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'));
1003
if ($this->page->user_is_editing()) {
1004
$output .= ' ' . course_get_cm_rename_action($mod, $sectionreturn);
1007
// Module can put text after the link (e.g. forum unread)
1008
$output .= $mod->get_after_link();
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
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;
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();
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();
1033
$modicons .= $this->course_section_cm_completion($course, $completioninfo, $mod, $displayoptions);
1035
if (!empty($modicons)) {
1036
$output .= html_writer::span($modicons, 'actions');
914
1039
// If there is content AND a link, then display the content here
915
1040
// (AFTER any icons). Otherwise it was displayed before
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;
1106
$sectionoutput = '';
976
1107
if (!empty($moduleshtml) || $ismoving) {
978
$output .= html_writer::start_tag('ul', array('class' => 'section img-text'));
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));
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;
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));
1000
$output .= html_writer::end_tag('ul'); // .section
1125
// Always output the section module list.
1126
$output .= html_writer::tag('ul', $sectionoutput, array('class' => 'section img-text'));
1003
1128
return $output;
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'));
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) {
1463
1586
$classes[] = 'with_children';
1464
1587
$classes[] = 'collapsed';
1466
// Make sure JS file to expand category content is included.
1467
$this->coursecat_include_js();
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';
1598
// Make sure JS file to expand category content is included.
1599
$this->coursecat_include_js();
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'));
1495
1619
$content .= html_writer::start_tag('div', array('class' => 'info'));
1496
$content .= html_writer::tag(($depth > 1) ? 'h4' : 'h3', $categoryname, array('class' => 'name'));
1621
$content .= html_writer::tag(($depth > 1) ? 'h4' : 'h3', $categoryname, array('class' => 'categoryname'));
1497
1622
$content .= html_writer::end_tag('div'); // .info
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);
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');
2098
return $this->add_new_course_button();
1980
2100
return $this->coursecat_courses($chelper, $courses, $totalcount);
2104
* Returns HTML to the "add new course" button for the page
2108
public function add_new_course_button() {
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');
1984
2119
* Returns HTML to print tree with course categories and courses for the frontpage
1986
2121
* @return string