Pārlūkot izejas kodu

Adding delete button for hotpotatoes attempts see BT#6638

Julio Montoya 11 gadi atpakaļ
vecāks
revīzija
f1ca812d3e

+ 28 - 15
main/exercice/exercise.lib.php

@@ -903,7 +903,6 @@ function get_count_exam_hotpotatoes_results($in_hotpot_path) {
  */
 function get_exam_results_hotpotatoes_data($in_from, $in_number_of_items, $in_column, $in_direction, $in_hotpot_path, $in_get_count = false, $where_condition = null)
 {
-    $tab_res = array();
     $course_code = api_get_course_id();
     // by default in_column = 1 If parameters given, it is the name of the column witch is the bdd field name
     if ($in_column == 1) {
@@ -915,10 +914,11 @@ function get_exam_results_hotpotatoes_data($in_from, $in_number_of_items, $in_co
     $in_number_of_items = intval($in_number_of_items);
     $in_from = intval($in_from);
 
-    $TBL_TRACK_HOTPOTATOES      = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
-    $TBL_USER                   = Database :: get_main_table(TABLE_MAIN_USER);
+    $TBL_TRACK_HOTPOTATOES = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
+    $TBL_USER = Database :: get_main_table(TABLE_MAIN_USER);
 
-    $sql = "SELECT * FROM $TBL_TRACK_HOTPOTATOES thp JOIN $TBL_USER u ON thp.exe_user_id = u.user_id
+    $sql = "SELECT * FROM $TBL_TRACK_HOTPOTATOES thp
+            JOIN $TBL_USER u ON thp.exe_user_id = u.user_id
             WHERE thp.exe_cours_id = '$course_code' AND exe_name LIKE '$in_hotpot_path%'";
 
     // just count how many answers
@@ -932,18 +932,31 @@ function get_exam_results_hotpotatoes_data($in_from, $in_number_of_items, $in_co
             LIMIT $in_from, $in_number_of_items";
 
     $res = Database::query($sql);
+    $result = array();
+    $apiIsAllowedToEdit = api_is_allowed_to_edit();
+    $urlBase = api_get_path(WEB_CODE_PATH).'exercice/hotpotatoes_exercise_report.php?action=delete&'.api_get_cidreq().'&id=';
     while ($data = Database::fetch_array($res)) {
-        $tab_one_res = array();
-        $tab_one_res['firstname'] = $data['firstname'];
-        $tab_one_res['lastname'] = $data['lastname'];
-        $tab_one_res['username'] = $data['username'];
-        $tab_one_res['group_name'] = implode("<br/>",GroupManager::get_user_group_name($data['user_id']));
-        $tab_one_res['exe_date'] = $data['exe_date'];
-        $tab_one_res['score'] = $data['exe_result'].'/'.$data['exe_weighting'];
-        $tab_one_res['actions'] = "";
-        $tab_res[] = $tab_one_res;
-    }
-    return $tab_res;
+        $actions = null;
+
+        if ($apiIsAllowedToEdit) {
+            $url = $urlBase.$data['id'].'&path='.$data['exe_name'];
+            $actions = Display::url(
+                Display::return_icon('delete.png', get_lang('Delete')),
+                $url
+            );
+        }
+
+        $result[] = array(
+            'firstname' => $data['firstname'],
+            'lastname' => $data['lastname'],
+            'username' => $data['username'],
+            'group_name' => implode("<br/>", GroupManager::get_user_group_name($data['user_id'])),
+            'exe_date' => $data['exe_date'],
+            'score' => $data['exe_result'].' / '.$data['exe_weighting'],
+            'actions' => $actions,
+        );
+    }
+    return $result;
 }
 
 /**

+ 12 - 0
main/exercice/hotpotatoes.lib.php

@@ -448,3 +448,15 @@ function HotPotGCt($folder, $flag, $user_id)
         }
     }
 }
+
+/**
+ * Deletes an attempt from TABLE_STATISTIC_TRACK_E_HOTPOTATOES
+ * @param int $id
+ */
+function deleteAttempt($id)
+{
+    $table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
+    $id = intval($id);
+    $sql = "DELETE FROM $table WHERE id = $id";
+    Database::query($sql);
+}

+ 36 - 19
main/exercice/hotpotatoes_exercise_report.php

@@ -9,6 +9,8 @@
 /**
  * Code
  */
+use ChamiloSession as Session;
+
 // name of the language file that needs to be included
 $language_file = array('exercice');
 
@@ -38,7 +40,7 @@ require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
 require_once api_get_path(LIBRARY_PATH) . 'statsUtils.lib.inc.php';
 
 // document path
-$documentPath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . "/document";
+$documentPath = api_get_path(SYS_COURSE_PATH).$_course['path']."/document";
 
 /*	Constants and variables */
 $is_allowedToEdit           = api_is_allowed_to_edit(null, true) || api_is_drh();
@@ -93,6 +95,19 @@ if ($is_allowedToEdit && $origin != 'learnpath') {
     $actions .= '<a href="exercice.php">' . Display :: return_icon('back.png', get_lang('GoBackToQuestionList'),'',ICON_SIZE_MEDIUM).'</a>';
 }
 
+if ($is_allowedToEdit) {
+    $action = isset($_GET['action']) ? $_GET['action'] : null;
+    switch ($action) {
+        case 'delete':
+            $fileToDelete = isset($_GET['id']) ? $_GET['id'] : null;
+            deleteAttempt($fileToDelete);
+            Session::write('message', Display::return_message(get_lang('ItemDeleted')));
+            break;
+
+    }
+}
+
+
 //Deleting an attempt
 //if ( ($is_allowedToEdit || $is_tutor || api_is_coach()) && $_GET['delete'] == 'delete' && !empty ($_GET['did']) && $locked == false) {
 //    $exe_id = intval($_GET['did']);
@@ -105,6 +120,7 @@ if ($is_allowedToEdit && $origin != 'learnpath') {
 //        exit;
 //    }
 //}
+$nameTools = get_lang('Results');
 
 if ($is_allowedToEdit || $is_tutor) {
     $nameTools = get_lang('StudentScore');
@@ -116,9 +132,9 @@ if ($is_allowedToEdit || $is_tutor) {
 } else {
     $interbreadcrumb[] = array("url" => "exercice.php","name" => get_lang('Exercices'));
     $objExerciseTmp = new Exercise();
-    if ($objExerciseTmp->read($exercise_id)) {
+    /*if ($objExerciseTmp->read($exercise_id)) {
         $nameTools = get_lang('Results').': '.$objExerciseTmp->name;
-    }
+    }*/
 }
 
 Display :: display_header($nameTools);
@@ -167,17 +183,16 @@ $form->setDefaults(array('export_format' => 'csv'));
 $extra .= $form->return_form();
 $extra .= '</div>';
 
-if ($is_allowedToEdit)
+if ($is_allowedToEdit) {
     echo $extra;
+}
 
 echo $actions;
 
 $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_hotpotatoes_exercise_results&path='.$hotpotatoes_path.'&filter_by_user='.$filter_user;
-
-//$activeurl = '?sidx=session_active';
 $action_links = '';
 
-//Generating group list
+// Generating group list
 
 $group_list = GroupManager::get_group_list();
 $group_parameters = array('group_all:'.get_lang('All'),'group_none:'.get_lang('None'));
@@ -190,8 +205,8 @@ if (!empty($group_parameters)) {
 }
 
 if ($is_allowedToEdit || $is_tutor) {
-	// The order is important you need to check the the $column variable in the model.ajax.php file
-	$columns = array(
+    // The order is important you need to check the the $column variable in the model.ajax.php file
+    $columns = array(
         get_lang('FirstName'),
         get_lang('LastName'),
         get_lang('LoginName'),
@@ -225,11 +240,15 @@ if ($is_allowedToEdit || $is_tutor) {
     }';
 } else {
     //The order is important you need to check the the $column variable in the model.ajax.php file
-	$columns = array(get_lang('StartDate'), get_lang('Score'), get_lang('Actions'));
+    $columns = array(
+        get_lang('StartDate'),
+        get_lang('Score'),
+        get_lang('Actions')
+    );
 
-  //Column config
-  // @todo fix search firstname/lastname that doesn't work. rmove search for the moment
-	$column_model  = array(
+    //Column config
+    // @todo fix search firstname/lastname that doesn't work. rmove search for the moment
+    $column_model  = array(
         array('name'=>'exe_date',		    'index'=>'exe_date',		'width'=>'60',   'align'=>'left', 'search' => 'false'),
         array('name'=>'score',			    'index'=>'exe_result',	'width'=>'50',   'align'=>'left', 'search' => 'false'),
         array('name'=>'actions',        'index'=>'actions',     'width'=>'60',  'align'=>'left', 'search' => 'false')
@@ -241,12 +260,8 @@ $extra_params['autowidth'] = 'true';
 
 //height auto
 $extra_params['height'] = 'auto';
-//$extra_params['excel'] = 'excel';
-//$extra_params['rowList'] = array(20, 50, 100, 500, 1000, 2000, 5000, 10000);
-
 ?>
 <script>
-
 function setSearchSelect(columnName) {
     $("#results").jqGrid('setColProp', columnName,
     {
@@ -287,8 +302,8 @@ function exportExcel() {
 }
 
 $(function() {
-    <?php
-    echo Display::grid_js('results', $url,$columns,$column_model, $extra_params, array(), $action_links, true);
+<?php
+    echo Display::grid_js('results', $url, $columns, $column_model, $extra_params, array(), $action_links, true);
 
     if ($is_allowedToEdit || $is_tutor) { ?>
 
@@ -323,5 +338,7 @@ $(function() {
 </form>
 <?php
 
+$message = Session::read('message');
+echo isset($message) ? $message : null;
 echo Display::grid_html('results');
 Display :: display_footer();