/** * @param array $source * * @return array * @throws \Exception */ public function run($source) { $results = array(); foreach ($source as $number => $line) { $result = new Result(); $line = trim($line); while (!empty($line)) { $match = $this->match($line); if ($match === false) { throw new \Exception("Unable to parse line " . ($number + 1) . "."); } $result->add($match); $line = substr($line, strlen(current($match))); } $results[] = $result; } return $results; }
} $add_user_form = new EvalForm(EvalForm::TYPE_ADD_USERS_TO_EVAL, $evaluation[0], null, 'add_users_to_evaluation', null, api_get_self() . '?selecteval=' . Security::remove_XSS($_GET['selecteval']), Security::remove_XSS($_GET['firstletter']), $newstudents); if (isset($_POST['submit_button'])) { $users = is_array($_POST['add_users']) ? $_POST['add_users'] : array(); foreach ($users as $key => $value) { $users[$key] = intval($value); } if (count($users) == 0) { header('Location: ' . api_get_self() . '?erroroneuser=&selecteval=' . Security::remove_XSS($_GET['selecteval'])); exit; } else { foreach ($users as $user_id) { $result = new Result(); $result->set_user_id($user_id); $result->set_evaluation_id($_GET['selecteval']); $result->add(); } } header('Location: gradebook_view_result.php?adduser=&selecteval=' . Security::remove_XSS($_GET['selecteval'])); exit; } elseif ($_POST['firstLetterUser']) { $firstletter = $_POST['firstLetterUser']; if (!empty($firstletter)) { header('Location: ' . api_get_self() . '?firstletter=' . Security::remove_XSS($firstletter) . '&selecteval=' . Security::remove_XSS($_GET['selecteval'])); exit; } } $interbreadcrumb[] = array('url' => Security::remove_XSS($_SESSION['gradebook_dest']), 'name' => get_lang('Gradebook')); $interbreadcrumb[] = array('url' => 'gradebook_view_result.php?selecteval=' . Security::remove_XSS($_GET['selecteval']), 'name' => get_lang('ViewResult')); Display::display_header(get_lang('AddUserToEval')); if (isset($_GET['erroroneuser'])) {
$evaluation = Evaluation::load($_GET['selecteval']); $category = !empty($_GET['selectcat']) ? $_GET['selectcat'] : ""; $add_result_form = new EvalForm(EvalForm::TYPE_RESULT_ADD, $evaluation[0], $resultadd, 'add_result_form', null, api_get_self() . '?selectcat=' . Security::remove_XSS($category) . '&selecteval=' . Security::remove_XSS($_GET['selecteval'])); $table = $add_result_form->toHtml(); if ($add_result_form->validate()) { $values = $add_result_form->exportValues(); $nr_users = $values['nr_users']; if ($nr_users == '0') { header('Location: gradebook_view_result.php?addresultnostudents=&selecteval=' . Security::remove_XSS($_GET['selecteval'])); exit; } $scores = $values['score']; foreach ($scores as $row) { $res = new Result(); $res->set_evaluation_id($values['evaluation_id']); $res->set_user_id(key($scores)); //if no scores are given, don't set the score if (!empty($row) || $row == '0') { $res->set_score($row); } $res->add(); next($scores); } header('Location: gradebook_view_result.php?addresult=&selecteval=' . Security::remove_XSS($_GET['selecteval'])); exit; } $interbreadcrumb[] = array('url' => Security::remove_XSS($_SESSION['gradebook_dest']), 'name' => get_lang('Gradebook')); Display::display_header(get_lang('AddResult')); DisplayGradebook::display_header_result($evaluation[0], null, 0, 0); echo $table; Display::display_footer();
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; } }