Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 379... Línea 379...
379
        } else {
379
        } else {
380
            return get_string('countfiles', 'assignsubmission_file', $count);
380
            return get_string('countfiles', 'assignsubmission_file', $count);
381
        }
381
        }
382
    }
382
    }
Línea -... Línea 383...
-
 
383
 
-
 
384
    #[\Override]
-
 
385
    public function submission_summary_for_messages(stdClass $submission): array {
-
 
386
        global $PAGE;
-
 
387
        $files = new assign_files($this->assignment->get_context(), $submission->id,
-
 
388
                ASSIGNSUBMISSION_FILE_FILEAREA, 'assignsubmission_file', $this->assignment->get_course(),
-
 
389
                $this->assignment->get_course_module());
-
 
390
 
-
 
391
        $filelist = $this->flatten_list_of_files($files->dir);
-
 
392
        if (!$filelist) {
-
 
393
            return ['', ''];
-
 
394
        }
-
 
395
 
-
 
396
        $renderer = $PAGE->get_renderer('mod_assign');
-
 
397
        $templatecontext = ['files' => $filelist];
-
 
398
        return [
-
 
399
            // Mustache strips off all trailing whitespace, but we want a newline at the end.
-
 
400
            $renderer->render_from_template(
-
 
401
               'assignsubmission_file/email_summary_text', $templatecontext) . "\n",
-
 
402
            $renderer->render_from_template(
-
 
403
               'assignsubmission_file/email_summary_html', $templatecontext),
-
 
404
        ];
-
 
405
    }
-
 
406
 
-
 
407
    /**
-
 
408
     * Turn the hierarchical list of files into a flat array.
-
 
409
     *
-
 
410
     * The returned array looks like
-
 
411
     * [
-
 
412
     *     ['filepath' => 'File 1.docx', 'filesize' => '12.3KB'],
-
 
413
     *     ['filepath' => 'subdir/extra data.txt, 'filesize' => '456B'],
-
 
414
     * ].
-
 
415
     *
-
 
416
     * @param array $dir as returned by {@see file_storage::get_area_tree()}.
-
 
417
     * @return array as above.
-
 
418
     */
-
 
419
    private function flatten_list_of_files(array $dir): array {
-
 
420
        if (empty($dir['subdirs']) && empty($dir['files'])) {
-
 
421
            return [];
-
 
422
        }
-
 
423
 
-
 
424
        $filessummary = [];
-
 
425
        /** @var stored_file $file */
-
 
426
        foreach ($dir['files'] as $file) {
-
 
427
            $filessummary[] = [
-
 
428
                'filepath' => ltrim($file->get_filepath(), '/') . $file->get_filename(),
-
 
429
                'filesize' => display_size($file->get_filesize()),
-
 
430
            ];
-
 
431
        }
-
 
432
 
-
 
433
        foreach ($dir['subdirs'] as $subdir) {
-
 
434
            $files = $this->flatten_list_of_files($subdir);
-
 
435
            $filessummary = array_merge($filessummary, $files);
-
 
436
        }
-
 
437
 
-
 
438
        return $filessummary;
-
 
439
    }
383
 
440
 
384
    /**
441
    /**
385
     * No full submission view - the summary contains the list of files and that is the whole submission
442
     * No full submission view - the summary contains the list of files and that is the whole submission
386
     *
443
     *
387
     * @param stdClass $submission
444
     * @param stdClass $submission