예제 #1
0
 function parseFile($basename)
 {
     $notify = $this->delegate;
     $notify("Parsing file: {$basename} <br/>\nConcepts: ");
     // Begin Processing
     $vQuestion = new Model_Shell_GenericQuestion($this->path . '/' . $basename);
     // Add to questionBase (if not already there)
     $vQuestionBase = Model_Quiz_QuestionBase::fromXml($basename);
     if ($vQuestionBase == null) {
         $vQuestionBase = Model_Quiz_QuestionBase::fromScratch($basename, $vQuestion->getDifficulty(), $vQuestion->getEstimatedTime(), $vQuestion->getFriendlyType(), strtotime("today"));
     }
     // Now look at the concepts
     $vConcepts = $vQuestion->getConcepts();
     foreach ($vConcepts as $vConcept) {
         // Make sure this concept exists in the database
         $vConceptObj = Model_Quiz_Concept::fromID($vConcept);
         if ($vConceptObj == null) {
             // Doesn't exist... we should make a record
             $vConceptObj = Model_Quiz_Concept::fromScratch($vConcept);
         }
         $notify($vConcept . "; ");
         // Now we need to make sure that this question has this concept associated with it
         $vQuestionBase->addConcept($vConceptObj);
     }
     // Update the questionBase's Difficulty & EstimatedTime (these are the things most likely to change)
     $vQuestionBase->setDifficulty($vQuestion->getDifficulty());
     $vQuestionBase->setEstimated_time($vQuestion->getEstimatedTime());
     $notify("<br/>Difficulty: " . $vQuestion->getDifficulty());
     $notify("<br/>Estimated time to complete: " . $vQuestion->getEstimatedTime());
     $notify("<br/><br/>\n");
 }
예제 #2
0
 public function init()
 {
     $this->setName('addquizconcept');
     $form_elements = array();
     //Setup some Validators
     $validatorPositive = new Zend_Validate_GreaterThan(0);
     $validatorLessthan = new Zend_Validate_LessThan(101);
     // Concepts
     $all_concepts = Model_Quiz_Concept::getAll();
     $all_concepts_array = array();
     // Form likes key=>val
     foreach ($all_concepts as $concept) {
         $all_concepts_array[$concept->getID()] = $concept->getName();
     }
     // Form Elements
     $this->addElement('text', 'number_of_questions', array('label' => 'Number of Questions', 'required' => true, 'filters' => array('StringTrim'), 'validators' => array($validatorPositive), 'placeholder' => "eg. 5"));
     $this->addElement('select', 'concept_id', array('label' => 'Concept', 'multiOptions' => $all_concepts_array, 'required' => true));
     $this->addElement('text', 'difficulty_from', array('label' => 'Difficulty (From)', 'required' => true, 'filters' => array('StringTrim'), 'validators' => array($validatorPositive), 'placeholder' => "eg. 1"));
     $this->addElement('text', 'difficulty_to', array('label' => 'Difficulty (To)', 'required' => true, 'filters' => array('StringTrim'), 'validators' => array($validatorPositive), 'placeholder' => "eg. 3"));
     $this->addElement('submit', 'submit', array('label' => 'Add Tested Concept'));
 }
예제 #3
0
 public function getConcepts()
 {
     $db = Zend_Registry::get("db");
     $vReturn = array();
     $sql = "SELECT * FROM question_concepts WHERE question_basequestion_id=" . $db->quote($this->question_id);
     $result = $db->query($sql);
     $rows = $result->fetchAll();
     foreach ($rows as $row) {
         $vReturn[] = Model_Quiz_Concept::fromID($row['conceptsconcept_name']);
     }
     return $vReturn;
 }
예제 #4
0
 /**
  * Update the Concept tested to that of the object passed
  * @param Model_Quiz_Concept $concept
  */
 public function updateConcept(Model_Quiz_Concept $concept)
 {
     $this->updateField("conceptsconcept_name", $concept->getName());
     // NAME? REALLY? NAME?
 }
예제 #5
0
 /**
  * Gets all quiz concepts in the database
  * @return multitype:Model_Quiz_Concept
  */
 public static function getAll()
 {
     $db = Zend_Registry::get("db");
     $vReturn = array();
     $result = $db->query("SELECT * FROM concepts");
     $rows = $result->fetchAll();
     foreach ($rows as $row) {
         $vReturn[] = Model_Quiz_Concept::fromID($row['concept_name']);
     }
     return $vReturn;
 }
예제 #6
0
 /**
  * Allows Adding and Editing a TestedConcept to a quiz
  * Expects [quiz_id] as a parameter if no [tested_concept] (id) is passed
  */
 public function addconceptAction()
 {
     $form = new Form_AddQuizConcept();
     $quiz_id = $this->_getParam("quiz_id");
     //part of the url
     $tested_concept = $this->_getParam("tested_concept");
     if (is_numeric($tested_concept)) {
         $tested_concept_ob = Model_Quiz_TestedConcept::fromID(intval($tested_concept));
         if (is_null($tested_concept_ob)) {
             throw new Exception("Invalid Tested Concept Identifier");
         }
         $form->getElement("submit")->setLabel("Edit Tested Concept");
         $this->view->action_text = "Edit";
         $form->populateFromConcept($tested_concept_ob);
     } elseif (is_numeric($quiz_id)) {
         $quiz_ob = Model_Quiz_Quiz::fromID(intval($quiz_id));
         if (is_null($quiz_ob)) {
             throw new Exception("Invalid Quiz Identifier");
         }
         $this->view->action_text = "Add";
     } else {
         throw new Exception("No quiz identifier or tested concept identifier passed");
     }
     if ($this->getRequest()->isPost()) {
         $formdata = $this->getRequest()->getPost();
         My_Logger::log(var_export($formdata, true));
         if ($form->isValid($formdata)) {
             // Either update the existing tested concept or add a new one
             if (isset($tested_concept_ob)) {
                 $vConcept = Model_Quiz_Concept::fromID($formdata['concept_id']);
                 $tested_concept_ob->updateConcept($vConcept);
                 $tested_concept_ob->updateLowerDifficulty($formdata['difficulty_from']);
                 $tested_concept_ob->updateHigherDifficulty($formdata['difficulty_to']);
                 $tested_concept_ob->updateNumberTested($formdata['number_of_questions']);
                 $params = array('id' => $tested_concept_ob->getQuiz()->getID());
             } else {
                 $vConcept = Model_Quiz_Concept::fromID($formdata['concept_id']);
                 $vTestedConcept = Model_Quiz_TestedConcept::fromScratch($formdata['difficulty_from'], $formdata['difficulty_to'], $formdata['number_of_questions'], $vConcept, $quiz_ob);
                 $params = array('id' => $quiz_ob->getID());
             }
             $this->_helper->redirector("showconcepts", "admin", null, $params);
         } else {
             $form->populate($formdata);
         }
     }
     $this->view->form = $form;
 }
예제 #7
0
 function addTestedConcept($quiz_ob, $concept_id, $nb_questions, $from = 1, $to = 1)
 {
     $vConcept = Model_Quiz_Concept::fromID($concept_id);
     return Model_Quiz_TestedConcept::fromScratch($from, $to, $nb_questions, $vConcept, $quiz_ob);
 }
 /**
  * This function rebuilds XML files
  * In doing so, all pre-generated questions will be removed.
  */
 public function rebuildxmlAction()
 {
     $process = $this->_getParam("process");
     if (is_null($process) || $process !== "1") {
         // Get the amount of files in the Questions Dir
         $counter = 0;
         if ($handle = opendir(APPLICATION_PATH . '/../xml/questions')) {
             while (false !== ($file = readdir($handle))) {
                 if (strtolower(substr($file, -3)) == "xml") {
                     $counter = $counter + 1;
                 }
             }
             closedir($handle);
         }
         $this->view->count = $counter;
     } else {
         // Process the XML Files
         if ($handle = opendir(APPLICATION_PATH . '/../xml/questions')) {
             while (false !== ($file = readdir($handle))) {
                 if (strtolower(substr($file, -3)) == "xml") {
                     echo "Parsing file: {$file} <br/>\nConcepts: ";
                     //Begin Processing
                     $vQuestion = new Model_Shell_GenericQuestion(APPLICATION_PATH . '/../xml/questions/' . $file);
                     //Add to questionBase (if not already there)
                     $vQuestionBase = Model_Quiz_QuestionBase::fromXml($file);
                     if ($vQuestionBase == null) {
                         $vQuestionBase = Model_Quiz_QuestionBase::fromScratch($file, $vQuestion->getDifficulty(), $vQuestion->getEstimatedTime(), $vQuestion->getFriendlyType(), strtotime("today"));
                     }
                     //Now look at the concepts
                     $vConcepts = $vQuestion->getConcepts();
                     foreach ($vConcepts as $vConcept) {
                         //Make sure this concept exists in the database
                         $vConceptObj = Model_Quiz_Concept::fromID($vConcept);
                         if ($vConceptObj == null) {
                             //Doesn't exist... we should make a record
                             $vConceptObj = Model_Quiz_Concept::fromScratch($vConcept);
                         }
                         echo $vConcept . "; ";
                         //Now we need to make sure that this question has this concept associated with it
                         $vQuestionBase->addConcept($vConceptObj);
                     }
                     //Update the questionBase's Difficulty & EstimatedTime (these are the things most likely to change)
                     $vQuestionBase->setDifficulty($vQuestion->getDifficulty());
                     $vQuestionBase->setEstimated_time($vQuestion->getEstimatedTime());
                     echo "<br/>Difficulty: " . $vQuestion->getDifficulty();
                     echo "<br/>Estimated time to complete: " . $vQuestion->getEstimatedTime();
                     echo "<br/><br/>\n";
                 }
             }
             closedir($handle);
             Model_Quiz_GeneratedQuestion::removePregeneratedQuestions();
             // Remove all Pre-Generated questions, so as to not cause any conficts
         }
     }
 }