PageRenderTime 74ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 0ms

/grade/lib.php

https://bitbucket.org/ngmares/moodle
PHP | 2668 lines | 1716 code | 311 blank | 641 comment | 355 complexity | cf90861941c649e1a2745322cd45c15f MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-3.0, MPL-2.0-no-copyleft-exception, GPL-3.0, Apache-2.0, BSD-3-Clause

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

  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. * Functions used by gradebook plugins and reports.
  18. *
  19. * @package core_grades
  20. * @copyright 2009 Petr Skoda and Nicolas Connault
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. require_once $CFG->libdir.'/gradelib.php';
  24. /**
  25. * This class iterates over all users that are graded in a course.
  26. * Returns detailed info about users and their grades.
  27. *
  28. * @author Petr Skoda <skodak@moodle.org>
  29. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  30. */
  31. class graded_users_iterator {
  32. /**
  33. * The couse whose users we are interested in
  34. */
  35. protected $course;
  36. /**
  37. * An array of grade items or null if only user data was requested
  38. */
  39. protected $grade_items;
  40. /**
  41. * The group ID we are interested in. 0 means all groups.
  42. */
  43. protected $groupid;
  44. /**
  45. * A recordset of graded users
  46. */
  47. protected $users_rs;
  48. /**
  49. * A recordset of user grades (grade_grade instances)
  50. */
  51. protected $grades_rs;
  52. /**
  53. * Array used when moving to next user while iterating through the grades recordset
  54. */
  55. protected $gradestack;
  56. /**
  57. * The first field of the users table by which the array of users will be sorted
  58. */
  59. protected $sortfield1;
  60. /**
  61. * Should sortfield1 be ASC or DESC
  62. */
  63. protected $sortorder1;
  64. /**
  65. * The second field of the users table by which the array of users will be sorted
  66. */
  67. protected $sortfield2;
  68. /**
  69. * Should sortfield2 be ASC or DESC
  70. */
  71. protected $sortorder2;
  72. /**
  73. * Should users whose enrolment has been suspended be ignored?
  74. */
  75. protected $onlyactive = false;
  76. /**
  77. * Constructor
  78. *
  79. * @param object $course A course object
  80. * @param array $grade_items array of grade items, if not specified only user info returned
  81. * @param int $groupid iterate only group users if present
  82. * @param string $sortfield1 The first field of the users table by which the array of users will be sorted
  83. * @param string $sortorder1 The order in which the first sorting field will be sorted (ASC or DESC)
  84. * @param string $sortfield2 The second field of the users table by which the array of users will be sorted
  85. * @param string $sortorder2 The order in which the second sorting field will be sorted (ASC or DESC)
  86. */
  87. public function __construct($course, $grade_items=null, $groupid=0,
  88. $sortfield1='lastname', $sortorder1='ASC',
  89. $sortfield2='firstname', $sortorder2='ASC') {
  90. $this->course = $course;
  91. $this->grade_items = $grade_items;
  92. $this->groupid = $groupid;
  93. $this->sortfield1 = $sortfield1;
  94. $this->sortorder1 = $sortorder1;
  95. $this->sortfield2 = $sortfield2;
  96. $this->sortorder2 = $sortorder2;
  97. $this->gradestack = array();
  98. }
  99. /**
  100. * Initialise the iterator
  101. *
  102. * @return boolean success
  103. */
  104. public function init() {
  105. global $CFG, $DB;
  106. $this->close();
  107. grade_regrade_final_grades($this->course->id);
  108. $course_item = grade_item::fetch_course_item($this->course->id);
  109. if ($course_item->needsupdate) {
  110. // can not calculate all final grades - sorry
  111. return false;
  112. }
  113. $coursecontext = get_context_instance(CONTEXT_COURSE, $this->course->id);
  114. $relatedcontexts = get_related_contexts_string($coursecontext);
  115. list($gradebookroles_sql, $params) =
  116. $DB->get_in_or_equal(explode(',', $CFG->gradebookroles), SQL_PARAMS_NAMED, 'grbr');
  117. list($enrolledsql, $enrolledparams) = get_enrolled_sql($coursecontext, '', 0, $this->onlyactive);
  118. $params = array_merge($params, $enrolledparams);
  119. if ($this->groupid) {
  120. $groupsql = "INNER JOIN {groups_members} gm ON gm.userid = u.id";
  121. $groupwheresql = "AND gm.groupid = :groupid";
  122. // $params contents: gradebookroles
  123. $params['groupid'] = $this->groupid;
  124. } else {
  125. $groupsql = "";
  126. $groupwheresql = "";
  127. }
  128. if (empty($this->sortfield1)) {
  129. // we must do some sorting even if not specified
  130. $ofields = ", u.id AS usrt";
  131. $order = "usrt ASC";
  132. } else {
  133. $ofields = ", u.$this->sortfield1 AS usrt1";
  134. $order = "usrt1 $this->sortorder1";
  135. if (!empty($this->sortfield2)) {
  136. $ofields .= ", u.$this->sortfield2 AS usrt2";
  137. $order .= ", usrt2 $this->sortorder2";
  138. }
  139. if ($this->sortfield1 != 'id' and $this->sortfield2 != 'id') {
  140. // user order MUST be the same in both queries,
  141. // must include the only unique user->id if not already present
  142. $ofields .= ", u.id AS usrt";
  143. $order .= ", usrt ASC";
  144. }
  145. }
  146. // $params contents: gradebookroles and groupid (for $groupwheresql)
  147. $users_sql = "SELECT u.* $ofields
  148. FROM {user} u
  149. JOIN ($enrolledsql) je ON je.id = u.id
  150. $groupsql
  151. JOIN (
  152. SELECT DISTINCT ra.userid
  153. FROM {role_assignments} ra
  154. WHERE ra.roleid $gradebookroles_sql
  155. AND ra.contextid $relatedcontexts
  156. ) rainner ON rainner.userid = u.id
  157. WHERE u.deleted = 0
  158. $groupwheresql
  159. ORDER BY $order";
  160. $this->users_rs = $DB->get_recordset_sql($users_sql, $params);
  161. if (!empty($this->grade_items)) {
  162. $itemids = array_keys($this->grade_items);
  163. list($itemidsql, $grades_params) = $DB->get_in_or_equal($itemids, SQL_PARAMS_NAMED, 'items');
  164. $params = array_merge($params, $grades_params);
  165. // $params contents: gradebookroles, enrolledparams, groupid (for $groupwheresql) and itemids
  166. $grades_sql = "SELECT g.* $ofields
  167. FROM {grade_grades} g
  168. JOIN {user} u ON g.userid = u.id
  169. JOIN ($enrolledsql) je ON je.id = u.id
  170. $groupsql
  171. JOIN (
  172. SELECT DISTINCT ra.userid
  173. FROM {role_assignments} ra
  174. WHERE ra.roleid $gradebookroles_sql
  175. AND ra.contextid $relatedcontexts
  176. ) rainner ON rainner.userid = u.id
  177. WHERE u.deleted = 0
  178. AND g.itemid $itemidsql
  179. $groupwheresql
  180. ORDER BY $order, g.itemid ASC";
  181. $this->grades_rs = $DB->get_recordset_sql($grades_sql, $params);
  182. } else {
  183. $this->grades_rs = false;
  184. }
  185. return true;
  186. }
  187. /**
  188. * Returns information about the next user
  189. * @return mixed array of user info, all grades and feedback or null when no more users found
  190. */
  191. public function next_user() {
  192. if (!$this->users_rs) {
  193. return false; // no users present
  194. }
  195. if (!$this->users_rs->valid()) {
  196. if ($current = $this->_pop()) {
  197. // this is not good - user or grades updated between the two reads above :-(
  198. }
  199. return false; // no more users
  200. } else {
  201. $user = $this->users_rs->current();
  202. $this->users_rs->next();
  203. }
  204. // find grades of this user
  205. $grade_records = array();
  206. while (true) {
  207. if (!$current = $this->_pop()) {
  208. break; // no more grades
  209. }
  210. if (empty($current->userid)) {
  211. break;
  212. }
  213. if ($current->userid != $user->id) {
  214. // grade of the next user, we have all for this user
  215. $this->_push($current);
  216. break;
  217. }
  218. $grade_records[$current->itemid] = $current;
  219. }
  220. $grades = array();
  221. $feedbacks = array();
  222. if (!empty($this->grade_items)) {
  223. foreach ($this->grade_items as $grade_item) {
  224. if (!isset($feedbacks[$grade_item->id])) {
  225. $feedbacks[$grade_item->id] = new stdClass();
  226. }
  227. if (array_key_exists($grade_item->id, $grade_records)) {
  228. $feedbacks[$grade_item->id]->feedback = $grade_records[$grade_item->id]->feedback;
  229. $feedbacks[$grade_item->id]->feedbackformat = $grade_records[$grade_item->id]->feedbackformat;
  230. unset($grade_records[$grade_item->id]->feedback);
  231. unset($grade_records[$grade_item->id]->feedbackformat);
  232. $grades[$grade_item->id] = new grade_grade($grade_records[$grade_item->id], false);
  233. } else {
  234. $feedbacks[$grade_item->id]->feedback = '';
  235. $feedbacks[$grade_item->id]->feedbackformat = FORMAT_MOODLE;
  236. $grades[$grade_item->id] =
  237. new grade_grade(array('userid'=>$user->id, 'itemid'=>$grade_item->id), false);
  238. }
  239. }
  240. }
  241. $result = new stdClass();
  242. $result->user = $user;
  243. $result->grades = $grades;
  244. $result->feedbacks = $feedbacks;
  245. return $result;
  246. }
  247. /**
  248. * Close the iterator, do not forget to call this function
  249. */
  250. public function close() {
  251. if ($this->users_rs) {
  252. $this->users_rs->close();
  253. $this->users_rs = null;
  254. }
  255. if ($this->grades_rs) {
  256. $this->grades_rs->close();
  257. $this->grades_rs = null;
  258. }
  259. $this->gradestack = array();
  260. }
  261. /**
  262. * Should all enrolled users be exported or just those with an active enrolment?
  263. *
  264. * @param bool $onlyactive True to limit the export to users with an active enrolment
  265. */
  266. public function require_active_enrolment($onlyactive = true) {
  267. if (!empty($this->users_rs)) {
  268. debugging('Calling require_active_enrolment() has no effect unless you call init() again', DEBUG_DEVELOPER);
  269. }
  270. $this->onlyactive = $onlyactive;
  271. }
  272. /**
  273. * Add a grade_grade instance to the grade stack
  274. *
  275. * @param grade_grade $grade Grade object
  276. *
  277. * @return void
  278. */
  279. private function _push($grade) {
  280. array_push($this->gradestack, $grade);
  281. }
  282. /**
  283. * Remove a grade_grade instance from the grade stack
  284. *
  285. * @return grade_grade current grade object
  286. */
  287. private function _pop() {
  288. global $DB;
  289. if (empty($this->gradestack)) {
  290. if (empty($this->grades_rs) || !$this->grades_rs->valid()) {
  291. return null; // no grades present
  292. }
  293. $current = $this->grades_rs->current();
  294. $this->grades_rs->next();
  295. return $current;
  296. } else {
  297. return array_pop($this->gradestack);
  298. }
  299. }
  300. }
  301. /**
  302. * Print a selection popup form of the graded users in a course.
  303. *
  304. * @deprecated since 2.0
  305. *
  306. * @param int $course id of the course
  307. * @param string $actionpage The page receiving the data from the popoup form
  308. * @param int $userid id of the currently selected user (or 'all' if they are all selected)
  309. * @param int $groupid id of requested group, 0 means all
  310. * @param int $includeall bool include all option
  311. * @param bool $return If true, will return the HTML, otherwise, will print directly
  312. * @return null
  313. */
  314. function print_graded_users_selector($course, $actionpage, $userid=0, $groupid=0, $includeall=true, $return=false) {
  315. global $CFG, $USER, $OUTPUT;
  316. return $OUTPUT->render(grade_get_graded_users_select(substr($actionpage, 0, strpos($actionpage, '/')), $course, $userid, $groupid, $includeall));
  317. }
  318. function grade_get_graded_users_select($report, $course, $userid, $groupid, $includeall) {
  319. global $USER;
  320. if (is_null($userid)) {
  321. $userid = $USER->id;
  322. }
  323. $menu = array(); // Will be a list of userid => user name
  324. $gui = new graded_users_iterator($course, null, $groupid);
  325. $gui->init();
  326. $label = get_string('selectauser', 'grades');
  327. if ($includeall) {
  328. $menu[0] = get_string('allusers', 'grades');
  329. $label = get_string('selectalloroneuser', 'grades');
  330. }
  331. while ($userdata = $gui->next_user()) {
  332. $user = $userdata->user;
  333. $menu[$user->id] = fullname($user);
  334. }
  335. $gui->close();
  336. if ($includeall) {
  337. $menu[0] .= " (" . (count($menu) - 1) . ")";
  338. }
  339. $select = new single_select(new moodle_url('/grade/report/'.$report.'/index.php', array('id'=>$course->id)), 'userid', $menu, $userid);
  340. $select->label = $label;
  341. $select->formid = 'choosegradeuser';
  342. return $select;
  343. }
  344. /**
  345. * Print grading plugin selection popup form.
  346. *
  347. * @param array $plugin_info An array of plugins containing information for the selector
  348. * @param boolean $return return as string
  349. *
  350. * @return nothing or string if $return true
  351. */
  352. function print_grade_plugin_selector($plugin_info, $active_type, $active_plugin, $return=false) {
  353. global $CFG, $OUTPUT, $PAGE;
  354. $menu = array();
  355. $count = 0;
  356. $active = '';
  357. foreach ($plugin_info as $plugin_type => $plugins) {
  358. if ($plugin_type == 'strings') {
  359. continue;
  360. }
  361. $first_plugin = reset($plugins);
  362. $sectionname = $plugin_info['strings'][$plugin_type];
  363. $section = array();
  364. foreach ($plugins as $plugin) {
  365. $link = $plugin->link->out(false);
  366. $section[$link] = $plugin->string;
  367. $count++;
  368. if ($plugin_type === $active_type and $plugin->id === $active_plugin) {
  369. $active = $link;
  370. }
  371. }
  372. if ($section) {
  373. $menu[] = array($sectionname=>$section);
  374. }
  375. }
  376. // finally print/return the popup form
  377. if ($count > 1) {
  378. $select = new url_select($menu, $active, null, 'choosepluginreport');
  379. if ($return) {
  380. return $OUTPUT->render($select);
  381. } else {
  382. echo $OUTPUT->render($select);
  383. }
  384. } else {
  385. // only one option - no plugin selector needed
  386. return '';
  387. }
  388. }
  389. /**
  390. * Print grading plugin selection tab-based navigation.
  391. *
  392. * @param string $active_type type of plugin on current page - import, export, report or edit
  393. * @param string $active_plugin active plugin type - grader, user, cvs, ...
  394. * @param array $plugin_info Array of plugins
  395. * @param boolean $return return as string
  396. *
  397. * @return nothing or string if $return true
  398. */
  399. function grade_print_tabs($active_type, $active_plugin, $plugin_info, $return=false) {
  400. global $CFG, $COURSE;
  401. if (!isset($currenttab)) { //TODO: this is weird
  402. $currenttab = '';
  403. }
  404. $tabs = array();
  405. $top_row = array();
  406. $bottom_row = array();
  407. $inactive = array($active_plugin);
  408. $activated = array();
  409. $count = 0;
  410. $active = '';
  411. foreach ($plugin_info as $plugin_type => $plugins) {
  412. if ($plugin_type == 'strings') {
  413. continue;
  414. }
  415. // If $plugins is actually the definition of a child-less parent link:
  416. if (!empty($plugins->id)) {
  417. $string = $plugins->string;
  418. if (!empty($plugin_info[$active_type]->parent)) {
  419. $string = $plugin_info[$active_type]->parent->string;
  420. }
  421. $top_row[] = new tabobject($plugin_type, $plugins->link, $string);
  422. continue;
  423. }
  424. $first_plugin = reset($plugins);
  425. $url = $first_plugin->link;
  426. if ($plugin_type == 'report') {
  427. $url = $CFG->wwwroot.'/grade/report/index.php?id='.$COURSE->id;
  428. }
  429. $top_row[] = new tabobject($plugin_type, $url, $plugin_info['strings'][$plugin_type]);
  430. if ($active_type == $plugin_type) {
  431. foreach ($plugins as $plugin) {
  432. $bottom_row[] = new tabobject($plugin->id, $plugin->link, $plugin->string);
  433. if ($plugin->id == $active_plugin) {
  434. $inactive = array($plugin->id);
  435. }
  436. }
  437. }
  438. }
  439. $tabs[] = $top_row;
  440. $tabs[] = $bottom_row;
  441. if ($return) {
  442. return print_tabs($tabs, $active_type, $inactive, $activated, true);
  443. } else {
  444. print_tabs($tabs, $active_type, $inactive, $activated);
  445. }
  446. }
  447. /**
  448. * grade_get_plugin_info
  449. *
  450. * @param int $courseid The course id
  451. * @param string $active_type type of plugin on current page - import, export, report or edit
  452. * @param string $active_plugin active plugin type - grader, user, cvs, ...
  453. *
  454. * @return array
  455. */
  456. function grade_get_plugin_info($courseid, $active_type, $active_plugin) {
  457. global $CFG, $SITE;
  458. $context = get_context_instance(CONTEXT_COURSE, $courseid);
  459. $plugin_info = array();
  460. $count = 0;
  461. $active = '';
  462. $url_prefix = $CFG->wwwroot . '/grade/';
  463. // Language strings
  464. $plugin_info['strings'] = grade_helper::get_plugin_strings();
  465. if ($reports = grade_helper::get_plugins_reports($courseid)) {
  466. $plugin_info['report'] = $reports;
  467. }
  468. //showing grade categories and items make no sense if we're not within a course
  469. if ($courseid!=$SITE->id) {
  470. if ($edittree = grade_helper::get_info_edit_structure($courseid)) {
  471. $plugin_info['edittree'] = $edittree;
  472. }
  473. }
  474. if ($scale = grade_helper::get_info_scales($courseid)) {
  475. $plugin_info['scale'] = array('view'=>$scale);
  476. }
  477. if ($outcomes = grade_helper::get_info_outcomes($courseid)) {
  478. $plugin_info['outcome'] = $outcomes;
  479. }
  480. if ($letters = grade_helper::get_info_letters($courseid)) {
  481. $plugin_info['letter'] = $letters;
  482. }
  483. if ($imports = grade_helper::get_plugins_import($courseid)) {
  484. $plugin_info['import'] = $imports;
  485. }
  486. if ($exports = grade_helper::get_plugins_export($courseid)) {
  487. $plugin_info['export'] = $exports;
  488. }
  489. foreach ($plugin_info as $plugin_type => $plugins) {
  490. if (!empty($plugins->id) && $active_plugin == $plugins->id) {
  491. $plugin_info['strings']['active_plugin_str'] = $plugins->string;
  492. break;
  493. }
  494. foreach ($plugins as $plugin) {
  495. if (is_a($plugin, 'grade_plugin_info')) {
  496. if ($active_plugin == $plugin->id) {
  497. $plugin_info['strings']['active_plugin_str'] = $plugin->string;
  498. }
  499. }
  500. }
  501. }
  502. //hide course settings if we're not in a course
  503. if ($courseid!=$SITE->id) {
  504. if ($setting = grade_helper::get_info_manage_settings($courseid)) {
  505. $plugin_info['settings'] = array('course'=>$setting);
  506. }
  507. }
  508. // Put preferences last
  509. if ($preferences = grade_helper::get_plugins_report_preferences($courseid)) {
  510. $plugin_info['preferences'] = $preferences;
  511. }
  512. foreach ($plugin_info as $plugin_type => $plugins) {
  513. if (!empty($plugins->id) && $active_plugin == $plugins->id) {
  514. $plugin_info['strings']['active_plugin_str'] = $plugins->string;
  515. break;
  516. }
  517. foreach ($plugins as $plugin) {
  518. if (is_a($plugin, 'grade_plugin_info')) {
  519. if ($active_plugin == $plugin->id) {
  520. $plugin_info['strings']['active_plugin_str'] = $plugin->string;
  521. }
  522. }
  523. }
  524. }
  525. return $plugin_info;
  526. }
  527. /**
  528. * A simple class containing info about grade plugins.
  529. * Can be subclassed for special rules
  530. *
  531. * @package core_grades
  532. * @copyright 2009 Nicolas Connault
  533. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  534. */
  535. class grade_plugin_info {
  536. /**
  537. * A unique id for this plugin
  538. *
  539. * @var mixed
  540. */
  541. public $id;
  542. /**
  543. * A URL to access this plugin
  544. *
  545. * @var mixed
  546. */
  547. public $link;
  548. /**
  549. * The name of this plugin
  550. *
  551. * @var mixed
  552. */
  553. public $string;
  554. /**
  555. * Another grade_plugin_info object, parent of the current one
  556. *
  557. * @var mixed
  558. */
  559. public $parent;
  560. /**
  561. * Constructor
  562. *
  563. * @param int $id A unique id for this plugin
  564. * @param string $link A URL to access this plugin
  565. * @param string $string The name of this plugin
  566. * @param object $parent Another grade_plugin_info object, parent of the current one
  567. *
  568. * @return void
  569. */
  570. public function __construct($id, $link, $string, $parent=null) {
  571. $this->id = $id;
  572. $this->link = $link;
  573. $this->string = $string;
  574. $this->parent = $parent;
  575. }
  576. }
  577. /**
  578. * Prints the page headers, breadcrumb trail, page heading, (optional) dropdown navigation menu and
  579. * (optional) navigation tabs for any gradebook page. All gradebook pages MUST use these functions
  580. * in favour of the usual print_header(), print_header_simple(), print_heading() etc.
  581. * !IMPORTANT! Use of tabs.php file in gradebook pages is forbidden unless tabs are switched off at
  582. * the site level for the gradebook ($CFG->grade_navmethod = GRADE_NAVMETHOD_DROPDOWN).
  583. *
  584. * @param int $courseid Course id
  585. * @param string $active_type The type of the current page (report, settings,
  586. * import, export, scales, outcomes, letters)
  587. * @param string $active_plugin The plugin of the current page (grader, fullview etc...)
  588. * @param string $heading The heading of the page. Tries to guess if none is given
  589. * @param boolean $return Whether to return (true) or echo (false) the HTML generated by this function
  590. * @param string $bodytags Additional attributes that will be added to the <body> tag
  591. * @param string $buttons Additional buttons to display on the page
  592. * @param boolean $shownavigation should the gradebook navigation drop down (or tabs) be shown?
  593. *
  594. * @return string HTML code or nothing if $return == false
  595. */
  596. function print_grade_page_head($courseid, $active_type, $active_plugin=null,
  597. $heading = false, $return=false,
  598. $buttons=false, $shownavigation=true) {
  599. global $CFG, $OUTPUT, $PAGE;
  600. $plugin_info = grade_get_plugin_info($courseid, $active_type, $active_plugin);
  601. // Determine the string of the active plugin
  602. $stractive_plugin = ($active_plugin) ? $plugin_info['strings']['active_plugin_str'] : $heading;
  603. $stractive_type = $plugin_info['strings'][$active_type];
  604. if (empty($plugin_info[$active_type]->id) || !empty($plugin_info[$active_type]->parent)) {
  605. $title = $PAGE->course->fullname.': ' . $stractive_type . ': ' . $stractive_plugin;
  606. } else {
  607. $title = $PAGE->course->fullname.': ' . $stractive_plugin;
  608. }
  609. if ($active_type == 'report') {
  610. $PAGE->set_pagelayout('report');
  611. } else {
  612. $PAGE->set_pagelayout('admin');
  613. }
  614. $PAGE->set_title(get_string('grades') . ': ' . $stractive_type);
  615. $PAGE->set_heading($title);
  616. if ($buttons instanceof single_button) {
  617. $buttons = $OUTPUT->render($buttons);
  618. }
  619. $PAGE->set_button($buttons);
  620. grade_extend_settings($plugin_info, $courseid);
  621. $returnval = $OUTPUT->header();
  622. if (!$return) {
  623. echo $returnval;
  624. }
  625. // Guess heading if not given explicitly
  626. if (!$heading) {
  627. $heading = $stractive_plugin;
  628. }
  629. if ($shownavigation) {
  630. if ($CFG->grade_navmethod == GRADE_NAVMETHOD_COMBO || $CFG->grade_navmethod == GRADE_NAVMETHOD_DROPDOWN) {
  631. $returnval .= print_grade_plugin_selector($plugin_info, $active_type, $active_plugin, $return);
  632. }
  633. if ($return) {
  634. $returnval .= $OUTPUT->heading($heading);
  635. } else {
  636. echo $OUTPUT->heading($heading);
  637. }
  638. if ($CFG->grade_navmethod == GRADE_NAVMETHOD_COMBO || $CFG->grade_navmethod == GRADE_NAVMETHOD_TABS) {
  639. $returnval .= grade_print_tabs($active_type, $active_plugin, $plugin_info, $return);
  640. }
  641. }
  642. if ($return) {
  643. return $returnval;
  644. }
  645. }
  646. /**
  647. * Utility class used for return tracking when using edit and other forms in grade plugins
  648. *
  649. * @package core_grades
  650. * @copyright 2009 Nicolas Connault
  651. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  652. */
  653. class grade_plugin_return {
  654. public $type;
  655. public $plugin;
  656. public $courseid;
  657. public $userid;
  658. public $page;
  659. /**
  660. * Constructor
  661. *
  662. * @param array $params - associative array with return parameters, if null parameter are taken from _GET or _POST
  663. */
  664. public function grade_plugin_return($params = null) {
  665. if (empty($params)) {
  666. $this->type = optional_param('gpr_type', null, PARAM_SAFEDIR);
  667. $this->plugin = optional_param('gpr_plugin', null, PARAM_PLUGIN);
  668. $this->courseid = optional_param('gpr_courseid', null, PARAM_INT);
  669. $this->userid = optional_param('gpr_userid', null, PARAM_INT);
  670. $this->page = optional_param('gpr_page', null, PARAM_INT);
  671. } else {
  672. foreach ($params as $key=>$value) {
  673. if (property_exists($this, $key)) {
  674. $this->$key = $value;
  675. }
  676. }
  677. }
  678. }
  679. /**
  680. * Returns return parameters as options array suitable for buttons.
  681. * @return array options
  682. */
  683. public function get_options() {
  684. if (empty($this->type)) {
  685. return array();
  686. }
  687. $params = array();
  688. if (!empty($this->plugin)) {
  689. $params['plugin'] = $this->plugin;
  690. }
  691. if (!empty($this->courseid)) {
  692. $params['id'] = $this->courseid;
  693. }
  694. if (!empty($this->userid)) {
  695. $params['userid'] = $this->userid;
  696. }
  697. if (!empty($this->page)) {
  698. $params['page'] = $this->page;
  699. }
  700. return $params;
  701. }
  702. /**
  703. * Returns return url
  704. *
  705. * @param string $default default url when params not set
  706. * @param array $extras Extra URL parameters
  707. *
  708. * @return string url
  709. */
  710. public function get_return_url($default, $extras=null) {
  711. global $CFG;
  712. if (empty($this->type) or empty($this->plugin)) {
  713. return $default;
  714. }
  715. $url = $CFG->wwwroot.'/grade/'.$this->type.'/'.$this->plugin.'/index.php';
  716. $glue = '?';
  717. if (!empty($this->courseid)) {
  718. $url .= $glue.'id='.$this->courseid;
  719. $glue = '&amp;';
  720. }
  721. if (!empty($this->userid)) {
  722. $url .= $glue.'userid='.$this->userid;
  723. $glue = '&amp;';
  724. }
  725. if (!empty($this->page)) {
  726. $url .= $glue.'page='.$this->page;
  727. $glue = '&amp;';
  728. }
  729. if (!empty($extras)) {
  730. foreach ($extras as $key=>$value) {
  731. $url .= $glue.$key.'='.$value;
  732. $glue = '&amp;';
  733. }
  734. }
  735. return $url;
  736. }
  737. /**
  738. * Returns string with hidden return tracking form elements.
  739. * @return string
  740. */
  741. public function get_form_fields() {
  742. if (empty($this->type)) {
  743. return '';
  744. }
  745. $result = '<input type="hidden" name="gpr_type" value="'.$this->type.'" />';
  746. if (!empty($this->plugin)) {
  747. $result .= '<input type="hidden" name="gpr_plugin" value="'.$this->plugin.'" />';
  748. }
  749. if (!empty($this->courseid)) {
  750. $result .= '<input type="hidden" name="gpr_courseid" value="'.$this->courseid.'" />';
  751. }
  752. if (!empty($this->userid)) {
  753. $result .= '<input type="hidden" name="gpr_userid" value="'.$this->userid.'" />';
  754. }
  755. if (!empty($this->page)) {
  756. $result .= '<input type="hidden" name="gpr_page" value="'.$this->page.'" />';
  757. }
  758. }
  759. /**
  760. * Add hidden elements into mform
  761. *
  762. * @param object &$mform moodle form object
  763. *
  764. * @return void
  765. */
  766. public function add_mform_elements(&$mform) {
  767. if (empty($this->type)) {
  768. return;
  769. }
  770. $mform->addElement('hidden', 'gpr_type', $this->type);
  771. $mform->setType('gpr_type', PARAM_SAFEDIR);
  772. if (!empty($this->plugin)) {
  773. $mform->addElement('hidden', 'gpr_plugin', $this->plugin);
  774. $mform->setType('gpr_plugin', PARAM_PLUGIN);
  775. }
  776. if (!empty($this->courseid)) {
  777. $mform->addElement('hidden', 'gpr_courseid', $this->courseid);
  778. $mform->setType('gpr_courseid', PARAM_INT);
  779. }
  780. if (!empty($this->userid)) {
  781. $mform->addElement('hidden', 'gpr_userid', $this->userid);
  782. $mform->setType('gpr_userid', PARAM_INT);
  783. }
  784. if (!empty($this->page)) {
  785. $mform->addElement('hidden', 'gpr_page', $this->page);
  786. $mform->setType('gpr_page', PARAM_INT);
  787. }
  788. }
  789. /**
  790. * Add return tracking params into url
  791. *
  792. * @param moodle_url $url A URL
  793. *
  794. * @return string $url with return tracking params
  795. */
  796. public function add_url_params(moodle_url $url) {
  797. if (empty($this->type)) {
  798. return $url;
  799. }
  800. $url->param('gpr_type', $this->type);
  801. if (!empty($this->plugin)) {
  802. $url->param('gpr_plugin', $this->plugin);
  803. }
  804. if (!empty($this->courseid)) {
  805. $url->param('gpr_courseid' ,$this->courseid);
  806. }
  807. if (!empty($this->userid)) {
  808. $url->param('gpr_userid', $this->userid);
  809. }
  810. if (!empty($this->page)) {
  811. $url->param('gpr_page', $this->page);
  812. }
  813. return $url;
  814. }
  815. }
  816. /**
  817. * Function central to gradebook for building and printing the navigation (breadcrumb trail).
  818. *
  819. * @param string $path The path of the calling script (using __FILE__?)
  820. * @param string $pagename The language string to use as the last part of the navigation (non-link)
  821. * @param mixed $id Either a plain integer (assuming the key is 'id') or
  822. * an array of keys and values (e.g courseid => $courseid, itemid...)
  823. *
  824. * @return string
  825. */
  826. function grade_build_nav($path, $pagename=null, $id=null) {
  827. global $CFG, $COURSE, $PAGE;
  828. $strgrades = get_string('grades', 'grades');
  829. // Parse the path and build navlinks from its elements
  830. $dirroot_length = strlen($CFG->dirroot) + 1; // Add 1 for the first slash
  831. $path = substr($path, $dirroot_length);
  832. $path = str_replace('\\', '/', $path);
  833. $path_elements = explode('/', $path);
  834. $path_elements_count = count($path_elements);
  835. // First link is always 'grade'
  836. $PAGE->navbar->add($strgrades, new moodle_url('/grade/index.php', array('id'=>$COURSE->id)));
  837. $link = null;
  838. $numberofelements = 3;
  839. // Prepare URL params string
  840. $linkparams = array();
  841. if (!is_null($id)) {
  842. if (is_array($id)) {
  843. foreach ($id as $idkey => $idvalue) {
  844. $linkparams[$idkey] = $idvalue;
  845. }
  846. } else {
  847. $linkparams['id'] = $id;
  848. }
  849. }
  850. $navlink4 = null;
  851. // Remove file extensions from filenames
  852. foreach ($path_elements as $key => $filename) {
  853. $path_elements[$key] = str_replace('.php', '', $filename);
  854. }
  855. // Second level links
  856. switch ($path_elements[1]) {
  857. case 'edit': // No link
  858. if ($path_elements[3] != 'index.php') {
  859. $numberofelements = 4;
  860. }
  861. break;
  862. case 'import': // No link
  863. break;
  864. case 'export': // No link
  865. break;
  866. case 'report':
  867. // $id is required for this link. Do not print it if $id isn't given
  868. if (!is_null($id)) {
  869. $link = new moodle_url('/grade/report/index.php', $linkparams);
  870. }
  871. if ($path_elements[2] == 'grader') {
  872. $numberofelements = 4;
  873. }
  874. break;
  875. default:
  876. // If this element isn't among the ones already listed above, it isn't supported, throw an error.
  877. debugging("grade_build_nav() doesn't support ". $path_elements[1] .
  878. " as the second path element after 'grade'.");
  879. return false;
  880. }
  881. $PAGE->navbar->add(get_string($path_elements[1], 'grades'), $link);
  882. // Third level links
  883. if (empty($pagename)) {
  884. $pagename = get_string($path_elements[2], 'grades');
  885. }
  886. switch ($numberofelements) {
  887. case 3:
  888. $PAGE->navbar->add($pagename, $link);
  889. break;
  890. case 4:
  891. if ($path_elements[2] == 'grader' AND $path_elements[3] != 'index.php') {
  892. $PAGE->navbar->add(get_string('pluginname', 'gradereport_grader'), new moodle_url('/grade/report/grader/index.php', $linkparams));
  893. }
  894. $PAGE->navbar->add($pagename);
  895. break;
  896. }
  897. return '';
  898. }
  899. /**
  900. * General structure representing grade items in course
  901. *
  902. * @package core_grades
  903. * @copyright 2009 Nicolas Connault
  904. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  905. */
  906. class grade_structure {
  907. public $context;
  908. public $courseid;
  909. /**
  910. * Reference to modinfo for current course (for performance, to save
  911. * retrieving it from courseid every time). Not actually set except for
  912. * the grade_tree type.
  913. * @var course_modinfo
  914. */
  915. public $modinfo;
  916. /**
  917. * 1D array of grade items only
  918. */
  919. public $items;
  920. /**
  921. * Returns icon of element
  922. *
  923. * @param array &$element An array representing an element in the grade_tree
  924. * @param bool $spacerifnone return spacer if no icon found
  925. *
  926. * @return string icon or spacer
  927. */
  928. public function get_element_icon(&$element, $spacerifnone=false) {
  929. global $CFG, $OUTPUT;
  930. require_once $CFG->libdir.'/filelib.php';
  931. switch ($element['type']) {
  932. case 'item':
  933. case 'courseitem':
  934. case 'categoryitem':
  935. $is_course = $element['object']->is_course_item();
  936. $is_category = $element['object']->is_category_item();
  937. $is_scale = $element['object']->gradetype == GRADE_TYPE_SCALE;
  938. $is_value = $element['object']->gradetype == GRADE_TYPE_VALUE;
  939. $is_outcome = !empty($element['object']->outcomeid);
  940. if ($element['object']->is_calculated()) {
  941. $strcalc = get_string('calculatedgrade', 'grades');
  942. return '<img src="'.$OUTPUT->pix_url('i/calc') . '" class="icon itemicon" title="'.
  943. s($strcalc).'" alt="'.s($strcalc).'"/>';
  944. } else if (($is_course or $is_category) and ($is_scale or $is_value)) {
  945. if ($category = $element['object']->get_item_category()) {
  946. switch ($category->aggregation) {
  947. case GRADE_AGGREGATE_MEAN:
  948. case GRADE_AGGREGATE_MEDIAN:
  949. case GRADE_AGGREGATE_WEIGHTED_MEAN:
  950. case GRADE_AGGREGATE_WEIGHTED_MEAN2:
  951. case GRADE_AGGREGATE_EXTRACREDIT_MEAN:
  952. $stragg = get_string('aggregation', 'grades');
  953. return '<img src="'.$OUTPUT->pix_url('i/agg_mean') . '" ' .
  954. 'class="icon itemicon" title="'.s($stragg).'" alt="'.s($stragg).'"/>';
  955. case GRADE_AGGREGATE_SUM:
  956. $stragg = get_string('aggregation', 'grades');
  957. return '<img src="'.$OUTPUT->pix_url('i/agg_sum') . '" ' .
  958. 'class="icon itemicon" title="'.s($stragg).'" alt="'.s($stragg).'"/>';
  959. }
  960. }
  961. } else if ($element['object']->itemtype == 'mod') {
  962. //prevent outcomes being displaying the same icon as the activity they are attached to
  963. if ($is_outcome) {
  964. $stroutcome = s(get_string('outcome', 'grades'));
  965. return '<img src="'.$OUTPUT->pix_url('i/outcomes') . '" ' .
  966. 'class="icon itemicon" title="'.$stroutcome.
  967. '" alt="'.$stroutcome.'"/>';
  968. } else {
  969. $strmodname = get_string('modulename', $element['object']->itemmodule);
  970. return '<img src="'.$OUTPUT->pix_url('icon',
  971. $element['object']->itemmodule) . '" ' .
  972. 'class="icon itemicon" title="' .s($strmodname).
  973. '" alt="' .s($strmodname).'"/>';
  974. }
  975. } else if ($element['object']->itemtype == 'manual') {
  976. if ($element['object']->is_outcome_item()) {
  977. $stroutcome = get_string('outcome', 'grades');
  978. return '<img src="'.$OUTPUT->pix_url('i/outcomes') . '" ' .
  979. 'class="icon itemicon" title="'.s($stroutcome).
  980. '" alt="'.s($stroutcome).'"/>';
  981. } else {
  982. $strmanual = get_string('manualitem', 'grades');
  983. return '<img src="'.$OUTPUT->pix_url('t/manual_item') . '" '.
  984. 'class="icon itemicon" title="'.s($strmanual).
  985. '" alt="'.s($strmanual).'"/>';
  986. }
  987. }
  988. break;
  989. case 'category':
  990. $strcat = get_string('category', 'grades');
  991. return '<img src="'.$OUTPUT->pix_url(file_folder_icon()) . '" class="icon itemicon" ' .
  992. 'title="'.s($strcat).'" alt="'.s($strcat).'" />';
  993. }
  994. if ($spacerifnone) {
  995. return $OUTPUT->spacer().' ';
  996. } else {
  997. return '';
  998. }
  999. }
  1000. /**
  1001. * Returns name of element optionally with icon and link
  1002. *
  1003. * @param array &$element An array representing an element in the grade_tree
  1004. * @param bool $withlink Whether or not this header has a link
  1005. * @param bool $icon Whether or not to display an icon with this header
  1006. * @param bool $spacerifnone return spacer if no icon found
  1007. *
  1008. * @return string header
  1009. */
  1010. public function get_element_header(&$element, $withlink=false, $icon=true, $spacerifnone=false) {
  1011. $header = '';
  1012. if ($icon) {
  1013. $header .= $this->get_element_icon($element, $spacerifnone);
  1014. }
  1015. $header .= $element['object']->get_name();
  1016. if ($element['type'] != 'item' and $element['type'] != 'categoryitem' and
  1017. $element['type'] != 'courseitem') {
  1018. return $header;
  1019. }
  1020. if ($withlink) {
  1021. $url = $this->get_activity_link($element);
  1022. if ($url) {
  1023. $a = new stdClass();
  1024. $a->name = get_string('modulename', $element['object']->itemmodule);
  1025. $title = get_string('linktoactivity', 'grades', $a);
  1026. $header = html_writer::link($url, $header, array('title' => $title));
  1027. }
  1028. }
  1029. return $header;
  1030. }
  1031. private function get_activity_link($element) {
  1032. global $CFG;
  1033. /** @var array static cache of the grade.php file existence flags */
  1034. static $hasgradephp = array();
  1035. $itemtype = $element['object']->itemtype;
  1036. $itemmodule = $element['object']->itemmodule;
  1037. $iteminstance = $element['object']->iteminstance;
  1038. $itemnumber = $element['object']->itemnumber;
  1039. // Links only for module items that have valid instance, module and are
  1040. // called from grade_tree with valid modinfo
  1041. if ($itemtype != 'mod' || !$iteminstance || !$itemmodule || !$this->modinfo) {
  1042. return null;
  1043. }
  1044. // Get $cm efficiently and with visibility information using modinfo
  1045. $instances = $this->modinfo->get_instances();
  1046. if (empty($instances[$itemmodule][$iteminstance])) {
  1047. return null;
  1048. }
  1049. $cm = $instances[$itemmodule][$iteminstance];
  1050. // Do not add link if activity is not visible to the current user
  1051. if (!$cm->uservisible) {
  1052. return null;
  1053. }
  1054. if (!array_key_exists($itemmodule, $hasgradephp)) {
  1055. if (file_exists($CFG->dirroot . '/mod/' . $itemmodule . '/grade.php')) {
  1056. $hasgradephp[$itemmodule] = true;
  1057. } else {
  1058. $hasgradephp[$itemmodule] = false;
  1059. }
  1060. }
  1061. // If module has grade.php, link to that, otherwise view.php
  1062. if ($hasgradephp[$itemmodule]) {
  1063. $args = array('id' => $cm->id, 'itemnumber' => $itemnumber);
  1064. if (isset($element['userid'])) {
  1065. $args['userid'] = $element['userid'];
  1066. }
  1067. return new moodle_url('/mod/' . $itemmodule . '/grade.php', $args);
  1068. } else {
  1069. return new moodle_url('/mod/' . $itemmodule . '/view.php', array('id' => $cm->id));
  1070. }
  1071. }
  1072. /**
  1073. * Returns URL of a page that is supposed to contain detailed grade analysis
  1074. *
  1075. * At the moment, only activity modules are supported. The method generates link
  1076. * to the module's file grade.php with the parameters id (cmid), itemid, itemnumber,
  1077. * gradeid and userid. If the grade.php does not exist, null is returned.
  1078. *
  1079. * @return moodle_url|null URL or null if unable to construct it
  1080. */
  1081. public function get_grade_analysis_url(grade_grade $grade) {
  1082. global $CFG;
  1083. /** @var array static cache of the grade.php file existence flags */
  1084. static $hasgradephp = array();
  1085. if (empty($grade->grade_item) or !($grade->grade_item instanceof grade_item)) {
  1086. throw new coding_exception('Passed grade without the associated grade item');
  1087. }
  1088. $item = $grade->grade_item;
  1089. if (!$item->is_external_item()) {
  1090. // at the moment, only activity modules are supported
  1091. return null;
  1092. }
  1093. if ($item->itemtype !== 'mod') {
  1094. throw new coding_exception('Unknown external itemtype: '.$item->itemtype);
  1095. }
  1096. if (empty($item->iteminstance) or empty($item->itemmodule) or empty($this->modinfo)) {
  1097. return null;
  1098. }
  1099. if (!array_key_exists($item->itemmodule, $hasgradephp)) {
  1100. if (file_exists($CFG->dirroot . '/mod/' . $item->itemmodule . '/grade.php')) {
  1101. $hasgradephp[$item->itemmodule] = true;
  1102. } else {
  1103. $hasgradephp[$item->itemmodule] = false;
  1104. }
  1105. }
  1106. if (!$hasgradephp[$item->itemmodule]) {
  1107. return null;
  1108. }
  1109. $instances = $this->modinfo->get_instances();
  1110. if (empty($instances[$item->itemmodule][$item->iteminstance])) {
  1111. return null;
  1112. }
  1113. $cm = $instances[$item->itemmodule][$item->iteminstance];
  1114. if (!$cm->uservisible) {
  1115. return null;
  1116. }
  1117. $url = new moodle_url('/mod/'.$item->itemmodule.'/grade.php', array(
  1118. 'id' => $cm->id,
  1119. 'itemid' => $item->id,
  1120. 'itemnumber' => $item->itemnumber,
  1121. 'gradeid' => $grade->id,
  1122. 'userid' => $grade->userid,
  1123. ));
  1124. return $url;
  1125. }
  1126. /**
  1127. * Returns an action icon leading to the grade analysis page
  1128. *
  1129. * @param grade_grade $grade
  1130. * @return string
  1131. */
  1132. public function get_grade_analysis_icon(grade_grade $grade) {
  1133. global $OUTPUT;
  1134. $url = $this->get_grade_analysis_url($grade);
  1135. if (is_null($url)) {
  1136. return '';
  1137. }
  1138. return $OUTPUT->action_icon($url, new pix_icon('t/preview',
  1139. get_string('gradeanalysis', 'core_grades')));
  1140. }
  1141. /**
  1142. * Returns the grade eid - the grade may not exist yet.
  1143. *
  1144. * @param grade_grade $grade_grade A grade_grade object
  1145. *
  1146. * @return string eid
  1147. */
  1148. public function get_grade_eid($grade_grade) {
  1149. if (empty($grade_grade->id)) {
  1150. return 'n'.$grade_grade->itemid.'u'.$grade_grade->userid;
  1151. } else {
  1152. return 'g'.$grade_grade->id;
  1153. }
  1154. }
  1155. /**
  1156. * Returns the grade_item eid
  1157. * @param grade_item $grade_item A grade_item object
  1158. * @return string eid
  1159. */
  1160. public function get_item_eid($grade_item) {
  1161. return 'i'.$grade_item->id;
  1162. }
  1163. /**
  1164. * Given a grade_tree element, returns an array of parameters
  1165. * used to build an icon for that element.
  1166. *
  1167. * @param array $element An array representing an element in the grade_tree
  1168. *
  1169. * @return array
  1170. */
  1171. public function get_params_for_iconstr($element) {
  1172. $strparams = new stdClass();
  1173. $strparams->category = '';
  1174. $strparams->itemname = '';
  1175. $strparams->itemmodule = '';
  1176. if (!method_exists($element['object'], 'get_name')) {
  1177. return $strparams;
  1178. }
  1179. $strparams->itemname = html_to_text($element['object']->get_name());
  1180. // If element name is categorytotal, get the name of the parent category
  1181. if ($strparams->itemname == get_string('categorytotal', 'grades')) {
  1182. $parent = $element['object']->get_parent_category();
  1183. $strparams->category = $parent->get_name() . ' ';
  1184. } else {
  1185. $strparams->category = '';
  1186. }
  1187. $strparams->itemmodule = null;
  1188. if (isset($element['object']->itemmodule)) {
  1189. $strparams->itemmodule = $element['object']->itemmodule;
  1190. }
  1191. return $strparams;
  1192. }
  1193. /**
  1194. * Return edit icon for give element
  1195. *
  1196. * @param array $element An array representing an element in the grade_tree
  1197. * @param object $gpr A grade_plugin_return object
  1198. *
  1199. * @return string
  1200. */
  1201. public function get_edit_icon($element, $gpr) {
  1202. global $CFG, $OUTPUT;
  1203. if (!has_capability('moodle/grade:manage', $this->context)) {
  1204. if ($element['type'] == 'grade' and has_capability('moodle/grade:edit', $this->context)) {
  1205. // oki - let them override grade
  1206. } else {
  1207. return '';
  1208. }
  1209. }
  1210. static $strfeedback = null;
  1211. static $streditgrade = null;
  1212. if (is_null($streditgrade)) {
  1213. $streditgrade = get_string('editgrade', 'grades');
  1214. $strfeedback = get_string('feedback');
  1215. }
  1216. $strparams = $this->get_params_for_iconstr($element);
  1217. $object = $element['object'];
  1218. switch ($element['type']) {
  1219. case 'item':
  1220. case 'categoryitem':
  1221. case 'courseitem':
  1222. $stredit = get_string('editverbose', 'grades', $strparams);
  1223. if (empty($object->outcomeid) || empty($CFG->enableoutcomes)) {
  1224. $url = new moodle_url('/grade/edit/tree/item.php',
  1225. array('courseid' => $this->courseid, 'id' => $object->id));
  1226. } else {
  1227. $url = new moodle_url('/grade/edit/tree/outcomeitem.php',
  1228. array('courseid' => $this->courseid, 'id' => $object->id));
  1229. }
  1230. break;
  1231. case 'category':
  1232. $stredit = get_string('editverbose', 'grades', $strparams);
  1233. $url = new moodle_url('/grade/edit/tree/category.php',
  1234. array('courseid' => $this->courseid, 'id' => $object->id));
  1235. break;
  1236. case 'grade':
  1237. $stredit = $streditgrade;
  1238. if (empty($object->id)) {
  1239. $url = new moodle_url('/grade/edit/tree/grade.php',
  1240. array('courseid' => $this->courseid, 'itemid' => $object->itemid, 'userid' => $object->userid));
  1241. } else {
  1242. $url = new moodle_url('/grade/edit/tree/grade.php',
  1243. array('courseid' => $this->courseid, 'id' => $object->id));
  1244. }
  1245. if (!empty($object->feedback)) {
  1246. $feedback = addslashes_js(trim(format_string($object->feedback, $object->feedbackformat)));
  1247. }
  1248. break;
  1249. default:
  1250. $url = null;
  1251. }
  1252. if ($url) {
  1253. return $OUTPUT->action_icon($gpr->add_url_params($url), new pix_icon('t/edit', $stredit));
  1254. } else {
  1255. return '';
  1256. }
  1257. }
  1258. /**
  1259. * Return hiding icon for give element
  1260. *
  1261. * @param array $element An array r…

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