Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
namespace mod_questionnaire;
18
 
19
/**
20
 * Defines the file stoeage class for questionnaire.
21
 * @package mod_questionnaire
22
 * @copyright  2020 onwards Mike Churchward (mike.churchward@poetopensource.org)
23
 * @author Mike Churchward
24
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 */
26
class file_storage extends \file_storage {
27
 
28
    /**
29
     * Copy all the files in a file area from one context to another.
30
     *
31
     * @param int $oldcontextid the context the files are being moved from.
32
     * @param int $newcontextid the context the files are being moved to.
33
     * @param string $component the plugin that these files belong to.
34
     * @param string $filearea the name of the file area.
35
     * @param int|boolean $olditemid The identifier for the old file area if required.
36
     * @param int|boolean $newitemid The identifier for the new file area if different than old.
37
     * @return int the number of files copied, for information.
38
     * @throws \coding_exception
39
     * @throws \file_exception
40
     * @throws \stored_file_creation_exception
41
     */
42
    public function copy_area_files_to_new_context($oldcontextid, $newcontextid, $component, $filearea, $olditemid = false,
43
                                                   $newitemid = false) {
44
        $count = 0;
45
 
46
        $oldfiles = $this->get_area_files($oldcontextid, $component, $filearea, $olditemid, 'id', false);
47
        foreach ($oldfiles as $oldfile) {
48
            $filerecord = new \stdClass();
49
            $filerecord->contextid = $newcontextid;
50
            if ($newitemid !== false) {
51
                $filerecord->itemid = $newitemid;
52
            } else {
53
                $filerecord->itemid = $olditemid;
54
            }
55
            $this->create_file_from_storedfile($filerecord, $oldfile);
56
            $count += 1;
57
        }
58
        return $count;
59
    }
60
}