From: Simon H. <sim...@us...> - 2010-11-01 18:18:38
|
Update of /cvsroot/stack/stack-dev/lib/database In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv12921/lib/database Modified Files: StackDBItem.php MoodleDB.php Log Message: Stable interim commit towards deployment updating. Index: MoodleDB.php =================================================================== RCS file: /cvsroot/stack/stack-dev/lib/database/MoodleDB.php,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** MoodleDB.php 30 Sep 2010 16:56:13 -0000 1.15 --- MoodleDB.php 1 Nov 2010 18:18:29 -0000 1.16 *************** *** 137,149 **** //check whether the question is already in the moodle question bank. $inQBank = $this->inMoodleQuestionBank($id, $engineID); - $this->logger->debug("tap"); if($inQBank === false) { ! $this->logger->debug("noob q"); //add the question return $this->newQuestion($engineID, $userID, $category, $itemID, $line, $itemName, $itemMaxMark, $itemGUID); } else { //update the question(s) ! $this->logger->debug("updating q in $inQBank"); return $this->updateQuestion($inQBank, $engineID, $userID, $category, $itemID, $itemName, $itemMaxMark, $itemGUID); } --- 137,148 ---- //check whether the question is already in the moodle question bank. $inQBank = $this->inMoodleQuestionBank($id, $engineID); if($inQBank === false) { ! $this->logger->debug("New question"); //add the question return $this->newQuestion($engineID, $userID, $category, $itemID, $line, $itemName, $itemMaxMark, $itemGUID); } else { //update the question(s) ! $this->logger->debug("Updating question in $inQBank"); return $this->updateQuestion($inQBank, $engineID, $userID, $category, $itemID, $itemName, $itemMaxMark, $itemGUID); } *************** *** 157,161 **** /** ! * Updates a question already in the moodle question bank * * @param int $qID moodle's question id --- 156,160 ---- /** ! * Updates a question already in the moodle question bank. * * @param int $qID moodle's question id *************** *** 334,337 **** --- 333,372 ---- } + /** + * Attempts to remove a stack question from moodle's question bank. Return success status. + * + * @param int $engineID Opaque engine id + * @param int $stackID The id of the question on stack. + * @access public + * @return bool + */ + public function hideQuestion($stackID, $engineID) + { + $this->logger->debug("attempting to hide stack question $stackID on engine $engineID"); + // find moodle question id + $moodleQuestions = $this->inMoodleQuestionBank($stackID, $engineID); // an array + + if(empty($moodleQuestions)) { + $this->logger->debug("STACK question $stackID does not appear to be in Moodle question bank"); + return false; + } + + // remove, i.e. set hidden flag to 1 + if(count($moodleQuestions) > 1) { + $where = "id IN (".implode($moodleQuestions).")"; //multiple questions + } + else { + $where = "id = ".$moodleQuestions[0]; // single question + } + + $sql = "UPDATE {$prefix}question SET hidden=1 WHERE ".$where; + + $this->connect(); + $result = $this->query($sql); + + $this->logger->debug("Query ".$sql."\n\n Returned".print_r($result,true)); + //$no = $this->noRows(); + } + /** * Recursively checks for child question categories, returning an array of sub categories. *************** *** 488,492 **** if($categories[$i]['id'] == $selected) { ! $xhtml .= '<option value="'.$categories[$i]['id'].'" selected>'.$categories[$i]['name'].'</option>'; } else --- 523,527 ---- if($categories[$i]['id'] == $selected) { ! $xhtml .= '<option value="'.$categories[$i]['id'].'" selected="">'.$categories[$i]['name'].'</option>'; } else *************** *** 703,706 **** --- 738,765 ---- return $return; } + + /** + * Returns the number of attempts on an STACK question + * @access public + * @param int $id + * @return int + */ + public function attemptsOnQuestion($id) { + global $config; + $prefix = $config->getMoodle('prefix'); + + $id = 'q'.$id; + $sql = "SELECT * FROM {$prefix}question_states, {$prefix}question_opaque " . + "WHERE question = questionid " . + "AND remoteid = ".$this->dbSafeString($id); + + $sql = "SELECT * FROM {$prefix}question_states";// test + $result = $this->query($sql); + $n = $this->noRows(); + //return $n; + //return $this->noRows(); + if($this->noRows() === false) return "noRows() === false for $sql"; + else return "$this->noRows() attempt states for this question"; + } } Index: StackDBItem.php =================================================================== RCS file: /cvsroot/stack/stack-dev/lib/database/StackDBItem.php,v retrieving revision 1.37 retrieving revision 1.38 diff -C2 -d -r1.37 -r1.38 *** StackDBItem.php 1 Oct 2010 15:02:54 -0000 1.37 --- StackDBItem.php 1 Nov 2010 18:18:29 -0000 1.38 *************** *** 118,128 **** * @return int * @access public ! * public function updateItem($id, $dbItemOptions, $dbItemTests, $dbQuestionVariables, $meta, $valid, $status, $published) { ! return addNewItem($dbItemOptions, $dbItemTests, $dbQuestionVariables, $meta, $valid, $status, $published); //update line ! /* //make meta db safe foreach($meta as $label => $val) --- 118,128 ---- * @return int * @access public ! **/ public function updateItem($id, $dbItemOptions, $dbItemTests, $dbQuestionVariables, $meta, $valid, $status, $published) { ! //return addNewItem($dbItemOptions, $dbItemTests, $dbQuestionVariables, $meta, $valid, $status, $published); //update line ! //make meta db safe foreach($meta as $label => $val) *************** *** 172,176 **** WHERE questionID = $id;"; ! }*/ --- 172,189 ---- WHERE questionID = $id;"; ! $updated = $this->query($sql); ! if($updated) ! { ! $this->logger->fine('Item updated.'); ! $result = true; ! } ! else ! { ! $result = false; ! $this->errorLog->addError('Could not update item.'); ! $this->logger->critical('Failed to update item named '.$meta['questionDescription'].' to the database'); ! } ! return $result; ! }//*/ |