Want to know function flow for adding and deleting a question in question table.

Want to know function flow for adding and deleting a question in question table.

Napisane przez: Manisha Howale ()
Liczba odpowiedzi: 0

Hi,

I m developing a new module called lessonplans(not same as lesson which exists in moodle) which is bit similar to quiz module but there is not grading mechanism as well as no attempt facility.

The way we add question to quiz, in lessonplans module(the one i m developing) one can add lessonplan.

(For my module quiz=lessonplans,question=lessonplan)

I have cut down some files for lessonplans as I do not have any lessonplan types as question has.

Currently I m able to view all the lessonplans in a list(currently entered using db) when a link is clicked for lessonplans instance in main menu, also selected lessonplan opens properly for editing.

but i m stuck for saving  a new lessonplan and also for deleting a lessonplan.

While deleting a lessonplan I get confirmation message " Are you sure you want to delete following lessonplans" plan1(plan1 is lessonplan name) but as yes button is clicked- lessonplan is not deleted.

Can someone please tell me the function flow

1. For saving question after form is submitted and posted to (c:/xampplite/moodle/question/question.php) in quiz module

2. For deleting a question(c:/xampplite/moodle/question/showbank.php) in quiz module after it executes else part of following code.

if (isset($_REQUEST['deleteselected'])) { // delete selected questions from the category
  if (isset($_REQUEST['confirm']) and confirm_sesskey()) { // teacher has already confirmed the action
   $deleteselected = required_param('deleteselected');
   if ($_REQUEST['confirm'] == md5($deleteselected)) {
    if ($questionlist = explode(',', $deleteselected)) {
     // for each question either hide it if it is in use or delete it
     foreach ($questionlist as $questionid) {
      if (record_exists('quiz_question_instances', 'question', $questionid) or
      record_exists('question_states', 'originalquestion', $questionid)) {
       if (!set_field('question', 'hidden', 1, 'id', $questionid)) {
        error('Was not able to hide question');
       }
      } else {
       delete_question($questionid);
      }
     }
    }
    redirect("edit.php?courseid=$course->id");
   } else {
    error("Confirmation string was incorrect");
   }
 
  } else { // teacher still has to confirm
   // make a list of all the questions that are selected
 
   $rawquestions = $_REQUEST;
   $questionlist = '';  // comma separated list of ids of questions to be deleted
   $questionnames = ''; // string with names of questions separated by <br /> with
   // an asterix in front of those that are in use
   $inuse = false;      // set to true if at least one of the questions is in use
   foreach ($rawquestions as $key => $value) {    // Parse input for question ids
    if (substr($key, 0, 1) == "q") {
     $key = substr($key,1);
     $questionlist .= $key.',';
     if (record_exists('quiz_question_instances', 'question', $key) or
     record_exists('question_states', 'originalquestion', $key)) {
      $questionnames .= '* ';
      $inuse = true;
     }
     $questionnames .= get_field('question', 'name', 'id', $key).'<br />';
    }
   }
   if (!$questionlist) { // no questions were selected
    echo "if (!$questionlist) { // no questions were selected";
    redirect("edit.php?courseid=$course->id");
   }
   $questionlist = rtrim($questionlist, ',');
 
   // Add an explanation about questions in use
   if ($inuse) {
    $questionnames .= get_string('questionsinuse', 'quiz');
   }
   notice_yesno(get_string("deletequestionscheck", "quiz", $questionnames),
   "edit.php?courseid=$course->id&amp;sesskey=$USER->sesskey&amp;deleteselected=$questionlist&amp;confirm=".md5($questionlist), "edit.php?courseid=$course->id");
   print_footer($course);
   exit;
  }
 }

am I missing something?

Please Help smutny

Regards,

Manisha