aboutsummaryrefslogtreecommitdiff
path: root/lib/filesystem/HomeworkFolder.php
blob: 8c811f3e4616a565d1fce90ea4dab9356a407d70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/**
 * HomeworkFolder.class.php
 *
 * This is a FolderType implementation for homework folders.
 *
 * A homework folder in Stud.IP can be writeable by all course members
 * but is only readable by teachers.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * @author    Moritz Strohm <strohm@data-quest.de>
 * @copyright 2016 data-quest
 * @license   http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
 * @category  Stud.IP
 */
class HomeworkFolder extends PermissionEnabledFolder
{
    public static $sorter = 2;

    /**
     * Returns a localised name of the HomeworkFolder type.
     *
     * @return string The localised name of this folder type.
     */
    public static function getTypeName()
    {
        return _('Ordner für Hausarbeiten');
    }

    public static function availableInRange($range_id_or_object, $user_id)
    {
        $course = Course::toObject($range_id_or_object);
        if ($course && !$course->isNew()) {
            return Seminar_Perm::get()->have_studip_perm('tutor', $course->id, $user_id);
        }
    }

    public function __construct($folderdata = null)
    {
        parent::__construct($folderdata);
        $this->permission = 3;
    }

    /**
     * Returns the Icon object for the HomeworkFolder type.
     *
     * @return Icon An icon object with the icon for this folder type.
     */
    public function getIcon($role = Icon::DEFAULT_ROLE)
    {
        $shape = $this->is_empty
              ? 'folder-lock-empty'
              : 'folder-lock-full';
        return Icon::create($shape, $role);
    }


    /**
     * Homework folders don't allow subfolders.
     *
     * @return bool False
     */
    public function isSubfolderAllowed($user_id)
    {
        //no subfolders allowed (I'm a homework folder, not a home folder backup!)
        return false;
    }

    /**
     * Returns the description template for a HomeworkFolder instance.
     *
     * @return string A description for the HomeworkFolder instance.
     */
    public function getDescriptionTemplate()
    {

        $template = $GLOBALS['template_factory']->open('filesystem/homework_folder/description.php');
        $template->folder     = $this;
        $template->folderdata = $this->folderdata;
        if (!Seminar_Perm::get()->have_studip_perm('tutor', $this->range_id)) {
            $files = new SimpleCollection($this->getFiles());
            $template->own_files = $files->findBy('user_id', $GLOBALS['user']->id)->orderBy('name');
        }

        return $template;
    }

    /**
     * Folders of this type don't have an edit template.
     *
     * @return string
     */
    public function getEditTemplate()
    {
        return '';
    }

    /**
     * @param FileRef|string $fileref_or_id
     * @param string $user_id
     * @return bool
     */
    public function isFileEditable($fileref_or_id, $user_id)
    {
        return $GLOBALS['perm']->have_studip_perm('tutor', $this->range_id, $user_id);
    }

    /**
     * Checks if a user has write permissions to a file.
     *
     * For standard folders write permissions are granted
     * if the user is the owner of the file or if the user has at least
     * tutor permissions on the Stud.IP object specified by range_id
     * (such objects may be courses or institutes for example).
     *
     * @param FileRef|string $fileref_or_id
     * @param string $user_id
     * @return bool
     */
    public function isFileWritable($fileref_or_id, $user_id)
    {
        return  $GLOBALS['perm']->have_studip_perm('tutor', $this->range_id, $user_id);
    }
}