Ejemplo n.º 1
0
 private function process_groupfile($data, $path)
 {
     global $CFG;
     $data = (object) $data;
     $fp = vpl_fopen($path . $data->name);
     fwrite($fp, $data->content);
     fclose($fp);
 }
Ejemplo n.º 2
0
 /**
  * Set/update grade
  * @param $info object with grade and comments fields
  * @param $automatic if automatic grading (default false)
  * @return void
  */
 function set_grade($info, $automatic = false)
 {
     global $USER;
     global $CFG;
     global $DB;
     ignore_user_abort(true);
     $scaleid = $this->vpl->get_grade();
     if ($scaleid == 0 && empty($CFG->enableoutcomes)) {
         //No scale no outcomes
         return;
     }
     if (!function_exists('grade_update')) {
         require_once $CFG->libdir . '/gradelib.php';
     }
     if ($automatic) {
         //Who grade
         $this->instance->grader = 0;
     } else {
         $this->instance->grader = $USER->id;
     }
     if ($this->vpl->is_group_activity()) {
         $usersid = array();
         foreach ($this->vpl->get_usergroup_members($this->instance->userid) as $user) {
             $usersid[] = $user->id;
         }
     } else {
         $usersid = array($this->instance->userid);
     }
     $this->instance->dategraded = time();
     if ($scaleid != 0) {
         //Sanitize grade
         if ($scaleid > 0) {
             $info->grade = (double) $info->grade;
         } else {
             $info->grade = (int) $info->grade;
         }
         $this->instance->grade = $info->grade;
         //Save assessment comments
         $comments = $info->comments;
         $fn = $this->get_gradecommentsfilename();
         if ($comments) {
             $fp = vpl_fopen($fn);
             fwrite($fp, $comments);
             fclose($fp);
         } elseif (file_exists($fn)) {
             unlink($fn);
         }
         //update gradebook
         $grades = array();
         $gradeinfo = array();
         //If no grade then don't set rawgrade and feedback
         if (!($info->grade == -1 && $scaleid < 0)) {
             $gradeinfo['rawgrade'] = $info->grade;
             $gradeinfo['feedback'] = $this->result_to_HTML($comments, false);
             $gradeinfo['feedbackformat'] = FORMAT_HTML;
         }
         if ($this->instance->grader > 0) {
             //Don't add grader if automatic
             $gradeinfo['usermodified'] = $this->instance->grader;
         } else {
             //This avoid to use an unexisting userid (0) in the gradebook
             $gradeinfo['usermodified'] = $USER->id;
         }
         $gradeinfo['datesubmitted'] = $this->instance->datesubmitted;
         $gradeinfo['dategraded'] = $this->instance->dategraded;
         foreach ($usersid as $userid) {
             $gradeinfo['userid'] = $userid;
             $grades[$userid] = $gradeinfo;
         }
         if (grade_update('mod/vpl', $this->vpl->get_course()->id, 'mod', VPL, $this->vpl->get_instance()->id, 0, $grades) != GRADE_UPDATE_OK) {
             return false;
         }
     }
     if (!empty($CFG->enableoutcomes)) {
         foreach ($usersid as $userid) {
             $grading_info = grade_get_grades($this->vpl->get_course()->id, 'mod', 'vpl', $this->vpl->get_instance()->id, $userid);
             if (!empty($grading_info->outcomes)) {
                 $outcomes = array();
                 foreach ($grading_info->outcomes as $oid => $dummy) {
                     $field = 'outcome_grade_' . $oid;
                     if (isset($info->{$field})) {
                         $outcomes[$oid] = $info->{$field};
                     } else {
                         $outcomes[$oid] = null;
                     }
                 }
                 grade_update_outcomes('mod/vpl', $this->vpl->get_course()->id, 'mod', VPL, $this->vpl->get_instance()->id, $userid, $outcomes);
             }
         }
     }
     if (!$DB->update_record('vpl_submissions', $this->instance)) {
         print_error('DB error updating submission grade info');
     }
     return true;
 }
Ejemplo n.º 3
0
 function set_initial_file($name, $files)
 {
     $filelist = '';
     $basepath = $this->get_submission_directory();
     foreach ($files as $file) {
         $name = basename($file['name']);
         if ($name > '') {
             if ($filelist > '') {
                 $filelist .= "\n";
             }
             $filelist .= $name;
             $fp = vpl_fopen($basepath . $name);
             fwrite($fp, $file['data']);
             fclose($fp);
         }
     }
     $fp = vpl_fopen($this->get_submissionfilelistname());
     fwrite($fp, $filelist);
     fclose($fp);
 }
Ejemplo n.º 4
0
 /**
  * Add a new file to the group/Modify the data file
  *
  * @param string $filename
  * @param string $data
  * @return bool (added==true)
  */
 function addFile($filename, $data = null)
 {
     if (!vpl_is_valid_path_name($filename)) {
         return false;
     }
     ignore_user_abort(true);
     $filelist = $this->getFileList();
     foreach ($filelist as $f) {
         if ($filename == $f) {
             if ($data !== null) {
                 $path = $this->dir . self::encodeFileName($filename);
                 $fd = vpl_fopen($path);
                 fwrite($fd, $data);
                 fclose($fd);
             }
             return true;
         }
     }
     if (count($filelist) >= $this->maxnumfiles) {
         return false;
     }
     $filelist[] = $filename;
     $this->setFileList($filelist);
     if ($data) {
         $path = $this->dir . self::encodeFileName($filename);
         $fd = vpl_fopen($path);
         fwrite($fd, $data);
         fclose($fd);
     }
     return true;
 }
 public static function create_zip_file($zipname, $zipdata)
 {
     $filename = self::get_zip_filepath($zipname);
     $fp = vpl_fopen($filename);
     fwrite($fp, $zipdata);
     fclose($fp);
 }