PageRenderTime 56ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/lib/deprecatedlib.php

https://bitbucket.org/ceu/moodle_demo
PHP | 1698 lines | 832 code | 236 blank | 630 comment | 198 complexity | 5973fcaef0e4561c6224f5c988461f0b MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. <?php // $Id: deprecatedlib.php,v 1.41.2.15 2011/07/26 09:23:16 moodlerobot Exp $
  2. ///////////////////////////////////////////////////////////////////////////
  3. // //
  4. // NOTICE OF COPYRIGHT //
  5. // //
  6. // Moodle - Modular Object-Oriented Dynamic Learning Environment //
  7. // http://moodle.org //
  8. // //
  9. // Copyright (C) 1999 onwards Martin Dougiamas, Moodle http://moodle.com//
  10. // //
  11. // This program is free software; you can redistribute it and/or modify //
  12. // it under the terms of the GNU General Public License as published by //
  13. // the Free Software Foundation; either version 2 of the License, or //
  14. // (at your option) any later version. //
  15. // //
  16. // This program is distributed in the hope that it will be useful, //
  17. // but WITHOUT ANY WARRANTY; without even the implied warranty of //
  18. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
  19. // GNU General Public License for more details: //
  20. // //
  21. // http://www.gnu.org/copyleft/gpl.html //
  22. // //
  23. ///////////////////////////////////////////////////////////////////////////
  24. /**
  25. * deprecatedlib.php - Old functions retained only for backward compatibility
  26. *
  27. * Old functions retained only for backward compatibility. New code should not
  28. * use any of these functions.
  29. *
  30. * @author Martin Dougiamas
  31. * @version $Id: deprecatedlib.php,v 1.41.2.15 2011/07/26 09:23:16 moodlerobot Exp $
  32. * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
  33. * @package moodlecore
  34. */
  35. /**
  36. * Ensure that a variable is set
  37. *
  38. * If $var is undefined throw an error, otherwise return $var.
  39. *
  40. * @param mixed $var the variable which may be unset
  41. * @param mixed $default the value to return if $var is unset
  42. */
  43. function require_variable($var) {
  44. global $CFG;
  45. if (!empty($CFG->disableglobalshack)) {
  46. error( 'The require_variable() function is deprecated.' );
  47. }
  48. if (! isset($var)) {
  49. error('A required parameter was missing');
  50. }
  51. }
  52. /**
  53. * Ensure that a variable is set
  54. *
  55. * If $var is undefined set it (by reference), otherwise return $var.
  56. *
  57. * @param mixed $var the variable which may be unset
  58. * @param mixed $default the value to return if $var is unset
  59. */
  60. function optional_variable(&$var, $default=0) {
  61. global $CFG;
  62. if (!empty($CFG->disableglobalshack)) {
  63. error( "The optional_variable() function is deprecated ($var, $default)." );
  64. }
  65. if (! isset($var)) {
  66. $var = $default;
  67. }
  68. }
  69. /**
  70. * Ensure that a variable is set
  71. *
  72. * Return $var if it is defined, otherwise return $default,
  73. * This function is very similar to {@link optional_variable()}
  74. *
  75. * @param mixed $var the variable which may be unset
  76. * @param mixed $default the value to return if $var is unset
  77. * @return mixed
  78. */
  79. function nvl(&$var, $default='') {
  80. global $CFG;
  81. if (!empty($CFG->disableglobalshack)) {
  82. error( "The nvl() function is deprecated ($var, $default)." );
  83. }
  84. return isset($var) ? $var : $default;
  85. }
  86. /**
  87. * Determines if a user an admin
  88. *
  89. * @uses $USER
  90. * @param int $userid The id of the user as is found in the 'user' table
  91. * @staticvar array $admins List of users who have been found to be admins by user id
  92. * @staticvar array $nonadmins List of users who have been found not to be admins by user id
  93. * @return bool
  94. */
  95. function isadmin($userid=0) {
  96. global $USER, $CFG;
  97. if (empty($CFG->rolesactive)) { // Then the user is likely to be upgrading NOW
  98. if (!$userid) {
  99. if (empty($USER->id)) {
  100. return false;
  101. }
  102. if (!empty($USER->admin)) {
  103. return true;
  104. }
  105. $userid = $USER->id;
  106. }
  107. return record_exists('user_admins', 'userid', $userid);
  108. }
  109. $context = get_context_instance(CONTEXT_SYSTEM);
  110. return has_capability('moodle/legacy:admin', $context, $userid, false);
  111. }
  112. /**
  113. * Determines if a user is a teacher (or better)
  114. *
  115. * @uses $CFG
  116. * @param int $courseid The id of the course that is being viewed, if any
  117. * @param int $userid The id of the user that is being tested against. Set this to 0 if you would just like to test against the currently logged in user.
  118. * @param bool $obsolete_includeadmin Not used any more
  119. * @return bool
  120. */
  121. function isteacher($courseid=0, $userid=0, $obsolete_includeadmin=true) {
  122. /// Is the user able to access this course as a teacher?
  123. global $CFG;
  124. if (empty($CFG->rolesactive)) { // Teachers are locked out during an upgrade to 1.7
  125. return false;
  126. }
  127. if ($courseid) {
  128. $context = get_context_instance(CONTEXT_COURSE, $courseid);
  129. } else {
  130. $context = get_context_instance(CONTEXT_SYSTEM);
  131. }
  132. return (has_capability('moodle/legacy:teacher', $context, $userid, false)
  133. or has_capability('moodle/legacy:editingteacher', $context, $userid, false)
  134. or has_capability('moodle/legacy:admin', $context, $userid, false));
  135. }
  136. /**
  137. * Determines if a user is a teacher in any course, or an admin
  138. *
  139. * @uses $USER
  140. * @param int $userid The id of the user that is being tested against. Set this to 0 if you would just like to test against the currently logged in user.
  141. * @param bool $includeadmin Include anyone wo is an admin as well
  142. * @return bool
  143. */
  144. function isteacherinanycourse($userid=0, $includeadmin=true) {
  145. global $USER, $CFG;
  146. if (empty($CFG->rolesactive)) { // Teachers are locked out during an upgrade to 1.7
  147. return false;
  148. }
  149. if (!$userid) {
  150. if (empty($USER->id)) {
  151. return false;
  152. }
  153. $userid = $USER->id;
  154. }
  155. if (!record_exists('role_assignments', 'userid', $userid)) { // Has no roles anywhere
  156. return false;
  157. }
  158. /// If this user is assigned as an editing teacher anywhere then return true
  159. if ($roles = get_roles_with_capability('moodle/legacy:editingteacher', CAP_ALLOW)) {
  160. foreach ($roles as $role) {
  161. if (record_exists('role_assignments', 'roleid', $role->id, 'userid', $userid)) {
  162. return true;
  163. }
  164. }
  165. }
  166. /// If this user is assigned as a non-editing teacher anywhere then return true
  167. if ($roles = get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW)) {
  168. foreach ($roles as $role) {
  169. if (record_exists('role_assignments', 'roleid', $role->id, 'userid', $userid)) {
  170. return true;
  171. }
  172. }
  173. }
  174. /// Include admins if required
  175. if ($includeadmin) {
  176. $context = get_context_instance(CONTEXT_SYSTEM);
  177. if (has_capability('moodle/legacy:admin', $context, $userid, false)) {
  178. return true;
  179. }
  180. }
  181. return false;
  182. }
  183. /**
  184. * Determines if a user is allowed to edit a given course
  185. *
  186. * @param int $courseid The id of the course that is being edited
  187. * @param int $userid The id of the user that is being tested against. Set this to 0 if you would just like to test against the currently logged in user.
  188. * @return bool
  189. */
  190. function isteacheredit($courseid, $userid=0, $obsolete_ignorestudentview=false) {
  191. global $CFG;
  192. if (empty($CFG->rolesactive)) {
  193. return false;
  194. }
  195. if (empty($courseid)) {
  196. $context = get_context_instance(CONTEXT_SYSTEM);
  197. } else {
  198. $context = get_context_instance(CONTEXT_COURSE, $courseid);
  199. }
  200. return (has_capability('moodle/legacy:editingteacher', $context, $userid, false)
  201. or has_capability('moodle/legacy:admin', $context, $userid, false));
  202. }
  203. /**
  204. * Determines if a user can create new courses
  205. *
  206. * @param int $userid The user being tested. You can set this to 0 or leave it blank to test the currently logged in user.
  207. * @return bool
  208. */
  209. function iscreator ($userid=0) {
  210. global $CFG;
  211. if (empty($CFG->rolesactive)) {
  212. return false;
  213. }
  214. $context = get_context_instance(CONTEXT_SYSTEM);
  215. return (has_capability('moodle/legacy:coursecreator', $context, $userid, false)
  216. or has_capability('moodle/legacy:admin', $context, $userid, false));
  217. }
  218. /**
  219. * Determines if a user is a student in the specified course
  220. *
  221. * If the course id specifies the site then this determines
  222. * if the user is a confirmed and valid user of this site.
  223. *
  224. * @uses $CFG
  225. * @uses SITEID
  226. * @param int $courseid The id of the course being tested
  227. * @param int $userid The user being tested. You can set this to 0 or leave it blank to test the currently logged in user.
  228. * @return bool
  229. */
  230. function isstudent($courseid=0, $userid=0) {
  231. global $CFG;
  232. if (empty($CFG->rolesactive)) {
  233. return false;
  234. }
  235. if ($courseid == 0) {
  236. $context = get_context_instance(CONTEXT_SYSTEM);
  237. } else {
  238. $context = get_context_instance(CONTEXT_COURSE, $courseid);
  239. }
  240. return has_capability('moodle/legacy:student', $context, $userid, false);
  241. }
  242. /**
  243. * Determines if the specified user is logged in as guest.
  244. *
  245. * @param int $userid The user being tested. You can set this to 0 or leave it blank to test the currently logged in user.
  246. * @return bool
  247. */
  248. function isguest($userid=0) {
  249. global $CFG;
  250. if (empty($CFG->rolesactive)) {
  251. return false;
  252. }
  253. $context = get_context_instance(CONTEXT_SYSTEM);
  254. return has_capability('moodle/legacy:guest', $context, $userid, false);
  255. }
  256. /**
  257. * Enrols (or re-enrols) a student in a given course
  258. *
  259. * NOTE: Defaults to 'manual' enrolment - enrolment plugins
  260. * must set it explicitly.
  261. *
  262. * @uses $CFG
  263. * @param int $userid The id of the user that is being tested against. Set this to 0 if you would just like to test against the currently logged in user.
  264. * @param int $courseid The id of the course that is being viewed
  265. * @param int $timestart ?
  266. * @param int $timeend ?
  267. * @param string $enrol ?
  268. * @return bool
  269. */
  270. function enrol_student($userid, $courseid, $timestart=0, $timeend=0, $enrol='manual') {
  271. global $CFG;
  272. if (!$user = get_record('user', 'id', $userid)) { // Check user
  273. return false;
  274. }
  275. if (!$roles = get_roles_with_capability('moodle/legacy:student', CAP_ALLOW)) {
  276. return false;
  277. }
  278. $role = array_shift($roles); // We can only use one, let's use the first one
  279. if (!$context = get_context_instance(CONTEXT_COURSE, $courseid)) {
  280. return false;
  281. }
  282. $res = role_assign($role->id, $user->id, 0, $context->id, $timestart, $timeend, 0, $enrol);
  283. return $res;
  284. }
  285. /**
  286. * Unenrols a student from a given course
  287. *
  288. * @param int $courseid The id of the course that is being viewed, if any
  289. * @param int $userid The id of the user that is being tested against.
  290. * @return bool
  291. */
  292. function unenrol_student($userid, $courseid=0) {
  293. global $CFG;
  294. $status = true;
  295. if ($courseid) {
  296. /// First delete any crucial stuff that might still send mail
  297. if ($forums = get_records('forum', 'course', $courseid)) {
  298. foreach ($forums as $forum) {
  299. delete_records('forum_subscriptions', 'forum', $forum->id, 'userid', $userid);
  300. }
  301. }
  302. /// remove from all legacy student roles
  303. if ($courseid == SITEID) {
  304. $context = get_context_instance(CONTEXT_SYSTEM);
  305. } else if (!$context = get_context_instance(CONTEXT_COURSE, $courseid)) {
  306. return false;
  307. }
  308. if (!$roles = get_roles_with_capability('moodle/legacy:student', CAP_ALLOW)) {
  309. return false;
  310. }
  311. foreach($roles as $role) {
  312. $status = role_unassign($role->id, $userid, 0, $context->id) and $status;
  313. }
  314. } else {
  315. // recursivelly unenroll student from all courses
  316. if ($courses = get_records('course')) {
  317. foreach($courses as $course) {
  318. $status = unenrol_student($userid, $course->id) and $status;
  319. }
  320. }
  321. }
  322. return $status;
  323. }
  324. /**
  325. * Add a teacher to a given course
  326. *
  327. * @param int $userid The id of the user that is being tested against. Set this to 0 if you would just like to test against the currently logged in user.
  328. * @param int $courseid The id of the course that is being viewed, if any
  329. * @param int $editall Can edit the course
  330. * @param string $role Obsolete
  331. * @param int $timestart The time they start
  332. * @param int $timeend The time they end in this role
  333. * @param string $enrol The type of enrolment this is
  334. * @return bool
  335. */
  336. function add_teacher($userid, $courseid, $editall=1, $role='', $timestart=0, $timeend=0, $enrol='manual') {
  337. global $CFG;
  338. if (!$user = get_record('user', 'id', $userid)) { // Check user
  339. return false;
  340. }
  341. $capability = $editall ? 'moodle/legacy:editingteacher' : 'moodle/legacy:teacher';
  342. if (!$roles = get_roles_with_capability($capability, CAP_ALLOW)) {
  343. return false;
  344. }
  345. $role = array_shift($roles); // We can only use one, let's use the first one
  346. if (!$context = get_context_instance(CONTEXT_COURSE, $courseid)) {
  347. return false;
  348. }
  349. $res = role_assign($role->id, $user->id, 0, $context->id, $timestart, $timeend, 0, $enrol);
  350. return $res;
  351. }
  352. /**
  353. * Removes a teacher from a given course (or ALL courses)
  354. * Does not delete the user account
  355. *
  356. * @param int $courseid The id of the course that is being viewed, if any
  357. * @param int $userid The id of the user that is being tested against.
  358. * @return bool
  359. */
  360. function remove_teacher($userid, $courseid=0) {
  361. global $CFG;
  362. $roles = get_roles_with_capability('moodle/legacy:editingteacher', CAP_ALLOW);
  363. if ($roles) {
  364. $roles += get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW);
  365. } else {
  366. $roles = get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW);
  367. }
  368. if (empty($roles)) {
  369. return true;
  370. }
  371. $return = true;
  372. if ($courseid) {
  373. if (!$context = get_context_instance(CONTEXT_COURSE, $courseid)) {
  374. return false;
  375. }
  376. /// First delete any crucial stuff that might still send mail
  377. if ($forums = get_records('forum', 'course', $courseid)) {
  378. foreach ($forums as $forum) {
  379. delete_records('forum_subscriptions', 'forum', $forum->id, 'userid', $userid);
  380. }
  381. }
  382. /// No need to remove from groups now
  383. foreach ($roles as $role) { // Unassign them from all the teacher roles
  384. $newreturn = role_unassign($role->id, $userid, 0, $context->id);
  385. if (empty($newreturn)) {
  386. $return = false;
  387. }
  388. }
  389. } else {
  390. delete_records('forum_subscriptions', 'userid', $userid);
  391. $return = true;
  392. foreach ($roles as $role) { // Unassign them from all the teacher roles
  393. $newreturn = role_unassign($role->id, $userid, 0, 0);
  394. if (empty($newreturn)) {
  395. $return = false;
  396. }
  397. }
  398. }
  399. return $return;
  400. }
  401. /**
  402. * Add an admin to a site
  403. *
  404. * @uses SITEID
  405. * @param int $userid The id of the user that is being tested against.
  406. * @return bool
  407. * @TODO: remove from cvs
  408. */
  409. function add_admin($userid) {
  410. return true;
  411. }
  412. function get_user_info_from_db($field, $value) { // For backward compatibility
  413. return get_complete_user_data($field, $value);
  414. }
  415. /**
  416. * Get the guest user information from the database
  417. *
  418. * @return object(user) An associative array with the details of the guest user account.
  419. * @todo Is object(user) a correct return type? Or is array the proper return type with a note that the contents include all details for a user.
  420. */
  421. function get_guest() {
  422. return get_complete_user_data('username', 'guest');
  423. }
  424. /**
  425. * Returns $user object of the main teacher for a course
  426. *
  427. * @uses $CFG
  428. * @param int $courseid The course in question.
  429. * @return user|false A {@link $USER} record of the main teacher for the specified course or false if error.
  430. * @todo Finish documenting this function
  431. */
  432. function get_teacher($courseid) {
  433. global $CFG;
  434. $context = get_context_instance(CONTEXT_COURSE, $courseid);
  435. // Pass $view=true to filter hidden caps if the user cannot see them
  436. if ($users = get_users_by_capability($context, 'moodle/course:update', 'u.*', 'u.id ASC',
  437. '', '', '', '', false, true)) {
  438. $users = sort_by_roleassignment_authority($users, $context);
  439. return array_shift($users);
  440. }
  441. return false;
  442. }
  443. /**
  444. * Searches logs to find all enrolments since a certain date
  445. *
  446. * used to print recent activity
  447. *
  448. * @uses $CFG
  449. * @param int $courseid The course in question.
  450. * @return object|false {@link $USER} records or false if error.
  451. * @todo Finish documenting this function
  452. */
  453. function get_recent_enrolments($courseid, $timestart) {
  454. global $CFG;
  455. $context = get_context_instance(CONTEXT_COURSE, $courseid);
  456. return get_records_sql("SELECT DISTINCT u.id, u.firstname, u.lastname, l.time
  457. FROM {$CFG->prefix}user u,
  458. {$CFG->prefix}role_assignments ra,
  459. {$CFG->prefix}log l
  460. WHERE l.time > '$timestart'
  461. AND l.course = '$courseid'
  462. AND l.module = 'course'
  463. AND l.action = 'enrol'
  464. AND ".sql_cast_char2int('l.info')." = u.id
  465. AND u.id = ra.userid
  466. AND ra.contextid ".get_related_contexts_string($context)."
  467. ORDER BY l.time ASC");
  468. }
  469. /**
  470. * Returns array of userinfo of all students in this course
  471. * or on this site if courseid is id of site
  472. *
  473. * @uses $CFG
  474. * @uses SITEID
  475. * @param int $courseid The course in question.
  476. * @param string $sort ?
  477. * @param string $dir ?
  478. * @param int $page ?
  479. * @param int $recordsperpage ?
  480. * @param string $firstinitial ?
  481. * @param string $lastinitial ?
  482. * @param ? $group ?
  483. * @param string $search ?
  484. * @param string $fields A comma separated list of fields to be returned from the chosen table.
  485. * @param string $exceptions ?
  486. * @return object
  487. * @todo Finish documenting this function
  488. */
  489. function get_course_students($courseid, $sort='ul.timeaccess', $dir='', $page='', $recordsperpage='',
  490. $firstinitial='', $lastinitial='', $group=NULL, $search='', $fields='', $exceptions='') {
  491. global $CFG;
  492. // make sure it works on the site course
  493. $context = get_context_instance(CONTEXT_COURSE, $courseid);
  494. /// For the site course, old way was to check if $CFG->allusersaresitestudents was set to true.
  495. /// The closest comparible method using roles is if the $CFG->defaultuserroleid is set to the legacy
  496. /// student role. This function should be replaced where it is used with something more meaningful.
  497. if (($courseid == SITEID) && !empty($CFG->defaultuserroleid) && empty($CFG->nodefaultuserrolelists)) {
  498. if ($roles = get_roles_with_capability('moodle/legacy:student', CAP_ALLOW, $context)) {
  499. $hascap = false;
  500. foreach ($roles as $role) {
  501. if ($role->id == $CFG->defaultuserroleid) {
  502. $hascap = true;
  503. break;
  504. }
  505. }
  506. if ($hascap) {
  507. if (empty($fields)) {
  508. $fields = '*';
  509. }
  510. // return users with confirmed, undeleted accounts who are not site teachers
  511. // the following is a mess because of different conventions in the different user functions
  512. $sort = str_replace('s.timeaccess', 'lastaccess', $sort); // site users can't be sorted by timeaccess
  513. $sort = str_replace('timeaccess', 'lastaccess', $sort); // site users can't be sorted by timeaccess
  514. $sort = str_replace('u.', '', $sort); // the get_user function doesn't use the u. prefix to fields
  515. $sort = str_replace('ul.', '', $sort); // the get_user function doesn't use the ul. prefix to fields
  516. // the following is a mess because of different conventions in the different user functions. MDL-17200
  517. $fields = str_replace('u.', '', $fields);
  518. $fields = str_replace('ul.', '', $fields);
  519. $fields = str_replace('timeaccess', 'lastaccess', $fields);
  520. if ($sort) {
  521. $sort = $sort .' '. $dir;
  522. }
  523. // Now we have to make sure site teachers are excluded
  524. if ($teachers = get_course_teachers(SITEID)) {
  525. foreach ($teachers as $teacher) {
  526. $exceptions .= ','. $teacher->userid;
  527. }
  528. $exceptions = ltrim($exceptions, ',');
  529. }
  530. return get_users(true, $search, true, $exceptions, $sort, $firstinitial, $lastinitial,
  531. $page, $recordsperpage, $fields);
  532. }
  533. }
  534. }
  535. $LIKE = sql_ilike();
  536. $fullname = sql_fullname('u.firstname','u.lastname');
  537. $groupmembers = '';
  538. $select = "c.contextlevel=".CONTEXT_COURSE." AND "; // Must be on a course
  539. if ($courseid != SITEID) {
  540. // If not site, require specific course
  541. $select.= "c.instanceid=$courseid AND ";
  542. }
  543. $select.="rc.capability='moodle/legacy:student' AND rc.permission=".CAP_ALLOW." AND ";
  544. $select .= ' u.deleted = \'0\' ';
  545. if (!$fields) {
  546. $fields = 'u.id, u.confirmed, u.username, u.firstname, u.lastname, '.
  547. 'u.maildisplay, u.mailformat, u.maildigest, u.email, u.city, '.
  548. 'u.country, u.picture, u.idnumber, u.department, u.institution, '.
  549. 'u.emailstop, u.lang, u.timezone, ul.timeaccess as lastaccess';
  550. }
  551. if ($search) {
  552. $search = ' AND ('. $fullname .' '. $LIKE .'\'%'. $search .'%\' OR email '. $LIKE .'\'%'. $search .'%\') ';
  553. }
  554. if ($firstinitial) {
  555. $select .= ' AND u.firstname '. $LIKE .'\''. $firstinitial .'%\' ';
  556. }
  557. if ($lastinitial) {
  558. $select .= ' AND u.lastname '. $LIKE .'\''. $lastinitial .'%\' ';
  559. }
  560. if ($group === 0) { /// Need something here to get all students not in a group
  561. return array();
  562. } else if ($group !== NULL) {
  563. $groupmembers = "INNER JOIN {$CFG->prefix}groups_members gm on u.id=gm.userid";
  564. $select .= ' AND gm.groupid = \''. $group .'\'';
  565. }
  566. if (!empty($exceptions)) {
  567. $select .= ' AND u.id NOT IN ('. $exceptions .')';
  568. }
  569. if ($sort) {
  570. $sort = ' ORDER BY '. $sort .' ';
  571. }
  572. $students = get_records_sql("SELECT $fields
  573. FROM {$CFG->prefix}user u INNER JOIN
  574. {$CFG->prefix}role_assignments ra on u.id=ra.userid INNER JOIN
  575. {$CFG->prefix}role_capabilities rc ON ra.roleid=rc.roleid INNER JOIN
  576. {$CFG->prefix}context c ON c.id=ra.contextid LEFT OUTER JOIN
  577. {$CFG->prefix}user_lastaccess ul on ul.userid=ra.userid AND ul.courseid = $courseid
  578. $groupmembers
  579. WHERE $select $search $sort $dir", $page, $recordsperpage);
  580. return $students;
  581. }
  582. /**
  583. * Counts the students in a given course (or site), or a subset of them
  584. *
  585. * @param object $course The course in question as a course object.
  586. * @param string $search ?
  587. * @param string $firstinitial ?
  588. * @param string $lastinitial ?
  589. * @param ? $group ?
  590. * @param string $exceptions ?
  591. * @return int
  592. * @todo Finish documenting this function
  593. */
  594. function count_course_students($course, $search='', $firstinitial='', $lastinitial='', $group=NULL, $exceptions='') {
  595. if ($students = get_course_students($course->id, '', '', 0, 999999, $firstinitial, $lastinitial, $group, $search, '', $exceptions)) {
  596. return count($students);
  597. }
  598. return 0;
  599. }
  600. /**
  601. * Returns list of all teachers in this course
  602. *
  603. * If $courseid matches the site id then this function
  604. * returns a list of all teachers for the site.
  605. *
  606. * @uses $CFG
  607. * @param int $courseid The course in question.
  608. * @param string $sort ?
  609. * @param string $exceptions ?
  610. * @return object
  611. * @todo Finish documenting this function
  612. */
  613. function get_course_teachers($courseid, $sort='t.authority ASC', $exceptions='') {
  614. global $CFG;
  615. $sort = 'ul.timeaccess DESC';
  616. $context = get_context_instance(CONTEXT_COURSE, $courseid);
  617. /// For the site course, if the $CFG->defaultuserroleid is set to the legacy teacher role, then all
  618. /// users are teachers. This function should be replaced where it is used with something more
  619. /// meaningful.
  620. if (($courseid == SITEID) && !empty($CFG->defaultuserroleid) && empty($CFG->nodefaultuserrolelists)) {
  621. if ($roles = get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW, $context)) {
  622. $hascap = false;
  623. foreach ($roles as $role) {
  624. if ($role->id == $CFG->defaultuserroleid) {
  625. $hascap = true;
  626. break;
  627. }
  628. }
  629. if ($hascap) {
  630. if (empty($fields)) {
  631. $fields = '*';
  632. }
  633. return get_users(true, '', true, $exceptions, 'lastname ASC', '', '', '', '', $fields);
  634. }
  635. }
  636. }
  637. $users = get_users_by_capability($context, 'moodle/course:update',
  638. 'u.*, ul.timeaccess as lastaccess',
  639. $sort, '','','',$exceptions, false);
  640. return sort_by_roleassignment_authority($users, $context);
  641. /// some fields will be missing, like authority, editall
  642. /*
  643. return get_records_sql("SELECT u.id, u.username, u.firstname, u.lastname, u.maildisplay, u.mailformat, u.maildigest,
  644. u.email, u.city, u.country, u.lastlogin, u.picture, u.lang, u.timezone,
  645. u.emailstop, t.authority,t.role,t.editall,t.timeaccess as lastaccess
  646. FROM {$CFG->prefix}user u,
  647. {$CFG->prefix}user_teachers t
  648. WHERE t.course = '$courseid' AND t.userid = u.id
  649. AND u.deleted = '0' AND u.confirmed = '1' $exceptions $sort");
  650. */
  651. }
  652. /**
  653. * Returns all the users of a course: students and teachers
  654. *
  655. * @param int $courseid The course in question.
  656. * @param string $sort ?
  657. * @param string $exceptions A comma separated list of user->id to be skiped in the result returned by the function
  658. * @param string $fields A comma separated list of fields to be returned from the chosen table.
  659. * @param int $limitfrom return a subset of records, starting at this point (optional, required if $limitnum is set).
  660. * @param int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set).
  661. * @todo Finish documenting this function
  662. */
  663. function get_course_users($courseid, $sort='ul.timeaccess DESC', $exceptions='', $fields='u.*, ul.timeaccess as lastaccess', $limitfrom='', $limitnum='') {
  664. global $CFG;
  665. $context = get_context_instance(CONTEXT_COURSE, $courseid);
  666. /// If the course id is the SITEID, we need to return all the users if the "defaultuserroleid"
  667. /// has the capbility of accessing the site course. $CFG->nodefaultuserrolelists set to true can
  668. /// over-rule using this.
  669. if (($courseid == SITEID) && !empty($CFG->defaultuserroleid) && empty($CFG->nodefaultuserrolelists)) {
  670. if ($roles = get_roles_with_capability('moodle/course:view', CAP_ALLOW, $context)) {
  671. $hascap = false;
  672. foreach ($roles as $role) {
  673. if ($role->id == $CFG->defaultuserroleid) {
  674. $hascap = true;
  675. break;
  676. }
  677. }
  678. if ($hascap) {
  679. if (empty($fields)) {
  680. $fields = '*';
  681. }
  682. // the following is a mess because of different conventions in the different user functions. MDL-17200
  683. $fields = str_replace('u.', '', $fields);
  684. $fields = str_replace('ul.', '', $fields);
  685. $fields = str_replace('timeaccess', 'lastaccess', $fields);
  686. return get_users(true, '', true, $exceptions, 'lastname ASC', '', '', $limitfrom, $limitnum, $fields);
  687. }
  688. }
  689. }
  690. return get_users_by_capability($context, 'moodle/course:view', $fields, $sort, $limitfrom, $limitnum,'',$exceptions, false);
  691. }
  692. /**
  693. * Returns an array of user objects
  694. *
  695. * @uses $CFG
  696. * @param int $groupid The group(s) in question.
  697. * @param string $sort How to sort the results
  698. * @return object (changed to groupids)
  699. */
  700. function get_group_students($groupids, $sort='ul.timeaccess DESC') {
  701. if (is_array($groupids)){
  702. $groups = $groupids;
  703. // all groups must be from one course anyway...
  704. $group = groups_get_group(array_shift($groups));
  705. } else {
  706. $group = groups_get_group($groupids);
  707. }
  708. if (!$group) {
  709. return NULL;
  710. }
  711. $context = get_context_instance(CONTEXT_COURSE, $group->courseid);
  712. return get_users_by_capability($context, 'moodle/legacy:student', 'u.*, ul.timeaccess as lastaccess', $sort, '','',$groupids, '', false);
  713. }
  714. /**
  715. * Returns list of all the teachers who can access a group
  716. *
  717. * @uses $CFG
  718. * @param int $courseid The course in question.
  719. * @param int $groupid The group in question.
  720. * @return object
  721. */
  722. function get_group_teachers($courseid, $groupid) {
  723. /// Returns a list of all the teachers who can access a group
  724. if ($teachers = get_course_teachers($courseid)) {
  725. foreach ($teachers as $key => $teacher) {
  726. if ($teacher->editall) { // These can access anything
  727. continue;
  728. }
  729. if (($teacher->authority > 0) and groups_is_member($groupid, $teacher->id)) { // Specific group teachers
  730. continue;
  731. }
  732. unset($teachers[$key]);
  733. }
  734. }
  735. return $teachers;
  736. }
  737. ########### FROM weblib.php ##########################################################################
  738. /**
  739. * Creates a nicely formatted table and returns it.
  740. *
  741. * @param array $table is an object with several properties.
  742. * <ul<li>$table->head - An array of heading names.
  743. * <li>$table->align - An array of column alignments
  744. * <li>$table->size - An array of column sizes
  745. * <li>$table->wrap - An array of "nowrap"s or nothing
  746. * <li>$table->data[] - An array of arrays containing the data.
  747. * <li>$table->class - A css class name
  748. * <li>$table->fontsize - Is the size of all the text
  749. * <li>$table->tablealign - Align the whole table
  750. * <li>$table->width - A percentage of the page
  751. * <li>$table->cellpadding - Padding on each cell
  752. * <li>$table->cellspacing - Spacing between cells
  753. * </ul>
  754. * @return string
  755. * @todo Finish documenting this function
  756. */
  757. function make_table($table) {
  758. return print_table($table, true);
  759. }
  760. /**
  761. * Print a message in a standard themed box.
  762. * This old function used to implement boxes using tables. Now it uses a DIV, but the old
  763. * parameters remain. If possible, $align, $width and $color should not be defined at all.
  764. * Preferably just use print_box() in weblib.php
  765. *
  766. * @param string $align, alignment of the box, not the text (default center, left, right).
  767. * @param string $width, width of the box, including units %, for example '100%'.
  768. * @param string $color, background colour of the box, for example '#eee'.
  769. * @param int $padding, padding in pixels, specified without units.
  770. * @param string $class, space-separated class names.
  771. * @param string $id, space-separated id names.
  772. * @param boolean $return, return as string or just print it
  773. */
  774. function print_simple_box($message, $align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) {
  775. $output = '';
  776. $output .= print_simple_box_start($align, $width, $color, $padding, $class, $id, true);
  777. $output .= stripslashes_safe($message);
  778. $output .= print_simple_box_end(true);
  779. if ($return) {
  780. return $output;
  781. } else {
  782. echo $output;
  783. }
  784. }
  785. /**
  786. * This old function used to implement boxes using tables. Now it uses a DIV, but the old
  787. * parameters remain. If possible, $align, $width and $color should not be defined at all.
  788. * Even better, please use print_box_start() in weblib.php
  789. *
  790. * @param string $align, alignment of the box, not the text (default center, left, right). DEPRECATED
  791. * @param string $width, width of the box, including % units, for example '100%'. DEPRECATED
  792. * @param string $color, background colour of the box, for example '#eee'. DEPRECATED
  793. * @param int $padding, padding in pixels, specified without units. OBSOLETE
  794. * @param string $class, space-separated class names.
  795. * @param string $id, space-separated id names.
  796. * @param boolean $return, return as string or just print it
  797. */
  798. function print_simple_box_start($align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) {
  799. $output = '';
  800. $divclasses = 'box '.$class.' '.$class.'content';
  801. $divstyles = '';
  802. if ($align) {
  803. $divclasses .= ' boxalign'.$align; // Implement alignment using a class
  804. }
  805. if ($width) { // Hopefully we can eliminate these in calls to this function (inline styles are bad)
  806. if (substr($width, -1, 1) == '%') { // Width is a % value
  807. $width = (int) substr($width, 0, -1); // Extract just the number
  808. if ($width < 40) {
  809. $divclasses .= ' boxwidthnarrow'; // Approx 30% depending on theme
  810. } else if ($width > 60) {
  811. $divclasses .= ' boxwidthwide'; // Approx 80% depending on theme
  812. } else {
  813. $divclasses .= ' boxwidthnormal'; // Approx 50% depending on theme
  814. }
  815. } else {
  816. $divstyles .= ' width:'.$width.';'; // Last resort
  817. }
  818. }
  819. if ($color) { // Hopefully we can eliminate these in calls to this function (inline styles are bad)
  820. $divstyles .= ' background:'.$color.';';
  821. }
  822. if ($divstyles) {
  823. $divstyles = ' style="'.$divstyles.'"';
  824. }
  825. if ($id) {
  826. $id = ' id="'.$id.'"';
  827. }
  828. $output .= '<div'.$id.$divstyles.' class="'.$divclasses.'">';
  829. if ($return) {
  830. return $output;
  831. } else {
  832. echo $output;
  833. }
  834. }
  835. /**
  836. * Print the end portion of a standard themed box.
  837. * Preferably just use print_box_end() in weblib.php
  838. */
  839. function print_simple_box_end($return=false) {
  840. $output = '</div>';
  841. if ($return) {
  842. return $output;
  843. } else {
  844. echo $output;
  845. }
  846. }
  847. /**
  848. * deprecated - use clean_param($string, PARAM_FILE); instead
  849. * Check for bad characters ?
  850. *
  851. * @param string $string ?
  852. * @param int $allowdots ?
  853. * @todo Finish documenting this function - more detail needed in description as well as details on arguments
  854. */
  855. function detect_munged_arguments($string, $allowdots=1) {
  856. if (substr_count($string, '..') > $allowdots) { // Sometimes we allow dots in references
  857. return true;
  858. }
  859. if (ereg('[\|\`]', $string)) { // check for other bad characters
  860. return true;
  861. }
  862. if (empty($string) or $string == '/') {
  863. return true;
  864. }
  865. return false;
  866. }
  867. /** Deprecated function - returns the code of the current charset - originally depended on the selected language pack.
  868. *
  869. * @param $ignorecache not used anymore
  870. * @return string always returns 'UTF-8'
  871. */
  872. function current_charset($ignorecache = false) {
  873. return 'UTF-8';
  874. }
  875. /////////////////////////////////////////////////////////////
  876. /// Old functions not used anymore - candidates for removal
  877. /////////////////////////////////////////////////////////////
  878. /**
  879. * Load a template from file - this function dates back to Moodle 1 :-) not used anymore
  880. *
  881. * Returns a (big) string containing the contents of a template file with all
  882. * the variables interpolated. all the variables must be in the $var[] array or
  883. * object (whatever you decide to use).
  884. *
  885. * <b>WARNING: do not use this on big files!!</b>
  886. *
  887. * @param string $filename Location on the server's filesystem where template can be found.
  888. * @param mixed $var Passed in by reference. An array or object which will be loaded with data from the template file.
  889. *
  890. */
  891. function read_template($filename, &$var) {
  892. $temp = str_replace("\\", "\\\\", implode(file($filename), ''));
  893. $temp = str_replace('"', '\"', $temp);
  894. eval("\$template = \"$temp\";");
  895. return $template;
  896. }
  897. /**
  898. * deprecated - relies on register globals; use new formslib instead
  899. *
  900. * Set a variable's value depending on whether or not it already has a value.
  901. *
  902. * If variable is set, set it to the set_value otherwise set it to the
  903. * unset_value. used to handle checkboxes when you are expecting them from
  904. * a form
  905. *
  906. * @param mixed $var Passed in by reference. The variable to check.
  907. * @param mixed $set_value The value to set $var to if $var already has a value.
  908. * @param mixed $unset_value The value to set $var to if $var does not already have a value.
  909. */
  910. function checked(&$var, $set_value = 1, $unset_value = 0) {
  911. if (empty($var)) {
  912. $var = $unset_value;
  913. } else {
  914. $var = $set_value;
  915. }
  916. }
  917. /**
  918. * deprecated - use new formslib instead
  919. *
  920. * Prints the word "checked" if a variable is true, otherwise prints nothing,
  921. * used for printing the word "checked" in a checkbox form element.
  922. *
  923. * @param boolean $var Variable to be checked for true value
  924. * @param string $true_value Value to be printed if $var is true
  925. * @param string $false_value Value to be printed if $var is false
  926. */
  927. function frmchecked(&$var, $true_value = 'checked', $false_value = '') {
  928. if ($var) {
  929. echo $true_value;
  930. } else {
  931. echo $false_value;
  932. }
  933. }
  934. /**
  935. * Legacy function, provided for backward compatability.
  936. * This method now simply calls {@link use_html_editor()}
  937. *
  938. * @deprecated Use {@link use_html_editor()} instead.
  939. * @param string $name Form element to replace with HTMl editor by name
  940. * @todo Finish documenting this function
  941. */
  942. function print_richedit_javascript($form, $name, $source='no') {
  943. use_html_editor($name);
  944. }
  945. /** various deprecated groups function **/
  946. /**
  947. * Returns the table in which group members are stored, with a prefix 'gm'.
  948. * @return SQL string.
  949. */
  950. function groups_members_from_sql() {
  951. global $CFG;
  952. return " {$CFG->prefix}groups_members gm ";
  953. }
  954. /**
  955. * Returns a join testing user.id against member's user ID.
  956. * Relies on 'user' table being included as 'user u'.
  957. * Used in Quiz module reports.
  958. * @param group ID, optional to include a test for this in the SQL.
  959. * @return SQL string.
  960. */
  961. function groups_members_join_sql($groupid=false) {
  962. $sql = ' JOIN '.groups_members_from_sql().' ON u.id = gm.userid ';
  963. if ($groupid) {
  964. $sql = "AND gm.groupid = '$groupid' ";
  965. }
  966. return $sql;
  967. }
  968. /**
  969. * Returns SQL for a WHERE clause testing the group ID.
  970. * Optionally test the member's ID against another table's user ID column.
  971. * @param groupid
  972. * @param userid_sql Optional user ID column selector, example "mdl_user.id", or false.
  973. * @return SQL string.
  974. */
  975. function groups_members_where_sql($groupid, $userid_sql=false) {
  976. $sql = " gm.groupid = '$groupid' ";
  977. if ($userid_sql) {
  978. $sql .= "AND $userid_sql = gm.userid ";
  979. }
  980. return $sql;
  981. }
  982. /**
  983. * Returns an array of group objects that the user is a member of
  984. * in the given course. If userid isn't specified, then return a
  985. * list of all groups in the course.
  986. *
  987. * @uses $CFG
  988. * @param int $courseid The id of the course in question.
  989. * @param int $userid The id of the user in question as found in the 'user' table 'id' field.
  990. * @return object
  991. */
  992. function get_groups($courseid, $userid=0) {
  993. return groups_get_all_groups($courseid, $userid);
  994. }
  995. /**
  996. * Returns the user's groups in a particular course
  997. * note: this function originally returned only one group
  998. *
  999. * @uses $CFG
  1000. * @param int $courseid The course in question.
  1001. * @param int $userid The id of the user as found in the 'user' table.
  1002. * @param int $groupid The id of the group the user is in.
  1003. * @return aray of groups
  1004. */
  1005. function user_group($courseid, $userid) {
  1006. return groups_get_all_groups($courseid, $userid);
  1007. }
  1008. /**
  1009. * Determines if the user is a member of the given group.
  1010. *
  1011. * @param int $groupid The group to check for membership.
  1012. * @param int $userid The user to check against the group.
  1013. * @return boolean True if the user is a member, false otherwise.
  1014. */
  1015. function ismember($groupid, $userid = null) {
  1016. return groups_is_member($groupid, $userid);
  1017. }
  1018. /**
  1019. * Get the IDs for the user's groups in the given course.
  1020. *
  1021. * @uses $USER
  1022. * @param int $courseid The course being examined - the 'course' table id field.
  1023. * @return array An _array_ of groupids.
  1024. * (Was return $groupids[0] - consequences!)
  1025. */
  1026. function mygroupid($courseid) {
  1027. global $USER;
  1028. if ($groups = groups_get_all_groups($courseid, $USER->id)) {
  1029. return array_keys($groups);
  1030. } else {
  1031. return false;
  1032. }
  1033. }
  1034. /**
  1035. * Add a user to a group, return true upon success or if user already a group
  1036. * member
  1037. *
  1038. * @param int $groupid The group id to add user to
  1039. * @param int $userid The user id to add to the group
  1040. * @return bool
  1041. */
  1042. function add_user_to_group($groupid, $userid) {
  1043. global $CFG;
  1044. require_once($CFG->dirroot.'/group/lib.php');
  1045. return groups_add_member($groupid, $userid);
  1046. }
  1047. /**
  1048. * Returns an array of user objects
  1049. *
  1050. * @uses $CFG
  1051. * @param int $groupid The group in question.
  1052. * @param string $sort ?
  1053. * @param string $exceptions A comma separated list of user->id to be skiped in the result returned by the function
  1054. * @param string $fields A comma separated list of fields to be returned from the chosen table.
  1055. * @param int $limitfrom return a subset of records, starting at this point (optional, required if $limitnum is set).
  1056. * @param int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set).
  1057. * @return array array of user objects
  1058. * @todo Finish documenting this function
  1059. */
  1060. function get_group_users($groupid, $sort='u.lastaccess DESC', $exceptions='', $fields='u.*', $limitfrom='', $limitnum='') {
  1061. global $CFG;
  1062. if (!empty($exceptions)) {
  1063. $except = ' AND u.id NOT IN ('. $exceptions .') ';
  1064. } else {
  1065. $except = '';
  1066. }
  1067. // in postgres, you can't have things in sort that aren't in the select, so...
  1068. $extrafield = str_replace('ASC','',$sort);
  1069. $extrafield = str_replace('DESC','',$extrafield);
  1070. $extrafield = trim($extrafield);
  1071. if (!empty($extrafield)) {
  1072. $extrafield = ','.$extrafield;
  1073. }
  1074. return get_records_sql("SELECT DISTINCT $fields $extrafield
  1075. FROM {$CFG->prefix}user u,
  1076. {$CFG->prefix}groups_members m
  1077. WHERE m.groupid = '$groupid'
  1078. AND m.userid = u.id $except
  1079. ORDER BY $sort",
  1080. $limitfrom, $limitnum);
  1081. }
  1082. /**
  1083. * Returns the current group mode for a given course or activity module
  1084. *
  1085. * Could be false, SEPARATEGROUPS or VISIBLEGROUPS (<-- Martin)
  1086. */
  1087. function groupmode($course, $cm=null) {
  1088. if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
  1089. return $cm->groupmode;
  1090. }
  1091. return $course->groupmode;
  1092. }
  1093. /**
  1094. * Sets the current group in the session variable
  1095. * When $SESSION->currentgroup[$courseid] is set to 0 it means, show all groups.
  1096. * Sets currentgroup[$courseid] in the session variable appropriately.
  1097. * Does not do any permission checking.
  1098. * @uses $SESSION
  1099. * @param int $courseid The course being examined - relates to id field in
  1100. * 'course' table.
  1101. * @param int $groupid The group being examined.
  1102. * @return int Current group id which was set by this function
  1103. */
  1104. function set_current_group($courseid, $groupid) {
  1105. global $SESSION;
  1106. return $SESSION->currentgroup[$courseid] = $groupid;
  1107. }
  1108. /**
  1109. * Gets the current group - either from the session variable or from the database.
  1110. *
  1111. * @uses $USER
  1112. * @uses $SESSION
  1113. * @param int $courseid The course being examined - relates to id field in
  1114. * 'course' table.
  1115. * @param bool $full If true, the return value is a full record object.
  1116. * If false, just the id of the record.
  1117. */
  1118. function get_current_group($courseid, $full = false) {
  1119. global $SESSION;
  1120. if (isset($SESSION->currentgroup[$courseid])) {
  1121. if ($full) {
  1122. return groups_get_group($SESSION->currentgroup[$courseid]);
  1123. } else {
  1124. return $SESSION->currentgroup[$courseid];
  1125. }
  1126. }
  1127. $mygroupid = mygroupid($courseid);
  1128. if (is_array($mygroupid)) {
  1129. $mygroupid = array_shift($mygroupid);
  1130. set_current_group($courseid, $mygroupid);
  1131. if ($full) {
  1132. return groups_get_group($mygroupid);
  1133. } else {
  1134. return $mygroupid;
  1135. }
  1136. }
  1137. if ($full) {
  1138. return false;
  1139. } else {
  1140. return 0;
  1141. }
  1142. }
  1143. /**
  1144. * A combination function to make it easier for modules
  1145. * to set up groups.
  1146. *
  1147. * It will use a given "groupid" parameter and try to use
  1148. * that to reset the current group for the user.
  1149. *
  1150. * @uses VISIBLEGROUPS
  1151. * @param course $course A {@link $COURSE} object
  1152. * @param int $groupmode Either NOGROUPS, SEPARATEGROUPS or VISIBLEGROUPS
  1153. * @param int $groupid Will try to use this optional parameter to
  1154. * reset the current group for the user
  1155. * @return int|false Returns the current group id or false if error.
  1156. */
  1157. function get_and_set_current_group($course, $groupmode, $groupid=-1) {
  1158. // Sets to the specified group, provided the current user has view permission
  1159. if (!$groupmode) { // Groups don't even apply
  1160. return false;
  1161. }
  1162. $currentgroupid = get_current_group($course->id);
  1163. if ($groupid < 0) { // No change was specified
  1164. return $currentgroupid;
  1165. }
  1166. $context = get_context_instance(CONTEXT_COURSE, $course->id);
  1167. if ($groupid and $group = get_record('groups', 'id', $groupid)) { // Try to change the current group to this groupid
  1168. if ($group->courseid == $course->id) {
  1169. if (has_capability('moodle/site:accessallgroups', $context)) { // Sets current default group
  1170. $currentgroupid = set_current_group($course->id, $groupid);
  1171. } elseif ($groupmode == VISIBLEGROUPS) {
  1172. // All groups are visible
  1173. //if (groups_is_member($group->id)){
  1174. $currentgroupid = set_current_group($course->id, $groupid); //set this since he might post
  1175. /*)}else {
  1176. $currentgroupid = $group->id;*/
  1177. } elseif ($groupmode == SEPARATEGROUPS) { // student in separate groups switching
  1178. if (groups_is_member($groupid)) { //check if is a member
  1179. $currentgroupid = set_current_group($course->id, $groupid); //might need to set_current_group?
  1180. }
  1181. else {
  1182. notify('You do not belong to this group! ('.$groupid.')', 'error');
  1183. }
  1184. }
  1185. }
  1186. } else { // When groupid = 0 it means show ALL groups
  1187. // this is changed, non editting teacher needs access to group 0 as well,
  1188. // for viewing work in visible groups (need to set current group for multiple pages)
  1189. if (has_capability('moodle/site:accessallgroups', $context)) { // Sets current default group
  1190. $currentgroupid = set_current_group($course->id, 0);
  1191. } else if ($groupmode == VISIBLEGROUPS) { // All groups are visib…

Large files files are truncated, but you can click here to view the full file