示例#1
0
 public function batch_save_solutions($task_set_id)
 {
     $this->_transaction_isolation();
     $this->db->trans_begin();
     $task_set = new Task_set();
     $task_set->get_by_id($task_set_id);
     if ($task_set->exists()) {
         $data = $this->input->post('batch_valuation');
         $saved_count = 0;
         $save_status = TRUE;
         if (is_array($data) && count($data) > 0) {
             foreach ($data as $student_id => $solution_data) {
                 $student = new Student();
                 $student->get_by_id($student_id);
                 $task_set_check = new Task_set();
                 $task_set_check->where_related('course/participant/student', 'id', intval($student_id));
                 $task_set_check->where_related('course/participant', 'allowed', 1);
                 $task_set_check->group_start();
                 $task_set_check->or_group_start();
                 $task_set_check->group_start();
                 $task_set_check->or_where('group_id', NULL);
                 $task_set_check->or_where('`course_participants`.`group_id` = `task_sets`.`group_id`');
                 $task_set_check->group_end();
                 $task_set_check->where_subquery(0, '(SELECT COUNT(`tsp`.`id`) AS `count` FROM `task_set_permissions` tsp WHERE `tsp`.`task_set_id` = `task_sets`.`id` AND `tsp`.`enabled` = 1)');
                 $task_set_check->group_end();
                 $task_set_check->or_where_related('task_set_permission', '`group_id` = `course_participants`.`group_id`');
                 $task_set_check->or_where_related('solution', 'student_id', $student->id);
                 $task_set_check->group_end();
                 $task_set_check->get_by_id($task_set_id);
                 if ($student->exists() && $task_set_check->exists() && array_key_exists('points', $solution_data) && is_numeric($solution_data['points'])) {
                     $solution = new Solution();
                     $solution->where_related_student('id', $student->id);
                     $solution->where_related_task_set('id', $task_set->id);
                     $solution->get();
                     if (is_null($solution->points) || floatval($solution->points) !== floatval($solution_data['points']) || $solution->not_considered != intval(@$solution_data['not_considered'])) {
                         $solution->teacher_id = $this->usermanager->get_teacher_id();
                         $solution->points = floatval($solution_data['points']);
                         $solution->revalidate = 0;
                         $solution->not_considered = intval(@$solution_data['not_considered']);
                         $save_status = $save_status & $solution->save(array($task_set, $student));
                         $saved_count++;
                     }
                 }
             }
         }
         if ($this->db->trans_status() && $save_status && $saved_count > 0) {
             $this->db->trans_commit();
             $this->messages->add_message('lang:admin_solutions_batch_valuation_success_message_save_ok', Messages::MESSAGE_TYPE_SUCCESS);
             $this->_action_success();
         } else {
             $this->db->trans_rollback();
             $this->messages->add_message('lang:admin_solutions_batch_valuation_error_message_save_failed', Messages::MESSAGE_TYPE_ERROR);
         }
     } else {
         $this->db->trans_rollback();
         $this->messages->add_message('lang:admin_solutions_batch_valuation_error_message_save_failed', Messages::MESSAGE_TYPE_ERROR);
     }
     redirect(create_internal_url('admin_solutions/batch_valuation_list/' . $task_set_id));
 }