PageRenderTime 37ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/course/recent_form.php

https://bitbucket.org/synergylearning/campusconnect
PHP | 171 lines | 120 code | 23 blank | 28 comment | 23 complexity | 269883940b2426d7071f064ecdd70997 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, Apache-2.0, BSD-3-Clause, AGPL-3.0
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Display all recent activity in a flexible way
  18. *
  19. * @copyright 1999 Martin Dougiamas http://dougiamas.com
  20. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  21. * @package course
  22. */
  23. if (!defined('MOODLE_INTERNAL')) {
  24. die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
  25. }
  26. require_once($CFG->libdir.'/formslib.php');
  27. class recent_form extends moodleform {
  28. function definition() {
  29. global $CFG, $COURSE, $USER;
  30. $mform =& $this->_form;
  31. $context = context_course::instance($COURSE->id);
  32. $modinfo = get_fast_modinfo($COURSE);
  33. $mform->addElement('header', 'filters', get_string('managefilters')); //TODO: add better string
  34. $groupoptions = array();
  35. if (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) {
  36. // limited group access
  37. $groups = groups_get_user_groups($COURSE->id);
  38. $allgroups = groups_get_all_groups($COURSE->id);
  39. if (!empty($groups[$COURSE->defaultgroupingid])) {
  40. foreach ($groups[$COURSE->defaultgroupingid] AS $groupid) {
  41. $groupoptions[$groupid] = format_string($allgroups[$groupid]->name, true, array('context'=>$context));
  42. }
  43. }
  44. } else {
  45. $groupoptions = array('0'=>get_string('allgroups'));
  46. if (has_capability('moodle/site:accessallgroups', $context)) {
  47. // user can see all groups
  48. $allgroups = groups_get_all_groups($COURSE->id);
  49. } else {
  50. // user can see course level groups
  51. $allgroups = groups_get_all_groups($COURSE->id, 0, $COURSE->defaultgroupingid);
  52. }
  53. foreach($allgroups as $group) {
  54. $groupoptions[$group->id] = format_string($group->name, true, array('context'=>$context));
  55. }
  56. }
  57. if ($COURSE->id == SITEID) {
  58. $viewparticipants = has_capability('moodle/site:viewparticipants', context_system::instance());
  59. } else {
  60. $viewparticipants = has_capability('moodle/course:viewparticipants', $context);
  61. }
  62. if ($viewparticipants) {
  63. $viewfullnames = has_capability('moodle/site:viewfullnames', context_course::instance($COURSE->id));
  64. $options = array();
  65. $options[0] = get_string('allparticipants');
  66. $options[$CFG->siteguest] = get_string('guestuser');
  67. if (isset($groupoptions[0])) {
  68. // can see all enrolled users
  69. if ($enrolled = get_enrolled_users($context, null, 0, user_picture::fields('u'))) {
  70. foreach ($enrolled as $euser) {
  71. $options[$euser->id] = fullname($euser, $viewfullnames);
  72. }
  73. }
  74. } else {
  75. // can see users from some groups only
  76. foreach ($groupoptions as $groupid=>$unused) {
  77. if ($enrolled = get_enrolled_users($context, null, $groupid, user_picture::fields('u'))) {
  78. foreach ($enrolled as $euser) {
  79. if (!array_key_exists($euser->id, $options)) {
  80. $options[$euser->id] = fullname($euser, $viewfullnames);
  81. }
  82. }
  83. }
  84. }
  85. }
  86. $mform->addElement('select', 'user', get_string('participants'), $options);
  87. $mform->setAdvanced('user');
  88. } else {
  89. // Default to no user.
  90. $mform->addElement('hidden', 'user', 0);
  91. $mform->setType('user', PARAM_INT);
  92. $mform->setConstant('user', 0);
  93. }
  94. $options = array(''=>get_string('allactivities'));
  95. $modsused = array();
  96. foreach($modinfo->cms as $cm) {
  97. if (!$cm->uservisible) {
  98. continue;
  99. }
  100. $modsused[$cm->modname] = true;
  101. }
  102. foreach ($modsused as $modname=>$unused) {
  103. $libfile = "$CFG->dirroot/mod/$modname/lib.php";
  104. if (!file_exists($libfile)) {
  105. unset($modsused[$modname]);
  106. continue;
  107. }
  108. include_once($libfile);
  109. $libfunction = $modname."_get_recent_mod_activity";
  110. if (!function_exists($libfunction)) {
  111. unset($modsused[$modname]);
  112. continue;
  113. }
  114. $options["mod/$modname"] = get_string('allmods', '', get_string('modulenameplural', $modname));
  115. }
  116. foreach ($modinfo->sections as $section=>$cmids) {
  117. $options["section/$section"] = "-- ".get_section_name($COURSE, $section)." --";
  118. foreach ($cmids as $cmid) {
  119. $cm = $modinfo->cms[$cmid];
  120. if (empty($modsused[$cm->modname]) or !$cm->uservisible) {
  121. continue;
  122. }
  123. $options[$cm->id] = format_string($cm->name);
  124. }
  125. }
  126. $mform->addElement('select', 'modid', get_string('activities'), $options);
  127. $mform->setAdvanced('modid');
  128. if ($groupoptions) {
  129. $mform->addElement('select', 'group', get_string('groups'), $groupoptions);
  130. $mform->setAdvanced('group');
  131. } else {
  132. // no access to groups in separate mode
  133. $mform->addElement('hidden','group');
  134. $mform->setType('group', PARAM_INT);
  135. $mform->setConstants(array('group'=>-1));
  136. }
  137. $options = array('default' => get_string('bycourseorder'),
  138. 'dateasc' => get_string('datemostrecentlast'),
  139. 'datedesc' => get_string('datemostrecentfirst'));
  140. $mform->addElement('select', 'sortby', get_string('sortby'), $options);
  141. $mform->setAdvanced('sortby');
  142. $mform->addElement('date_time_selector', 'date', get_string('since'), array('optional'=>true));
  143. $mform->addElement('hidden','id');
  144. $mform->setType('id', PARAM_INT);
  145. $mform->setType('courseid', PARAM_INT);
  146. $this->add_action_buttons(false, get_string('showrecent'));
  147. }
  148. }