/blocks/social_activities/block_social_activities.php

https://github.com/scriby/moodle · PHP · 146 lines · 115 code · 26 blank · 5 comment · 25 complexity · 13e1d050255675b1c821acfda6937202 MD5 · raw file

  1. <?php
  2. class block_social_activities extends block_list {
  3. function init(){
  4. $this->title = get_string('pluginname', 'block_social_activities');
  5. }
  6. function applicable_formats() {
  7. return array('course-view-social' => true);
  8. }
  9. function get_content() {
  10. global $USER, $CFG, $DB, $OUTPUT;
  11. if ($this->content !== NULL) {
  12. return $this->content;
  13. }
  14. $this->content = new stdClass();
  15. $this->content->items = array();
  16. $this->content->icons = array();
  17. $this->content->footer = '';
  18. if (empty($this->instance)) {
  19. return $this->content;
  20. }
  21. $course = $this->page->course;
  22. require_once($CFG->dirroot.'/course/lib.php');
  23. $context = context_course::instance($course->id);
  24. $isediting = $this->page->user_is_editing() && has_capability('moodle/course:manageactivities', $context);
  25. $modinfo = get_fast_modinfo($course);
  26. /// extra fast view mode
  27. if (!$isediting) {
  28. if (!empty($modinfo->sections[0])) {
  29. $options = array('overflowdiv'=>true);
  30. foreach($modinfo->sections[0] as $cmid) {
  31. $cm = $modinfo->cms[$cmid];
  32. if (!$cm->uservisible) {
  33. continue;
  34. }
  35. list($content, $instancename) =
  36. get_print_section_cm_text($cm, $course);
  37. if (!($url = $cm->get_url())) {
  38. $this->content->items[] = $content;
  39. $this->content->icons[] = '';
  40. } else {
  41. $linkcss = $cm->visible ? '' : ' class="dimmed" ';
  42. //Accessibility: incidental image - should be empty Alt text
  43. $icon = '<img src="' . $cm->get_icon_url() . '" class="icon" alt="" />&nbsp;';
  44. $this->content->items[] = '<a title="'.$cm->modplural.'" '.$linkcss.' '.$cm->extra.
  45. ' href="' . $url . '">' . $icon . $instancename . '</a>';
  46. }
  47. }
  48. }
  49. return $this->content;
  50. }
  51. /// slow & hacky editing mode
  52. $ismoving = ismoving($course->id);
  53. $modinfo = get_fast_modinfo($course);
  54. $section = $modinfo->get_section_info(0);
  55. $groupbuttons = $course->groupmode;
  56. $groupbuttonslink = (!$course->groupmodeforce);
  57. if ($ismoving) {
  58. $strmovehere = get_string('movehere');
  59. $strmovefull = strip_tags(get_string('movefull', '', "'$USER->activitycopyname'"));
  60. $strcancel= get_string('cancel');
  61. $stractivityclipboard = $USER->activitycopyname;
  62. }
  63. /// Casting $course->modinfo to string prevents one notice when the field is null
  64. $editbuttons = '';
  65. if ($ismoving) {
  66. $this->content->icons[] = '&nbsp;<img align="bottom" src="'.$OUTPUT->pix_url('t/move') . '" class="iconsmall" alt="" />';
  67. $this->content->items[] = $USER->activitycopyname.'&nbsp;(<a href="'.$CFG->wwwroot.'/course/mod.php?cancelcopy=true&amp;sesskey='.sesskey().'">'.$strcancel.'</a>)';
  68. }
  69. if (!empty($modinfo->sections[0])) {
  70. $options = array('overflowdiv'=>true);
  71. foreach ($modinfo->sections[0] as $modnumber) {
  72. $mod = $modinfo->cms[$modnumber];
  73. if (!$mod->uservisible) {
  74. continue;
  75. }
  76. if (!$ismoving) {
  77. if ($groupbuttons) {
  78. if (! $mod->groupmodelink = $groupbuttonslink) {
  79. $mod->groupmode = $course->groupmode;
  80. }
  81. } else {
  82. $mod->groupmode = false;
  83. }
  84. $editbuttons = '<br />'.make_editing_buttons($mod, true, true);
  85. } else {
  86. $editbuttons = '';
  87. }
  88. if ($mod->visible || has_capability('moodle/course:viewhiddenactivities', $context)) {
  89. if ($ismoving) {
  90. if ($mod->id == $USER->activitycopy) {
  91. continue;
  92. }
  93. $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?moveto='.$mod->id.'&amp;sesskey='.sesskey().'">'.
  94. '<img style="height:16px; width:80px; border:0px" src="'.$OUTPUT->pix_url('movehere') . '" alt="'.$strmovehere.'" /></a>';
  95. $this->content->icons[] = '';
  96. }
  97. list($content, $instancename) =
  98. get_print_section_cm_text($modinfo->cms[$modnumber], $course);
  99. $linkcss = $mod->visible ? '' : ' class="dimmed" ';
  100. if (!($url = $mod->get_url())) {
  101. $this->content->items[] = $content . $editbuttons;
  102. $this->content->icons[] = '';
  103. } else {
  104. //Accessibility: incidental image - should be empty Alt text
  105. $icon = '<img src="' . $mod->get_icon_url() . '" class="icon" alt="" />&nbsp;';
  106. $this->content->items[] = '<a title="' . $mod->modfullname . '" ' . $linkcss . ' ' . $mod->extra .
  107. ' href="' . $url . '">' . $icon . $instancename . '</a>' . $editbuttons;
  108. }
  109. }
  110. }
  111. }
  112. if ($ismoving) {
  113. $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?movetosection='.$section->id.'&amp;sesskey='.sesskey().'">'.
  114. '<img style="height:16px; width:80px; border:0px" src="'.$OUTPUT->pix_url('movehere') . '" alt="'.$strmovehere.'" /></a>';
  115. $this->content->icons[] = '';
  116. }
  117. $this->content->footer = print_section_add_menus($course, 0, null, true, true);
  118. return $this->content;
  119. }
  120. }