@@ -50,6 +50,7 @@ public function definition() {
5050
5151 $ sid = $ questionnaire ->survey ->id ;
5252 $ mform =& $ this ->_form ;
53+ $ qidrestore = optional_param (QUESTIONNAIRE_RESTORE_PARAM , 0 , PARAM_INT );
5354
5455 $ mform ->addElement ('header ' , 'questionhdr ' , get_string ('addquestions ' , 'questionnaire ' ));
5556 $ mform ->addHelpButton ('questionhdr ' , 'questiontypes ' , 'questionnaire ' );
@@ -138,7 +139,7 @@ public function definition() {
138139
139140 // No page break in first position!
140141 if ($ tid == QUESPAGEBREAK && $ pos == 1 ) {
141- $ DB ->set_field ('questionnaire_question ' , 'deleted ' , ' y ' , ['id ' => $ qid , 'surveyid ' => $ sid ]);
142+ $ DB ->set_field ('questionnaire_question ' , 'deleted ' , time () , ['id ' => $ qid , 'surveyid ' => $ sid ]);
142143 if ($ records = $ DB ->get_records_select ('questionnaire_question ' , $ select , null , 'position ASC ' )) {
143144 foreach ($ records as $ record ) {
144145 $ DB ->set_field ('questionnaire_question ' , 'position ' , $ record ->position - 1 , array ('id ' => $ record ->id ));
@@ -172,7 +173,12 @@ public function definition() {
172173 // Begin div qn-container with indent if questionnaire has child.
173174 $ mform ->addElement ('html ' , '<div class="qn-container qn-indent"> ' );
174175 } else {
175- $ mform ->addElement ('html ' , '<div class="qn-container"> ' ); // Begin div qn-container.
176+ $ containerclass = "qn-container " ;
177+ if (isset ($ qidrestore ) && $ qidrestore == $ question ->id ) {
178+ $ containerclass .= " restored-question " ;
179+ }
180+ // Begin div qn-container.
181+ $ mform ->addElement ('html ' , "<div class=' $ containerclass'> " );
176182 }
177183
178184 $ mextra = array ('value ' => $ question ->id ,
@@ -220,14 +226,15 @@ public function definition() {
220226 // Do not allow moving or deleting a page break if immediately followed by a child question
221227 // or immediately preceded by a question with a dependency and followed by a non-dependent question.
222228 if ($ tid == QUESPAGEBREAK ) {
223- if ($ nextquestion = $ DB ->get_record ('questionnaire_question ' ,
224- ['surveyid ' => $ sid , 'position ' => $ pos + 1 , 'deleted ' => 'n ' ], 'id, name, content ' ) ) {
225-
229+ $ select = 'surveyid = ? AND position = ? AND deleted IS NULL ' ;
230+ $ nextquestion = $ DB ->get_record_select ('questionnaire_question ' , $ select ,
231+ [$ sid , $ pos + 1 ], 'id, name, content ' );
232+ if ($ nextquestion ) {
226233 $ nextquestiondependencies = $ DB ->get_records ('questionnaire_dependency ' ,
227234 ['questionid ' => $ nextquestion ->id , 'surveyid ' => $ sid ], 'id ASC ' );
228235
229- if ($ previousquestion = $ DB ->get_record ('questionnaire_question ' ,
230- [' surveyid ' => $ sid , ' position ' => $ pos - 1 , ' deleted ' => ' n ' ], 'id, name, content ' )) {
236+ if ($ previousquestion = $ DB ->get_record_select ('questionnaire_question ' , $ select ,
237+ [$ sid , $ pos - 1 ], 'id, name, content ' )) {
231238
232239 $ previousquestiondependencies = $ DB ->get_records ('questionnaire_dependency ' ,
233240 ['questionid ' => $ previousquestion ->id , 'surveyid ' => $ sid ], 'id ASC ' );
@@ -359,6 +366,66 @@ public function definition() {
359366 }
360367 }
361368
369+ // Question deletion area.
370+ $ mform ->addElement ('header ' , 'deletionq ' , get_string ('deletionquetions ' , 'questionnaire ' ));
371+ $ mform ->addHelpButton ('deletionq ' , 'deletionquetions ' , 'questionnaire ' );
372+ $ mform ->addElement ('html ' , '<div class="qcontainer"> ' );
373+ if (isset ($ questionnaire ->deletequestions )) {
374+ $ restoreimg = $ questionnaire ->renderer ->image_url ('i/up ' );
375+ $ deleteimg = $ questionnaire ->renderer ->image_url ('t/delete ' );
376+ $ rangetimecrontask = questionnaire_get_range_time_permanently ();
377+ foreach ($ questionnaire ->deletequestions as $ deletequestion ) {
378+ $ delquestiongroup = [];
379+ // Preparing deleted time to display time permanently question.
380+ $ timedeleted = $ deletequestion ->deleted ?? "" ;
381+ if ($ rangetimecrontask == 0 ) {
382+ $ timedeleted = get_string ('recylebindisabled ' , 'questionnaire ' );
383+ } else {
384+ if (!empty ($ timedeleted )) {
385+ $ timedeleted = get_string ('timedeletednext7days ' , 'questionnaire ' ,
386+ date ("D j M, Y " , $ timedeleted + $ rangetimecrontask ));
387+ }
388+ }
389+ $ qtypeandname = [];
390+ $ qtypeandname ['name ' ] = $ deletequestion ->name ;
391+ $ qtypeandname ['type ' ] = questionnaire_get_type ($ deletequestion ->type_id );
392+
393+ $ content = format_text (
394+ file_rewrite_pluginfile_urls ($ deletequestion ->content , 'pluginfile.php ' ,
395+ $ deletequestion ->context ->id ,
396+ 'mod_questionnaire ' , 'question ' , $ deletequestion ->id ),
397+ FORMAT_HTML , ['noclean ' => true ]
398+ );
399+
400+ $ qnumber = '<div class="qn-info"><h2 class="qn-number">NA</h2></div> ' ;
401+ $ restorextra = [
402+ 'value ' => $ deletequestion ->id ,
403+ 'alt ' => get_string ('restorebutton ' , 'questionnaire ' ),
404+ 'title ' => get_string ('restorebutton ' , 'questionnaire ' ),
405+ ];
406+ $ deleleextra = [
407+ 'value ' => $ deletequestion ->id ,
408+ 'alt ' => get_string ('deletepermanentlybutton ' , 'questionnaire ' ),
409+ 'title ' => get_string ('deletepermanentlybutton ' , 'questionnaire ' )
410+ ];
411+ $ mform ->addElement ('html ' , '<div class="qn-container"> ' ); // Begin div qn-container.
412+ $ delquestiongroup [] =& $ mform ->createElement ('static ' , 'opentag_ ' . $ deletequestion ->id , '' , '' );
413+ $ delquestiongroup [] =& $ mform ->createElement ('image ' , 'restorebutton[ ' . $ deletequestion ->id . '] ' ,
414+ $ restoreimg , $ restorextra );
415+ $ delquestiongroup [] =& $ mform ->createElement ('image ' , 'deletebutton[ ' . $ deletequestion ->id . '] ' ,
416+ $ deleteimg , $ deleleextra );
417+ $ delquestiongroup [] =& $ mform ->createElement ('static ' , 'closetag_ ' . $ deletequestion ->id , '' , '' );
418+ $ delquestiongroup [] =& $ mform ->createElement ('static ' , 'qinfo_ ' . $ deletequestion ->id , '' ,
419+ get_string ('questiontypeandname ' , 'questionnaire ' , $ qtypeandname ));
420+ $ delquestiongroup [] =& $ mform ->createElement ('static ' , 'qinfo_ ' . $ deletequestion ->id ,
421+ '' , $ timedeleted );
422+ $ mform ->addGroup ($ delquestiongroup , 'delquestiongroup ' , '' , ' ' , false );
423+ $ mform ->addElement ('static ' , 'qcontent_ ' .$ deletequestion ->id , '' ,
424+ $ qnumber .'<div class="qn-question"> ' .$ content .'</div> ' );
425+ $ mform ->addElement ('html ' , '</div> ' ); // End div qn-container.
426+ }
427+ }
428+
362429 if ($ this ->moveq ) {
363430 $ mform ->addElement ('hidden ' , 'moveq ' , $ this ->moveq );
364431 }
@@ -373,6 +440,9 @@ public function definition() {
373440 $ mform ->setType ('moveq ' , PARAM_RAW );
374441
375442 $ mform ->addElement ('html ' , '</div> ' );
443+ $ mform ->setExpanded ('questionhdr ' );
444+ $ mform ->setExpanded ('manageq ' );
445+ $ mform ->setExpanded ('deletionq ' );
376446 }
377447
378448 /**
0 commit comments