Пример #1
0
    /**
     * Retrieve results and return them as an array of Result objects
     * @param $id result id
     * @param $user_id user id (student)
     * @param $evaluation_id evaluation where this is a result for
     */
    public static function load($id = null, $user_id = null, $evaluation_id = null)
    {
        $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
        $tbl_grade_results = Database::get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
        $tbl_course_rel_course = Database::get_main_table(TABLE_MAIN_COURSE_USER);
        $tbl_session_rel_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
        if (is_null($id) && is_null($user_id) && !is_null($evaluation_id)) {
            $sql_verified_if_exist_evaluation = 'SELECT COUNT(*) AS count FROM ' . $tbl_grade_results . ' WHERE evaluation_id="' . Database::escape_string($evaluation_id) . '";';
            $res_verified_if_exist_evaluation = Database::query($sql_verified_if_exist_evaluation);
            $info_verified_if_exist_evaluation = Database::result($res_verified_if_exist_evaluation, 0, 0);
            if ($info_verified_if_exist_evaluation != 0) {
                $sql_course_rel_user = '';
                if (api_get_session_id()) {
                    $sql_course_rel_user = '******' . $tbl_session_rel_course_user . '
											WHERE status=0 AND c_id="' . api_get_course_int_id() . '" AND id_session=' . api_get_session_id();
                } else {
                    $sql_course_rel_user = '******' . $tbl_course_rel_course . '
					                        WHERE status ="' . STUDENT . '" AND c_id ="' . api_get_course_int_id() . '" ';
                }
                $res_course_rel_user = Database::query($sql_course_rel_user);
                $list_user_course_list = array();
                while ($row_course_rel_user = Database::fetch_array($res_course_rel_user, 'ASSOC')) {
                    $list_user_course_list[] = $row_course_rel_user;
                }
                $current_date = api_get_utc_datetime();
                for ($i = 0; $i < count($list_user_course_list); $i++) {
                    $sql_verified = 'SELECT COUNT(*) AS count FROM ' . $tbl_grade_results . ' WHERE user_id="' . intval($list_user_course_list[$i]['user_id']) . '" AND evaluation_id="' . intval($evaluation_id) . '";';
                    $res_verified = Database::query($sql_verified);
                    $info_verified = Database::result($res_verified, 0, 0);
                    if ($info_verified == 0) {
                        $sql_insert = 'INSERT INTO ' . $tbl_grade_results . '(user_id,evaluation_id,created_at,score)
									 VALUES ("' . intval($list_user_course_list[$i]['user_id']) . '","' . intval($evaluation_id) . '","' . $current_date . '",0);';
                        $res_insert = Database::query($sql_insert);
                    }
                }
                $list_user_course_list = array();
            }
        }
        $sql = "SELECT gr.id, gr.user_id, gr.evaluation_id, gr.created_at, gr.score \n                FROM {$tbl_grade_results} gr\n                LEFT JOIN {$tbl_user} u ON gr.user_id = u.user_id ";
        $paramcount = 0;
        if (!empty($id)) {
            $sql .= ' WHERE gr.id = ' . Database::escape_string($id);
            $paramcount++;
        }
        if (!empty($user_id)) {
            if ($paramcount != 0) {
                $sql .= ' AND';
            } else {
                $sql .= ' WHERE';
            }
            $sql .= ' user_id = ' . Database::escape_string($user_id);
            $paramcount++;
        }
        if (!empty($evaluation_id)) {
            if ($paramcount != 0) {
                $sql .= ' AND';
            } else {
                $sql .= ' WHERE';
            }
            $sql .= ' evaluation_id = ' . Database::escape_string($evaluation_id);
            $paramcount++;
        }
        $result = Database::query($sql);
        $allres = array();
        while ($data = Database::fetch_array($result)) {
            $res = new Result();
            $res->set_id($data['id']);
            $res->set_user_id($data['user_id']);
            $res->set_evaluation_id($data['evaluation_id']);
            $res->set_date(api_get_local_time($data['created_at']));
            $res->set_score($data['score']);
            $allres[] = $res;
        }
        return $allres;
    }
Пример #2
0
                 header('Location: gradebook_view_result.php?selecteval=' . Security::remove_XSS($_GET['selecteval']) . '&import_user_error=' . $importedresult['user_id']);
                 exit;
             }
         }
         if ($added != '1') {
             if ($importedresult['score'] > $eval[0]->get_max()) {
                 header('Location: gradebook_view_result.php?selecteval=' . Security::remove_XSS($_GET['selecteval']) . '&overwritemax=');
                 exit;
             }
             $result = new Result();
             $result->set_user_id($importedresult['user_id']);
             if (!empty($importedresult['score'])) {
                 $result->set_score(floatval(number_format($importedresult['score'], api_get_setting('gradebook_number_decimals'))));
             }
             if (!empty($importedresult['date'])) {
                 $result->set_date(api_get_utc_datetime($importedresult['date']));
             } else {
                 $result->set_date(api_get_utc_datetime());
             }
             $result->set_evaluation_id($_GET['selecteval']);
             $result->add();
             $nr_results_added++;
         }
     }
 } else {
     header('Location: ' . api_get_self() . '?import=&selecteval=' . Security::remove_XSS($_GET['selecteval']) . '&importnofile=');
     exit;
 }
 if ($overwritescore != 0) {
     header('Location: ' . api_get_self() . '?selecteval=' . Security::remove_XSS($_GET['selecteval']) . '&importoverwritescore=' . $overwritescore);
     exit;