1
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/>.
2
16
3
17
namespace tool_objectfs \local \tag ;
4
18
19
+ /**
20
+ * File type tag source.
21
+ * Provides tag values for files based on their 'type' - these are categories (not necessarily equivalent to fileareas)
22
+ * that make it possible to apply different permissions to. For example, move backups to a cheaper storage class but not general files.
23
+ *
24
+ * @package tool_objectfs
25
+ * @author Matthew Hilton <[email protected] >
26
+ * @copyright Catalyst IT
27
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28
+ */
5
29
class file_type_source implements tag_source {
6
- public const TYPE_STANDARD = 'standard ' ;
30
+ /**
31
+ * @var string Unknown/uncategorised
32
+ */
33
+ public const TYPE_UNCATEGORISED = 'uncategorised ' ;
7
34
8
- public const TYPE_BACKUP = 'backup ' ;
35
+ /**
36
+ * @var string A course backup
37
+ */
38
+ public const TYPE_COURSE_BACKUP = 'course_backup ' ;
9
39
40
+ /**
41
+ * Identifier used in tagging file. Is the 'key' of the tag.
42
+ * @return string
43
+ */
10
44
public static function get_identifier (): string {
11
45
return 'type ' ;
12
46
}
13
47
48
+ /**
49
+ * Returns the tag value for the given file contenthash
50
+ * @param string $contenthash
51
+ * @return string|null the category of the file, one of TYPE_*
52
+ */
14
53
public function get_value_for_contenthash (string $ contenthash ): ?string {
15
- // TODO implement types e.g. is backup, etc..
16
- return self ::TYPE_STANDARD ;
54
+ global $ DB ;
55
+ // TODO are there other unknown course backup files ?
56
+ $ iscoursebackup = $ DB ->record_exists ('files ' , ['contenthash ' => $ contenthash , 'component ' => 'backup ' , 'filearea ' => 'course ' ]);
57
+ if ($ iscoursebackup ) {
58
+ return self ::TYPE_COURSE_BACKUP ;
59
+ }
60
+
61
+ return self ::TYPE_UNCATEGORISED ;
17
62
}
18
63
}
0 commit comments