Skip to content

Commit

Permalink
New feature: Check question order during integrity check
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Mar 9, 2018
1 parent 8877379 commit f069b55
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
2 changes: 1 addition & 1 deletion application/config/version.php
Expand Up @@ -13,7 +13,7 @@


$config['versionnumber'] = '3.4.4'; //The current version of this branch, LS3
$config['dbversionnumber'] = 348;
$config['dbversionnumber'] = 347;
$config['buildnumber'] = '';
$config['updatable'] = true;
$config['assetsversionnumber'] = '30020';
Expand Down
53 changes: 52 additions & 1 deletion application/controllers/admin/checkintegrity.php
Expand Up @@ -826,6 +826,11 @@ protected function _checkintegrity()
/**********************************************************************/
$aDelete['groupOrderDuplicates'] = $this->checkGroupOrderDuplicates();

/**********************************************************************/
/* Check question sort order duplicates */
/**********************************************************************/
$aDelete['questionOrderDuplicates'] = $this->checkQuestionOrderDuplicates();

/**********************************************************************/
/* CHECK CPDB SURVEY_LINKS TABLE FOR REDUNDENT Survey participants tableS */
/**********************************************************************/
Expand All @@ -852,7 +857,7 @@ protected function _checkintegrity()

/**
* Check group order duplicates.
* @return array Result.
* @return array
*/
protected function checkGroupOrderDuplicates()
{
Expand Down Expand Up @@ -880,6 +885,52 @@ protected function checkGroupOrderDuplicates()
return $result;
}

/**
* Check question order duplicates.
* @return array
*/
protected function checkQuestionOrderDuplicates()
{
$sQuery = "
SELECT
q.question_order,
q.qid,
q.gid,
q.sid,
q.parent_qid,
COUNT(DISTINCT q.question_order) AS question_order,
COUNT(q.qid) AS qid
FROM lime_questions q
JOIN lime_groups g ON q.gid = g.gid
GROUP BY sid, gid, parent_qid
HAVING question_order != qid;
";
$result = Yii::app()->db->createCommand($sQuery)->queryAll();
if (!empty($result)) {
foreach ($result as &$info) {
$info['viewSurveyLink'] = Yii::app()->getController()->createUrl(
'admin/survey',
[
'sa' => 'view',
'surveyid' => $info['sid'],
]
);
if ($info['parent_qid'] != 0) {
$info['questionSummaryLink'] = Yii::app()->getController()->createUrl(
'admin/questions',
[
'sa' => 'subquestions',
'surveyid' => $info['sid'],
'gid' => $info['gid'],
'qid' => $info['parent_qid']
]
);
}
}
}
return $result;
}

/**
* Renders template(s) wrapped in header and footer
*
Expand Down
18 changes: 18 additions & 0 deletions application/views/admin/checkintegrity/check_view.php
Expand Up @@ -168,6 +168,24 @@
<li><?php eT("All questions meet consistency standards."); ?></li><?php
} ?>

<?php if (isset($questionOrderDuplicates) && !empty($questionOrderDuplicates)): ?>
<li><?php eT("The following surveys have an errorneous question order. Please go to each question respectively, check the question order and save it."); ?>
<ul>
<?php foreach ($questionOrderDuplicates as $info): ?>
<li>
SID: <a href="<?php echo $info['viewSurveyLink']; ?>"><?php echo $info['sid']; ?></a>
GID: <?php echo $info['sid']; ?>
QID: <?php echo $info['qid']; ?>
<?php if ($info['parent_qid'] != 0): ?>
Parent QID: <a href="<?php echo $info['questionSummaryLink']; ?>"><?php echo $info['parent_qid']; ?></a>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php else: ?>
<li><?php eT("No issues with question order found."); ?></li>
<?php endif; ?>

<?php
if (isset($groups))
{?>
Expand Down

0 comments on commit f069b55

Please sign in to comment.