예제 #1
0
 public function insert_to_task_set()
 {
     $this->load->library('form_validation');
     $task_set_id = intval($this->input->post('task_set_id'));
     $this->_transaction_isolation();
     $this->db->trans_begin();
     $task_set = new Task_set();
     $task_set->get_by_id($task_set_id);
     $this->form_validation->set_rules('task_id', 'task_id', 'required');
     $this->form_validation->set_rules('task_set_id', 'task_set_id', 'required');
     if ($task_set->exists()) {
         if ($task_set->content_type == 'task_set') {
             $this->form_validation->set_rules('points_total', 'lang:admin_tasks_add_to_task_set_form_field_points_total', 'required|number|greater_than_equal[0]');
             $this->form_validation->set_rules('test_max_points', 'lang:admin_tasks_add_to_task_set_form_field_test_max_points', 'required|number|greater_than_equal[0]');
             $this->form_validation->set_rules('test_min_points', 'lang:admin_tasks_add_to_task_set_form_field_test_min_points', 'required|number|less_than_field_or_equal[test_max_points]');
         } else {
             $this->form_validation->set_rules('max_projects_selections', 'lang:admin_tasks_add_to_task_set_form_field_max_projects_selections', 'required|integer|greater_than[0]');
         }
     }
     if ($this->form_validation->run()) {
         $task_id = intval($this->input->post('task_id'));
         $points_total = floatval($this->input->post('points_total'));
         $test_max_points = floatval($this->input->post('test_max_points'));
         $test_min_points = floatval($this->input->post('test_min_points'));
         $bonus_task = (int) (bool) intval($this->input->post('bonus_task'));
         $max_projects_selections = intval($this->input->post('max_projects_selections'));
         $internal_comment = $this->input->post('internal_comment');
         $task = new Task();
         $task->get_by_id($task_id);
         if (!$task->exists()) {
             $this->db->trans_rollback();
             $this->messages->add_message('lang:admin_tasks_error_message_task_not_found', Messages::MESSAGE_TYPE_ERROR);
         } elseif (!$task_set->exists()) {
             $this->db->trans_rollback();
             $this->messages->add_message('lang:admin_tasks_add_to_task_set_nothing_opened', Messages::MESSAGE_TYPE_ERROR);
         } elseif ($task_set->is_related_to($task)) {
             $this->db->trans_rollback();
             $this->messages->add_message('lang:admin_tasks_add_to_task_set_already_related', Messages::MESSAGE_TYPE_ERROR);
         } else {
             $related_task = $task_set->task->include_join_fields()->order_by('join_sorting', 'desc')->limit(1)->get();
             $new_sorting = $related_task->exists() ? intval($related_task->join_sorting) + 1 : 1;
             $task_set->save($task);
             $task_set->set_join_field($task, 'points_total', $points_total);
             $task_set->set_join_field($task, 'test_max_points', $test_max_points);
             $task_set->set_join_field($task, 'test_min_points', $test_min_points);
             $task_set->set_join_field($task, 'sorting', $new_sorting);
             $task_set->set_join_field($task, 'bonus_task', $bonus_task);
             $task_set->set_join_field($task, 'max_projects_selections', $max_projects_selections);
             $task_set->set_join_field($task, 'internal_comment', $internal_comment);
             if ($this->db->trans_status()) {
                 $this->db->trans_commit();
                 $this->messages->add_message('lang:admin_tasks_add_to_task_set_save_success', Messages::MESSAGE_TYPE_SUCCESS);
                 $this->_action_success();
             } else {
                 $this->db->trans_rollback();
                 $this->messages->add_message('lang:admin_tasks_add_to_task_set_save_failed', Messages::MESSAGE_TYPE_ERROR);
             }
         }
         redirect(create_internal_url('admin_tasks/add_to_task_set/task_id/' . $task_id));
     } else {
         $this->db->trans_rollback();
         $this->add_to_task_set();
     }
 }
예제 #2
0
 public function change_publication_status($task_set_id = null)
 {
     $output = new stdClass();
     $output->message = '';
     $output->status = FALSE;
     $this->_transaction_isolation();
     $this->db->trans_begin();
     $task_set = new Task_set();
     $task_set->get_by_id((int) $task_set_id);
     if ($task_set->exists()) {
         $task_set->published = 1 - (int) $task_set->published;
         $task_set->save();
         $this->db->trans_commit();
         $output->message = sprintf($this->lang->line('admin_task_sets_publication_status_switched'), $this->lang->get_overlay_with_default('task_sets', $task_set->id, 'name', $task_set->name));
         $output->status = TRUE;
         $this->_action_success();
     } else {
         $this->db->trans_rollback();
         $output->message = $this->lang->line('admin_task_sets_error_task_set_not_found');
     }
     $this->output->set_output(json_encode($output));
 }
예제 #3
0
 public function send_deadline_notifications($lang_idiom = NULL)
 {
     $this->load->database();
     $this->load->model('translations');
     if (!is_null($lang_idiom)) {
         $this->lang->reinitialize_for_idiom($lang_idiom);
     }
     $translations = $this->translations->get_translations_for_idiom($this->lang->get_current_idiom());
     $this->lang->add_custom_translations($translations);
     $this->lang->load('cli');
     $current_time = Date('Y-m-d H:i:s');
     $one_day_back_time = Date('Y-m-d H:i:s', strtotime('now -1 day'));
     $task_sets1 = new Task_set();
     $task_sets1->select('id, name, course_id, group_id AS common_group_id, upload_end_time AS common_upload_end_time, deadline_notified AS common_deadline_notified, deadline_notification_emails AS common_deadline_notification_emails, deadline_notification_emails_handler AS common_deadline_notification_emails_handler');
     $task_sets1->select('null AS `task_set_permission_id`', FALSE);
     $task_sets1->where('deadline_notified', 0);
     $task_sets1->where('deadline_notification_emails_handler >', 0);
     $task_sets1->group_start();
     $task_sets1->not_group_start();
     $task_sets1->where('upload_end_time', NULL);
     $task_sets1->group_end();
     $task_sets1->where('upload_end_time <', $current_time);
     $task_sets1->where('upload_end_time >=', $one_day_back_time);
     $task_sets1->group_end();
     $task_sets1->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_sets1->where('published', 1);
     $task_sets2 = new Task_set();
     $task_sets2->select('id, name, course_id');
     $task_sets2->include_related('task_set_permission', 'group_id', 'common');
     $task_sets2->include_related('task_set_permission', 'upload_end_time', 'common');
     $task_sets2->include_related('task_set_permission', 'deadline_notified', 'common');
     $task_sets2->include_related('task_set_permission', 'deadline_notification_emails', 'common');
     $task_sets2->include_related('task_set_permission', 'deadline_notification_emails_handler', 'common');
     $task_sets2->include_related('task_set_permission', 'id');
     $task_sets2->where_related('task_set_permission', 'enabled', 1);
     $task_sets2->where_related('task_set_permission', 'deadline_notified', 0);
     $task_sets2->where_related('task_set_permission', 'deadline_notification_emails_handler >', 0);
     $task_sets2->group_start();
     $task_sets2->not_group_start();
     $task_sets2->where_related('task_set_permission', 'upload_end_time', NULL);
     $task_sets2->group_end();
     $task_sets2->where_related('task_set_permission', 'upload_end_time <', $current_time);
     $task_sets2->where_related('task_set_permission', 'upload_end_time >=', $one_day_back_time);
     $task_sets2->group_end();
     $task_sets2->where('published', 1);
     $task_sets1->union_iterated($task_sets2, TRUE);
     $this->load->library('email');
     $sent_notifications = 0;
     foreach ($task_sets1 as $task_set) {
         if ($task_set->common_deadline_notification_emails_handler > 0) {
             $emails = trim($task_set->common_deadline_notification_emails) != '' ? explode(',', $task_set->common_deadline_notification_emails) : array();
             array_walk($emails, function (&$email, $key) {
                 $email = trim($email);
             });
             if ($task_set->common_deadline_notification_emails_handler == 1) {
                 $groups = new Group();
                 $groups->where_related('course', 'id', $task_set->course_id);
                 $groups->include_related('room/teacher', '*');
                 $groups->group_start('NOT');
                 $groups->where_related('room', 'id', null);
                 $groups->or_where_related('room/teacher', 'id', null);
                 $groups->group_end();
                 $groups->group_by_related('room/teacher', 'email');
                 if (!is_null($task_set->common_group_id)) {
                     $groups->where('id', $task_set->common_group_id);
                 }
                 $groups->get_iterated();
                 foreach ($groups as $teacher) {
                     if (trim($teacher->room_teacher_email) != '') {
                         $email = trim($teacher->room_teacher_email);
                         if (!in_array($email, $emails)) {
                             $emails[] = $email;
                         }
                     }
                 }
             }
             $group = new Group();
             if (!is_null($task_set->common_group_id)) {
                 $group->get_by_id((int) $task_set->common_group_id);
             }
             if (count($emails)) {
                 $this->email->from_system();
                 $this->email->reply_to_system();
                 $this->email->build_message_body('file:emails/cli/deadline_notification.tpl', array('task_set' => $task_set, 'group' => $group));
                 if ($this->config->item('email_multirecipient_batch_mode')) {
                     $this->email->to($emails);
                     $this->email->subject('LIST: ' . $this->lang->line('cli_deadline_notification_subject'));
                     $this->email->send();
                 } else {
                     foreach ($emails as $email) {
                         $this->email->to($email);
                         $this->email->subject('TEST');
                         $this->email->send();
                     }
                 }
                 $sent_notifications++;
                 if (!is_null($task_set->task_set_permission_id)) {
                     $task_set_permission = new Task_set_permission();
                     $task_set_permission->get_by_id($task_set->task_set_permission_id);
                     if ($task_set_permission->exists()) {
                         $task_set_permission->deadline_notified = 1;
                         $task_set_permission->save();
                     }
                 } else {
                     $task_set_update = new Task_set();
                     $task_set_update->get_by_id($task_set->id);
                     if ($task_set_update->exists()) {
                         $task_set_update->deadline_notified = 1;
                         $task_set_update->save();
                     }
                 }
             }
         }
     }
     echo "Process finished, {$sent_notifications} notifications were sent ...\n";
 }
예제 #4
0
function list_import_lamsfet_tasks_in_sets_relation($sets, $tasks, $tasks_in_sets)
{
    echo 'Starting task_task_set_rel import (' . count($tasks_in_sets) . ') [';
    if (count($tasks_in_sets)) {
        foreach ($tasks_in_sets as $task_in_set) {
            $task_set_id = $sets[$task_in_set->set_id]->_list_id;
            $task_id = $tasks[$task_in_set->task_id]->_list_id;
            $task_set = new Task_set();
            $task_set->get_by_id(intval($task_set_id));
            $task = new Task();
            $task->get_by_id(intval($task_id));
            if ($task_set->exists() && $task->exists()) {
                $task_set->save($task);
                $task_set->set_join_field($task, 'sorting', $task_in_set->order);
                $task_set->set_join_field($task, 'points_total', floatval($task_in_set->points));
                $task_set->set_join_field($task, 'bonus_task', 0);
            } else {
                echo ' ( TASK SET OR TASK NOT FOUND ' . $task_set_id . '(' . $task_in_set->set_id . ')/' . $task_id . '(' . $task_in_set->task_id . ') ) ';
            }
            echo '.';
        }
    }
    echo '] ... done' . "\n";
}