Search moodle.org's
Developer Documentation


  • Bug fixes for general core bugs in 2.8.x ended 9 November 2015 (12 months).
  • Bug fixes for security issues in 2.8.x ended 9 May 2016 (18 months).
  • minimum PHP 5.4.4 (always use latest PHP 5.4.x or 5.5.x on Windows - http://windows.php.net/download/), PHP 7 is NOT supported
  • Differences Between: [Versions 28 and 29] [Versions 28 and 30] [Versions 28 and 31] [Versions 28 and 32] [Versions 28 and 33] [Versions 28 and 34] [Versions 28 and 35] [Versions 28 and 36] [Versions 28 and 37]

       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  /**
      18   * This file contains the definition for the grading table which subclassses easy_table
      19   *
      20   * @package   mod_assign
      21   * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
      22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
      23   */
      24  
      25  defined('MOODLE_INTERNAL') || die();
      26  
      27  require_once($CFG->libdir.'/tablelib.php');
      28  require_once($CFG->libdir.'/gradelib.php');
      29  require_once($CFG->dirroot.'/mod/assign/locallib.php');
      30  
      31  /**
      32   * Extends table_sql to provide a table of assignment submissions
      33   *
      34   * @package   mod_assign
      35   * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
      36   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
      37   */
      38  class assign_grading_table extends table_sql implements renderable {
      39      /** @var assign $assignment */
      40      private $assignment = null;
      41      /** @var int $perpage */
      42      private $perpage = 10;
      43      /** @var int $rownum (global index of current row in table) */
      44      private $rownum = -1;
      45      /** @var renderer_base for getting output */
      46      private $output = null;
      47      /** @var stdClass gradinginfo */
      48      private $gradinginfo = null;
      49      /** @var int $tablemaxrows */
      50      private $tablemaxrows = 10000;
      51      /** @var boolean $quickgrading */
      52      private $quickgrading = false;
      53      /** @var boolean $hasgrantextension - Only do the capability check once for the entire table */
      54      private $hasgrantextension = false;
      55      /** @var boolean $hasgrade - Only do the capability check once for the entire table */
      56      private $hasgrade = false;
      57      /** @var array $groupsubmissions - A static cache of group submissions */
      58      private $groupsubmissions = array();
      59      /** @var array $submissiongroups - A static cache of submission groups */
      60      private $submissiongroups = array();
      61      /** @var string $plugingradingbatchoperations - List of plugin supported batch operations */
      62      public $plugingradingbatchoperations = array();
      63      /** @var array $plugincache - A cache of plugin lookups to match a column name to a plugin efficiently */
      64      private $plugincache = array();
      65      /** @var array $scale - A list of the keys and descriptions for the custom scale */
      66      private $scale = null;
      67  
      68      /**
      69       * overridden constructor keeps a reference to the assignment class that is displaying this table
      70       *
      71       * @param assign $assignment The assignment class
      72       * @param int $perpage how many per page
      73       * @param string $filter The current filter
      74       * @param int $rowoffset For showing a subsequent page of results
      75       * @param bool $quickgrading Is this table wrapped in a quickgrading form?
      76       * @param string $downloadfilename
      77       */
      78      public function __construct(assign $assignment,
      79                                  $perpage,
      80                                  $filter,
      81                                  $rowoffset,
      82                                  $quickgrading,
      83                                  $downloadfilename = null) {
      84          global $CFG, $PAGE, $DB, $USER;
      85          parent::__construct('mod_assign_grading');
      86          $this->assignment = $assignment;
      87  
      88          // Check permissions up front.
      89          $this->hasgrantextension = has_capability('mod/assign:grantextension',
      90                                                    $this->assignment->get_context());
      91          $this->hasgrade = $this->assignment->can_grade();
      92  
      93          // Check if we have the elevated view capablities to see the blind details.
      94          $this->hasviewblind = has_capability('mod/assign:viewblinddetails',
      95                  $this->assignment->get_context());
      96  
      97          foreach ($assignment->get_feedback_plugins() as $plugin) {
      98              if ($plugin->is_visible() && $plugin->is_enabled()) {
      99                  foreach ($plugin->get_grading_batch_operations() as $action => $description) {
     100                      if (empty($this->plugingradingbatchoperations)) {
     101                          $this->plugingradingbatchoperations[$plugin->get_type()] = array();
     102                      }
     103                      $this->plugingradingbatchoperations[$plugin->get_type()][$action] = $description;
     104                  }
     105              }
     106          }
     107          $this->perpage = $perpage;
     108          $this->quickgrading = $quickgrading && $this->hasgrade;
     109          $this->output = $PAGE->get_renderer('mod_assign');
     110  
     111          $urlparams = array('action'=>'grading', 'id'=>$assignment->get_course_module()->id);
     112          $url = new moodle_url($CFG->wwwroot . '/mod/assign/view.php', $urlparams);
     113          $this->define_baseurl($url);
     114  
     115          // Do some business - then set the sql.
     116          $currentgroup = groups_get_activity_group($assignment->get_course_module(), true);
     117  
     118          if ($rowoffset) {
     119              $this->rownum = $rowoffset - 1;
     120          }
     121  
     122          $users = array_keys( $assignment->list_participants($currentgroup, true));
     123          if (count($users) == 0) {
     124              // Insert a record that will never match to the sql is still valid.
     125              $users[] = -1;
     126          }
     127  
     128          $params = array();
     129          $params['assignmentid1'] = (int)$this->assignment->get_instance()->id;
     130          $params['assignmentid2'] = (int)$this->assignment->get_instance()->id;
     131          $params['assignmentid3'] = (int)$this->assignment->get_instance()->id;
     132  
     133          $extrauserfields = get_extra_user_fields($this->assignment->get_context());
     134  
     135          $fields = user_picture::fields('u', $extrauserfields) . ', ';
     136          $fields .= 'u.id as userid, ';
     137          $fields .= 's.status as status, ';
     138          $fields .= 's.id as submissionid, ';
     139          $fields .= 's.timecreated as firstsubmission, ';
     140          $fields .= 's.timemodified as timesubmitted, ';
     141          $fields .= 's.attemptnumber as attemptnumber, ';
     142          $fields .= 'g.id as gradeid, ';
     143          $fields .= 'g.grade as grade, ';
     144          $fields .= 'g.timemodified as timemarked, ';
     145          $fields .= 'g.timecreated as firstmarked, ';
     146          $fields .= 'uf.mailed as mailed, ';
     147          $fields .= 'uf.locked as locked, ';
     148          $fields .= 'uf.extensionduedate as extensionduedate, ';
     149          $fields .= 'uf.workflowstate as workflowstate, ';
     150          $fields .= 'uf.allocatedmarker as allocatedmarker ';
     151  
     152          $from = '{user} u
     153                           LEFT JOIN {assign_submission} s
     154                                  ON u.id = s.userid
     155                                 AND s.assignment = :assignmentid1
     156                                 AND s.latest = 1
     157                           LEFT JOIN {assign_grades} g
     158                                  ON u.id = g.userid
     159                                 AND g.assignment = :assignmentid2 ';
     160  
     161          // For group submissions we don't immediately create an entry in the assign_submission table for each user,
     162          // instead the userid is set to 0. In this case we use a different query to retrieve the grade for the user.
     163          if ($this->assignment->get_instance()->teamsubmission) {
     164              $params['assignmentid4'] = (int) $this->assignment->get_instance()->id;
     165              $grademaxattempt = 'SELECT mxg.userid, MAX(mxg.attemptnumber) AS maxattempt
     166                                    FROM {assign_grades} mxg
     167                                   WHERE mxg.assignment = :assignmentid4
     168                                GROUP BY mxg.userid';
     169              $from .= 'LEFT JOIN (' . $grademaxattempt . ') gmx
     170                               ON u.id = gmx.userid
     171                              AND g.attemptnumber = gmx.maxattempt ';
     172          } else {
     173              $from .= 'AND g.attemptnumber = s.attemptnumber ';
     174          }
     175  
     176          $from .= 'LEFT JOIN {assign_user_flags} uf
     177                           ON u.id = uf.userid
     178                          AND uf.assignment = :assignmentid3';
     179  
     180          $userparams = array();
     181          $userindex = 0;
     182  
     183          list($userwhere, $userparams) = $DB->get_in_or_equal($users, SQL_PARAMS_NAMED, 'user');
     184          $where = 'u.id ' . $userwhere;
     185          $params = array_merge($params, $userparams);
     186  
     187          // The filters do not make sense when there are no submissions, so do not apply them.
     188          if ($this->assignment->is_any_submission_plugin_enabled()) {
     189              if ($filter == ASSIGN_FILTER_SUBMITTED) {
     190                  $where .= ' AND (s.timemodified IS NOT NULL AND
     191                                   s.status = :submitted) ';
     192                  $params['submitted'] = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
     193  
     194              } else if ($filter == ASSIGN_FILTER_NOT_SUBMITTED) {
     195                  $where .= ' AND (s.timemodified IS NULL OR s.status != :submitted) ';
     196                  $params['submitted'] = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
     197              } else if ($filter == ASSIGN_FILTER_REQUIRE_GRADING) {
     198                  $where .= ' AND (s.timemodified IS NOT NULL AND
     199                                   s.status = :submitted AND
     200                                   (s.timemodified >= g.timemodified OR g.timemodified IS NULL OR g.grade IS NULL))';
     201                  $params['submitted'] = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
     202  
     203              } else if (strpos($filter, ASSIGN_FILTER_SINGLE_USER) === 0) {
     204                  $userfilter = (int) array_pop(explode('=', $filter));
     205                  $where .= ' AND (u.id = :userid)';
     206                  $params['userid'] = $userfilter;
     207              }
     208          }
     209  
     210          if ($this->assignment->get_instance()->markingworkflow &&
     211              $this->assignment->get_instance()->markingallocation) {
     212              if (has_capability('mod/assign:manageallocations', $this->assignment->get_context())) {
     213                  // Check to see if marker filter is set.
     214                  $markerfilter = (int)get_user_preferences('assign_markerfilter', '');
     215                  if (!empty($markerfilter)) {
     216                      if ($markerfilter == ASSIGN_MARKER_FILTER_NO_MARKER) {
     217                          $where .= ' AND (uf.allocatedmarker IS NULL OR uf.allocatedmarker = 0)';
     218                      } else {
     219                          $where .= ' AND uf.allocatedmarker = :markerid';
     220                          $params['markerid'] = $markerfilter;
     221                      }
     222                  }
     223              } else { // Only show users allocated to this marker.
     224                  $where .= ' AND uf.allocatedmarker = :markerid';
     225                  $params['markerid'] = $USER->id;
     226              }
     227          }
     228  
     229          if ($this->assignment->get_instance()->markingworkflow) {
     230              $workflowstates = $this->assignment->get_marking_workflow_states_for_current_user();
     231              if (!empty($workflowstates)) {
     232                  $workflowfilter = get_user_preferences('assign_workflowfilter', '');
     233                  if ($workflowfilter == ASSIGN_MARKING_WORKFLOW_STATE_NOTMARKED) {
     234                      $where .= ' AND (uf.workflowstate = :workflowstate OR uf.workflowstate IS NULL OR '.
     235                          $DB->sql_isempty('assign_user_flags', 'workflowstate', true, true).')';
     236                      $params['workflowstate'] = $workflowfilter;
     237                  } else if (array_key_exists($workflowfilter, $workflowstates)) {
     238                      $where .= ' AND uf.workflowstate = :workflowstate';
     239                      $params['workflowstate'] = $workflowfilter;
     240                  }
     241              }
     242          }
     243  
     244          $this->set_sql($fields, $from, $where, $params);
     245  
     246          if ($downloadfilename) {
     247              $this->is_downloading('csv', $downloadfilename);
     248          }
     249  
     250          $columns = array();
     251          $headers = array();
     252  
     253          // Select.
     254          if (!$this->is_downloading() && $this->hasgrade) {
     255              $columns[] = 'select';
     256              $headers[] = get_string('select') .
     257                      '<div class="selectall"><label class="accesshide" for="selectall">' . get_string('selectall') . '</label>
     258                      <input type="checkbox" id="selectall" name="selectall" title="' . get_string('selectall') . '"/></div>';
     259          }
     260  
     261          // User picture.
     262          if ($this->hasviewblind || !$this->assignment->is_blind_marking()) {
     263              if (!$this->is_downloading()) {
     264                  $columns[] = 'picture';
     265                  $headers[] = get_string('pictureofuser');
     266              } else {
     267                  $columns[] = 'recordid';
     268                  $headers[] = get_string('recordid', 'assign');
     269              }
     270  
     271              // Fullname.
     272              $columns[] = 'fullname';
     273              $headers[] = get_string('fullname');
     274  
     275              foreach ($extrauserfields as $extrafield) {
     276                  $columns[] = $extrafield;
     277                  $headers[] = get_user_field_name($extrafield);
     278              }
     279          } else {
     280              // Record ID.
     281              $columns[] = 'recordid';
     282              $headers[] = get_string('recordid', 'assign');
     283          }
     284  
     285          // Submission status.
     286          if ($assignment->is_any_submission_plugin_enabled()) {
     287              $columns[] = 'status';
     288              $headers[] = get_string('status', 'assign');
     289          } else if ($this->assignment->get_instance()->markingworkflow) {
     290              $columns[] = 'workflowstate';
     291              $headers[] = get_string('status', 'assign');
     292          }
     293  
     294          // Team submission columns.
     295          if ($assignment->get_instance()->teamsubmission) {
     296              $columns[] = 'team';
     297              $headers[] = get_string('submissionteam', 'assign');
     298          }
     299          // Allocated marker.
     300          if ($this->assignment->get_instance()->markingworkflow &&
     301              $this->assignment->get_instance()->markingallocation &&
     302              has_capability('mod/assign:manageallocations', $this->assignment->get_context())) {
     303              // Add a column for the allocated marker.
     304              $columns[] = 'allocatedmarker';
     305              $headers[] = get_string('marker', 'assign');
     306          }
     307          // Grade.
     308          $columns[] = 'grade';
     309          $headers[] = get_string('grade');
     310          if ($this->is_downloading()) {
     311              if ($this->assignment->get_instance()->grade >= 0) {
     312                  $columns[] = 'grademax';
     313                  $headers[] = get_string('maxgrade', 'assign');
     314              } else {
     315                  // This is a custom scale.
     316                  $columns[] = 'scale';
     317                  $headers[] = get_string('scale', 'assign');
     318              }
     319  
     320              if ($this->assignment->get_instance()->markingworkflow) {
     321                  // Add a column for the marking workflow state.
     322                  $columns[] = 'workflowstate';
     323                  $headers[] = get_string('markingworkflowstate', 'assign');
     324              }
     325              // Add a column for the list of valid marking workflow states.
     326              $columns[] = 'gradecanbechanged';
     327              $headers[] = get_string('gradecanbechanged', 'assign');
     328          }
     329          if (!$this->is_downloading() && $this->hasgrade) {
     330              // We have to call this column userid so we can use userid as a default sortable column.
     331              $columns[] = 'userid';
     332              $headers[] = get_string('edit');
     333          }
     334  
     335          // Submission plugins.
     336          if ($assignment->is_any_submission_plugin_enabled()) {
     337              $columns[] = 'timesubmitted';
     338              $headers[] = get_string('lastmodifiedsubmission', 'assign');
     339  
     340              foreach ($this->assignment->get_submission_plugins() as $plugin) {
     341                  if ($this->is_downloading()) {
     342                      if ($plugin->is_visible() && $plugin->is_enabled()) {
     343                          foreach ($plugin->get_editor_fields() as $field => $description) {
     344                              $index = 'plugin' . count($this->plugincache);
     345                              $this->plugincache[$index] = array($plugin, $field);
     346                              $columns[] = $index;
     347                              $headers[] = $plugin->get_name();
     348                          }
     349                      }
     350                  } else {
     351                      if ($plugin->is_visible() && $plugin->is_enabled() && $plugin->has_user_summary()) {
     352                          $index = 'plugin' . count($this->plugincache);
     353                          $this->plugincache[$index] = array($plugin);
     354                          $columns[] = $index;
     355                          $headers[] = $plugin->get_name();
     356                      }
     357                  }
     358              }
     359          }
     360  
     361          // Time marked.
     362          $columns[] = 'timemarked';
     363          $headers[] = get_string('lastmodifiedgrade', 'assign');
     364  
     365          // Feedback plugins.
     366          foreach ($this->assignment->get_feedback_plugins() as $plugin) {
     367              if ($this->is_downloading()) {
     368                  if ($plugin->is_visible() && $plugin->is_enabled()) {
     369                      foreach ($plugin->get_editor_fields() as $field => $description) {
     370                          $index = 'plugin' . count($this->plugincache);
     371                          $this->plugincache[$index] = array($plugin, $field);
     372                          $columns[] = $index;
     373                          $headers[] = $description;
     374                      }
     375                  }
     376              } else if ($plugin->is_visible() && $plugin->is_enabled() && $plugin->has_user_summary()) {
     377                  $index = 'plugin' . count($this->plugincache);
     378                  $this->plugincache[$index] = array($plugin);
     379                  $columns[] = $index;
     380                  $headers[] = $plugin->get_name();
     381              }
     382          }
     383  
     384          // Exclude 'Final grade' column in downloaded grading worksheets.
     385          if (!$this->is_downloading()) {
     386              // Final grade.
     387              $columns[] = 'finalgrade';
     388              $headers[] = get_string('finalgrade', 'grades');
     389          }
     390  
     391          // Load the grading info for all users.
     392          $this->gradinginfo = grade_get_grades($this->assignment->get_course()->id,
     393                                                'mod',
     394                                                'assign',
     395                                                $this->assignment->get_instance()->id,
     396                                                $users);
     397  
     398          if (!empty($CFG->enableoutcomes) && !empty($this->gradinginfo->outcomes)) {
     399              $columns[] = 'outcomes';
     400              $headers[] = get_string('outcomes', 'grades');
     401          }
     402  
     403          // Set the columns.
     404          $this->define_columns($columns);
     405          $this->define_headers($headers);
     406          foreach ($extrauserfields as $extrafield) {
     407               $this->column_class($extrafield, $extrafield);
     408          }
     409          $this->no_sorting('recordid');
     410          $this->no_sorting('finalgrade');
     411          $this->no_sorting('userid');
     412          $this->no_sorting('select');
     413          $this->no_sorting('outcomes');
     414  
     415          if ($assignment->get_instance()->teamsubmission) {
     416              $this->no_sorting('team');
     417          }
     418  
     419          $plugincolumnindex = 0;
     420          foreach ($this->assignment->get_submission_plugins() as $plugin) {
     421              if ($plugin->is_visible() && $plugin->is_enabled() && $plugin->has_user_summary()) {
     422                  $submissionpluginindex = 'plugin' . $plugincolumnindex++;
     423                  $this->no_sorting($submissionpluginindex);
     424              }
     425          }
     426          foreach ($this->assignment->get_feedback_plugins() as $plugin) {
     427              if ($plugin->is_visible() && $plugin->is_enabled() && $plugin->has_user_summary()) {
     428                  $feedbackpluginindex = 'plugin' . $plugincolumnindex++;
     429                  $this->no_sorting($feedbackpluginindex);
     430              }
     431          }
     432  
     433          // When there is no data we still want the column headers printed in the csv file.
     434          if ($this->is_downloading()) {
     435              $this->start_output();
     436          }
     437      }
     438  
     439      /**
     440       * Before adding each row to the table make sure rownum is incremented.
     441       *
     442       * @param array $row row of data from db used to make one row of the table.
     443       * @return array one row for the table
     444       */
     445      public function format_row($row) {
     446          if ($this->rownum < 0) {
     447              $this->rownum = $this->currpage * $this->pagesize;
     448          } else {
     449              $this->rownum += 1;
     450          }
     451  
     452          return parent::format_row($row);
     453      }
     454  
     455      /**
     456       * Add a column with an ID that uniquely identifies this user in this assignment.
     457       *
     458       * @param stdClass $row
     459       * @return string
     460       */
     461      public function col_recordid(stdClass $row) {
     462          return get_string('hiddenuser', 'assign') .
     463                 $this->assignment->get_uniqueid_for_user($row->userid);
     464      }
     465  
     466  
     467      /**
     468       * Add the userid to the row class so it can be updated via ajax.
     469       *
     470       * @param stdClass $row The row of data
     471       * @return string The row class
     472       */
     473      public function get_row_class($row) {
     474          return 'user' . $row->userid;
     475      }
     476  
     477      /**
     478       * Return the number of rows to display on a single page.
     479       *
     480       * @return int The number of rows per page
     481       */
     482      public function get_rows_per_page() {
     483          return $this->perpage;
     484      }
     485  
     486      /**
     487       * list current marking workflow state
     488       *
     489       * @param stdClass $row
     490       * @return string
     491       */
     492      public function col_workflowstatus(stdClass $row) {
     493          $o = '';
     494  
     495          $gradingdisabled = $this->assignment->grading_disabled($row->id);
     496          // The function in the assignment keeps a static cache of this list of states.
     497          $workflowstates = $this->assignment->get_marking_workflow_states_for_current_user();
     498          $workflowstate = $row->workflowstate;
     499          if (empty($workflowstate)) {
     500              $workflowstate = ASSIGN_MARKING_WORKFLOW_STATE_NOTMARKED;
     501          }
     502          if ($this->quickgrading && !$gradingdisabled) {
     503              $notmarked = get_string('markingworkflowstatenotmarked', 'assign');
     504              $name = 'quickgrade_' . $row->id . '_workflowstate';
     505              $o .= html_writer::select($workflowstates, $name, $workflowstate, array('' => $notmarked));
     506              // Check if this user is a marker that can't manage allocations and doesn't have the marker column added.
     507              if ($this->assignment->get_instance()->markingworkflow &&
     508                  $this->assignment->get_instance()->markingallocation &&
     509                  !has_capability('mod/assign:manageallocations', $this->assignment->get_context())) {
     510  
     511                  $name = 'quickgrade_' . $row->id . '_allocatedmarker';
     512                  $o .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $name,
     513                          'value' => $row->allocatedmarker));
     514              }
     515          } else {
     516              $o .= $this->output->container(get_string('markingworkflowstate' . $workflowstate, 'assign'), $workflowstate);
     517          }
     518          return $o;
     519      }
     520  
     521      /**
     522       * For download only - list current marking workflow state
     523       *
     524       * @param stdClass $row - The row of data
     525       * @return string The current marking workflow state
     526       */
     527      public function col_workflowstate($row) {
     528          $state = $row->workflowstate;
     529          if (empty($state)) {
     530              $state = ASSIGN_MARKING_WORKFLOW_STATE_NOTMARKED;
     531          }
     532  
     533          return get_string('markingworkflowstate' . $state, 'assign');
     534      }
     535  
     536      /**
     537       * list current marker
     538       *
     539       * @param stdClass $row - The row of data
     540       * @return id the user->id of the marker.
     541       */
     542      public function col_allocatedmarker(stdClass $row) {
     543          static $markers = null;
     544          static $markerlist = array();
     545          if ($markers === null) {
     546              list($sort, $params) = users_order_by_sql();
     547              $markers = get_users_by_capability($this->assignment->get_context(), 'mod/assign:grade', '', $sort);
     548              $markerlist[0] = get_string('choosemarker', 'assign');
     549              foreach ($markers as $marker) {
     550                  $markerlist[$marker->id] = fullname($marker);
     551              }
     552          }
     553          if (empty($markerlist)) {
     554              // TODO: add some form of notification here that no markers are available.
     555              return '';
     556          }
     557          if ($this->is_downloading()) {
     558              if (isset($markers[$row->allocatedmarker])) {
     559                  return fullname($markers[$row->allocatedmarker]);
     560              } else {
     561                  return '';
     562              }
     563          }
     564  
     565          if ($this->quickgrading && has_capability('mod/assign:manageallocations', $this->assignment->get_context()) &&
     566              (empty($row->workflowstate) ||
     567               $row->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_INMARKING ||
     568               $row->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_NOTMARKED)) {
     569  
     570              $name = 'quickgrade_' . $row->id . '_allocatedmarker';
     571              return  html_writer::select($markerlist, $name, $row->allocatedmarker, false);
     572          } else if (!empty($row->allocatedmarker)) {
     573              $output = '';
     574              if ($this->quickgrading) { // Add hidden field for quickgrading page.
     575                  $name = 'quickgrade_' . $row->id . '_allocatedmarker';
     576                  $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>$name, 'value'=>$row->allocatedmarker));
     577              }
     578              $output .= $markerlist[$row->allocatedmarker];
     579              return $output;
     580          }
     581      }
     582      /**
     583       * For download only - list all the valid options for this custom scale.
     584       *
     585       * @param stdClass $row - The row of data
     586       * @return string A list of valid options for the current scale
     587       */
     588      public function col_scale($row) {
     589          global $DB;
     590  
     591          if (empty($this->scale)) {
     592              $dbparams = array('id'=>-($this->assignment->get_instance()->grade));
     593              $this->scale = $DB->get_record('scale', $dbparams);
     594          }
     595  
     596          if (!empty($this->scale->scale)) {
     597              return implode("\n", explode(',', $this->scale->scale));
     598          }
     599          return '';
     600      }
     601  
     602      /**
     603       * Display a grade with scales etc.
     604       *
     605       * @param string $grade
     606       * @param boolean $editable
     607       * @param int $userid The user id of the user this grade belongs to
     608       * @param int $modified Timestamp showing when the grade was last modified
     609       * @return string The formatted grade
     610       */
     611      public function display_grade($grade, $editable, $userid, $modified) {
     612          if ($this->is_downloading()) {
     613              if ($this->assignment->get_instance()->grade >= 0) {
     614                  if ($grade == -1 || $grade === null) {
     615                      return '';
     616                  }
     617                  return format_float($grade, 2);
     618              } else {
     619                  // This is a custom scale.
     620                  $scale = $this->assignment->display_grade($grade, false);
     621                  if ($scale == '-') {
     622                      $scale = '';
     623                  }
     624                  return $scale;
     625              }
     626          }
     627          return $this->assignment->display_grade($grade, $editable, $userid, $modified);
     628      }
     629  
     630      /**
     631       * Get the team info for this user.
     632       *
     633       * @param stdClass $row
     634       * @return string The team name
     635       */
     636      public function col_team(stdClass $row) {
     637          $submission = false;
     638          $group = false;
     639          $this->get_group_and_submission($row->id, $group, $submission, -1);
     640          if ($group) {
     641              return $group->name;
     642          }
     643          return get_string('defaultteam', 'assign');
     644      }
     645  
     646      /**
     647       * Use a static cache to try and reduce DB calls.
     648       *
     649       * @param int $userid The user id for this submission
     650       * @param int $group The groupid (returned)
     651       * @param stdClass|false $submission The stdClass submission or false (returned)
     652       * @param int $attemptnumber Return a specific attempt number (-1 for latest)
     653       */
     654      protected function get_group_and_submission($userid, &$group, &$submission, $attemptnumber) {
     655          $group = false;
     656          if (isset($this->submissiongroups[$userid])) {
     657              $group = $this->submissiongroups[$userid];
     658          } else {
     659              $group = $this->assignment->get_submission_group($userid, false);
     660              $this->submissiongroups[$userid] = $group;
     661          }
     662  
     663          $groupid = 0;
     664          if ($group) {
     665              $groupid = $group->id;
     666          }
     667  
     668          // Static cache is keyed by groupid and attemptnumber.
     669          // We may need both the latest and previous attempt in the same page.
     670          if (isset($this->groupsubmissions[$groupid . ':' . $attemptnumber])) {
     671              $submission = $this->groupsubmissions[$groupid . ':' . $attemptnumber];
     672          } else {
     673              $submission = $this->assignment->get_group_submission($userid, $groupid, false, $attemptnumber);
     674              $this->groupsubmissions[$groupid . ':' . $attemptnumber] = $submission;
     675          }
     676      }
     677  
     678      /**
     679       * Format a list of outcomes.
     680       *
     681       * @param stdClass $row
     682       * @return string
     683       */
     684      public function col_outcomes(stdClass $row) {
     685          $outcomes = '';
     686          foreach ($this->gradinginfo->outcomes as $index => $outcome) {
     687              $options = make_grades_menu(-$outcome->scaleid);
     688  
     689              $options[0] = get_string('nooutcome', 'grades');
     690              if ($this->quickgrading && !($outcome->grades[$row->userid]->locked)) {
     691                  $select = '<select name="outcome_' . $index . '_' . $row->userid . '" class="quickgrade">';
     692                  foreach ($options as $optionindex => $optionvalue) {
     693                      $selected = '';
     694                      if ($outcome->grades[$row->userid]->grade == $optionindex) {
     695                          $selected = 'selected="selected"';
     696                      }
     697                      $select .= '<option value="' . $optionindex . '"' . $selected . '>' . $optionvalue . '</option>';
     698                  }
     699                  $select .= '</select>';
     700                  $outcomes .= $this->output->container($outcome->name . ': ' . $select, 'outcome');
     701              } else {
     702                  $name = $outcome->name . ': ' . $options[$outcome->grades[$row->userid]->grade];
     703                  if ($this->is_downloading()) {
     704                      $outcomes .= $name;
     705                  } else {
     706                      $outcomes .= $this->output->container($name, 'outcome');
     707                  }
     708              }
     709          }
     710  
     711          return $outcomes;
     712      }
     713  
     714  
     715      /**
     716       * Format a user picture for display.
     717       *
     718       * @param stdClass $row
     719       * @return string
     720       */
     721      public function col_picture(stdClass $row) {
     722          return $this->output->user_picture($row);
     723      }
     724  
     725      /**
     726       * Format a user record for display (link to profile).
     727       *
     728       * @param stdClass $row
     729       * @return string
     730       */
     731      public function col_fullname($row) {
     732          if (!$this->is_downloading()) {
     733              $courseid = $this->assignment->get_course()->id;
     734              $link= new moodle_url('/user/view.php', array('id' =>$row->id, 'course'=>$courseid));
     735              $fullname = $this->output->action_link($link, $this->assignment->fullname($row));
     736          } else {
     737              $fullname = $this->assignment->fullname($row);
     738          }
     739  
     740          if (!$this->assignment->is_active_user($row->id)) {
     741              $suspendedstring = get_string('userenrolmentsuspended', 'grades');
     742              $fullname .= ' ' . html_writer::empty_tag('img', array('src' => $this->output->pix_url('i/enrolmentsuspended'),
     743                  'title' => $suspendedstring, 'alt' => $suspendedstring, 'class' => 'usersuspendedicon'));
     744              $fullname = html_writer::tag('span', $fullname, array('class' => 'usersuspended'));
     745          }
     746          return $fullname;
     747      }
     748  
     749      /**
     750       * Insert a checkbox for selecting the current row for batch operations.
     751       *
     752       * @param stdClass $row
     753       * @return string
     754       */
     755      public function col_select(stdClass $row) {
     756          $selectcol = '<label class="accesshide" for="selectuser_' . $row->userid . '">';
     757          $selectcol .= get_string('selectuser', 'assign', $this->assignment->fullname($row));
     758          $selectcol .= '</label>';
     759          $selectcol .= '<input type="checkbox"
     760                                id="selectuser_' . $row->userid . '"
     761                                name="selectedusers"
     762                                value="' . $row->userid . '"/>';
     763          $selectcol .= '<input type="hidden"
     764                                name="grademodified_' . $row->userid . '"
     765                                value="' . $row->timemarked . '"/>';
     766          return $selectcol;
     767      }
     768  
     769      /**
     770       * Return a users grades from the listing of all grade data for this assignment.
     771       *
     772       * @param int $userid
     773       * @return mixed stdClass or false
     774       */
     775      private function get_gradebook_data_for_user($userid) {
     776          if (isset($this->gradinginfo->items[0]) && $this->gradinginfo->items[0]->grades[$userid]) {
     777              return $this->gradinginfo->items[0]->grades[$userid];
     778          }
     779          return false;
     780      }
     781  
     782      /**
     783       * Format a column of data for display.
     784       *
     785       * @param stdClass $row
     786       * @return string
     787       */
     788      public function col_gradecanbechanged(stdClass $row) {
     789          $gradingdisabled = $this->assignment->grading_disabled($row->id);
     790          if ($gradingdisabled) {
     791              return get_string('no');
     792          } else {
     793              return get_string('yes');
     794          }
     795      }
     796  
     797      /**
     798       * Format a column of data for display
     799       *
     800       * @param stdClass $row
     801       * @return string
     802       */
     803      public function col_grademax(stdClass $row) {
     804          return format_float($this->assignment->get_instance()->grade, 2);
     805      }
     806  
     807      /**
     808       * Format a column of data for display.
     809       *
     810       * @param stdClass $row
     811       * @return string
     812       */
     813      public function col_grade(stdClass $row) {
     814          $o = '';
     815  
     816          $link = '';
     817          $separator = $this->output->spacer(array(), true);
     818          $grade = '';
     819          $gradingdisabled = $this->assignment->grading_disabled($row->id);
     820  
     821          if (!$this->is_downloading() && $this->hasgrade) {
     822              $name = $this->assignment->fullname($row);
     823              $icon = $this->output->pix_icon('gradefeedback',
     824                                              get_string('gradeuser', 'assign', $name),
     825                                              'mod_assign');
     826              $urlparams = array('id' => $this->assignment->get_course_module()->id,
     827                                 'rownum'=>$this->rownum,
     828                                 'action'=>'grade');
     829              $url = new moodle_url('/mod/assign/view.php', $urlparams);
     830              $link = $this->output->action_link($url, $icon);
     831              $grade .= $link . $separator;
     832          }
     833  
     834          $grade .= $this->display_grade($row->grade,
     835                                         $this->quickgrading && !$gradingdisabled,
     836                                         $row->userid,
     837                                         $row->timemarked);
     838  
     839          return $grade;
     840      }
     841  
     842      /**
     843       * Format a column of data for display.
     844       *
     845       * @param stdClass $row
     846       * @return string
     847       */
     848      public function col_finalgrade(stdClass $row) {
     849          $o = '';
     850  
     851          $grade = $this->get_gradebook_data_for_user($row->userid);
     852          if ($grade) {
     853              $o = $this->display_grade($grade->grade, false, $row->userid, $row->timemarked);
     854          }
     855  
     856          return $o;
     857      }
     858  
     859      /**
     860       * Format a column of data for display.
     861       *
     862       * @param stdClass $row
     863       * @return string
     864       */
     865      public function col_timemarked(stdClass $row) {
     866          $o = '-';
     867  
     868          if ($row->timemarked && $row->grade !== null && $row->grade >= 0) {
     869              $o = userdate($row->timemarked);
     870          }
     871          if ($row->timemarked && $this->is_downloading()) {
     872              // Force it for downloads as it affects import.
     873              $o = userdate($row->timemarked);
     874          }
     875  
     876          return $o;
     877      }
     878  
     879      /**
     880       * Format a column of data for display.
     881       *
     882       * @param stdClass $row
     883       * @return string
     884       */
     885      public function col_timesubmitted(stdClass $row) {
     886          $o = '-';
     887  
     888          $group = false;
     889          $submission = false;
     890          $this->get_group_and_submission($row->id, $group, $submission, -1);
     891          if ($submission && $submission->timemodified && $submission->status != ASSIGN_SUBMISSION_STATUS_NEW) {
     892              $o = userdate($submission->timemodified);
     893          } else if ($row->timesubmitted) {
     894              $o = userdate($row->timesubmitted);
     895          }
     896  
     897          return $o;
     898      }
     899  
     900      /**
     901       * Format a column of data for display
     902       *
     903       * @param stdClass $row
     904       * @return string
     905       */
     906      public function col_status(stdClass $row) {
     907          $o = '';
     908  
     909          $instance = $this->assignment->get_instance();
     910  
     911          $due = $instance->duedate;
     912          if ($row->extensionduedate) {
     913              $due = $row->extensionduedate;
     914          }
     915  
     916          $group = false;
     917          $submission = false;
     918          $this->get_group_and_submission($row->id, $group, $submission, -1);
     919          if ($submission) {
     920              $timesubmitted = $submission->timemodified;
     921              $status = $submission->status;
     922          } else {
     923              $timesubmitted = $row->timesubmitted;
     924              $status = $row->status;
     925          }
     926  
     927          if ($this->assignment->is_any_submission_plugin_enabled()) {
     928  
     929              $o .= $this->output->container(get_string('submissionstatus_' . $status, 'assign'),
     930                                             array('class'=>'submissionstatus' .$status));
     931              if ($due && $timesubmitted > $due) {
     932                  $usertime = format_time($timesubmitted - $due);
     933                  $latemessage = get_string('submittedlateshort',
     934                                            'assign',
     935                                            $usertime);
     936                  $o .= $this->output->container($latemessage, 'latesubmission');
     937              }
     938              if ($row->locked) {
     939                  $lockedstr = get_string('submissionslockedshort', 'assign');
     940                  $o .= $this->output->container($lockedstr, 'lockedsubmission');
     941              }
     942  
     943              // Add status of "grading", use markflow if enabled.
     944              if ($instance->markingworkflow) {
     945                  $o .= $this->col_workflowstatus($row);
     946              } else if ($row->grade !== null && $row->grade >= 0) {
     947                  $o .= $this->output->container(get_string('graded', 'assign'), 'submissiongraded');
     948              } else if (!$timesubmitted) {
     949                  $now = time();
     950                  if ($due && ($now > $due)) {
     951                      $overduestr = get_string('overdue', 'assign', format_time($now - $due));
     952                      $o .= $this->output->container($overduestr, 'overduesubmission');
     953                  }
     954              }
     955  
     956              if ($row->extensionduedate) {
     957                  $userdate = userdate($row->extensionduedate);
     958                  $extensionstr = get_string('userextensiondate', 'assign', $userdate);
     959                  $o .= $this->output->container($extensionstr, 'extensiondate');
     960              }
     961          }
     962  
     963          if ($this->is_downloading()) {
     964              $o = strip_tags(str_replace('</div>', "\n", $o));
     965          }
     966  
     967          return $o;
     968      }
     969  
     970      /**
     971       * Format a column of data for display.
     972       *
     973       * @param stdClass $row
     974       * @return string
     975       */
     976      public function col_userid(stdClass $row) {
     977          global $USER;
     978  
     979          $edit = '';
     980  
     981          $actions = array();
     982  
     983          $urlparams = array('id'=>$this->assignment->get_course_module()->id,
     984                             'rownum'=>$this->rownum,
     985                             'action'=>'grade');
     986          $url = new moodle_url('/mod/assign/view.php', $urlparams);
     987          $noimage = null;
     988  
     989          if (!$row->grade) {
     990              $description = get_string('grade');
     991          } else {
     992              $description = get_string('updategrade', 'assign');
     993          }
     994          $actions['grade'] = new action_menu_link_secondary(
     995              $url,
     996              $noimage,
     997              $description
     998          );
     999  
    1000          // Everything we need is in the row.
    1001          $submission = $row;
    1002          $flags = $row;
    1003          if ($this->assignment->get_instance()->teamsubmission) {
    1004              // Use the cache for this.
    1005              $submission = false;
    1006              $group = false;
    1007              $this->get_group_and_submission($row->id, $group, $submission, -1);
    1008          }
    1009  
    1010          $submissionsopen = $this->assignment->submissions_open($row->id,
    1011                                                                 true,
    1012                                                                 $submission,
    1013                                                                 $flags,
    1014                                                                 $this->gradinginfo);
    1015          $caneditsubmission = $this->assignment->can_edit_submission($row->id, $USER->id);
    1016  
    1017          // Hide for offline assignments.
    1018          if ($this->assignment->is_any_submission_plugin_enabled()) {
    1019              if (!$row->status ||
    1020                      $row->status == ASSIGN_SUBMISSION_STATUS_DRAFT ||
    1021                      !$this->assignment->get_instance()->submissiondrafts) {
    1022  
    1023                  if (!$row->locked) {
    1024                      $urlparams = array('id' => $this->assignment->get_course_module()->id,
    1025                                         'userid'=>$row->id,
    1026                                         'action'=>'lock',
    1027                                         'sesskey'=>sesskey(),
    1028                                         'page'=>$this->currpage);
    1029                      $url = new moodle_url('/mod/assign/view.php', $urlparams);
    1030  
    1031                      $description = get_string('preventsubmissionsshort', 'assign');
    1032                      $actions['lock'] = new action_menu_link_secondary(
    1033                          $url,
    1034                          $noimage,
    1035                          $description
    1036                      );
    1037                  } else {
    1038                      $urlparams = array('id' => $this->assignment->get_course_module()->id,
    1039                                         'userid'=>$row->id,
    1040                                         'action'=>'unlock',
    1041                                         'sesskey'=>sesskey(),
    1042                                         'page'=>$this->currpage);
    1043                      $url = new moodle_url('/mod/assign/view.php', $urlparams);
    1044                      $description = get_string('allowsubmissionsshort', 'assign');
    1045                      $actions['unlock'] = new action_menu_link_secondary(
    1046                          $url,
    1047                          $noimage,
    1048                          $description
    1049                      );
    1050                  }
    1051              }
    1052  
    1053              if (($this->assignment->get_instance()->duedate ||
    1054                     $this->assignment->get_instance()->cutoffdate) &&
    1055                     $this->hasgrantextension) {
    1056                  $urlparams = array('id' => $this->assignment->get_course_module()->id,
    1057                                     'userid'=>$row->id,
    1058                                     'action'=>'grantextension',
    1059                                     'sesskey'=>sesskey(),
    1060                                     'page'=>$this->currpage);
    1061                  $url = new moodle_url('/mod/assign/view.php', $urlparams);
    1062                  $description = get_string('grantextension', 'assign');
    1063                  $actions['grantextension'] = new action_menu_link_secondary(
    1064                      $url,
    1065                      $noimage,
    1066                      $description
    1067                  );
    1068              }
    1069              if ($submissionsopen &&
    1070                      $USER->id != $row->id &&
    1071                      $caneditsubmission) {
    1072                  $urlparams = array('id' => $this->assignment->get_course_module()->id,
    1073                                     'userid'=>$row->id,
    1074                                     'action'=>'editsubmission',
    1075                                     'sesskey'=>sesskey(),
    1076                                     'page'=>$this->currpage);
    1077                  $url = new moodle_url('/mod/assign/view.php', $urlparams);
    1078                  $description = get_string('editsubmission', 'assign');
    1079                  $actions['editsubmission'] = new action_menu_link_secondary(
    1080                      $url,
    1081                      $noimage,
    1082                      $description
    1083                  );
    1084              }
    1085          }
    1086          if ($row->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED &&
    1087                  $this->assignment->get_instance()->submissiondrafts) {
    1088              $urlparams = array('id' => $this->assignment->get_course_module()->id,
    1089                                 'userid'=>$row->id,
    1090                                 'action'=>'reverttodraft',
    1091                                 'sesskey'=>sesskey(),
    1092                                 'page'=>$this->currpage);
    1093              $url = new moodle_url('/mod/assign/view.php', $urlparams);
    1094              $description = get_string('reverttodraftshort', 'assign');
    1095              $actions['reverttodraft'] = new action_menu_link_secondary(
    1096                  $url,
    1097                  $noimage,
    1098                  $description
    1099              );
    1100          }
    1101          if ($row->status == ASSIGN_SUBMISSION_STATUS_DRAFT &&
    1102                  $this->assignment->get_instance()->submissiondrafts &&
    1103                  $caneditsubmission &&
    1104                  $submissionsopen &&
    1105                  $row->id != $USER->id) {
    1106              $urlparams = array('id' => $this->assignment->get_course_module()->id,
    1107                                 'userid'=>$row->id,
    1108                                 'action'=>'submitotherforgrading',
    1109                                 'sesskey'=>sesskey(),
    1110                                 'page'=>$this->currpage);
    1111              $url = new moodle_url('/mod/assign/view.php', $urlparams);
    1112              $description = get_string('submitforgrading', 'assign');
    1113              $actions['submitforgrading'] = new action_menu_link_secondary(
    1114                  $url,
    1115                  $noimage,
    1116                  $description
    1117              );
    1118          }
    1119  
    1120          $ismanual = $this->assignment->get_instance()->attemptreopenmethod == ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL;
    1121          $hassubmission = !empty($row->status);
    1122          $notreopened = $hassubmission && $row->status != ASSIGN_SUBMISSION_STATUS_REOPENED;
    1123          $isunlimited = $this->assignment->get_instance()->maxattempts == ASSIGN_UNLIMITED_ATTEMPTS;
    1124          $hasattempts = $isunlimited || $row->attemptnumber < $this->assignment->get_instance()->maxattempts - 1;
    1125  
    1126          if ($ismanual && $hassubmission && $notreopened && $hasattempts) {
    1127              $urlparams = array('id' => $this->assignment->get_course_module()->id,
    1128                                 'userid'=>$row->id,
    1129                                 'action'=>'addattempt',
    1130                                 'sesskey'=>sesskey(),
    1131                                 'page'=>$this->currpage);
    1132              $url = new moodle_url('/mod/assign/view.php', $urlparams);
    1133              $description = get_string('addattempt', 'assign');
    1134              $actions['addattempt'] = new action_menu_link_secondary(
    1135                  $url,
    1136                  $noimage,
    1137                  $description
    1138              );
    1139          }
    1140  
    1141          $menu = new action_menu();
    1142          $menu->set_owner_selector('.gradingtable-actionmenu');
    1143          $menu->set_alignment(action_menu::TL, action_menu::BL);
    1144          $menu->set_constraint('.gradingtable > .no-overflow');
    1145          $menu->set_menu_trigger(get_string('edit'));
    1146          foreach ($actions as $action) {
    1147              $menu->add($action);
    1148          }
    1149  
    1150          // Prioritise the menu ahead of all other actions.
    1151          $menu->prioritise = true;
    1152  
    1153          $edit .= $this->output->render($menu);
    1154  
    1155          return $edit;
    1156      }
    1157  
    1158      /**
    1159       * Write the plugin summary with an optional link to view the full feedback/submission.
    1160       *
    1161       * @param assign_plugin $plugin Submission plugin or feedback plugin
    1162       * @param stdClass $item Submission or grade
    1163       * @param string $returnaction The return action to pass to the
    1164       *                             view_submission page (the current page)
    1165       * @param string $returnparams The return params to pass to the view_submission
    1166       *                             page (the current page)
    1167       * @return string The summary with an optional link
    1168       */
    1169      private function format_plugin_summary_with_link(assign_plugin $plugin,
    1170                                                       stdClass $item,
    1171                                                       $returnaction,
    1172                                                       $returnparams) {
    1173          $link = '';
    1174          $showviewlink = false;
    1175  
    1176          $summary = $plugin->view_summary($item, $showviewlink);
    1177          $separator = '';
    1178          if ($showviewlink) {
    1179              $viewstr = get_string('view' . substr($plugin->get_subtype(), strlen('assign')), 'assign');
    1180              $icon = $this->output->pix_icon('t/preview', $viewstr);
    1181              $urlparams = array('id' => $this->assignment->get_course_module()->id,
    1182                                                       'sid'=>$item->id,
    1183                                                       'gid'=>$item->id,
    1184                                                       'plugin'=>$plugin->get_type(),
    1185                                                       'action'=>'viewplugin' . $plugin->get_subtype(),
    1186                                                       'returnaction'=>$returnaction,
    1187                                                       'returnparams'=>http_build_query($returnparams));
    1188              $url = new moodle_url('/mod/assign/view.php', $urlparams);
    1189              $link = $this->output->action_link($url, $icon);
    1190              $separator = $this->output->spacer(array(), true);
    1191          }
    1192  
    1193          return $link . $separator . $summary;
    1194      }
    1195  
    1196  
    1197      /**
    1198       * Format the submission and feedback columns.
    1199       *
    1200       * @param string $colname The column name
    1201       * @param stdClass $row The submission row
    1202       * @return mixed string or NULL
    1203       */
    1204      public function other_cols($colname, $row) {
    1205          // For extra user fields the result is already in $row.
    1206          if (empty($this->plugincache[$colname])) {
    1207              return $row->$colname;
    1208          }
    1209  
    1210          // This must be a plugin field.
    1211          $plugincache = $this->plugincache[$colname];
    1212  
    1213          $plugin = $plugincache[0];
    1214  
    1215          $field = null;
    1216          if (isset($plugincache[1])) {
    1217              $field = $plugincache[1];
    1218          }
    1219  
    1220          if ($plugin->is_visible() && $plugin->is_enabled()) {
    1221              if ($plugin->get_subtype() == 'assignsubmission') {
    1222                  if ($this->assignment->get_instance()->teamsubmission) {
    1223                      $group = false;
    1224                      $submission = false;
    1225  
    1226                      $this->get_group_and_submission($row->id, $group, $submission, -1);
    1227                      if ($submission) {
    1228                          if ($submission->status == ASSIGN_SUBMISSION_STATUS_REOPENED) {
    1229                              // For a newly reopened submission - we want to show the previous submission in the table.
    1230                              $this->get_group_and_submission($row->id, $group, $submission, $submission->attemptnumber-1);
    1231                          }
    1232                          if (isset($field)) {
    1233                              return $plugin->get_editor_text($field, $submission->id);
    1234                          }
    1235                          return $this->format_plugin_summary_with_link($plugin,
    1236                                                                        $submission,
    1237                                                                        'grading',
    1238                                                                        array());
    1239                      }
    1240                  } else if ($row->submissionid) {
    1241                      if ($row->status == ASSIGN_SUBMISSION_STATUS_REOPENED) {
    1242                          // For a newly reopened submission - we want to show the previous submission in the table.
    1243                          $submission = $this->assignment->get_user_submission($row->userid, false, $row->attemptnumber - 1);
    1244                      } else {
    1245                          $submission = new stdClass();
    1246                          $submission->id = $row->submissionid;
    1247                          $submission->timecreated = $row->firstsubmission;
    1248                          $submission->timemodified = $row->timesubmitted;
    1249                          $submission->assignment = $this->assignment->get_instance()->id;
    1250                          $submission->userid = $row->userid;
    1251                          $submission->attemptnumber = $row->attemptnumber;
    1252                      }
    1253                      // Field is used for only for import/export and refers the the fieldname for the text editor.
    1254                      if (isset($field)) {
    1255                          return $plugin->get_editor_text($field, $submission->id);
    1256                      }
    1257                      return $this->format_plugin_summary_with_link($plugin,
    1258                                                                    $submission,
    1259                                                                    'grading',
    1260                                                                    array());
    1261                  }
    1262              } else {
    1263                  $grade = null;
    1264                  if (isset($field)) {
    1265                      return $plugin->get_editor_text($field, $row->gradeid);
    1266                  }
    1267  
    1268                  if ($row->gradeid) {
    1269                      $grade = new stdClass();
    1270                      $grade->id = $row->gradeid;
    1271                      $grade->timecreated = $row->firstmarked;
    1272                      $grade->timemodified = $row->timemarked;
    1273                      $grade->assignment = $this->assignment->get_instance()->id;
    1274                      $grade->userid = $row->userid;
    1275                      $grade->grade = $row->grade;
    1276                      $grade->mailed = $row->mailed;
    1277                      $grade->attemptnumber = $row->attemptnumber;
    1278                  }
    1279                  if ($this->quickgrading && $plugin->supports_quickgrading()) {
    1280                      return $plugin->get_quickgrading_html($row->userid, $grade);
    1281                  } else if ($grade) {
    1282                      return $this->format_plugin_summary_with_link($plugin,
    1283                                                                    $grade,
    1284                                                                    'grading',
    1285                                                                    array());
    1286                  }
    1287              }
    1288          }
    1289          return '';
    1290      }
    1291  
    1292      /**
    1293       * Using the current filtering and sorting - load all rows and return a single column from them.
    1294       *
    1295       * @param string $columnname The name of the raw column data
    1296       * @return array of data
    1297       */
    1298      public function get_column_data($columnname) {
    1299          $this->setup();
    1300          $this->currpage = 0;
    1301          $this->query_db($this->tablemaxrows);
    1302          $result = array();
    1303          foreach ($this->rawdata as $row) {
    1304              $result[] = $row->$columnname;
    1305          }
    1306          return $result;
    1307      }
    1308  
    1309      /**
    1310       * Return things to the renderer.
    1311       *
    1312       * @return string the assignment name
    1313       */
    1314      public function get_assignment_name() {
    1315          return $this->assignment->get_instance()->name;
    1316      }
    1317  
    1318      /**
    1319       * Return things to the renderer.
    1320       *
    1321       * @return int the course module id
    1322       */
    1323      public function get_course_module_id() {
    1324          return $this->assignment->get_course_module()->id;
    1325      }
    1326  
    1327      /**
    1328       * Return things to the renderer.
    1329       *
    1330       * @return int the course id
    1331       */
    1332      public function get_course_id() {
    1333          return $this->assignment->get_course()->id;
    1334      }
    1335  
    1336      /**
    1337       * Return things to the renderer.
    1338       *
    1339       * @return stdClass The course context
    1340       */
    1341      public function get_course_context() {
    1342          return $this->assignment->get_course_context();
    1343      }
    1344  
    1345      /**
    1346       * Return things to the renderer.
    1347       *
    1348       * @return bool Does this assignment accept submissions
    1349       */
    1350      public function submissions_enabled() {
    1351          return $this->assignment->is_any_submission_plugin_enabled();
    1352      }
    1353  
    1354      /**
    1355       * Return things to the renderer.
    1356       *
    1357       * @return bool Can this user view all grades (the gradebook)
    1358       */
    1359      public function can_view_all_grades() {
    1360          $context = $this->assignment->get_course_context();
    1361          return has_capability('gradereport/grader:view', $context) &&
    1362                 has_capability('moodle/grade:viewall', $context);
    1363      }
    1364  
    1365      /**
    1366       * Always return a valid sort - even if the userid column is missing.
    1367       * @return array column name => SORT_... constant.
    1368       */
    1369      public function get_sort_columns() {
    1370          $result = parent::get_sort_columns();
    1371          $result = array_merge($result, array('userid' => SORT_ASC));
    1372          return $result;
    1373      }
    1374  
    1375      /**
    1376       * Override the table show_hide_link to not show for select column.
    1377       *
    1378       * @param string $column the column name, index into various names.
    1379       * @param int $index numerical index of the column.
    1380       * @return string HTML fragment.
    1381       */
    1382      protected function show_hide_link($column, $index) {
    1383          if ($index > 0 || !$this->hasgrade) {
    1384              return parent::show_hide_link($column, $index);
    1385          }
    1386          return '';
    1387      }
    1388  }
    

    Search This Site: