Newer
Older
* a deputy (true) or not (false). Defaults to true.
*
* @return Course[] A list of courses.
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
*/
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()]);
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
}
}
/**
* @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();
}
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
/**
* @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 = self::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 = self::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);
}