From a2b3c3c09de2acf1f0c5e2468dce864e8c75a5bf Mon Sep 17 00:00:00 2001 From: baelmyhu Date: Thu, 20 Feb 2014 10:50:03 +0100 Subject: [PATCH] Clean all results for this test before the selected date -ref #6970 --- main/exercice/exercise.class.php | 19 +++- main/exercice/exercise_report.php | 106 ++++++++++++++++++++-- main/img/icons/32/clean_before_date.png | Bin 0 -> 1530 bytes main/inc/lib/internationalization.lib.php | 33 +++++++ main/inc/lib/main_api.lib.php | 34 +++++++ 5 files changed, 181 insertions(+), 11 deletions(-) create mode 100644 main/img/icons/32/clean_before_date.png diff --git a/main/exercice/exercise.class.php b/main/exercice/exercise.class.php index 6204db91f8..076b9eb994 100644 --- a/main/exercice/exercise.class.php +++ b/main/exercice/exercise.class.php @@ -1482,11 +1482,13 @@ class Exercise { /** * Cleans the student's results only for the Exercise tool (Not from the LP) - * The LP results are NOT deleted + * The LP results are NOT deleted by default, otherwise put $clean_lp_tests = true * Works with exercises in sessions + * @param bool $clean_lp_tests + * @param int $clean_result_before_date * @return int quantity of user's exercises deleted */ - function clean_results($clean_lp_tests = false) { + function clean_results($clean_lp_tests = false, $clean_result_before_date = '0') { $table_track_e_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); $table_track_e_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); @@ -1494,10 +1496,17 @@ class Exercise { orig_lp_id = 0 AND orig_lp_item_id = 0'; + // if we want to delete results from LP too if ($clean_lp_tests) { $sql_where = ""; } + // if we want to delete attempts before date $clean_result_before_date + // $clean_result_before_date must be a valid UTC-0 date yyyy-mm-dd + if ($clean_result_before_date != '0') { + $sql_where .= " AND exe_date <= '$clean_result_before_date' "; + } + $sql_select = "SELECT exe_id FROM $table_track_e_exercises WHERE exe_cours_id = '".api_get_course_id()."' AND exe_exo_id = ".$this->id." AND @@ -1507,7 +1516,8 @@ class Exercise { $result = Database::query($sql_select); $exe_list = Database::store_result($result); - //deleting TRACK_E_ATTEMPT table + // deleting TRACK_E_ATTEMPT table + // check if exe in learning path or not $i = 0; if (is_array($exe_list) && count($exe_list) > 0) { foreach($exe_list as $item) { @@ -1517,13 +1527,12 @@ class Exercise { } } - //delete TRACK_E_EXERCICES table + // delete TRACK_E_EXERCICES table $sql = "DELETE FROM $table_track_e_exercises WHERE exe_cours_id = '".api_get_course_id()."' AND exe_exo_id = ".$this->id." $sql_where AND session_id = ".api_get_session_id().""; - Database::query($sql); return $i; diff --git a/main/exercice/exercise_report.php b/main/exercice/exercise_report.php index 504f361fd8..d66bf44368 100644 --- a/main/exercice/exercise_report.php +++ b/main/exercice/exercise_report.php @@ -23,6 +23,7 @@ require_once '../gradebook/lib/be.inc.php'; $this_section = SECTION_COURSES; $htmlHeadXtra[] = api_get_jqgrid_js(); +$htmlHeadXtra[] = api_get_datepicker_js(); // Access control api_protect_course_script(true, false, true); @@ -221,7 +222,19 @@ if ($is_allowedToEdit && $origin != 'learnpath') { $actions .=''.Display :: return_icon('statistics.png', get_lang('ReportByQuestion'), '', ICON_SIZE_MEDIUM).''; $actions .= ''. Display::return_icon('save.png', get_lang('Export'), '', ICON_SIZE_MEDIUM).''; - $actions .= Display::url(Display::return_icon('clean_before_date.png', get_lang('CleanStudentsResultsBeforeDate'), '', ICON_SIZE_MEDIUM), '', array('onclick' => "javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('AreYouSureToEmptyTestResults'), ENT_QUOTES, $charset))." ".addslashes($row['title'])."?"."')) return false;", 'href' => 'exercice_report.php?'.api_get_cidreq().'&choice=clean_all_test&sec_token='.$token)); + // clean result before a selected date icon + $actions .= Display::url( + Display::return_icon('clean_before_date.png', get_lang('CleanStudentsResultsBeforeDate'), '', ICON_SIZE_MEDIUM), '', array('onclick' => "javascript:display_date_picker()", 'href' => '#') + ); + // clean result before a selected date datepicker popup + $actions .= Display::span( + Display::input('input', 'datepicker_start', get_lang('SelectADateOnTheCalendar'), + array('onmouseover'=>'datepicker_input_mouseover()', 'id'=>'datepicker_start', 'onchange'=>'datepicker_input_changed()', 'readonly'=>'readonly') + ). + Display::button('delete', get_lang('Delete'), + array('onclick'=>'submit_datepicker()')), + array('style'=>'display:none', 'id'=>'datepicker_span') + ); } } else { $actions .= ''.Display :: return_icon('back.png', get_lang('GoBackToQuestionList'), '', ICON_SIZE_MEDIUM).''; @@ -240,6 +253,7 @@ if (($is_allowedToEdit || $is_tutor || api_is_coach()) && $_GET['delete'] == 'de } } + if ($is_allowedToEdit || $is_tutor) { $nameTools = get_lang('StudentScore'); $interbreadcrumb[] = array("url" => "exercice.php?gradebook=$gradebook", "name" => get_lang('Exercices')); @@ -257,6 +271,27 @@ if ($is_allowedToEdit || $is_tutor) { Display :: display_header($nameTools); +// Clean all results for this test before the selected date +$datepicker_language = get_datepicker_langage_code(); +if (($is_allowedToEdit || $is_tutor || api_is_coach()) && isset($_GET['delete_before_date']) && $locked == false) { + // ask for the date + $check = Security::check_token('get'); + if ($check) { + // delete attempts before date $_GET['delete_before_date'] + $dateUTC = api_get_utc_datetime($_GET['delete_before_date']); + if (api_is_valid_date($_GET['delete_before_date'])) { + $objExerciseTmp = new Exercise(); + if ($objExerciseTmp->read($exercise_id)) { + $nb_del = $objExerciseTmp->clean_results(true, $_GET['delete_before_date']); + Display :: display_confirmation_message(sprintf(get_lang('XResultsCleaned'), $nb_del)); + } + } + } +} + +// Security token to protect deletion +$token = Security::get_token(); + $actions = Display::div($actions, array('class' => 'actions')); $extra = '
+ c-mj#PnPRIHZt82`Ti~3Uk?B!Ylp0*+7m{3+ootz+WN)WnQ(*-(AUCxn zQK2F?C$HG5!d3}vt`(3C64qBz04piUwpD^SD#ABF!8yMuRl!uxKsVXI%uvD1M9IxIyg#@@$ndN=gc>^!3Zj z%k|2Q_413-^$jg8E%gnI^o@*kfhu&1EAvVcD|GXUm0>2hq!uR^WfqiV=I1GZOiWD5 zFD$Tv3bSNU;+l1ennz|zM-B0$V)JVzP|XC=H|jx7ncO3BHWAB;NpiyW)Z+ZoqGVvir744~DzI`cN=+=uFAB-e&w+(vKt_H^esM;Afr4|esh*)icxGNo zet9uiy|1s8XI^nhVqS8pr;Du;&;-5A%oHmpLo-VwBWE)UR|^9}Lsw%9R~HjUb4O=a zGiOH^6Bi4ZUYGpj(%jU%5}4i;gkE!;dO=Acw*Y9fOKMSOS!#+~QGTuh*vnR#xZPrc z(>$o&6x?nx#i>^x=oo!a#3DsBObD2IKumbD1#;jCKQ#}S+KYh6x>nzU1(+og0(?ST zfByYJ)Peja=A z`^81G|7B&*uBG(|aNa)Z{NdB*?~nYpHK=}l(fjGusXIsN_D%A>X=3v8=FQDpxBdVB zfBD%Tp+LJ7N`m}?fn0omAtpxpEdvANHBT4EkcwM5le;G^RuFLAt;jMpq2pGP!lVEH zpPKQ{z4<0+YS%T(JKdh#$M>JkSUlO|E89K=3Ec|S6CO;>Al}~ED_uI{_oqPZm$;noph<{NUpNsHoh0}weK$Y zRw(;L&q*(wm!!|B;3BHBDs#s3^X}!zwue?1NLVxL9!UGgXc#2;Bd~Ga;~Pt(7>l2M zmbtXJ)Mn{_oQ<$_v>*)rGVD6nP z8cop`HB&nO&&>MM^LLX@*LUkD9Ok+!nEuRFD0I5F=Na2kUd8_R{R}P^g)GlF%mQZp zDVp"); + * and message contains character " + * @param $in_text + */ +function convert_double_quote_to_single($in_text) { + return api_preg_replace('/"/', "''", $in_text); +} \ No newline at end of file