Newer
Older
* Permission levels may be supplied to limit the course list.
*
* @param string $user_id The ID of the user whose courses shall be retrieved.
*
* @param string[] $perms The permission levels of the user that shall be
* regarded when retrieving courses.
*
* @param bool $with_deputies Whether to include courses where the user is
* a deputy (true) or not (false). Defaults to true.
*
* @return Course[] A list of courses.
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
*/
public static function findByUser($user_id, $perms = [], $with_deputies = true)
{
if (!$user_id) {
return [];
}
$db = DBManager::get();
$sql = "SELECT `seminar_id`
FROM `seminar_user`
WHERE `user_id` = :user_id";
$sql_params = ['user_id' => $user_id];
if (is_array($perms) && count($perms)) {
$sql .= ' AND `status` IN (:perms)';
$sql_params['perms'] = $perms;
}
$seminar_ids = $db->fetchFirst($sql, $sql_params);
if (Config::get()->DEPUTIES_ENABLE && $with_deputies) {
$sql = 'SELECT range_id FROM `deputies` WHERE `deputies`.`user_id` = :user_id';
$seminar_ids = array_merge($seminar_ids, $db->fetchFirst($sql, $sql_params));
}
$name_sort = Config::get()->IMPORTANT_SEMNUMBER ? 'VeranstaltungsNummer, Name' : 'Name';
return Course::findBySQL(
"LEFT JOIN semester_courses ON (semester_courses.course_id = seminare.Seminar_id)
WHERE Seminar_id IN (?)
GROUP BY seminare.Seminar_id
ORDER BY semester_courses.semester_id IS NULL DESC, start_time DESC, {$name_sort}",
[$seminar_ids]
);
}
/**
* Returns whether this course is a studygroup
* @return bool
*/
public function isStudygroup()
{
return in_array($this->status, studygroup_sem_types());
}
/**
*
*/
public function setDefaultTools()
{
$this->tools = [];

André Noack
committed
foreach (array_values($this->getSemClass()->getActivatedModuleObjects()) as $module) {
PluginManager::getInstance()->setPluginActivated($module->getPluginId(), $this->id, true);
$this->tools[] = ToolActivation::find([$this->id, $module->getPluginId()]);
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
}
}
/**
* @param $name string name of tool / plugin
* @return bool
*/
public function isToolActive($name)
{
$plugin = PluginEngine::getPlugin($name);
return $plugin && $this->tools->findOneby('plugin_id', $plugin->getPluginId());
}
/**
* returns all activated plugins/modules for this course
* @return StudipModule[]
*/
public function getActivatedTools()
{
return array_filter($this->tools->getStudipModule());
}
/**
* @see Range::__toString()
*/
public function __toString() : string
{
return $this->getFullName();
}
/**
* @inheritDoc
*/
public static function getCalendarOwner(string $owner_id): ?\Studip\Calendar\Owner
{
return self::find($owner_id);
}
/**
* @inheritDoc
*/
public function isCalendarReadable(?string $user_id = null): bool
{
if ($user_id === null) {
$user_id = User::findCurrent()->id;
}
//Calendar read permissions are granted for all participants
//that have at least user permissions.
return $GLOBALS['perm']->have_studip_perm('user', $this->id, $user_id);
}
/**
* @inheritDoc
*/
public function isCalendarWritable(string $user_id = null): bool
{
if ($user_id === null) {
$user_id = User::findCurrent()->id;
}
//Calendar write permissions are granted for all participants
//that have autor permissions or higher.
return $GLOBALS['perm']->have_studip_perm('autor', $this->id, $user_id);
}
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
/**
* Get user information for all users in this course
*
*/
public function getMembersData(?string $status = ''): array
{
$result = [];
if (!$status) {
foreach ($this->members->orderBy('position, nachname') as $member) {
$result[$member->user_id] = $member->getExportData();
}
foreach ($this->admission_applicants->findBy('status', 'accepted')->orderBy('position') as $member) {
$result[$member->user_id] = $member->getExportData();
}
} elseif ($status === 'awaiting') {
foreach ($this->admission_applicants->findBy('status', $status)->orderBy('position') as $member) {
$result[$member->user_id] = $member->getExportData();
}
} elseif ($status === 'claiming') {
$cs = CourseSet::getSetForCourse($this->id);
if (is_object($cs) && !$cs->hasAlgorithmRun()) {
$claiming_users = User::findFullMany(array_keys(AdmissionPriority::getPrioritiesByCourse($cs->getId(), $this->id)), 'ORDER BY nachname');
foreach ($claiming_users as $claiming_user) {
$studycourse = [];
$claiming_user->studycourses->map(function($sc) use (&$studycourse) {
$studycourse[]= $sc->studycourse->name . ',' . $sc->degree->name . ',' . $sc->semester;
});
$export_data = [
'status' => $status,
'salutation' => $claiming_user->salutation,
'Titel' => $claiming_user->title_front,
'Vorname' => $claiming_user->vorname,
'Nachname' => $claiming_user->nachname,
'Titel2' => $claiming_user->title_rear,
'username' => $claiming_user->username,
'privadr' => $claiming_user->privadr,
'privatnr' => $claiming_user->privatnr,
'Email' => $claiming_user->email,
'Anmeldedatum' => '',
'Matrikelnummer' => $claiming_user->matriculation_number,
'studiengaenge' => implode(';', $studycourse),
'position' => 0,
];
$result[$claiming_user->user_id] = $export_data;
}
}
}
return $result;
}