blob: 1c42799a7b8d06a9abe50d71c56ca1b46d92b56c (
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
<?php
/**
* CourseDateFolder.php
*
* 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 André Noack <noack@data-quest.de>
* @copyright 2018 Stud.IP Core-Group
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
* @category Stud.IP
*/
class CourseDateFolder extends PermissionEnabledFolder implements FolderType
{
public static $sorter = 1;
private $date;
public static function formatDate(CourseDate $date)
{
return sprintf(
_("%'.02d. %s am %s"),
CourseDate::getConsecutiveNumber($date),
$date->getTypeName(),
$date->getFullname()
);
}
public static function getTypeName()
{
return _('Sitzungs-Ordner');
}
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)
&& CourseDate::countBySql("range_id = ?" , [$course->id]);
}
return false;
}
public function __construct($folderdata = null)
{
parent::__construct($folderdata);
$this->getDate();
}
public function getIcon($role = Icon::DEFAULT_ROLE)
{
return Icon::create(
count($this->getFiles()) ? 'folder-topic-full' : 'folder-topic-empty',
$role
);
}
public function getDate(): ?CourseDate
{
if (isset($this->folderdata['data_content']['termin_id'])) {
if ($this->date === null) {
$this->date = CourseDate::find($this->folderdata['data_content']['termin_id']);
}
if ($this->date) {
$this->folderdata['name'] = self::formatDate($this->date);
} else {
$this->folderdata['name'] = _('(Termin gelöscht)') . ' ' . $this->folderdata['name'];
}
return $this->date;
}
return null;
}
/**
* @param CourseDate $date
* @return CourseDate
*/
public function setDate(CourseDate $date)
{
$this->date = $date;
$this->folderdata['data_content']['termin_id'] = $this->date->id;
return $this->getDate();
}
/**
* This method returns the special part for the edit template
*
* @return Flexi_Template edit template
*/
public function getEditTemplate()
{
$template = $GLOBALS['template_factory']->open('filesystem/date_folder/edit.php');
$template->date = $this->getDate();
$template->folder = $this;
return $template;
}
/**
* Stores the data which was edited in the edit template
* @return FolderType|MessageBox The template with the edited data
*/
public function setDataFromEditTemplate($request)
{
$date = CourseDate::find($request['course_date_folder_termin_id']);
if ($date === null) {
return MessageBox::error(_('Es wurde kein Termin ausgewählt.'));
} else {
$this->setDate($date);
}
if (isset($request['course_date_folder_perm_write'])) {
$this->folderdata['data_content']['permission'] = 7;
} else {
$this->folderdata['data_content']['permission'] = 5;
}
$this->folderdata['description'] = $request['description'] ?: '';
return $this;
}
/**
* Returns the description template
*
* @return Flexi_Template description template
*/
public function getDescriptionTemplate()
{
$template = $GLOBALS['template_factory']->open('filesystem/date_folder/description.php');
$template->type = self::getTypeName();
$template->folder = $this;
$template->date = $this->getDate();
$template->folderdata = $this->folderdata;
return $template;
}
/**
* @see FolderType::copySettings()
*/
public function copySettings()
{
return ['description' => $this->description];
}
}
|