Beispiel #1
0
 public function selected_teachers()
 {
     if (!is_null($this->id)) {
         $teachers = new Teacher();
         $teachers->where_related($this);
         $teachers->get_iterated();
         $output = array();
         foreach ($teachers as $teacher) {
             $output[$teacher->id] = $teacher->id;
         }
         return $output;
     }
     return array();
 }
Beispiel #2
0
 private function inject_task_set_authors($task_set_id)
 {
     $teachers = new Teacher();
     $teachers->where_related('task/task_set', 'id', (int) $task_set_id);
     $teachers->order_by_as_fullname('fullname');
     $teachers->get_iterated();
     $authors = array();
     foreach ($teachers as $teacher) {
         $authors[$teacher->id] = $teacher->fullname;
     }
     $this->parser->assign('authors', $authors);
 }
Beispiel #3
0
 private function create_comment()
 {
     $post_data = $this->input->post('comment');
     if (array_key_exists('text', $post_data) && array_key_exists('task_set_id', $post_data) && array_key_exists('reply_at_id', $post_data)) {
         $task_set = new Task_set();
         $task_set->get_by_id(intval($post_data['task_set_id']));
         $student = new Student();
         $student->get_by_id($this->usermanager->get_student_id());
         if ($task_set->exists() && $student->exists() && (bool) $task_set->comments_enabled) {
             if (trim(strip_tags($post_data['text'])) != '') {
                 $text = strip_tags($post_data['text'], '<a><strong><em><span>');
                 $comment = new Comment();
                 $comment->text = $text;
                 $comment->approved = (bool) $task_set->comments_moderated ? 0 : 1;
                 $comment->reply_at_id = empty($post_data['reply_at_id']) ? NULL : intval($post_data['reply_at_id']);
                 $this->_transaction_isolation();
                 $this->db->trans_begin();
                 if ($comment->save(array($task_set, $student))) {
                     $this->db->trans_commit();
                     $this->messages->add_message('lang:tasks_comments_message_comment_post_success_save', Messages::MESSAGE_TYPE_SUCCESS);
                     if ((bool) $comment->approved) {
                         $all_students = $task_set->comment_subscriber_student;
                         $all_students->where('id !=', $this->usermanager->get_student_id());
                         $all_students->get();
                         $this->_send_multiple_emails($all_students, 'lang:tasks_comments_email_subject_new_post', 'file:emails/frontend/comments/new_comment_student.tpl', array('task_set' => $task_set, 'student' => $student, 'comment' => $comment));
                         $task_set_related_teachers = new Teacher();
                         if (!is_null($task_set->group_id)) {
                             $task_set_related_teachers->where_related('room/group', 'id', $task_set->group_id);
                         } else {
                             $task_set_related_teachers->where_related('room/group/course', 'id', $task_set->course_id);
                         }
                         $task_set_related_teachers->group_by('id');
                         $all_teachers = new Teacher();
                         $all_teachers->where_related('comment_subscription', 'id', $task_set->id);
                         $all_teachers->union($task_set_related_teachers, FALSE, '', NULL, NULL, 'id');
                         $all_teachers->check_last_query();
                         $this->_send_multiple_emails($all_teachers, 'lang:tasks_comments_email_subject_new_post', 'file:emails/frontend/comments/new_comment_teacher.tpl', array('task_set' => $task_set, 'student' => $student, 'comment' => $comment));
                     }
                     return TRUE;
                 } else {
                     $this->db->trans_rollback();
                     $this->messages->add_message('lang:tasks_comments_message_comment_post_error_save', Messages::MESSAGE_TYPE_ERROR);
                     return FALSE;
                 }
             } else {
                 $this->messages->add_message('lang:tasks_comments_message_comment_post_error_empty', Messages::MESSAGE_TYPE_ERROR);
                 return FALSE;
             }
         } else {
             $this->messages->add_message('lang:tasks_comments_message_not_found_or_disabled', Messages::MESSAGE_TYPE_ERROR);
             return FALSE;
         }
     } else {
         $this->messages->add_message('lang:tasks_comments_message_comment_post_error_data', Messages::MESSAGE_TYPE_ERROR);
         return FALSE;
     }
 }