瀏覽代碼

survey report BT#149

César Perales 11 年之前
父節點
當前提交
511d67a437
共有 5 個文件被更改,包括 236 次插入7 次删除
  1. 37 0
      main/inc/ajax/model.ajax.php
  2. 83 1
      main/inc/lib/sessionmanager.lib.php
  3. 54 4
      main/mySpace/index.php
  4. 57 0
      main/mySpace/myspace.lib.php
  5. 5 2
      main/survey/survey.lib.php

+ 37 - 0
main/inc/ajax/model.ajax.php

@@ -279,6 +279,9 @@ switch ($action) {
         $records = SessionManager::get_user_data_access_tracking_overview(intval($_GET['session_id']), intval($_GET['course_id']), intval($_GET['student_id']), 0, $options);
         $count = count($records);
         break;
+    case 'get_survey_overview':
+        $count = 10; //temp
+        break;
     /*case 'get_extra_fields':
         $type = $_REQUEST['type'];
         $obj = new ExtraField($type);
@@ -679,6 +682,39 @@ switch ($action) {
             )
         );
         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']);
+            //$course    = api_get_course_info_by_id($courseId);
+        }
+        /**
+         * Add lessons of course
+         */
+        $columns = array(
+            'username',
+            'firstname',
+            'lastname',
+        );
+
+        $questions = survey_manager::get_questions($surveyId, $courseId);
+
+        foreach ($questions as $question_id => $question)
+        {
+            $columns[] = $question_id;
+        }
+        
+        $result = SessionManager::get_survey_overview($sessionId, $courseId, $surveyId,
+            array(
+                'where' => $where_condition,
+                'order' => "$sidx $sord",
+                'limit'=> "$start , $limit"
+            )
+        );
+        break;
     case 'get_session_progress':
         $columns = array(
             'lastname',
@@ -969,6 +1005,7 @@ $allowed_actions = array(
     'get_session_access_overview',
     'get_sessions_tracking',
     'get_session_lp_progress',
+    'get_survey_overview',
     'get_session_progress',
     'get_exercise_progress',
     'get_exercise_results',

+ 83 - 1
main/inc/lib/sessionmanager.lib.php

@@ -521,7 +521,7 @@ class SessionManager
         $where = " WHERE a.session_id = %d
         AND a.course_code = '%s' 
         AND q.id = %d";
-        
+
         if ($answer != 2) 
         {
             $where .= sprintf(' AND qa.correct = %d', $answer); 
@@ -672,6 +672,88 @@ class SessionManager
         }
         return $table;
     }
+    /**
+     * Gets the progress of learning paths in the given session
+     * @param int   session id
+     * @param array options order and limit keys
+     * @return array table with user name, lp name, progress
+     */
+    public static function get_survey_overview($sessionId = 0, $courseId = 0, $surveyId = 0, $options)
+    {
+        //tables
+        $session_course_user    = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
+        $user                   = Database::get_main_table(TABLE_MAIN_USER);
+        $tbl_course_lp_view     = Database::get_course_table(TABLE_LP_VIEW);
+
+        $course = api_get_course_info_by_id($courseId); 
+
+        $where = " WHERE course_code = '%s'
+        AND s.status <> 2 and id_session = %s";
+
+        $limit = null;
+        if (!empty($options['limit'])) {
+            $limit = " LIMIT ".$options['limit'];
+        }
+
+        if (!empty($options['where'])) {
+           $where .= ' AND '.$options['where'];
+        }
+
+        $order = null;
+        if (!empty($options['order'])) {
+            $order = " ORDER BY ".$options['order'];
+        }
+
+        $sql = "SELECT u.user_id, u.lastname, u.firstname, u.username, u.email, s.course_code
+        FROM $session_course_user s
+        INNER JOIN $user u ON u.user_id = s.id_user
+        $where $order $limit";
+
+        $sql_query = sprintf($sql, $course['code'], $sessionId);
+        
+        $rs = Database::query($sql_query);
+        while ($user = Database::fetch_array($rs))
+        {
+            $users[$user['user_id']] = $user;
+        }
+
+        //Get survey questions
+        $questions = survey_manager::get_questions($surveyId, $courseId);
+        $table = array();
+        foreach ($users as $user)
+        {
+            $data = array(
+                'lastname'  => $user[1],
+                'firstname' => $user[2],
+                'username'  => $user[3],
+            );
+
+            //Get questions by user
+            $sql = "SELECT sa.question_id, sa.option_id
+            FROM c_survey_answer sa
+            INNER JOIN c_survey_question sq ON sq.question_id = sa.question_id
+            WHERE sa.survey_id = %d AND sa.c_id = %d AND sa.user = %d";
+
+            $sql_query = sprintf($sql, $surveyId, $courseId, $user['user_id']);
+
+            $result = Database::query($sql_query);
+
+            $user_questions = array();
+            while ($row = Database::fetch_array($result))
+            {
+                $user_questions[$row['question_id']] = $row;
+            }
+
+            //Match course lessons with user progress
+            foreach ($questions as $question_id => $question)
+            {
+                $data[$question_id] = $user_questions[$question_id]['option_id'];
+            }
+
+            $table[] = $data;
+        }
+        return $table;
+    }    
     /**
      * Gets the progress of the given session
      * @param int   session id

+ 54 - 4
main/mySpace/index.php

@@ -160,7 +160,7 @@ echo '<a href="javascript: void(0);" onclick="javascript: window.print()">'.
     Display::return_icon('printer.png', get_lang('Print'),'',ICON_SIZE_MEDIUM).'</a>';
 echo '</span>';
 
-if (!empty($session_id) && !in_array($display, array('accessoverview','lpprogressoverview','progressoverview','exerciseprogress'))) {
+if (!empty($session_id) && !in_array($display, array('accessoverview','lpprogressoverview','progressoverview','exerciseprogress', 'surveyoverview'))) {
     echo '<a href="index.php">'.Display::return_icon('back.png', get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
     if (!api_is_platform_admin()) {
         if (api_get_setting('add_users_by_coach') == 'true') {
@@ -183,7 +183,7 @@ if (!empty($session_id) && !in_array($display, array('accessoverview','lpprogres
 
 // Actions menu
 $nb_menu_items = count($menu_items);
-if (empty($session_id) || in_array($display, array('accessoverview','lpprogressoverview', 'progressoverview', 'exerciseprogress'))) {
+if (empty($session_id) || in_array($display, array('accessoverview','lpprogressoverview', 'progressoverview', 'exerciseprogress', 'surveyoverview'))) {
     if ($nb_menu_items > 1) {
         foreach ($menu_items as $key => $item) {
             echo $item;
@@ -594,6 +594,7 @@ if ($is_platform_admin && in_array($view, array('admin')) && $display != 'yourst
 	}
 	echo ' | <a href="'.api_get_self().'?view=admin&amp;display=sessionoverview">'.get_lang('DisplaySessionOverview').'</a>';
 	echo ' | <a href="'.api_get_self().'?view=admin&amp;display=accessoverview">'.get_lang('DisplayAccessOverview').'</a>';
+    echo ' | <a href="'.api_get_self().'?view=admin&amp;display=surveyoverview">'.get_lang('Displaysurveyoverview').'</a>';
     echo ' | <a href="'.api_get_self().'?view=admin&amp;display=lpprogressoverview">'.get_lang('DisplayLpProgressOverview').'</a>';
     echo ' | <a href="'.api_get_self().'?view=admin&amp;display=progressoverview">'.get_lang('DisplayProgressOverview').'</a>';
     echo ' | <a href="'.api_get_self().'?view=admin&amp;display=exerciseprogress">'.get_lang('DisplayExerciseProgress').'</a>';
@@ -602,7 +603,7 @@ if ($is_platform_admin && in_array($view, array('admin')) && $display != 'yourst
     echo ' | <a href="'.api_get_path(WEB_CODE_PATH).'tracking/course_session_report.php?view=admin">'.get_lang('LPExerciseResultsBySession').'</a>';
 	echo '<br /><br />';
 
-    if ($is_platform_admin && $view == 'admin' && in_array($display, array('accessoverview','lpprogressoverview', 'progressoverview', 'exerciseprogress'))) {
+    if ($is_platform_admin && $view == 'admin' && in_array($display, array('accessoverview','lpprogressoverview', 'progressoverview', 'exerciseprogress', 'surveyoverview'))) {
         //Session Filter
         $sessionFilter = new FormValidator('session_filter', 'get', '', '', array('class'=> 'form-search'), false);
         $url = api_get_path(WEB_AJAX_PATH).'session.ajax.php?a=search_session';
@@ -628,7 +629,7 @@ if ($is_platform_admin && in_array($view, array('admin')) && $display != 'yourst
         });
         </script>';
         //Course filter
-        if (in_array($display, array('accessoverview','lpprogressoverview', 'progressoverview', 'exerciseprogress')))
+        if (in_array($display, array('accessoverview','lpprogressoverview', 'progressoverview', 'exerciseprogress', 'surveyoverview')))
         {
                 $courseFilter = new FormValidator('course_filter', 'get', '', '', array('class'=> 'form-search'), false);
                 $url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_course_by_session&session_id=' . $_GET['session_id'];
@@ -667,7 +668,10 @@ if ($is_platform_admin && in_array($view, array('admin')) && $display != 'yourst
                     $studentInfo = UserManager::get_user_info_by_id($studentId);
                     $studentList[] = array('id' => $studentInfo['id'], 'text' => $studentInfo['username']);
                 }
+
                 $studentFilter->addElement('select_ajax', 'student_name', get_lang('SearchStudent'), null, array('url' => $url, 'defaults' => $studentList));
+                //$studentFilter->addElement('datepicker', 'startdate', get_lang('StartDate'), array('form_name'=>'lp_add'), 5);
+                //$studentFilter->addElement('datepicker', 'enddate', get_lang('EndDate'), array('form_name'=>'lp_add', 'class' => 'block'), 3);
                 $courseListUrl = api_get_self();
 
                 echo '<div class="">'; 
@@ -684,6 +688,33 @@ if ($is_platform_admin && in_array($view, array('admin')) && $display != 'yourst
                         });
                     });
                 </script>';
+
+                /*//profile filter  
+                $profileFilter = new FormValidator('answer_filter', 'get', '', '', array('class'=> 'form-search'), false);
+                $options = array(
+                    STUDENT         => get_lang('Student'),
+                    COURSEMANAGER   => get_lang('CourseManager'),
+                    DRH             => get_lang('Drh'),
+                    ANONYMOUS       => get_lang('Anonymous'),
+                    );
+                $profileFilter->addElement('select', 'profile', get_lang('Profile'),$options, array('id' => 'profile'));
+                $courseListUrl = api_get_self();
+
+                echo '<div class="">'; 
+                echo $profileFilter->return_form();
+                echo '</div>';
+
+                echo '<script>
+                $(function() {
+                    $("#profile").on("change", function() {
+                        var sessionId = $("#session_name").val();
+                        var courseId = $("#course_name").val();
+                        var studentId  = $("#student_name").val();
+                        var profileId  = $("#profile").val();
+                        window.location = "'.$courseListUrl.'?view=admin&display='.$display.'&session_id="+sessionId+"&course_id="+courseId+"&student_id="+studentId+"&profile_id="+profileId;
+                        });
+                    });
+                </script>';*/
         }
         if (in_array($display, array('exerciseprogress')))
         {
@@ -812,6 +843,25 @@ if ($is_platform_admin && in_array($view, array('admin')) && $display != 'yourst
         } else {
             Display::display_warning_message(get_lang('ChooseSession'));
         }
+    } else if($display == 'surveyoverview') {
+        if (!empty($_GET['session_id'])) 
+        {
+            if (!empty($_GET['course_id'])) 
+            {
+                if (!empty($_GET['survey_id'])) 
+                {
+                    echo MySpace::display_survey_overview(intval($_GET['session_id']), intval($_GET['course_id']), intval($_GET['survey_id']));
+                } else 
+                {
+                    Display::display_warning_message(get_lang('ChooseExercise'));
+                }
+            } else
+            {
+                Display::display_warning_message(get_lang('ChooseCourse'));
+            }
+        } else {
+            Display::display_warning_message(get_lang('ChooseSession'));
+        }
 	} else if($display == 'courseoverview') {
 		MySpace::display_tracking_course_overview();
 	} else {

+ 57 - 0
main/mySpace/myspace.lib.php

@@ -393,6 +393,63 @@ class MySpace {
         $return .= Display::grid_html($tableId);
         return $return;
     }
+    /**
+     * Display a sortable table that contains an overview off all the progress of the user in a session
+     * @author César Perales <cesar.perales@beeznest.com>, Beeznest Team
+     */
+    function display_survey_overview($sessionId = 0, $courseId = 0, $surveyId = 0, $answer = 2) {
+
+        $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
+        $questions = survey_manager::get_questions($surveyId, $courseId);
+
+        foreach ($questions as $question_id => $question)
+        {
+            $columns[] = $question['question'];
+        }
+
+        /**
+         * Column config
+         */
+        $column_model   = array(
+            array('name'=>'username',   'index'=>'username',  'width'=>'160',  'align'=>'left', 'search' => 'true', 'wrap_cell' => "true"),
+            array('name'=>'firstname',  'index'=>'firstname',   'width'=>'100',   'align'=>'left', 'search' => 'true'),
+            array('name'=>'lastname',   'index'=>'lastname',    'width'=>'100',   'align'=>'left', 'search' => 'true'),
+        );
+        //get dinamic column names
+        foreach ($questions as $question_id => $question)
+        {
+            $column_model[] = array('name'=> $question_id,   'index'=>$question_id,    'width'=>'70',   '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_survey_overview&session_id=' . intval($sessionId) . '&course_id=' . intval($courseId) . '&survey_id=' . intval($surveyId);
+        $tableId = 'lpProgress';
+        $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;
+    }
     /**
      * Display a sortable table that contains an overview off all the progress of the user in a session
      * @author César Perales <cesar.perales@beeznest.com>, Beeznest Team

+ 5 - 2
main/survey/survey.lib.php

@@ -694,12 +694,15 @@ class survey_manager
 	 *
 	 * @todo one sql call should do the trick
 	 */
-    public static function get_questions($survey_id) {
+    public static function get_questions($survey_id, $course_id = '') {
 		// Table definitions
 		$tbl_survey_question 			= Database :: get_course_table(TABLE_SURVEY_QUESTION);
 		$table_survey_question_option 	= Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
 
-        $course_id = api_get_course_int_id();
+		if (empty($course_id))
+		{
+			$course_id = api_get_course_int_id();
+		}
 
 		// Getting the information of the question
 		$sql = "SELECT * FROM $tbl_survey_question WHERE c_id = $course_id AND survey_id='".Database::escape_string($survey_id)."'";