public function save()

in locallib.php [217:284]


    public function save(stdClass $grade, stdClass $data) {
        global $DB, $COURSE, $USER;

        // Get the OneNote page id corresponding to the teacher's feedback for this submission.
        $record = $DB->get_record('local_onenote_assign_pages', ['assign_id' => $grade->assignment, 'user_id' => $grade->userid]);
        if (empty($record) || empty($record->feedback_teacher_page_id)) {
            return true;
        }

        try {
            $onenoteapi = \local_onenote\api\base::getinstance();
        } catch (\Exception $e) {
            // Display error.
            $this->set_error($e->getMessage());
            return false;
        }

        $tempfolder = $onenoteapi->create_temp_folder();
        $tempfile = join(DIRECTORY_SEPARATOR, array(rtrim($tempfolder, DIRECTORY_SEPARATOR), uniqid('asg_'))) . '.zip';

        $o365userid = \local_o365\utils::get_o365_userid($USER->id);
        // Create zip file containing onenote page and related files.
        $downloadinfo = $onenoteapi->download_page($record->feedback_teacher_page_id, $tempfile, $o365userid);

        if ($downloadinfo) {

            // Get feedback zip size.
            $feedbacksize = filesize($downloadinfo['path']);

            // Check if feedback size is greater than course upload limit.
            if (($COURSE->maxbytes > 0) && ($feedbacksize > $COURSE->maxbytes)) {

                // Display error if true.
                $this->set_error(get_string('feedbacklimitexceed', 'assignfeedback_onenote'));
                return false;
            }

            $fs = get_file_storage();

            // Delete any previous feedbacks.
            $fs->delete_area_files($this->assignment->get_context()->id, 'assignfeedback_onenote',
                    \local_onenote\api\base::ASSIGNFEEDBACK_ONENOTE_FILEAREA, $grade->id);

            // Prepare file record object.
            $fileinfo = array(
                'contextid' => $this->assignment->get_context()->id,
                'component' => 'assignfeedback_onenote',
                'filearea' => \local_onenote\api\base::ASSIGNFEEDBACK_ONENOTE_FILEAREA,
                'itemid' => $grade->id,
                'filepath' => '/',
                'filename' => 'OneNote_' . time() . '.zip'
            );

            // Save it.
            $fs->create_file_from_pathname($fileinfo, $downloadinfo['path']);
            fulldelete($tempfolder);
        } else {
            if ($onenoteapi->is_logged_in()) {
                $this->set_error(get_string('feedbackdownloadfailed', 'assignfeedback_onenote'));
            } else {
                $this->set_error(get_string('notsignedin', 'assignfeedback_onenote'));
            }

            return false;
        }

        return $this->update_file_count($grade);
    }