Example #1
0
 private function remove_points_iteration($task_set, $points_to_remove, $task_set_id, $task_set_course_id, $task_set_group_id, &$error_code = 0, &$students = NULL)
 {
     $this->_transaction_isolation();
     $this->db->trans_begin();
     if (!is_null($task_set->upload_end_time)) {
         $timestamp_end = strtotime($task_set->upload_end_time);
         if (time() > $timestamp_end) {
             $participants = new Participant();
             $participants->select('*');
             $participants->select_subquery('(SELECT `solutions`.`id` FROM `solutions` WHERE `solutions`.`task_set_id` = ' . $task_set_id . ' AND `solutions`.`student_id` = `${parent}`.`student_id`)', 'solution_id');
             $participants->where_related_course('id', $task_set_course_id);
             if ($task_set->group->exists() && !is_null($task_set_group_id)) {
                 $participants->where_related_group('id', $task_set_group_id);
             }
             $participants->where('allowed', 1);
             $participants->get_iterated();
             $notify_students = array(0);
             foreach ($participants as $participant) {
                 if (is_null($participant->solution_id) && !is_null($participant->student_id)) {
                     $solution = new Solution();
                     $solution->task_set_id = $task_set_id;
                     $solution->student_id = $participant->student_id;
                     $solution->teacher_id = $this->usermanager->get_teacher_id();
                     $solution->points = -$points_to_remove;
                     $solution->revalidate = 0;
                     if ($solution->save()) {
                         $notify_students[] = $participant->student_id;
                     }
                 }
             }
             if ($this->db->trans_status()) {
                 $this->db->trans_commit();
                 $students = new Student();
                 $students->where_in('id', $notify_students);
                 $students->get();
                 //$result->mail_sent = $this->_send_multiple_emails($students, 'lang:admin_solutions_remove_points_notification_subject', 'file:emails/backend/solutions/remove_points_notify.tpl', array('task_set' => $task_set, 'points_to_remove' => $points_to_remove));
                 return TRUE;
             } else {
                 $this->db->trans_rollback();
                 //$result->message = $this->lang->line('admin_solutions_remove_points_error_unknown');
                 $error_code = 1;
                 return FALSE;
             }
         } else {
             $this->db->trans_rollback();
             //$result->message = $this->lang->line('admin_solutions_remove_points_error_task_set_upload_limit_not_reached');
             $error_code = 2;
             return FALSE;
         }
     } else {
         $this->db->trans_rollback();
         //$result->message = $this->lang->line('admin_solutions_remove_points_error_task_set_upload_not_limited');
         $error_code = 3;
         return FALSE;
     }
 }