$form = new FormValidator('search_simple', 'POST', '', '', null, false);
$form->addElement('select', 'session_id', get_lang('Sessions'), $my_session_list, array('id' => 'session_id', 'onchange' => 'load_courses();'));
$form->addElement('select', 'course_code', get_lang('Courses'), $course_select_list);
$form->addElement('style_submit_button', 'submit_form', get_lang('Filter'));
if (!empty($_REQUEST['course_code'])) {
    $course_code = $_REQUEST['course_code'];
} else {
    $course_code = '';
}
if (empty($course_code)) {
    $course_code = 0;
}
$form->setDefaults(array('course_code' => (string) $course_code));
$course_info = api_get_course_info($course_code);
if (!empty($course_info)) {
    $list = new LearnpathList('', $course_code);
    $lp_list = $list->get_flat_list();
    $_course = $course_info;
    $main_question_list = array();
    foreach ($lp_list as $lp_id => $lp) {
        $exercise_list = ExerciseLib::get_all_exercises_from_lp($lp_id, $course_info['real_id']);
        foreach ($exercise_list as $exercise) {
            $my_exercise = new Exercise();
            $my_exercise->read($exercise['path']);
            $question_list = $my_exercise->selectQuestionList();
            $exercise_stats = get_all_exercise_event_from_lp($exercise['path'], $course_info['real_id'], $session_id);
            foreach ($question_list as $question_id) {
                $question_data = Question::read($question_id);
                $main_question_list[$question_id] = $question_data;
                $quantity_exercises = 0;
                $question_result = 0;
Example #2
0
     $columns = array('session', 'exercise_id', 'quiz_title', 'username', 'lastname', 'firstname', 'time', 'question_id', 'question', 'description', 'answer', 'correct');
     $result = Tracking::get_exercise_progress($sessionId, $courseId, $exerciseId, $date_from, $date_to, array('where' => $whereCondition, 'order' => "{$sidx} {$sord}", 'limit' => "{$start} , {$limit}"));
     break;
 case 'get_session_lp_progress':
     $sessionId = 0;
     if (!empty($_GET['session_id']) && !empty($_GET['course_id'])) {
         $sessionId = intval($_GET['session_id']);
         $courseId = intval($_GET['course_id']);
         $course = api_get_course_info_by_id($courseId);
     }
     /**
      * Add lessons of course
      *
      */
     $columns = array('username', 'firstname', 'lastname');
     $lessons = LearnpathList::get_course_lessons($course['code'], $sessionId);
     foreach ($lessons as $lesson_id => $lesson) {
         $columns[] = $lesson_id;
     }
     $columns[] = 'total';
     $result = SessionManager::get_session_lp_progress($sessionId, $courseId, $date_from, $date_to, array('where' => $whereCondition, 'order' => "{$sidx} {$sord}", 'limit' => "{$start} , {$limit}"));
     break;
 case 'get_survey_overview':
     $sessionId = 0;
     if (!empty($_GET['session_id']) && !empty($_GET['course_id']) && !empty($_GET['survey_id'])) {
         $sessionId = intval($_GET['session_id']);
         $courseId = intval($_GET['course_id']);
         $surveyId = intval($_GET['survey_id']);
         $date_from = $_GET['date_from'];
         $date_to = $_GET['date_to'];
         //$course    = api_get_course_info_by_id($courseId);
 /**
  * function which redefines Question::createAnswersForm
  * @param FormValidator $form
  */
 public function createAnswersForm($form)
 {
     // Getting the exercise list
     $obj_ex = $_SESSION['objExercise'];
     $editor_config = array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '125');
     //this line defines how many questions by default appear when creating a choice question
     // The previous default value was 2. See task #1759.
     $nb_answers = isset($_POST['nb_answers']) ? (int) $_POST['nb_answers'] : 4;
     $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0);
     /*
         Types of Feedback
         $feedback_option[0]=get_lang('Feedback');
        $feedback_option[1]=get_lang('DirectFeedback');
        $feedback_option[2]=get_lang('NoFeedback');
     */
     $feedback_title = '';
     if ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
         //Scenario
         $editor_config['Width'] = '250';
         $editor_config['Height'] = '110';
         $comment_title = '<th width="500px" >' . get_lang('Comment') . '</th>';
         $feedback_title = '<th width="350px" >' . get_lang('Scenario') . '</th>';
     } else {
         $comment_title = '<th>' . get_lang('Comment') . '</th>';
     }
     $html = '<table class="data_table">
             <tr style="text-align: center;">
                 <th width="10px">
                     ' . get_lang('Number') . '
                 </th>
                 <th width="10px" >
                     ' . get_lang('True') . '
                 </th>
                 <th width="50%">
                     ' . get_lang('Answer') . '
                 </th>
                     ' . $comment_title . '
                     ' . $feedback_title . '
                 <th width="50px">
                     ' . get_lang('Weighting') . '
                 </th>
             </tr>';
     $form->addElement('label', get_lang('Answers') . '<br /> <img src="../img/fill_field.png">', $html);
     $defaults = array();
     $correct = 0;
     if (!empty($this->id)) {
         $answer = new Answer($this->id);
         $answer->read();
         if (count($answer->nbrAnswers) > 0 && !$form->isSubmitted()) {
             $nb_answers = $answer->nbrAnswers;
         }
     }
     $form->addElement('hidden', 'nb_answers');
     //Feedback SELECT
     $question_list = $obj_ex->selectQuestionList();
     $select_question = array();
     $select_question[0] = get_lang('SelectTargetQuestion');
     require_once '../newscorm/learnpathList.class.php';
     if (is_array($question_list)) {
         foreach ($question_list as $key => $questionid) {
             //To avoid warning messages
             if (!is_numeric($questionid)) {
                 continue;
             }
             $question = Question::read($questionid);
             $select_question[$questionid] = 'Q' . $key . ' :' . cut($question->selectTitle(), 20);
         }
     }
     $select_question[-1] = get_lang('ExitTest');
     $list = new LearnpathList(api_get_user_id());
     $flat_list = $list->get_flat_list();
     $select_lp_id = array();
     $select_lp_id[0] = get_lang('SelectTargetLP');
     foreach ($flat_list as $id => $details) {
         $select_lp_id[$id] = cut($details['lp_name'], 20);
     }
     $temp_scenario = array();
     if ($nb_answers < 1) {
         $nb_answers = 1;
         Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
     }
     for ($i = 1; $i <= $nb_answers; ++$i) {
         $form->addElement('html', '<tr>');
         if (isset($answer) && is_object($answer)) {
             if ($answer->correct[$i]) {
                 $correct = $i;
             }
             $defaults['answer[' . $i . ']'] = $answer->answer[$i];
             $defaults['comment[' . $i . ']'] = $answer->comment[$i];
             $defaults['weighting[' . $i . ']'] = float_format($answer->weighting[$i], 1);
             $item_list = explode('@@', $answer->destination[$i]);
             $try = $item_list[0];
             $lp = $item_list[1];
             $list_dest = $item_list[2];
             $url = $item_list[3];
             if ($try == 0) {
                 $try_result = 0;
             } else {
                 $try_result = 1;
             }
             if ($url == 0) {
                 $url_result = '';
             } else {
                 $url_result = $url;
             }
             $temp_scenario['url' . $i] = $url_result;
             $temp_scenario['try' . $i] = $try_result;
             $temp_scenario['lp' . $i] = $lp;
             $temp_scenario['destination' . $i] = $list_dest;
         } else {
             $defaults['answer[1]'] = get_lang('DefaultUniqueAnswer1');
             $defaults['weighting[1]'] = 10;
             $defaults['answer[2]'] = get_lang('DefaultUniqueAnswer2');
             $defaults['weighting[2]'] = 0;
             $temp_scenario['destination' . $i] = array('0');
             $temp_scenario['lp' . $i] = array('0');
         }
         $defaults['scenario'] = $temp_scenario;
         $renderer = $form->defaultRenderer();
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'correct');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'counter[' . $i . ']');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'answer[' . $i . ']');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment[' . $i . ']');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'weighting[' . $i . ']');
         $answer_number = $form->addElement('text', 'counter[' . $i . ']', null, ' value = "' . $i . '"');
         $answer_number->freeze();
         $form->addElement('radio', 'correct', null, null, $i, 'class="checkbox" style="margin-left: 0em;"');
         $form->addElement('html_editor', 'answer[' . $i . ']', null, 'style="vertical-align:middle"', $editor_config);
         $form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required');
         if ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
             $form->addElement('html_editor', 'comment[' . $i . ']', null, 'style="vertical-align:middle"', $editor_config);
             // Direct feedback
             //Adding extra feedback fields
             $group = array();
             $group['try' . $i] = $form->createElement('checkbox', 'try' . $i, null, get_lang('TryAgain'));
             $group['lp' . $i] = $form->createElement('select', 'lp' . $i, get_lang('SeeTheory') . ': ', $select_lp_id);
             $group['destination' . $i] = $form->createElement('select', 'destination' . $i, get_lang('GoToQuestion') . ': ', $select_question);
             $group['url' . $i] = $form->createElement('text', 'url' . $i, get_lang('Other') . ': ', array('class' => 'span2', 'placeholder' => get_lang('Other')));
             $form->addGroup($group, 'scenario');
             $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}', 'scenario');
         } else {
             $form->addElement('html_editor', 'comment[' . $i . ']', null, 'style="vertical-align:middle"', $editor_config);
         }
         $form->addElement('text', 'weighting[' . $i . ']', null, array('class' => "span1", 'value' => '0'));
         $form->addElement('html', '</tr>');
     }
     $form->addElement('html', '</table>');
     $form->addElement('html', '<br />');
     $navigator_info = api_get_navigator();
     global $text, $class;
     //ie6 fix
     if ($obj_ex->edit_exercise_in_lp == true) {
         if ($navigator_info['name'] == 'Internet Explorer' && $navigator_info['version'] == '6') {
             $form->addElement('submit', 'lessAnswers', get_lang('LessAnswer'), 'class="btn minus"');
             $form->addElement('submit', 'moreAnswers', get_lang('PlusAnswer'), 'class="btn plus"');
             $form->addElement('submit', 'submitQuestion', $text, 'class="' . $class . '"');
         } else {
             //setting the save button here and not in the question class.php
             $form->addElement('style_submit_button', 'lessAnswers', get_lang('LessAnswer'), 'class="btn minus"');
             $form->addElement('style_submit_button', 'moreAnswers', get_lang('PlusAnswer'), 'class="btn plus"');
             $form->addElement('style_submit_button', 'submitQuestion', $text, 'class="' . $class . '"');
         }
     }
     $renderer->setElementTemplate('{element}&nbsp;', 'submitQuestion');
     $renderer->setElementTemplate('{element}&nbsp;', 'lessAnswers');
     $renderer->setElementTemplate('{element}&nbsp;', 'moreAnswers');
     $form->addElement('html', '</div></div>');
     // We check the first radio button to be sure a radio button will be check
     if ($correct == 0) {
         $correct = 1;
     }
     $defaults['correct'] = $correct;
     if (!empty($this->id)) {
         $form->setDefaults($defaults);
     } else {
         if ($this->isContent == 1) {
             // Default sample content.
             $form->setDefaults($defaults);
         } else {
             $form->setDefaults(array('correct' => 1));
         }
     }
     $form->setConstants(array('nb_answers' => $nb_answers));
 }
 /**
  * @param $id
  * @param $copy_courses
  * @param $copy_users
  * @param $create_new_courses
  * @param $set_exercises_lp_invisible
  * @return int
  */
 public static function copy_session($id, $copy_courses = true, $copy_users = true, $create_new_courses = false, $set_exercises_lp_invisible = false)
 {
     $id = intval($id);
     $params = self::fetch($id);
     $params['name'] = $params['name'] . ' ' . get_lang('CopyLabelSuffix');
     $sid = self::add($params);
     if (!is_numeric($sid) || empty($sid)) {
         return false;
     }
     if ($copy_courses) {
         // Register courses from the original session to the new session
         $courses = self::get_course_list_by_session_id($id);
         $short_courses = $new_short_courses = array();
         if (is_array($courses) && count($courses) > 0) {
             foreach ($courses as $course) {
                 $short_courses[] = $course;
             }
         }
         $courses = null;
         //We will copy the current courses of the session to new courses
         if (!empty($short_courses)) {
             if ($create_new_courses) {
                 //Just in case
                 if (function_exists('ini_set')) {
                     api_set_memory_limit('256M');
                     ini_set('max_execution_time', 0);
                 }
                 $params = array();
                 $params['skip_lp_dates'] = true;
                 foreach ($short_courses as $course_data) {
                     $course_info = CourseManager::copy_course_simple($course_data['title'] . ' ' . get_lang('CopyLabelSuffix'), $course_data['course_code'], $id, $sid, $params);
                     if ($course_info) {
                         //By default new elements are invisible
                         if ($set_exercises_lp_invisible) {
                             $list = new LearnpathList('', $course_info['code'], $sid);
                             $flat_list = $list->get_flat_list();
                             if (!empty($flat_list)) {
                                 foreach ($flat_list as $lp_id => $data) {
                                     api_item_property_update($course_info, TOOL_LEARNPATH, $lp_id, 'invisible', api_get_user_id(), 0, 0, 0, 0, $sid);
                                     api_item_property_update($course_info, TOOL_LEARNPATH, $lp_id, 'invisible', api_get_user_id(), 0, 0, 0, 0);
                                 }
                             }
                             $quiz_table = Database::get_course_table(TABLE_QUIZ_TEST);
                             $course_id = $course_info['real_id'];
                             //@todo check this query
                             //Disabling quiz items
                             $sql = "UPDATE {$quiz_table} SET active = 0 WHERE c_id = {$course_id} ";
                             Database::query($sql);
                         }
                         $new_short_courses[] = $course_info['code'];
                     }
                 }
             } else {
                 foreach ($short_courses as $course_data) {
                     $new_short_courses[] = $course_data['id'];
                 }
             }
             $short_courses = $new_short_courses;
             $res = self::add_courses_to_session($sid, $short_courses, true);
             $short_courses = null;
         }
     }
     if ($copy_users) {
         // Register users from the original session to the new session
         $users = self::get_users_by_session($id);
         $short_users = array();
         if (is_array($users) && count($users) > 0) {
             foreach ($users as $user) {
                 $short_users[] = $user['user_id'];
             }
         }
         $users = null;
         //Subscribing in read only mode
         $res = self::suscribe_users_to_session($sid, $short_users, SESSION_VISIBLE_READ_ONLY, true, false);
         $short_users = null;
     }
     return $sid;
 }
Example #5
0
 /**
  * Shows the user detail progress (when clicking in the details link)
  * @param   int     $user_id
  * @param   string  $course_code
  * @param   int     $session_id
  * @return  string  html code
  */
 public static function show_course_detail($user_id, $course_code, $session_id)
 {
     $html = '';
     if (isset($course_code)) {
         $user_id = intval($user_id);
         $session_id = intval($session_id);
         $course = Database::escape_string($course_code);
         $course_info = CourseManager::get_course_information($course);
         $html .= Display::page_subheader($course_info['title']);
         $html .= '<table class="data_table" width="100%">';
         //Course details
         $html .= '
             <tr>
             <th class="head" style="color:#000">' . get_lang('Exercises') . '</th>
             <th class="head" style="color:#000">' . get_lang('Attempts') . '</th>
             <th class="head" style="color:#000">' . get_lang('BestAttempt') . '</th>
             <th class="head" style="color:#000">' . get_lang('Ranking') . '</th>
             <th class="head" style="color:#000">' . get_lang('BestResultInCourse') . '</th>
             <th class="head" style="color:#000">' . get_lang('Statistics') . ' ' . Display::return_icon('info3.gif', get_lang('OnlyBestResultsPerStudent'), array('align' => 'absmiddle', 'hspace' => '3px')) . '</th>
             </tr>';
         if (empty($session_id)) {
             $user_list = CourseManager::get_user_list_from_course_code($course, $session_id, null, null, STUDENT);
         } else {
             $user_list = CourseManager::get_user_list_from_course_code($course, $session_id, null, null, 0);
         }
         // Show exercise results of invisible exercises? see BT#4091
         $exercise_list = ExerciseLib::get_all_exercises($course_info, $session_id, false, null, false, 2);
         $to_graph_exercise_result = array();
         if (!empty($exercise_list)) {
             $score = $weighting = $exe_id = 0;
             foreach ($exercise_list as $exercices) {
                 $exercise_obj = new Exercise($course_info['real_id']);
                 $exercise_obj->read($exercices['id']);
                 $visible_return = $exercise_obj->is_visible();
                 $score = $weighting = $attempts = 0;
                 // Getting count of attempts by user
                 $attempts = Event::count_exercise_attempts_by_user(api_get_user_id(), $exercices['id'], $course_info['real_id'], $session_id);
                 $html .= '<tr class="row_even">';
                 $url = api_get_path(WEB_CODE_PATH) . "exercice/overview.php?cidReq={$course_info['code']}&id_session={$session_id}&exerciseId={$exercices['id']}";
                 if ($visible_return['value'] == true) {
                     $exercices['title'] = Display::url($exercices['title'], $url, array('target' => SESSION_LINK_TARGET));
                 }
                 $html .= Display::tag('td', $exercices['title']);
                 // Exercise configuration show results or show only score
                 if ($exercices['results_disabled'] == 0 || $exercices['results_disabled'] == 2) {
                     //For graphics
                     $best_exercise_stats = Event::get_best_exercise_results_by_user($exercices['id'], $course_info['real_id'], $session_id);
                     $to_graph_exercise_result[$exercices['id']] = array('title' => $exercices['title'], 'data' => $best_exercise_stats);
                     $latest_attempt_url = '';
                     $best_score = $position = $percentage_score_result = '-';
                     $graph = $normal_graph = null;
                     // Getting best results
                     $best_score_data = ExerciseLib::get_best_attempt_in_course($exercices['id'], $course_info['real_id'], $session_id);
                     $best_score = '';
                     if (!empty($best_score_data)) {
                         $best_score = ExerciseLib::show_score($best_score_data['exe_result'], $best_score_data['exe_weighting']);
                     }
                     if ($attempts > 0) {
                         $exercise_stat = ExerciseLib::get_best_attempt_by_user(api_get_user_id(), $exercices['id'], $course_info['real_id'], $session_id);
                         if (!empty($exercise_stat)) {
                             //Always getting the BEST attempt
                             $score = $exercise_stat['exe_result'];
                             $weighting = $exercise_stat['exe_weighting'];
                             $exe_id = $exercise_stat['exe_id'];
                             $latest_attempt_url .= api_get_path(WEB_CODE_PATH) . 'exercice/result.php?id=' . $exe_id . '&cidReq=' . $course_info['code'] . '&show_headers=1&id_session=' . $session_id;
                             $percentage_score_result = Display::url(ExerciseLib::show_score($score, $weighting), $latest_attempt_url);
                             $my_score = 0;
                             if (!empty($weighting) && intval($weighting) != 0) {
                                 $my_score = $score / $weighting;
                             }
                             //@todo this function slows the page
                             $position = ExerciseLib::get_exercise_result_ranking($my_score, $exe_id, $exercices['id'], $course_info['code'], $session_id, $user_list);
                             $graph = self::generate_exercise_result_thumbnail_graph($to_graph_exercise_result[$exercices['id']]);
                             $normal_graph = self::generate_exercise_result_graph($to_graph_exercise_result[$exercices['id']]);
                         }
                     }
                     $html .= Display::div($normal_graph, array('id' => 'main_graph_' . $exercices['id'], 'class' => 'dialog', 'style' => 'display:none'));
                     if (empty($graph)) {
                         $graph = '-';
                     } else {
                         $graph = Display::url('<img src="' . $graph . '" >', $normal_graph, array('id' => $exercices['id'], 'class' => 'expand-image'));
                     }
                     $html .= Display::tag('td', $attempts, array('align' => 'center'));
                     $html .= Display::tag('td', $percentage_score_result, array('align' => 'center'));
                     $html .= Display::tag('td', $position, array('align' => 'center'));
                     $html .= Display::tag('td', $best_score, array('align' => 'center'));
                     $html .= Display::tag('td', $graph, array('align' => 'center'));
                     //$html .= Display::tag('td', $latest_attempt_url,       array('align'=>'center', 'width'=>'25'));
                 } else {
                     // Exercise configuration NO results
                     $html .= Display::tag('td', $attempts, array('align' => 'center'));
                     $html .= Display::tag('td', '-', array('align' => 'center'));
                     $html .= Display::tag('td', '-', array('align' => 'center'));
                     $html .= Display::tag('td', '-', array('align' => 'center'));
                     $html .= Display::tag('td', '-', array('align' => 'center'));
                 }
                 $html .= '</tr>';
             }
         } else {
             $html .= '<tr><td colspan="5" align="center">' . get_lang('NoEx') . '</td></tr>';
         }
         $html .= '</table>';
         // LP table results
         $html .= '<table class="data_table">';
         $html .= Display::tag('th', get_lang('Learnpaths'), array('class' => 'head', 'style' => 'color:#000'));
         $html .= Display::tag('th', get_lang('LatencyTimeSpent'), array('class' => 'head', 'style' => 'color:#000'));
         $html .= Display::tag('th', get_lang('Progress'), array('class' => 'head', 'style' => 'color:#000'));
         $html .= Display::tag('th', get_lang('Score'), array('class' => 'head', 'style' => 'color:#000'));
         $html .= Display::tag('th', get_lang('LastConnexion'), array('class' => 'head', 'style' => 'color:#000'));
         $html .= '</tr>';
         $list = new LearnpathList(api_get_user_id(), $course_info['code'], $session_id, 'publicated_on ASC', true);
         $lp_list = $list->get_flat_list();
         if (!empty($lp_list) > 0) {
             foreach ($lp_list as $lp_id => $learnpath) {
                 $progress = Tracking::get_avg_student_progress($user_id, $course, array($lp_id), $session_id);
                 $last_connection_in_lp = Tracking::get_last_connection_time_in_lp($user_id, $course, $lp_id, $session_id);
                 $time_spent_in_lp = Tracking::get_time_spent_in_lp($user_id, $course, array($lp_id), $session_id);
                 $percentage_score = Tracking::get_avg_student_score($user_id, $course, array($lp_id), $session_id);
                 if (is_numeric($percentage_score)) {
                     $percentage_score = $percentage_score . '%';
                 } else {
                     $percentage_score = '0%';
                 }
                 $time_spent_in_lp = api_time_to_hms($time_spent_in_lp);
                 $html .= '<tr class="row_even">';
                 $url = api_get_path(WEB_CODE_PATH) . "newscorm/lp_controller.php?cidReq={$course_code}&id_session={$session_id}&lp_id={$lp_id}&action=view";
                 if ($learnpath['lp_visibility'] == 0) {
                     $html .= Display::tag('td', $learnpath['lp_name']);
                 } else {
                     $html .= Display::tag('td', Display::url($learnpath['lp_name'], $url, array('target' => SESSION_LINK_TARGET)));
                 }
                 $html .= Display::tag('td', $time_spent_in_lp, array('align' => 'center'));
                 if (is_numeric($progress)) {
                     $progress = $progress . '%';
                 }
                 $html .= Display::tag('td', $progress, array('align' => 'center'));
                 $html .= Display::tag('td', $percentage_score);
                 $last_connection = '-';
                 if (!empty($last_connection_in_lp)) {
                     $last_connection = api_convert_and_format_date($last_connection_in_lp, DATE_TIME_FORMAT_LONG);
                 }
                 $html .= Display::tag('td', $last_connection, array('align' => 'center', 'width' => '180px'));
                 $html .= "</tr>";
             }
         } else {
             $html .= '<tr>
                     <td colspan="4" align="center">
                         ' . get_lang('NoLearnpath') . '
                     </td>
                   </tr>';
         }
         $html .= '</table>';
     }
     return $html;
 }
 /**
  * Copies a session with the same data to a new session.
  * The new copy is not assigned to the same promotion. @see suscribe_sessions_to_promotions() for that
  * @param   int     Session ID
  * @param   bool    Whether to copy the relationship with courses
  * @param   bool    Whether to copy the relationship with users
  * @param   bool    New courses will be created
  * @param   bool    Whether to set exercises and learning paths in the new session to invisible by default
  * @return  int     The new session ID on success, 0 otherwise
  * @todo make sure the extra session fields are copied too
  */
 public static function copy($id, $copy_courses = true, $copy_users = true, $create_new_courses = false, $set_exercises_lp_invisible = false)
 {
     $id = intval($id);
     $s = self::fetch($id);
     // Check all dates before copying
     // Get timestamp for now in UTC - see http://php.net/manual/es/function.time.php#117251
     $now = time() - date('Z');
     // Timestamp in one month
     $inOneMonth = $now + 30 * 24 * 3600;
     $inOneMonth = api_get_local_time($inOneMonth);
     if (api_strtotime($s['access_start_date']) < $now) {
         $s['access_start_date'] = api_get_local_time($now);
     }
     if (api_strtotime($s['display_start_date']) < $now) {
         $s['display_start_date'] = api_get_local_time($now);
     }
     if (api_strtotime($s['coach_access_start_date']) < $now) {
         $s['coach_access_start_date'] = api_get_local_time($now);
     }
     if (api_strtotime($s['access_end_date']) < $now) {
         $s['access_end_date'] = $inOneMonth;
     }
     if (api_strtotime($s['display_end_date']) < $now) {
         $s['display_end_date'] = $inOneMonth;
     }
     if (api_strtotime($s['coach_access_end_date']) < $now) {
         $s['coach_access_end_date'] = $inOneMonth;
     }
     // Now try to create the session
     $sid = self::create_session($s['name'] . ' ' . get_lang('CopyLabelSuffix'), $s['access_start_date'], $s['access_end_date'], $s['display_start_date'], $s['display_end_date'], $s['coach_access_start_date'], $s['coach_access_end_date'], (int) $s['id_coach'], $s['session_category_id'], (int) $s['visibility'], true);
     if (!is_numeric($sid) || empty($sid)) {
         return false;
     }
     if ($copy_courses) {
         // Register courses from the original session to the new session
         $courses = self::get_course_list_by_session_id($id);
         $short_courses = $new_short_courses = array();
         if (is_array($courses) && count($courses) > 0) {
             foreach ($courses as $course) {
                 $short_courses[] = $course;
             }
         }
         $courses = null;
         //We will copy the current courses of the session to new courses
         if (!empty($short_courses)) {
             if ($create_new_courses) {
                 //Just in case
                 if (function_exists('ini_set')) {
                     api_set_memory_limit('256M');
                     ini_set('max_execution_time', 0);
                 }
                 $params = array();
                 $params['skip_lp_dates'] = true;
                 foreach ($short_courses as $course_data) {
                     $course_info = CourseManager::copy_course_simple($course_data['title'] . ' ' . get_lang('CopyLabelSuffix'), $course_data['course_code'], $id, $sid, $params);
                     if ($course_info) {
                         //By default new elements are invisible
                         if ($set_exercises_lp_invisible) {
                             $list = new LearnpathList('', $course_info['code'], $sid);
                             $flat_list = $list->get_flat_list();
                             if (!empty($flat_list)) {
                                 foreach ($flat_list as $lp_id => $data) {
                                     api_item_property_update($course_info, TOOL_LEARNPATH, $lp_id, 'invisible', api_get_user_id(), 0, 0, 0, 0, $sid);
                                 }
                             }
                             $quiz_table = Database::get_course_table(TABLE_QUIZ_TEST);
                             $course_id = $course_info['real_id'];
                             //@todo check this query
                             $sql = "UPDATE {$quiz_table} SET active = 0 WHERE c_id = {$course_id} AND session_id = {$sid}";
                             $result = Database::query($sql);
                         }
                         $new_short_courses[] = $course_info['real_id'];
                     }
                 }
             } else {
                 foreach ($short_courses as $course_data) {
                     $new_short_courses[] = $course_data['id'];
                 }
             }
             $short_courses = $new_short_courses;
             self::add_courses_to_session($sid, $short_courses, true);
             $short_courses = null;
         }
     }
     if ($copy_users) {
         // Register users from the original session to the new session
         $users = self::get_users_by_session($id);
         $short_users = array();
         if (is_array($users) && count($users) > 0) {
             foreach ($users as $user) {
                 $short_users[] = $user['user_id'];
             }
         }
         $users = null;
         //Subscribing in read only mode
         self::suscribe_users_to_session($sid, $short_users, SESSION_VISIBLE_READ_ONLY, true);
         $short_users = null;
     }
     return $sid;
 }
Example #7
0
 /**
  * Gets the exam'data results
  * @todo this function should be moved in a library  + no global calls
  * @param int $from
  * @param int $number_of_items
  * @param int $column
  * @param string $direction
  * @param int $exercise_id
  * @param null $extra_where_conditions
  * @param bool $get_count
  * @return array
  */
 public static function get_exam_results_data($from, $number_of_items, $column, $direction, $exercise_id, $extra_where_conditions = null, $get_count = false)
 {
     //@todo replace all this globals
     global $documentPath, $filter;
     $course_id = api_get_course_int_id();
     $sessionId = api_get_session_id();
     $is_allowedToEdit = api_is_allowed_to_edit(null, true) || api_is_allowed_to_edit(true) || api_is_drh() || api_is_student_boss();
     $TBL_USER = Database::get_main_table(TABLE_MAIN_USER);
     $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
     $TBL_GROUP_REL_USER = Database::get_course_table(TABLE_GROUP_USER);
     $TBL_GROUP = Database::get_course_table(TABLE_GROUP);
     $TBL_TRACK_EXERCICES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
     $TBL_TRACK_HOTPOTATOES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
     $TBL_TRACK_ATTEMPT_RECORDING = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
     $session_id_and = ' AND te.session_id = ' . $sessionId . ' ';
     $exercise_id = intval($exercise_id);
     $exercise_where = '';
     if (!empty($exercise_id)) {
         $exercise_where .= ' AND te.exe_exo_id = ' . $exercise_id . '  ';
     }
     $hotpotatoe_where = '';
     if (!empty($_GET['path'])) {
         $hotpotatoe_path = Database::escape_string($_GET['path']);
         $hotpotatoe_where .= ' AND exe_name = "' . $hotpotatoe_path . '"  ';
     }
     // sql for chamilo-type tests for teacher / tutor view
     $sql_inner_join_tbl_track_exercices = "\n        (\n            SELECT DISTINCT ttte.*, if(tr.exe_id,1, 0) as revised\n            FROM {$TBL_TRACK_EXERCICES} ttte LEFT JOIN {$TBL_TRACK_ATTEMPT_RECORDING} tr\n            ON (ttte.exe_id = tr.exe_id)\n            WHERE\n                c_id = {$course_id} AND\n                exe_exo_id = {$exercise_id} AND\n                ttte.session_id = " . $sessionId . "\n        )";
     if ($is_allowedToEdit) {
         //@todo fix to work with COURSE_RELATION_TYPE_RRHH in both queries
         // Hack in order to filter groups
         $sql_inner_join_tbl_user = '';
         if (strpos($extra_where_conditions, 'group_id')) {
             $sql_inner_join_tbl_user = "******" . $course_id . ")\n                    INNER JOIN {$TBL_GROUP} g\n                    ON (gru.group_id = g.id AND g.c_id=" . $course_id . ")\n                )";
         }
         if (strpos($extra_where_conditions, 'group_all')) {
             $extra_where_conditions = str_replace("AND (  group_id = 'group_all'  )", '', $extra_where_conditions);
             $extra_where_conditions = str_replace("AND group_id = 'group_all'", '', $extra_where_conditions);
             $extra_where_conditions = str_replace("group_id = 'group_all' AND", '', $extra_where_conditions);
             $sql_inner_join_tbl_user = "******";
             $sql_inner_join_tbl_user = null;
         }
         if (strpos($extra_where_conditions, 'group_none')) {
             $extra_where_conditions = str_replace("AND (  group_id = 'group_none'  )", "AND (  group_id is null  )", $extra_where_conditions);
             $extra_where_conditions = str_replace("AND group_id = 'group_none'", "AND (  group_id is null  )", $extra_where_conditions);
             $sql_inner_join_tbl_user = "******" . $course_id . " )\n                LEFT OUTER JOIN {$TBL_GROUP} g\n                ON (gru.group_id = g.id AND g.c_id = " . $course_id . ")\n            )";
         }
         // All
         $is_empty_sql_inner_join_tbl_user = false;
         if (empty($sql_inner_join_tbl_user)) {
             $is_empty_sql_inner_join_tbl_user = true;
             $sql_inner_join_tbl_user = "******" . api_get_users_status_ignored_in_reports('string') . ")\n            )";
         }
         $sqlFromOption = " , {$TBL_GROUP_REL_USER} AS gru ";
         $sqlWhereOption = "  AND gru.c_id = " . $course_id . " AND gru.user_id = user.user_id ";
         $first_and_last_name = api_is_western_name_order() ? "firstname, lastname" : "lastname, firstname";
         if ($get_count) {
             $sql_select = "SELECT count(te.exe_id) ";
         } else {
             $sql_select = "SELECT DISTINCT\n                    user_id,\n                    {$first_and_last_name},\n                    official_code,\n                    ce.title,\n                    username,\n                    te.exe_result,\n                    te.exe_weighting,\n                    te.exe_date,\n                    te.exe_id,\n                    email as exemail,\n                    te.start_date,\n                    steps_counter,\n                    exe_user_id,\n                    te.exe_duration,\n                    propagate_neg,\n                    revised,\n                    group_name,\n                    group_id,\n                    orig_lp_id,\n                    te.user_ip";
         }
         $sql = " {$sql_select}\n                FROM {$TBL_EXERCICES} AS ce\n                INNER JOIN {$sql_inner_join_tbl_track_exercices} AS te\n                ON (te.exe_exo_id = ce.id)\n                INNER JOIN {$sql_inner_join_tbl_user} AS user\n                ON (user.user_id = exe_user_id)\n                WHERE\n                    te.status != 'incomplete' AND\n                    te.c_id = " . $course_id . " {$session_id_and} AND\n                    ce.active <>-1 AND ce.c_id = " . $course_id . "\n                    {$exercise_where}\n                    {$extra_where_conditions}\n                ";
         // sql for hotpotatoes tests for teacher / tutor view
         if ($get_count) {
             $hpsql_select = "SELECT count(username)";
         } else {
             $hpsql_select = "SELECT\n                    {$first_and_last_name} ,\n                    username,\n                    official_code,\n                    tth.exe_name,\n                    tth.exe_result ,\n                    tth.exe_weighting,\n                    tth.exe_date";
         }
         $hpsql = " {$hpsql_select}\n                FROM\n                    {$TBL_TRACK_HOTPOTATOES} tth,\n                    {$TBL_USER} user\n                    {$sqlFromOption}\n                WHERE\n                    user.user_id=tth.exe_user_id\n                    AND tth.c_id = " . $course_id . "\n                    {$hotpotatoe_where}\n                    {$sqlWhereOption}\n                    AND user.status NOT IN(" . api_get_users_status_ignored_in_reports('string') . ")\n                ORDER BY\n                    tth.c_id ASC,\n                    tth.exe_date DESC";
     }
     if ($get_count) {
         $resx = Database::query($sql);
         $rowx = Database::fetch_row($resx, 'ASSOC');
         return $rowx[0];
     }
     $teacher_list = CourseManager::getTeacherListFromCourse(api_get_course_int_id());
     $teacher_id_list = array();
     if (!empty($teacher_list)) {
         foreach ($teacher_list as $teacher) {
             $teacher_id_list[] = $teacher['user_id'];
         }
     }
     $list_info = array();
     // Simple exercises
     if (empty($hotpotatoe_where)) {
         $column = !empty($column) ? Database::escape_string($column) : null;
         $from = intval($from);
         $number_of_items = intval($number_of_items);
         if (!empty($column)) {
             $sql .= " ORDER BY {$column} {$direction} ";
         }
         $sql .= " LIMIT {$from}, {$number_of_items}";
         $results = array();
         $resx = Database::query($sql);
         while ($rowx = Database::fetch_array($resx, 'ASSOC')) {
             $results[] = $rowx;
         }
         $group_list = GroupManager::get_group_list();
         $clean_group_list = array();
         if (!empty($group_list)) {
             foreach ($group_list as $group) {
                 $clean_group_list[$group['id']] = $group['name'];
             }
         }
         $lp_list_obj = new LearnpathList(api_get_user_id());
         $lp_list = $lp_list_obj->get_flat_list();
         if (is_array($results)) {
             $users_array_id = array();
             $from_gradebook = false;
             if (isset($_GET['gradebook']) && $_GET['gradebook'] == 'view') {
                 $from_gradebook = true;
             }
             $sizeof = count($results);
             $user_list_id = array();
             $locked = api_resource_is_locked_by_gradebook($exercise_id, LINK_EXERCISE);
             // Looping results
             for ($i = 0; $i < $sizeof; $i++) {
                 $revised = $results[$i]['revised'];
                 if ($from_gradebook && $is_allowedToEdit) {
                     if (in_array($results[$i]['username'] . $results[$i]['firstname'] . $results[$i]['lastname'], $users_array_id)) {
                         continue;
                     }
                     $users_array_id[] = $results[$i]['username'] . $results[$i]['firstname'] . $results[$i]['lastname'];
                 }
                 $lp_obj = isset($results[$i]['orig_lp_id']) && isset($lp_list[$results[$i]['orig_lp_id']]) ? $lp_list[$results[$i]['orig_lp_id']] : null;
                 $lp_name = null;
                 if ($lp_obj) {
                     $url = api_get_path(WEB_CODE_PATH) . 'newscorm/lp_controller.php?' . api_get_cidreq() . '&action=view&lp_id=' . $results[$i]['orig_lp_id'];
                     $lp_name = Display::url($lp_obj['lp_name'], $url, array('target' => '_blank'));
                 }
                 //Add all groups by user
                 $group_name_list = null;
                 if ($is_empty_sql_inner_join_tbl_user) {
                     $group_list = GroupManager::get_group_ids(api_get_course_int_id(), $results[$i]['user_id']);
                     foreach ($group_list as $id) {
                         $group_name_list .= $clean_group_list[$id] . '<br/>';
                     }
                     $results[$i]['group_name'] = $group_name_list;
                 }
                 $results[$i]['exe_duration'] = !empty($results[$i]['exe_duration']) ? round($results[$i]['exe_duration'] / 60) : 0;
                 $user_list_id[] = $results[$i]['exe_user_id'];
                 $id = $results[$i]['exe_id'];
                 $dt = api_convert_and_format_date($results[$i]['exe_weighting']);
                 // we filter the results if we have the permission to
                 if (isset($results[$i]['results_disabled'])) {
                     $result_disabled = intval($results[$i]['results_disabled']);
                 } else {
                     $result_disabled = 0;
                 }
                 if ($result_disabled == 0) {
                     $my_res = $results[$i]['exe_result'];
                     $my_total = $results[$i]['exe_weighting'];
                     $results[$i]['start_date'] = api_get_local_time($results[$i]['start_date']);
                     $results[$i]['exe_date'] = api_get_local_time($results[$i]['exe_date']);
                     if (!$results[$i]['propagate_neg'] && $my_res < 0) {
                         $my_res = 0;
                     }
                     $score = self::show_score($my_res, $my_total);
                     $actions = '';
                     if ($is_allowedToEdit) {
                         if (isset($teacher_id_list)) {
                             if (in_array($results[$i]['exe_user_id'], $teacher_id_list)) {
                                 $actions .= Display::return_icon('teachers.gif', get_lang('Teacher'));
                             }
                         }
                         if ($revised) {
                             $actions .= "<a href='exercise_show.php?" . api_get_cidreq() . "&action=edit&id={$id}'>" . Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL);
                             $actions .= '&nbsp;';
                         } else {
                             $actions .= "<a href='exercise_show.php?" . api_get_cidreq() . "&action=qualify&id={$id}'>" . Display::return_icon('quiz.gif', get_lang('Qualify'));
                             $actions .= '&nbsp;';
                         }
                         $actions .= "</a>";
                         if ($filter == 2) {
                             $actions .= ' <a href="exercise_history.php?' . api_get_cidreq() . '&exe_id=' . $id . '">' . Display::return_icon('history.gif', get_lang('ViewHistoryChange')) . '</a>';
                         }
                         //Admin can always delete the attempt
                         if (($locked == false || api_is_platform_admin()) && !api_is_student_boss()) {
                             $ip = TrackingUserLog::get_ip_from_user_event($results[$i]['exe_user_id'], date('Y-m-d h:i:s'), false);
                             $actions .= '<a href="http://www.whatsmyip.org/ip-geo-location/?ip=' . $ip . '" target="_blank">';
                             $actions .= Display::return_icon('info.png', $ip, ['title' => $ip]);
                             $actions .= '</a>';
                             $delete_link = '<a href="exercise_report.php?' . api_get_cidreq() . '&filter_by_user='******'filter_by_user']) . '&filter=' . $filter . '&exerciseId=' . $exercise_id . '&delete=delete&did=' . $id . '"
                             onclick="javascript:if(!confirm(\'' . sprintf(get_lang('DeleteAttempt'), $results[$i]['username'], $dt) . '\')) return false;">' . Display::return_icon('delete.png', get_lang('Delete')) . '</a>';
                             $delete_link = utf8_encode($delete_link);
                             if (api_is_drh() && !api_is_platform_admin()) {
                                 $delete_link = null;
                             }
                             $actions .= $delete_link . '&nbsp;';
                         }
                     } else {
                         $attempt_url = api_get_path(WEB_CODE_PATH) . 'exercice/result.php?' . api_get_cidreq() . '&id=' . $results[$i]['exe_id'] . '&id_session=' . $sessionId;
                         $attempt_link = Display::url(get_lang('Show'), $attempt_url, ['class' => 'ajax btn btn-default', 'data-title' => get_lang('Show')]);
                         $actions .= $attempt_link;
                     }
                     if ($revised) {
                         $revised = Display::label(get_lang('Validated'), 'success');
                     } else {
                         $revised = Display::label(get_lang('NotValidated'), 'info');
                     }
                     if ($is_allowedToEdit) {
                         $results[$i]['status'] = $revised;
                         $results[$i]['score'] = $score;
                         $results[$i]['lp'] = $lp_name;
                         $results[$i]['actions'] = $actions;
                         $list_info[] = $results[$i];
                     } else {
                         $results[$i]['status'] = $revised;
                         $results[$i]['score'] = $score;
                         $results[$i]['actions'] = $actions;
                         $list_info[] = $results[$i];
                     }
                 }
             }
         }
     } else {
         $hpresults = StatsUtils::getManyResultsXCol($hpsql, 6);
         // Print HotPotatoes test results.
         if (is_array($hpresults)) {
             for ($i = 0; $i < sizeof($hpresults); $i++) {
                 $hp_title = GetQuizName($hpresults[$i][3], $documentPath);
                 if ($hp_title == '') {
                     $hp_title = basename($hpresults[$i][3]);
                 }
                 $hp_date = api_get_local_time($hpresults[$i][6], null, date_default_timezone_get());
                 $hp_result = round($hpresults[$i][4] / ($hpresults[$i][5] != 0 ? $hpresults[$i][5] : 1) * 100, 2) . '% (' . $hpresults[$i][4] . ' / ' . $hpresults[$i][5] . ')';
                 if ($is_allowedToEdit) {
                     $list_info[] = array($hpresults[$i][0], $hpresults[$i][1], $hpresults[$i][2], '', $hp_title, '-', $hp_date, $hp_result, '-');
                 } else {
                     $list_info[] = array($hp_title, '-', $hp_date, $hp_result, '-');
                 }
             }
         }
     }
     return $list_info;
 }
Example #8
0
 /**
  * Display a sortable table that contains an overview off all the progress of the user in a session
  * @author César Perales <*****@*****.**>, Beeznest Team
  */
 public static function display_tracking_lp_progress_overview($sessionId = '', $courseId = '', $date_from, $date_to)
 {
     $course = api_get_course_info_by_id($courseId);
     /**
      * Column name
      * The order is important you need to check the $column variable in the model.ajax.php file
      */
     $columns = array(get_lang('Username'), get_lang('FirstName'), get_lang('LastName'));
     //add lessons of course
     $lessons = LearnpathList::get_course_lessons($course['code'], $sessionId);
     //create columns array
     foreach ($lessons as $lesson_id => $lesson) {
         $columns[] = $lesson['name'];
     }
     $columns[] = get_lang('Total');
     /**
      * Column config
      */
     $column_model = array(array('name' => 'username', 'index' => 'username', 'align' => 'left', 'search' => 'true', 'wrap_cell' => "true"), array('name' => 'firstname', 'index' => 'firstname', 'align' => 'left', 'search' => 'true'), array('name' => 'lastname', 'index' => 'lastname', 'align' => 'left', 'search' => 'true'));
     // Get dinamic column names
     foreach ($lessons as $lesson_id => $lesson) {
         $column_model[] = array('name' => $lesson['id'], 'index' => $lesson['id'], 'align' => 'left', 'search' => 'true');
     }
     $column_model[] = array('name' => 'total', 'index' => 'total', 'align' => 'left', 'search' => 'true');
     $action_links = '';
     // jqgrid will use this URL to do the selects
     $url = api_get_path(WEB_AJAX_PATH) . 'model.ajax.php?a=get_session_lp_progress&session_id=' . $sessionId . '&course_id=' . $courseId . '&date_to=' . $date_to . '&date_from=' . $date_from;
     //Table Id
     $tableId = 'lpProgress';
     //Autowidth
     $extra_params['autowidth'] = 'true';
     //height auto
     $extra_params['height'] = 'auto';
     $table = Display::grid_js($tableId, $url, $columns, $column_model, $extra_params, array(), $action_links, true);
     $return = '<script>$(function() {' . $table . 'jQuery("#' . $tableId . '").jqGrid("navGrid","#' . $tableId . '_pager",{view:false, edit:false, add:false, del:false, search:false, excel:true});
             jQuery("#' . $tableId . '").jqGrid("navButtonAdd","#' . $tableId . '_pager",{
                    caption:"",
                    title:"' . get_lang('ExportExcel') . '",
                    onClickButton : function () {
                        jQuery("#' . $tableId . '").jqGrid("excelExport",{"url":"' . $url . '&export_format=xls"});
                    }
             });
         });</script>';
     $return .= Display::grid_html($tableId);
     return $return;
 }
    /**
     * Copies a session with the same data to a new session.
     * The new copy is not assigned to the same promotion. @see suscribe_sessions_to_promotions() for that
     * @param   int     Session ID
     * @param   bool    Whether to copy the relationship with courses
     * @param   bool    Whether to copy the relationship with users
     * @param	bool	New courses will be created
     * @return  int     The new session ID on success, 0 otherwise
     * @todo make sure the extra session fields are copied too
     */
    public static function copy_session($id, $copy_courses = true, $copy_users = true, $create_new_courses = false, $set_exercises_lp_invisible = false)
    {
        $id = intval($id);
        $s = self::fetch($id);
        $s['year_start'] = substr($s['date_start'], 0, 4);
        $s['month_start'] = substr($s['date_start'], 5, 2);
        $s['day_start'] = substr($s['date_start'], 8, 2);
        $s['year_end'] = substr($s['date_end'], 0, 4);
        $s['month_end'] = substr($s['date_end'], 5, 2);
        $s['day_end'] = substr($s['date_end'], 8, 2);
        $consider_start = true;
        if ($s['year_start'] . '-' . $s['month_start'] . '-' . $s['day_start'] == '0000-00-00') {
            $consider_start = false;
        }
        $consider_end = true;
        if ($s['year_end'] . '-' . $s['month_end'] . '-' . $s['day_end'] == '0000-00-00') {
            $consider_end = false;
        }

        $sid = self::create_session(
            $s['name'] . ' ' . get_lang('CopyLabelSuffix'),
            $s['year_start'],
            $s['month_start'],
            $s['day_start'],
            $s['year_end'],
            $s['month_end'],
            $s['day_end'],
            $s['nb_days_acess_before_beginning'],
            $s['nb_days_acess_after_end'],
            false,
            (int)$s['id_coach'],
            $s['session_category_id'],
            (int)$s['visibility'],
            $consider_start,
            $consider_end,
            true
        );

        if (!is_numeric($sid) || empty($sid)) {
            return false;
        }

        if ($copy_courses) {
            // Register courses from the original session to the new session
            $courses = self::get_course_list_by_session_id($id);

            $short_courses = $new_short_courses = array();
            if (is_array($courses) && count($courses) > 0) {
                foreach ($courses as $course) {
                    $short_courses[] = $course;
                }
            }

            $courses = null;

            //We will copy the current courses of the session to new courses
            if (!empty($short_courses)) {
                if ($create_new_courses) {
                    //Just in case
                    if (function_exists('ini_set')) {
                        api_set_memory_limit('256M');
                        ini_set('max_execution_time', 0);
                    }
                    $params = array();
                    $params['skip_lp_dates'] = true;

                    foreach ($short_courses as $course_data) {
                        $course_info = CourseManager::copy_course_simple($course_data['title'] . ' ' . get_lang('CopyLabelSuffix'), $course_data['course_code'], $id, $sid, $params);
                        if ($course_info) {
                            //By default new elements are invisible
                            if ($set_exercises_lp_invisible) {
                                require_once api_get_path(SYS_CODE_PATH) . 'newscorm/learnpathList.class.php';
                                $list = new LearnpathList('', $course_info['code'], $sid);
                                $flat_list = $list->get_flat_list();
                                if (!empty($flat_list)) {
                                    foreach ($flat_list as $lp_id => $data) {
                                        api_item_property_update($course_info, TOOL_LEARNPATH, $lp_id, 'invisible', api_get_user_id(), 0, 0, 0, 0, $sid);
                                        api_item_property_update($course_info, TOOL_LEARNPATH, $lp_id, 'invisible', api_get_user_id(), 0, 0, 0, 0);
                                    }
                                }
                                $quiz_table = Database::get_course_table(TABLE_QUIZ_TEST);
                                $course_id = $course_info['real_id'];
                                //@todo check this query
                                $sql = "UPDATE $quiz_table SET active = 0 WHERE c_id = $course_id ";
                                $result = Database::query($sql);
                            }
                            $new_short_courses[] = $course_info['code'];
                        }
                    }
                } else {
                    foreach ($short_courses as $course_data) {
                        $new_short_courses[] = $course_data['code'];
                    }
                }

                $short_courses = $new_short_courses;
                self::add_courses_to_session($sid, $short_courses, true);
                $short_courses = null;
            }
        }
        if ($copy_users) {
            // Register users from the original session to the new session
            $users = self::get_users_by_session($id);
            $short_users = array();
            if (is_array($users) && count($users) > 0) {
                foreach ($users as $user) {
                    $short_users[] = $user['user_id'];
                }
            }
            $users = null;
            //Subscribing in read only mode
            self::suscribe_users_to_session($sid, $short_users, SESSION_VISIBLE_READ_ONLY, true, false);
            $short_users = null;
        }
        return $sid;
    }
Example #10
0
/**
 * @param array $params
 * @return int|string
 */
function WSGetLpList($params)
{
    global $debug;
    if (!WSHelperVerifyKey($params)) {
        return return_error(WS_ERROR_SECRET_KEY);
    }
    require_once api_get_path(SYS_CODE_PATH) . 'newscorm/learnpathList.class.php';
    require_once api_get_path(SYS_CODE_PATH) . 'newscorm/learnpath.class.php';
    require_once api_get_path(SYS_CODE_PATH) . 'newscorm/learnpathItem.class.php';
    $courseIdName = $params['course_id_name'];
    $courseIdValue = $params['course_id_value'];
    $sessionIdName = isset($params['session_id_name']) ? $params['session_id_name'] : null;
    $sessionIdValue = isset($params['session_id_value']) ? $params['session_id_value'] : null;
    $courseInfo = CourseManager::getCourseInfoFromOriginalId($courseIdValue, $courseIdName);
    if (empty($courseInfo)) {
        if ($debug) {
            error_log("Course not found: {$courseIdName} : {$courseIdValue}");
        }
        return 'Course not found';
    }
    $courseId = $courseInfo['real_id'];
    $sessionId = 0;
    if (!empty($sessionIdName) && !empty($sessionIdValue)) {
        $sessionId = SessionManager::get_session_id_from_original_id($sessionIdValue, $sessionIdName);
        if (empty($sessionId)) {
            if ($debug) {
                error_log('Session not found');
            }
            return 'Session not found';
        }
    }
    $list = new LearnpathList(null, $courseInfo['code'], $sessionId);
    $flatList = $list->get_flat_list();
    $result = array();
    foreach ($flatList as $id => $lp) {
        $result[] = array('id' => $id, 'name' => $lp['lp_name']);
    }
    return $result;
}
 public function createAnswersForm($form)
 {
     /** @var Exercise $objExercise */
     $objExercise = Session::read('objExercise');
     $editorConfig = array('ToolbarSet' => 'TestFreeAnswer', 'Width' => '100%', 'Height' => '125');
     //this line defines how many questions by default appear when creating a choice question
     // The previous default value was 2. See task #1759.
     $numberAnswers = isset($_POST['nb_answers']) ? (int) $_POST['nb_answers'] : 4;
     $numberAnswers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0);
     $feedbackTitle = '';
     if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
         //Scenario
         $commentTitle = '<th>' . get_lang('Comment') . '</th>';
         $feedbackTitle = '<th>' . get_lang('Scenario') . '</th>';
     } else {
         $commentTitle = '<th >' . get_lang('Comment') . '</th>';
     }
     $html = '<div class="alert alert-success" role="alert">' . get_lang('UniqueAnswerImagePreferredSize200x150') . '</div>';
     $html .= '<table class="table table-striped table-hover">
         <thead>
             <tr style="text-align: center;">
                 <th width="10">' . get_lang('Number') . '</th>
                 <th>' . get_lang('True') . '</th>
                 <th>' . get_lang('Answer') . '</th>
                     ' . $commentTitle . '
                     ' . $feedbackTitle . '
                 <th width="15">' . get_lang('Weighting') . '</th>
             </tr>
         </thead>
         <tbody>';
     $form->addHeader(get_lang('Answers'));
     $form->addHtml($html);
     $defaults = array();
     $correct = 0;
     if (!empty($this->id)) {
         $answer = new Answer($this->id);
         $answer->read();
         if (count($answer->nbrAnswers) > 0 && !$form->isSubmitted()) {
             $numberAnswers = $answer->nbrAnswers;
         }
     }
     $form->addElement('hidden', 'nb_answers');
     //Feedback SELECT
     $questionList = $objExercise->selectQuestionList();
     $selectQuestion = array();
     $selectQuestion[0] = get_lang('SelectTargetQuestion');
     if (is_array($questionList)) {
         foreach ($questionList as $key => $questionid) {
             //To avoid warning messages
             if (!is_numeric($questionid)) {
                 continue;
             }
             $question = Question::read($questionid);
             $selectQuestion[$questionid] = 'Q' . $key . ' :' . cut($question->selectTitle(), 20);
         }
     }
     $selectQuestion[-1] = get_lang('ExitTest');
     $list = new LearnpathList(api_get_user_id());
     $flatList = $list->get_flat_list();
     $selectLpId = array();
     $selectLpId[0] = get_lang('SelectTargetLP');
     foreach ($flatList as $id => $details) {
         $selectLpId[$id] = cut($details['lp_name'], 20);
     }
     $tempScenario = array();
     if ($numberAnswers < 1) {
         $numberAnswers = 1;
         Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
     }
     for ($i = 1; $i <= $numberAnswers; ++$i) {
         $form->addHtml('<tr>');
         if (isset($answer) && is_object($answer)) {
             if ($answer->correct[$i]) {
                 $correct = $i;
             }
             $defaults['answer[' . $i . ']'] = $answer->answer[$i];
             $defaults['comment[' . $i . ']'] = $answer->comment[$i];
             $defaults['weighting[' . $i . ']'] = float_format($answer->weighting[$i], 1);
             $itemList = explode('@@', $answer->destination[$i]);
             $try = $itemList[0];
             $lp = $itemList[1];
             $listDestination = $itemList[2];
             $url = $itemList[3];
             $try = 0;
             if ($try != 0) {
                 $tryResult = 1;
             }
             $urlResult = '';
             if ($url != 0) {
                 $urlResult = $url;
             }
             $tempScenario['url' . $i] = $urlResult;
             $tempScenario['try' . $i] = $tryResult;
             $tempScenario['lp' . $i] = $lp;
             $tempScenario['destination' . $i] = $listDestination;
         } else {
             $defaults['answer[1]'] = get_lang('DefaultUniqueAnswer1');
             $defaults['weighting[1]'] = 10;
             $defaults['answer[2]'] = get_lang('DefaultUniqueAnswer2');
             $defaults['weighting[2]'] = 0;
             $tempScenario['destination' . $i] = array('0');
             $tempScenario['lp' . $i] = array('0');
         }
         $defaults['scenario'] = $tempScenario;
         $renderer = $form->defaultRenderer();
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'correct');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'counter[' . $i . ']');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'answer[' . $i . ']');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment[' . $i . ']');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'weighting[' . $i . ']');
         $answerNumber = $form->addElement('text', 'counter[' . $i . ']', null, ' value = "' . $i . '"');
         $answerNumber->freeze();
         $form->addElement('radio', 'correct', null, null, $i, 'class="checkbox"');
         $form->addHtmlEditor('answer[' . $i . ']', null, null, true, $editorConfig);
         $form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required');
         if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
             $form->addHtmlEditor('comment[' . $i . ']', null, null, false, $editorConfig);
             // Direct feedback
             //Adding extra feedback fields
             $group = array();
             $group['try' . $i] = $form->createElement('checkbox', 'try' . $i, null, get_lang('TryAgain'));
             $group['lp' . $i] = $form->createElement('select', 'lp' . $i, get_lang('SeeTheory') . ': ', $selectLpId);
             $group['destination' . $i] = $form->createElement('select', 'destination' . $i, get_lang('GoToQuestion') . ': ', $selectQuestion);
             $group['url' . $i] = $form->createElement('text', 'url' . $i, get_lang('Other') . ': ', array('class' => 'col-md-2', 'placeholder' => get_lang('Other')));
             $form->addGroup($group, 'scenario');
             $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}', 'scenario');
         } else {
             $form->addHtmlEditor('comment[' . $i . ']', null, null, false, $editorConfig);
         }
         $form->addText('weighting[' . $i . ']', null, null, array('class' => "col-md-1", 'value' => '0'));
         $form->addHtml('</tr>');
     }
     $form->addHtml('</tbody>');
     $form->addHtml('</table>');
     global $text, $class;
     $buttonGroup = [];
     if ($objExercise->edit_exercise_in_lp == true) {
         //setting the save button here and not in the question class.php
         $buttonGroup[] = $form->addButtonDelete(get_lang('LessAnswer'), 'lessAnswers', true);
         $buttonGroup[] = $form->addButtonCreate(get_lang('PlusAnswer'), 'moreAnswers', true);
         $buttonGroup[] = $form->addButtonSave($text, 'submitQuestion', true);
         $form->addGroup($buttonGroup);
     }
     // We check the first radio button to be sure a radio button will be check
     if ($correct == 0) {
         $correct = 1;
     }
     $defaults['correct'] = $correct;
     if (!empty($this->id)) {
         $form->setDefaults($defaults);
     } else {
         if ($this->isContent == 1) {
             // Default sample content.
             $form->setDefaults($defaults);
         } else {
             $form->setDefaults(array('correct' => 1));
         }
     }
     $form->setConstants(array('nb_answers' => $numberAnswers));
 }
 /**
  * Get the number of stars achieved for an user in a session
  * @param int $sessionId The session ID
  * @param int $userId The user ID
  *
  * @return int The number of stars
  */
 public static function getSessionStars($sessionId, $userId)
 {
     $totalStars = 0;
     $courses = SessionManager::get_course_list_by_session_id($sessionId);
     if (empty($courses)) {
         return 0;
     }
     foreach ($courses as $course) {
         $learnPathListObject = new LearnpathList($userId, $course['code'], $sessionId);
         $learnPaths = $learnPathListObject->get_flat_list();
         if (empty($learnPaths)) {
             continue;
         }
         $stars = 0;
         foreach ($learnPaths as $learnPathId => $learnPathInfo) {
             if (empty($learnPathInfo['seriousgame_mode'])) {
                 continue;
             }
             $learnPath = new learnpath($course['code'], $learnPathId, $userId);
             $stars += $learnPath->getCalculateStars($sessionId);
         }
         $totalStars += round($stars / count($learnPaths));
     }
     return round($totalStars / count($courses));
 }