Merge branch 'wip-MDL-59363-master' of git://github.com/marinaglancy/moodle
authorDavid Monllao <david.monllao@gmail.com>
Tue, 11 Jul 2017 10:36:58 +0000 (12:36 +0200)
committerDavid Monllao <david.monllao@gmail.com>
Tue, 11 Jul 2017 10:36:58 +0000 (12:36 +0200)
1  2 
mod/workshop/lib.php

diff --combined mod/workshop/lib.php
@@@ -95,15 -95,11 +95,15 @@@ function workshop_add_instance(stdclas
      }
  
      if (isset($workshop->submissionfiletypes)) {
 -        $workshop->submissionfiletypes = workshop::clean_file_extensions($workshop->submissionfiletypes);
 +        $filetypesutil = new \core_form\filetypes_util();
 +        $submissionfiletypes = $filetypesutil->normalize_file_types($workshop->submissionfiletypes);
 +        $workshop->submissionfiletypes = implode(' ', $submissionfiletypes);
      }
  
      if (isset($workshop->overallfeedbackfiletypes)) {
 -        $workshop->overallfeedbackfiletypes = workshop::clean_file_extensions($workshop->overallfeedbackfiletypes);
 +        $filetypesutil = new \core_form\filetypes_util();
 +        $overallfeedbackfiletypes = $filetypesutil->normalize_file_types($workshop->overallfeedbackfiletypes);
 +        $workshop->overallfeedbackfiletypes = implode(' ', $overallfeedbackfiletypes);
      }
  
      // insert the new record so we get the id
  
      // create calendar events
      workshop_calendar_update($workshop, $workshop->coursemodule);
 +    if (!empty($workshop->completionexpected)) {
 +        \core_completion\api::update_completion_date_event($cmid, 'workshop', $workshop->id, $workshop->completionexpected);
 +    }
  
      return $workshop->id;
  }
@@@ -178,15 -171,11 +178,15 @@@ function workshop_update_instance(stdcl
      }
  
      if (isset($workshop->submissionfiletypes)) {
 -        $workshop->submissionfiletypes = workshop::clean_file_extensions($workshop->submissionfiletypes);
 +        $filetypesutil = new \core_form\filetypes_util();
 +        $submissionfiletypes = $filetypesutil->normalize_file_types($workshop->submissionfiletypes);
 +        $workshop->submissionfiletypes = implode(' ', $submissionfiletypes);
      }
  
      if (isset($workshop->overallfeedbackfiletypes)) {
 -        $workshop->overallfeedbackfiletypes = workshop::clean_file_extensions($workshop->overallfeedbackfiletypes);
 +        $filetypesutil = new \core_form\filetypes_util();
 +        $overallfeedbackfiletypes = $filetypesutil->normalize_file_types($workshop->overallfeedbackfiletypes);
 +        $workshop->overallfeedbackfiletypes = implode(' ', $overallfeedbackfiletypes);
      }
  
      // todo - if the grading strategy is being changed, we may want to replace all aggregated peer grades with nulls
  
      // update calendar events
      workshop_calendar_update($workshop, $workshop->coursemodule);
 +    $completionexpected = (!empty($workshop->completionexpected)) ? $workshop->completionexpected : null;
 +    \core_completion\api::update_completion_date_event($workshop->coursemodule, 'workshop', $workshop->id, $completionexpected);
  
      return true;
  }
@@@ -304,29 -291,11 +304,29 @@@ function workshop_delete_instance($id) 
   * only workshop events belonging to the course specified are checked.
   *
   * @param  integer $courseid The Course ID.
 + * @param int|stdClass $instance workshop module instance or ID.
 + * @param int|stdClass $cm Course module object or ID.
   * @return bool Returns true if the calendar events were successfully updated.
   */
 -function workshop_refresh_events($courseid = 0) {
 +function workshop_refresh_events($courseid = 0, $instance = null, $cm = null) {
      global $DB;
  
 +    // If we have instance information then we can just update the one event instead of updating all events.
 +    if (isset($instance)) {
 +        if (!is_object($instance)) {
 +            $instance = $DB->get_record('workshop', array('id' => $instance), '*', MUST_EXIST);
 +        }
 +        if (isset($cm)) {
 +            if (!is_object($cm)) {
 +                $cm = (object)array('id' => $cm);
 +            }
 +        } else {
 +            $cm = get_coursemodule_from_instance('workshop', $instance->id);
 +        }
 +        workshop_calendar_update($instance, $cm->id);
 +        return true;
 +    }
 +
      if ($courseid) {
          // Make sure that the course id is numeric.
          if (!is_numeric($courseid)) {
@@@ -1553,7 -1522,8 +1553,8 @@@ function workshop_get_file_info($browse
  
          } else {
  
-             $sql = "SELECT s.id, u.lastname, u.firstname
+             $userfields = get_all_user_name_fields(true, 'u');
+             $sql = "SELECT s.id, $userfields
                        FROM {workshop_submissions} s
                        JOIN {user} u ON (s.authorid = u.id)
                       WHERE s.example = 0 AND s.workshopid = ?";