예제 #1
0
파일: topics.php 프로젝트: ratbird/hope
 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');
 }
예제 #2
0
파일: dates.php 프로젝트: ratbird/hope
 public function add_topic_action()
 {
     if (!$GLOBALS['perm']->have_studip_perm("tutor", $_SESSION['SessionSeminar'])) {
         throw new AccessDeniedException();
     }
     if (!Request::get("title")) {
         throw new Exception("Geben Sie einen Titel an.");
     }
     $date = new CourseDate(Request::option("termin_id"));
     $seminar_id = $date['range_id'];
     $title = studip_utf8decode(Request::get("title"));
     $topic = CourseTopic::findByTitle($seminar_id, $title);
     if (!$topic) {
         $topic = new CourseTopic();
         $topic['title'] = $title;
         $topic['seminar_id'] = $seminar_id;
         $topic['author_id'] = $GLOBALS['user']->id;
         $topic['description'] = "";
         $topic->store();
     }
     $date->addTopic($topic);
     $factory = $this->get_template_factory();
     $output = array('topic_id' => $topic->getId());
     $template = $factory->open($this->get_default_template("_topic_li"));
     $template->set_attribute("topic", $topic);
     $template->set_attribute("date", $date);
     $output['li'] = $template->render();
     $this->render_json($output);
 }