public function index_action() { if (Request::isPost() && Request::get("edit") && $GLOBALS['perm']->have_studip_perm("tutor", $_SESSION['SessionSeminar'])) { $topic = new CourseTopic(Request::option("issue_id")); if ($topic['seminar_id'] && $topic['seminar_id'] !== $_SESSION['SessionSeminar']) { throw new AccessDeniedException(); } if (Request::submitted("delete_topic")) { $topic->delete(); PageLayout::postMessage(MessageBox::success(_("Thema gelöscht."))); } else { $topic['title'] = Request::get("title"); $topic['description'] = Studip\Markup::purifyHtml(Request::get("description")); if ($topic->isNew()) { $topic['seminar_id'] = $_SESSION['SessionSeminar']; } $topic->store(); //change dates for this topic $former_date_ids = $topic->dates->pluck("termin_id"); $new_date_ids = array_keys(Request::getArray("date")); foreach (array_diff($former_date_ids, $new_date_ids) as $delete_termin_id) { $topic->dates->unsetByPk($delete_termin_id); } foreach (array_diff($new_date_ids, $former_date_ids) as $add_termin_id) { $date = CourseDate::find($add_termin_id); if ($date) { $topic->dates[] = $date; } } $topic->store(); if (Request::get("folder") && !$topic->folder) { $topic->connectWithDocumentFolder(); } // create a connection to the module forum (can be anything) // will update title and description automagically if (Request::get("forumthread")) { $topic->connectWithForumThread(); } if (Request::option("issue_id") === "new") { Request::set("open", $topic->getId()); } PageLayout::postMessage(MessageBox::success(_("Thema gespeichert."))); $this->redirect("course/topics/index"); } } if (Request::isPost() && Request::option("move_down")) { $topics = CourseTopic::findBySeminar_id($_SESSION['SessionSeminar']); $mainkey = null; foreach ($topics as $key => $topic) { if ($topic->getId() === Request::option("move_down")) { $mainkey = $key; } $topic['priority'] = $key + 1; } if ($mainkey !== null && $mainkey < count($topics)) { $topics[$mainkey]->priority++; $topics[$mainkey + 1]->priority--; } foreach ($topics as $key => $topic) { $topic->store(); } } if (Request::isPost() && Request::option("move_up")) { $topics = CourseTopic::findBySeminar_id($_SESSION['SessionSeminar']); foreach ($topics as $key => $topic) { if ($topic->getId() === Request::option("move_up") && $key > 0) { $topic['priority'] = $key; $topics[$key - 1]->priority = $key + 1; $topics[$key - 1]->store(); } else { $topic['priority'] = $key + 1; } $topic->store(); } } Navigation::activateItem('/course/schedule/topics'); $this->topics = CourseTopic::findBySeminar_id($_SESSION['SessionSeminar']); $this->cancelled_dates_locked = LockRules::Check($_SESSION['SessionSeminar'], 'cancelled_dates'); }
/** * Moves a topic from one date to another. * This action will be called from an ajax request and will return only * the neccessary output for a single topic element. * * @param String $topic_id The id of the topic * @param String $old_date_id The id of the original date of the topic * @param String $new_date_id The id of the new date of the topic * @throws MethodNotAllowedException if request method is not post * @throws AccessDeniedException if the user is not allowed to execute the * action (at least tutor of the course) */ public function move_topic_action($topic_id, $old_date_id, $new_date_id) { if (!Request::isPost()) { throw new MethodNotAllowedException(); } if (!$GLOBALS['perm']->have_studip_perm('tutor', $_SESSION['SessionSeminar'])) { throw new AccessDeniedException(); } $this->topic = CourseTopic::find($topic_id); $this->date = new CourseDate($new_date_id); $this->topic->dates->unsetByPK($old_date_id); if (!$this->topic->dates->findOneBy('termin_id', $new_date_id)) { $this->topic->dates[] = CourseDate::find($new_date_id); } $this->topic->store(); $this->set_content_type('text/html;charset=windows-1252'); $this->render_template('course/dates/_topic_li.php'); }
/** * Deletes a date. * * @param String $termin_id Id of the date * @param String $sub_cmd Sub command to be executed * @param String $cycle_id Id of the associated cycle */ private function deleteDate($termin_id, $sub_cmd, $cycle_id) { //cancel cycledate entry if ($sub_cmd === 'cancel') { $termin = CourseDate::find($termin_id); $seminar_id = $termin->range_id; $room = $termin->getRoom(); $termin->cancelDate(); log_event('SEM_DELETE_SINGLEDATE', $termin_id, $seminar_id, 'Cycle_id: ' . $cycle_id); //delete singledate entry } else { if ($sub_cmd === 'delete') { $termin = CourseDate::find($termin_id) ?: CourseExDate::find($termin_id); $seminar_id = $termin->range_id; $termin_room = $termin->getRoom(); $termin_date = $termin->getFullname(); if ($termin->delete()) { log_event("SEM_DELETE_SINGLEDATE", $termin_id, $seminar_id, 'appointment cancelled'); if (Request::get('approveDelete')) { if (Config::get()->RESOURCES_ENABLE_EXPERT_SCHEDULE_VIEW) { $this->course->createMessage(sprintf(_('Sie haben den Termin %s gelöscht, dem ein Thema zugeorndet war.' . ' Sie können das Thema in der %sExpertenansicht des Ablaufplans%s einem anderen Termin (z.B. einem Ausweichtermin) zuordnen.'), $termin_date, '<a href="' . URLHelper::getLink('themen.php?cmd=changeViewMode&newFilter=expert') . '">', '</a>')); } elseif ($room) { $this->course->createMessage(sprintf(_('Der Termin %s wurde gelöscht! Die Buchung für den Raum %s wurde gelöscht.'), $termin_date, $termin_room)); } else { $this->course->createMessage(sprintf(_('Der Termin %s wurde gelöscht!'), $termin_date)); } } else { // no approval needed, delete unquestioned $this->course->createMessage(sprintf(_('Der Termin %s wurde gelöscht!'), $termin_date)); } } } } }
/** * Stores this date. * * @return bool indicating whether the date was stored or not */ public function store() { $old_entry = CourseDate::find($this->termin_id); if ($this->isNew() && !isset($this->metadate_id) && parent::store()) { log_event('SEM_ADD_SINGLEDATE', $this->range_id, $this->getFullname()); return true; } if (!$this->isNew() && !isset($this->metadate_id) && parent::store()) { if ($old_entry->date != $this->date || $old_entry->end_time != $this->end_time) { log_event('SINGLEDATE_CHANGE_TIME', $this->range_id, $old_entry->getFullname(), $old_entry->getFullname() . ' -> ' . $this->getFullname()); } return true; } if (parent::store()) { return true; } return false; }