Esempio n. 1
0
 public function fetch_topics_action()
 {
     if (!$GLOBALS['perm']->have_studip_perm("tutor", Request::option("seminar_id"))) {
         throw new AccessDeniedException();
     }
     $this->topics = CourseTopic::findBySeminar_id(Request::option("seminar_id"));
     $output = array('html' => $this->render_template_as_string("course/topics/_topiclist.php"));
     $this->render_json($output);
 }
Esempio n. 2
0
 /**
  * Stores this cycle.
  * @return int number of changed rows
  */
 public function store()
 {
     $cycle = parent::findByMetadate_id($this->metadate_id);
     //create new entry in seminare_cycle_date
     if (!$cycle) {
         $result = parent::store();
         if ($result) {
             $new_dates = $this->createTerminSlots();
             foreach ($new_dates as $semester_dates) {
                 foreach ($semester_dates['dates'] as $date) {
                     $result += $date->store();
                 }
             }
             StudipLog::log('SEM_ADD_CYCLE', $this->seminar_id, NULL, $this->toString());
             return $result;
         }
         return 0;
     }
     //change existing cycledate, changes also corresponding single dates
     $old_cycle = SeminarCycleDate::find($this->metadate_id);
     if (!parent::store()) {
         return false;
     }
     if (mktime($this->start_time) >= mktime($old_cycle->start_time) && mktime($this->end_time) <= mktime($old_cycle->end_time) && $this->weekday == $old_cycle->weekday && $this->end_offset == $old_cycle->end_offset) {
         $update_count = 0;
         foreach ($this->getAllDates() as $date) {
             $tos = $date->date;
             $toe = $date->end_time;
             //Update future dates
             if ($toe > time()) {
                 $date->date = mktime(date('G', strtotime($this->start_time)), date('i', strtotime($this->start_time)), 0, date('m', $tos), date('d', $tos), date('Y', $tos));
                 $date->end_time = mktime(date('G', strtotime($this->end_time)), date('i', strtotime($this->end_time)), 0, date('m', $toe), date('d', $toe), date('Y', $toe));
             }
             if ($date->isDirty()) {
                 $date->store();
                 $update_count++;
             }
         }
         StudipLog::log('SEM_CHANGE_CYCLE', $this->seminar_id, NULL, $old_cycle->toString() . ' -> ' . $this->toString());
         return $update_count;
     }
     //collect topics for existing future dates (CourseDate)
     $topics = array();
     foreach ($this->getAllDates() as $date) {
         if ($date->end_time >= time()) {
             $topics_tmp = CourseTopic::findByTermin_id($date->termin_id);
             if (!empty($topics_tmp)) {
                 $topics[] = $topics_tmp;
             }
             //uncomment below
             $date->delete();
         }
     }
     $new_dates = $this->createTerminSlots(time());
     $topic_count = 0;
     $update_count = 0;
     foreach ($new_dates as $semester_dates) {
         foreach ($semester_dates['dates'] as $date) {
             if ($date instanceof CourseDate) {
                 if (isset($topics[$topic_count])) {
                     $date->topics = $topics[$topic_count];
                     $topic_count++;
                 }
             }
             $date->store();
             $update_count++;
         }
     }
     StudipLog::log('SEM_CHANGE_CYCLE', $this->seminar_id, NULL, $old_cycle->toString() . ' -> ' . $this->toString());
     return $update_count;
 }
Esempio n. 3
0
 /**
  * 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');
 }
Esempio n. 4
0
 /**
  * Adds a topic to this date.
  *
  * @param mixed $topic Topic definition (might be an id, an array or an
  *                     object)
  * @return number addition of all return values, false if none was called
  */
 public function addTopic($topic)
 {
     $topic = CourseTopic::toObject($topic);
     if (!$this->topics->find($topic->id)) {
         $this->topics[] = $topic;
         return $this->storeRelations('topics');
     }
 }