Skip to content

Commit

Permalink
Port the Excel export and survey logic file generation in EM to use t…
Browse files Browse the repository at this point in the history
…he question objects.

Add AJS tags to a bunch of code throughout the codebase that still needs porting
Fix some issues in the question creation area of the backend.
Numerous other bugfixes.
  • Loading branch information
aaronschmitz committed Aug 13, 2012
1 parent e008f7a commit 550133e
Show file tree
Hide file tree
Showing 28 changed files with 247 additions and 212 deletions.
2 changes: 1 addition & 1 deletion application/controllers/admin/conditionsaction.php
Expand Up @@ -1112,7 +1112,7 @@ function index($subaction, $iSurveyID=null, $gid=null, $qid=null)
{
$javascriptpre .= "QFieldnames[$jn]='$cqn[3]';\n"
."Qcqids[$jn]='$cqn[1]';\n"
."Qtypes[$jn]='$cqn[2]';\n";
."Qtypes[$jn]='$cqn[2]';\n"; //AJS
$jn++;
}
}
Expand Down
35 changes: 16 additions & 19 deletions application/controllers/admin/database.php
Expand Up @@ -548,29 +548,26 @@ function index($sa = null)
LimeExpressionManager::RevertUpgradeConditionsToRelevance($surveyid);

$cqr=Questions::model()->findByAttributes(array('qid'=>$qid));
$oldtype=$cqr['type'];
$oldtid=$cqr['tid'];
$oldgid=$cqr['gid'];

// Remove invalid question attributes on saving
$q = objectizeQuestion(Yii::app()->request->getPost('type')); //AJS
$q = tidToQuestion(Yii::app()->request->getPost('type'));
$qattributes=linkedAttributes($q);

$criteria = new CDbCriteria;
$criteria->compare('qid',$qid);
$validAttributes=$qattributes;
foreach ($validAttributes as $validAttribute)

foreach ($qattributes as $validAttribute)
{
$criteria->compare('attribute', '<>'.$validAttribute['name']);
}
Question_attributes::model()->deleteAll($criteria);

$aLanguages=array_merge(array(Survey::model()->findByPk($surveyid)->language),Survey::model()->findByPk($surveyid)->additionalLanguages);


//now save all valid attributes
$validAttributes=$qattributes[Yii::app()->request->getPost('type')];

foreach ($validAttributes as $validAttribute)
foreach ($qattributes as $validAttribute)
{
if ($validAttribute['i18n'])
{
Expand Down Expand Up @@ -633,34 +630,32 @@ function index($sa = null)
}

// These are the questions types that have no answers and therefore we delete the answer in that case
$q = objectizeQuestion(Yii::app()->request->getPost('type')); //AJS
$qproperties=$q->questionProperties();
$iAnswerScales = $qproperties['answerscales'];
$iSubquestionScales = $qproperties['subquestions'];

$options = $q->availableOptions();
// These are the questions types that have the other option therefore we set everything else to 'No Other'
if ((Yii::app()->request->getPost('type')!= "L") && (Yii::app()->request->getPost('type')!= "!") && (Yii::app()->request->getPost('type')!= "P") && (Yii::app()->request->getPost('type')!="M"))
if (!$options['other'])
{
$_POST['other']='N';
}

// These are the questions types that have no validation - so zap it accordingly

if (Yii::app()->request->getPost('type')== "!" || Yii::app()->request->getPost('type')== "L" || Yii::app()->request->getPost('type')== "M" || Yii::app()->request->getPost('type')== "P" ||
Yii::app()->request->getPost('type')== "F" || Yii::app()->request->getPost('type')== "H" ||
Yii::app()->request->getPost('type')== "X" || Yii::app()->request->getPost('type')== "")
if (!$options['valid'])
{
$_POST['preg']='';
}

// These are the questions types that have no mandatory property - so zap it accordingly
if (Yii::app()->request->getPost('type')== "X" || Yii::app()->request->getPost('type')== "|")
if (!$options['mandatory'])
{
$_POST['mandatory']='N';
}


if ($oldtype != Yii::app()->request->getPost('type'))
if ($oldtid != Yii::app()->request->getPost('type'))
{
// TMSW Conditions->Relevance: Do similar check via EM, but do allow such a change since will be easier to modify relevance
//Make sure there are no conditions based on this question, since we are changing the type
Expand Down Expand Up @@ -712,9 +707,10 @@ function index($sa = null)

if (isset($qlang) && $qlang != "")
{ // ToDo: Sanitize the POST variables !

$type = Question_types::model()->findByPk(Yii::app()->request->getPost('type')); //AJS
$udata = array(
'type' => Yii::app()->request->getPost('type'),
'tid' => Yii::app()->request->getPost('type'),
'type' => $type['legacy'],
'title' => Yii::app()->request->getPost('title'),
'question' => Yii::app()->request->getPost('question_'.$qlang),
'preg' => Yii::app()->request->getPost('preg'),
Expand Down Expand Up @@ -771,9 +767,10 @@ function index($sa = null)
// then change the cfieldname accordingly
fixMovedQuestionConditions($qid, $oldgid, $gid);
}
if ($oldtype != Yii::app()->request->getPost('type'))
if ($oldtid != Yii::app()->request->getPost('type'))
{
Questions::model()->updateAll(array('type'=>Yii::app()->request->getPost('type')), 'parent_qid=:qid', array(':qid'=>$qid));
$type = Question_types::model()->findByPk(Yii::app()->request->getPost('type')); //AJS
Questions::model()->updateAll(array('tid'=>Yii::app()->request->getPost('type'), 'type'=>$type['legacy']), 'parent_qid=:qid', array(':qid'=>$qid));
}

Answers::model()->deleteAllByAttributes(array('qid' => $qid), 'scale_id >= :scale_id', array(':scale_id' => $iAnswerScales));
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/admin/dataentry.php
Expand Up @@ -1305,7 +1305,7 @@ public function view($surveyid, $lang=NULL)
$cdata['hh'] = $hh;
//$aDataentryoutput .= "\t<img src='$imageurl/help.gif' alt='".$blang->gT("Help about this question")."' align='right' onclick=\"javascript:alert('Question {$deqrow['title']} Help: $hh')\" />\n";
}
switch($deqrow['type'])
switch($deqrow['type']) //AJS
{
case "Q": //MULTIPLE SHORT TEXT
case "K":
Expand Down
17 changes: 11 additions & 6 deletions application/controllers/admin/question.php
Expand Up @@ -694,7 +694,7 @@ public function index($sa, $surveyid, $gid, $qid=null)
'question_order' => $esrow['question_order'],
'other' => $esrow['other'],
'mandatory' => $esrow['mandatory'],
'type' => $esrow['type'],
'type' => $esrow['type'], //AJS
'title' => $esrow['title'],
'preg' => $esrow['preg'],
'question' => $esrow['question'],
Expand All @@ -714,7 +714,7 @@ public function index($sa, $surveyid, $gid, $qid=null)
'qid' => $qid,
'sid' => $surveyid,
'gid' => $gid,
'type' => $basesettings['type'],
'type' => $basesettings['type'], //AJS
'title' => $basesettings['title'],
'question' => $basesettings['question'],
'preg' => $basesettings['preg'],
Expand Down Expand Up @@ -742,14 +742,19 @@ public function index($sa, $surveyid, $gid, $qid=null)

$types = Question_types::model()->with('question_type_groups')->findAll(array('order' => 'question_type_groups.order, t.order'));
$qDescToCode = 'qDescToCode = {';
$qScreenshots = 'qScreenshots = {';
$selections = array();
foreach ($types as $type)
{
$q = createQuestion($type['class']);
$props = $q->questionProperties();
$screenshots = $q->screenshotCount();
$qDescToCode .= " '{$props['description']}' : '{$type['class']}', \n";
$typegroups[$type->question_type_groups['name']][] = $type;
$qScreenshots .= " '{$type['class']}' : '{$screenshots}', \n";
$selections[$type['class']] = $q->availableOptions();
}
$aData['qTypeOutput'] = "$qDescToCode 'null':'null' };";
$aData['qTypeOutput'] = "$qDescToCode 'null':'null' };$qScreenshots 'null':'null' };";
$aData['qTypeGroups'] = $typegroups;

if (!$adding)
Expand All @@ -766,7 +771,7 @@ public function index($sa, $surveyid, $gid, $qid=null)
$eqrow['title'] = '';
$eqrow['question'] = '';
$eqrow['help'] = '';
$eqrow['tid'] = 25; //AJS - WHY IS THIS HARDCODED?
$eqrow['class'] = 'LongText'; //AJS - WHY IS THIS HARDCODED?
$eqrow['lid'] = 0;
$eqrow['lid1'] = 0;
$eqrow['gid'] = $gid;
Expand Down Expand Up @@ -821,7 +826,7 @@ public function index($sa, $surveyid, $gid, $qid=null)
}

$aViewUrls['editQuestion_view'][] = $aData;
$aViewUrls['questionJavascript_view'][] = array('type' => $eqrow['type']);
$aViewUrls['questionJavascript_view'][] = array('class' => $eqrow['class'], 'selections' => $selections);
}
else
include('accessDenied.php');
Expand Down Expand Up @@ -912,7 +917,7 @@ public function delete($surveyid, $gid, $qid)
*/
public function ajaxquestionattributes()
{
$q = objectizeQuestion($_POST['question_type'], array('surveyid' => (int) $_POST['sid'], 'id' => (int) $_POST['qid'])); //AJS
$q = createQuestion($_POST['class'], array('surveyid' => (int) $_POST['sid'], 'id' => (int) $_POST['qid']));

$aLanguages = array_merge(array(Survey::model()->findByPk($q->surveyid)->language), Survey::model()->findByPk($q->surveyid)->additionalLanguages);
$thissurvey = getSurveyInfo($q->surveyid);
Expand Down
2 changes: 1 addition & 1 deletion application/core/Survey_Common_Action.php
Expand Up @@ -351,7 +351,7 @@ function _questionbar($iSurveyID, $gid, $qid, $action = null)

foreach ($qrresult as $qrrow)
{
$q = createQuestion($qrrow->question_types['class'], array('surveyid'=>$iSurveyId, 'id'=>$qid));
$q = createQuestion($qrrow->question_types['class'], array('surveyid'=>$iSurveyID, 'id'=>$qid));
$qrrow = $qrrow->attributes;
if (hasSurveyPermission($iSurveyID, 'surveycontent', 'read'))
{
Expand Down
6 changes: 3 additions & 3 deletions application/helpers/common_helper.php
Expand Up @@ -4224,9 +4224,9 @@ function reverseTranslateFieldNames($iOldSID,$iNewSID,$aGIDReplacements,$aQIDRep
if ($q->id!=null)
{
$aFieldMappings[$sFieldname]=$iOldSID.'X'.$aGIDReplacements[$q->gid].'X'.$aQIDReplacements[$q->id].$q->aid;
if ($pos=strrpos($sFieldname, 'X'.$q->id.'#'))
if (isset($q->scale))
{
$aFieldMappings[$sFieldname].= substr($sFieldname,$pos+strlen($q->id)+1); //AJS
$aFieldMappings[$sFieldname].= '#' . $q->scale;
}
// now also add a shortened field mapping which is needed for certain kind of condition mappings
$aFieldMappings[$q->surveyid.'X'.$q->gid.'X'.$q->id]=$iOldSID.'X'.$aGIDReplacements[$q->gid].'X'.$aQIDReplacements[$q->id];
Expand Down Expand Up @@ -4949,7 +4949,7 @@ function getFullResponseTable($iSurveyID, $iResponseID, $sLanguageCode, $bHonorC
if ($oldqid !== $q->id)
{
$oldqid = $q->id;
if (isset($fname['subquestion']) || isset($fname['subquestion1']) || isset($fname['subquestion2'])) //AJS
if (isset($q->sq) || isset($q->sq1) || isset($q->sq2))
{
$aResultTable['qid_'.$q->surveyid.'X'.$q->gid.'X'.$q->id]=array($q->text,'','');
}
Expand Down

0 comments on commit 550133e

Please sign in to comment.