}
if (isset($_GET['selecteval'])) {
    $allresults = Result::load(null, null, $select_eval);
    $iscourse = $currentcat[0]->get_course_code() == null ? 1 : 0;
}
if (isset($_GET['editres'])) {
    $edit_res_xml = Security::remove_XSS($_GET['editres']);
    $select_eval_edit = Security::remove_XSS($_GET['selecteval']);
    $resultedit = Result::load($edit_res_xml);
    $edit_res_form = new EvalForm(EvalForm::TYPE_RESULT_EDIT, $eval[0], $resultedit[0], 'edit_result_form', null, api_get_self() . '?editres=' . $resultedit[0]->get_id() . '&selecteval=' . $select_eval_edit . '&' . api_get_cidreq());
    if ($edit_res_form->validate()) {
        $values = $edit_res_form->exportValues();
        $result = new Result();
        $resultlog = new Result();
        $resultlog->add_result__log($values['hid_user_id'], $select_eval_edit);
        $result->set_id($edit_res_xml);
        $result->set_user_id($values['hid_user_id']);
        $result->set_evaluation_id($select_eval_edit);
        $row_value = isset($values['score']) ? (double) $values['score'] : 0;
        if (!empty($row_value) || $row_value == 0) {
            $result->set_score(floatval(number_format($row_value, api_get_setting('gradebook_number_decimals'))));
        }
        $result->save();
        unset($result);
        header('Location: gradebook_view_result.php?selecteval=' . $select_eval_edit . '&editresmessage=&' . api_get_cidreq());
        exit;
    }
}
$file_type = null;
if (isset($_GET['import'])) {
    $interbreadcrumb[] = array('url' => 'gradebook_view_result.php?selecteval=' . Security::remove_XSS($_GET['selecteval']) . '&' . api_get_cidreq(), 'name' => get_lang('ViewResult'));
Beispiel #2
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;
    }
 static function transaction_33($original_data, $web_service_details)
 {
     global $data_list;
     $data = Migration::soap_call($web_service_details, 'notaDetalles', array('uididpersona' => $original_data['item_id'], 'uididprograma' => $original_data['orig_id'], 'intIdSede' => $original_data['branch_id']));
     if ($data['error'] == false) {
         $uidIdPrograma = $original_data['orig_id'];
         $uidIdPersona = $original_data['item_id'];
         $score = $data['name'];
         $session_id = self::get_session_id_by_programa_id($uidIdPrograma, $data_list);
         $user_id = self::get_user_id_by_persona_id($uidIdPersona, $data_list);
         if (empty($user_id)) {
             return array('message' => "User does not exists in DB: {$uidIdPersona}", 'status_id' => self::TRANSACTION_STATUS_FAILED);
         }
         if (empty($session_id)) {
             return array('message' => "Session does not exists in DB: {$uidIdPrograma}", 'status_id' => self::TRANSACTION_STATUS_FAILED);
         }
         $course_list = SessionManager::get_course_list_by_session_id($session_id);
         if (!empty($course_list)) {
             $course_data = current($course_list);
             if (isset($course_data['code'])) {
                 $gradebook = new Gradebook();
                 $gradebook = $gradebook->get_first(array('where' => array('course_code = ? AND session_id = ?' => array($course_data['code'], $session_id))));
                 error_log("Looking gradebook in course code:  {$course_data['code']} - session_id: {$session_id}");
                 if (!empty($gradebook)) {
                     //Check if gradebook exists
                     $eval = new Evaluation();
                     $evals_found = $eval->load(null, null, null, $gradebook['id'], null, null);
                     //Try to create a gradebook evaluation
                     if (empty($evals_found)) {
                         error_log("Trying to create a new evaluation in course code:  {$course_data['code']} - session_id: {$session_id}");
                         $params = array('session_id' => $session_id, 'gradebook_description' => 'Evaluación General', 'gradebook_evaluation_type_id' => 0);
                         self::create_gradebook_evaluation($params);
                         $evals_found = $eval->load(null, null, null, $gradebook['id'], null, null);
                     }
                     if (!empty($evals_found)) {
                         $evaluation = current($evals_found);
                         $eval_id = $evaluation->get_id();
                         error_log("Gradebook exists: {$gradebook['id']} eval_id: {$eval_id}");
                         //Eval found
                         $res = new Result();
                         $check_result = Result::load(null, $user_id, $eval_id);
                         if (!empty($check_result) && isset($check_result[0])) {
                             // Gradebook result found. Updating...
                             $res->set_evaluation_id($eval_id);
                             $res->set_user_id($user_id);
                             $res->set_score($score);
                             $res->set_id($check_result[0]->get_id());
                             $res->save();
                             $eval_result = Result::load(null, $user_id, $eval_id);
                             return array('entity' => 'gradebook_evaluation_result', 'before' => $check_result, 'after' => $eval_result, 'message' => "Gradebook result edited ", 'status_id' => self::TRANSACTION_STATUS_SUCCESSFUL);
                         } else {
                             // Gradebook result not found. Creating...
                             // @todo disable when moving to production
                             $res->set_evaluation_id($eval_id);
                             $res->set_user_id($user_id);
                             //if no scores are given, don't set the score
                             $res->set_score($score);
                             $res->add();
                             $eval_result = Result::load(null, $user_id, $eval_id);
                             //$message = "Gradebook result not modified because gradebook result does not exist for user_id: $user_id - eval_id: $eval_id - gradebook_id: {$gradebook['id']} - course: {$course_data['code']} - session_id: $session_id";
                             return array('entity' => 'gradebook_evaluation_result', 'before' => null, 'after' => $eval_result, 'message' => "Gradebook result added because it did not exist for update", 'status_id' => self::TRANSACTION_STATUS_SUCCESSFUL);
                         }
                     } else {
                         $message = "Evaluation not found in gradebook: {$gradebook['id']} : in course: {$course_data['code']} - session_id: {$session_id}";
                     }
                 } else {
                     $message = "Gradebook does not exists in course: {$course_data['code']} - session_id: {$session_id}";
                 }
             } else {
                 $message = "Something is wrong with the course ";
             }
         } else {
             $message = "NO course found for session id: {$session_id}";
         }
         return array('message' => $message, 'status_id' => self::TRANSACTION_STATUS_FAILED);
     } else {
         return $data;
     }
 }