Skip to content
Snippets Groups Projects
Commit a32c2f64 authored by Moritz Strohm's avatar Moritz Strohm
Browse files

removed action course/studygroup/create, fixes #4576

Closes #4576

Merge request studip/studip!3388
parent 9669b1d5
No related branches found
No related tags found
No related merge requests found
......@@ -161,193 +161,6 @@ class Course_StudygroupController extends AuthenticatedController
$this->studygroup = $studygroup;
}
/**
* @addtogroup notifications
*
* Creating a new studygroup triggers a StudygroupDidCreate
* notification. The ID of the studygroup is transmitted as
* subject of the notification.
*/
/**
* creates a new studygroup with respect to given form data
*
* Triggers a StudygroupDidCreate notification using the ID of the
* new studygroup as subject.
*
* @return void
*/
public function create_action()
{
$admin = $GLOBALS['perm']->have_perm('admin');
$errors = [];
CSRFProtection::verifyUnsafeRequest();
foreach ($GLOBALS['SEM_CLASS'] as $key => $class) {
if ($class['studygroup_mode']) {
$sem_class = $class;
break;
}
}
if (Request::getArray('founders')) {
$founders = Request::optionArray('founders');
$this->flash['founders'] = $founders;
}
// search for founder
if ($admin && Request::submitted('search_founder')) {
$search_for_founder = Request::get('search_for_founder');
// do not allow to search with the empty string
if ($search_for_founder) {
// search for the user
$query = "SELECT user_id, {$GLOBALS['_fullname_sql']['full_rev']} AS fullname, username, perms
FROM auth_user_md5
LEFT JOIN user_info USING (user_id)
WHERE perms NOT IN ('root', 'admin')
AND (username LIKE CONCAT('%', :needle, '%')
OR Vorname LIKE CONCAT('%', :needle, '%')
OR Nachname LIKE CONCAT('%', :needle, '%'))
LIMIT 500";
$statement = DBManager::get()->prepare($query);
$statement->bindValue(':needle', $search_for_founder);
$statement->execute();
$results_founders = $statement->fetchGrouped();
}
if (is_array($results_founders)) {
PageLayout::postSuccess(sprintf(
ngettext(
'Es wurde %s Person gefunden:',
'Es wurden %s Personen gefunden:',
count($results_founders)
),
count($results_founders)
));
} else {
PageLayout::postInfo(_('Es wurden keine Personen gefunden.'));
}
$this->flash['create'] = true;
$this->flash['results_choose_founders'] = $results_founders;
$this->flash['request'] = Request::getInstance();
// go to the form again
$this->redirect('course/studygroup/new/');
} // add a new founder
else if ($admin && Request::submitted('add_founder')) {
$founders = [Request::option('choose_founder')];
$this->flash['founders'] = $founders;
$this->flash['create'] = true;
$this->flash['request'] = Request::getInstance();
$this->redirect('course/studygroup/new/');
} // remove a founder
else if ($admin && Request::submitted('remove_founder')) {
$founders = [];
$this->flash['founders'] = $founders;
$this->flash['create'] = true;
$this->flash['request'] = Request::getInstance();
$this->redirect('course/studygroup/new/');
} // reset search
else if ($admin && Request::submitted('new_search')) {
$this->flash['create'] = true;
$this->flash['request'] = Request::getInstance();
$this->redirect('course/studygroup/new/');
} //checks
else {
if (!Request::get('groupname')) {
$errors[] = _("Bitte Gruppennamen angeben");
} else {
$query = "SELECT 1 FROM seminare WHERE name = ?";
$statement = DBManager::get()->prepare($query);
$statement->execute([
Request::get('groupname'),
]);
if ($statement->fetchColumn()) {
$errors[] = _("Eine Veranstaltung/Studiengruppe mit diesem Namen existiert bereits. Bitte wählen Sie einen anderen Namen");
}
}
if (!Request::get('grouptermsofuse_ok')) {
$errors[] = _("Sie müssen die Nutzungsbedingungen durch Setzen des Häkchens bei 'Einverstanden' akzeptieren.");
}
if ($admin && (!is_array($founders) || !sizeof($founders))) {
$errors[] = _("Sie müssen mindestens einen Gruppengründer eintragen!");
}
if (count($errors)) {
$this->flash['errors'] = $errors;
$this->flash['create'] = true;
$this->flash['request'] = Request::getInstance();
$this->redirect('course/studygroup/new/');
} else {
// Everything seems fine, let's create a studygroup
$sem_types = studygroup_sem_types();
$sem = new Seminar();
$sem->name = Request::get('groupname'); // seminar-class quotes itself
$sem->description = Request::get('groupdescription'); // seminar-class quotes itself
$sem->status = $sem_types[0];
$sem->read_level = 1;
$sem->write_level = 1;
$sem->institut_id = Config::Get()->STUDYGROUP_DEFAULT_INST;
$sem->visible = 1;
if (Request::get('groupaccess') == 'all') {
$sem->admission_prelim = 0;
} else {
$sem->admission_prelim = 1;
if (Config::get()->STUDYGROUPS_INVISIBLE_ALLOWED && Request::get('groupaccess') == 'invisible') {
$sem->visible = 0;
}
$sem->admission_prelim_txt = _("Die ModeratorInnen der Studiengruppe können Ihren Aufnahmewunsch bestätigen oder ablehnen. Erst nach Bestätigung erhalten Sie vollen Zugriff auf die Gruppe.");
}
$sem->admission_binding = 0;
$this_semester = Semester::findCurrent();
$sem->semester_start_time = $this_semester['beginn'];
$sem->semester_duration_time = -1;
if ($admin) {
// insert founder(s)
foreach ($founders as $user_id) {
CourseMember::create([
'seminar_id' => $sem->id,
'user_id' => $user_id,
'status' => 'dozent',
'gruppe' => 8
]);
}
$this->founders = null;
$this->flash['founders'] = null;
} else {
$user_id = $GLOBALS['auth']->auth['uid'];
// insert dozent
CourseMember::create([
'seminar_id' => $sem->id,
'user_id' => $user_id,
'status' => 'dozent',
'gruppe' => 8
]);
}
$sem->store();
NotificationCenter::postNotification('StudygroupDidCreate', $sem->id);
// the work is done. let's visit the brand new studygroup.
$this->redirect(URLHelper::getURL('seminar_main.php?auswahl=' . $sem->id));
}
}
}
/**
* displays a form for editing studygroups with corresponding data
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment