In my situation, the admin is creating a multiple choice question, and in the default case there are 4 choices. However, they may want 2,3, or 5. How can I code it so that the interface changes. I am using pnform to do this. I have made several attempts at this, but it always seems to get hung up when I try to refresh the interface. Here is the code I am using.
Code
function quickcheck_admin_newMCQuest($args) {
$num_mc_choices = $arg['num_mc_choices'];
if(!isset($num_mc_choices)){
$num_mc_choices = 5;
}
// Security check - important to do this as early as possible to avoid
// potential security holes or just too much wasted processing
if (!SecurityUtil::checkPermission('quickcheck::', '::', ACCESS_ADD)) {
return DataUtil::formatForDisplayHTML(_MODULENOAUTH);
}
// Create output object - this object will store all of our output so that
// we can return it easily when required
$pnForm =FormUtil::newpnForm('Quickcheck');
//a test array for now
$pnForm->assign('num_mc_choices', $num_mc_choices);
// Return the output that has been generated by this function
return $pnForm->pnFormExecute('quickcheck_admin_new_MC_question.htm', new quickcheck_admin_newMCQuestionHandler);
}
/**
* quickcheck_admin_newTextQuestionHandler
*
* This is a class to handle creating a new exam.
*
* @author Timothy Paustian
* @param name the name of the exam
* @param questions questions to place on the exam
*/
class quickcheck_admin_newMCQuestionHandler {
function initialize(&$render) {
// load the categories system
// [... snip ...]
return true;
}
function handleCommand(&$render, &$args) {
if ($args['commandName'] == 'update') {
if (!$render->pnFormIsValid())
return false;
$data = $render->pnFormGetValues();
//set the type of question
$data['q_type'] = _QUICKCHECK_MULTIPLECHOICE_TYPE;
//grab the various MC options
if(!pnModAPIFunc('quickcheck', 'admin', 'createquestion', $data)) {
return LogUtil::registerError (_CREATEFAILED);
}
//if we have gotten here, we were successful
SessionUtil::setVar('statusmsg', '_QUICKCHECK_NEW_QUEST_CREATED');
pnRedirect(pnModURL('quickcheck', 'admin', 'view'));
}
if( $args['commandName'] == 'cancel') {
pnRedirect(pnModURL('quickcheck', 'admin', 'view'));
}
if( $args['commandName'] == 'removeChoice') {
//find the number of current choices
$choices = FormUtil::getPassedValue('q_text');
$a_size = count($choices);
if($a_size > 2){
$value = array_pop($choices);
}
$a_size = count($choices);
//pnRedirect(pnModURL('quickcheck', 'admin', 'newMCQuest', array('num_mc_quests' => $a_size)));
}
return true;
}
}
$num_mc_choices = $arg['num_mc_choices'];
if(!isset($num_mc_choices)){
$num_mc_choices = 5;
}
// Security check - important to do this as early as possible to avoid
// potential security holes or just too much wasted processing
if (!SecurityUtil::checkPermission('quickcheck::', '::', ACCESS_ADD)) {
return DataUtil::formatForDisplayHTML(_MODULENOAUTH);
}
// Create output object - this object will store all of our output so that
// we can return it easily when required
$pnForm =FormUtil::newpnForm('Quickcheck');
//a test array for now
$pnForm->assign('num_mc_choices', $num_mc_choices);
// Return the output that has been generated by this function
return $pnForm->pnFormExecute('quickcheck_admin_new_MC_question.htm', new quickcheck_admin_newMCQuestionHandler);
}
/**
* quickcheck_admin_newTextQuestionHandler
*
* This is a class to handle creating a new exam.
*
* @author Timothy Paustian
* @param name the name of the exam
* @param questions questions to place on the exam
*/
class quickcheck_admin_newMCQuestionHandler {
function initialize(&$render) {
// load the categories system
// [... snip ...]
return true;
}
function handleCommand(&$render, &$args) {
if ($args['commandName'] == 'update') {
if (!$render->pnFormIsValid())
return false;
$data = $render->pnFormGetValues();
//set the type of question
$data['q_type'] = _QUICKCHECK_MULTIPLECHOICE_TYPE;
//grab the various MC options
if(!pnModAPIFunc('quickcheck', 'admin', 'createquestion', $data)) {
return LogUtil::registerError (_CREATEFAILED);
}
//if we have gotten here, we were successful
SessionUtil::setVar('statusmsg', '_QUICKCHECK_NEW_QUEST_CREATED');
pnRedirect(pnModURL('quickcheck', 'admin', 'view'));
}
if( $args['commandName'] == 'cancel') {
pnRedirect(pnModURL('quickcheck', 'admin', 'view'));
}
if( $args['commandName'] == 'removeChoice') {
//find the number of current choices
$choices = FormUtil::getPassedValue('q_text');
$a_size = count($choices);
if($a_size > 2){
$value = array_pop($choices);
}
$a_size = count($choices);
//pnRedirect(pnModURL('quickcheck', 'admin', 'newMCQuest', array('num_mc_quests' => $a_size)));
}
return true;
}
}
Any help with this is appreciated.If you look at removeChoice, this is the code that I was hoping would do the trick. I can grab the variable I need (q_text) and change its size. My question is, how do I get this to update?
Tim
edited by: Paustian, datetimebrief
