Skip to content

Commit

Permalink
Dev: Factor out checkGroupOrderDuplicates()
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Mar 9, 2018
1 parent ab352f6 commit 4bb18c0
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions application/controllers/admin/checkintegrity.php
Expand Up @@ -824,29 +824,7 @@ protected function _checkintegrity()
/**********************************************************************/
/* Check group sort order duplicates */
/**********************************************************************/
$sQuery = "
SELECT
sid,
COUNT(DISTINCT group_order) AS group_order,
COUNT(gid) AS gid
FROM
lime_groups
GROUP BY sid
HAVING group_order != gid";
$result = Yii::app()->db->createCommand($sQuery)->queryAll();
if (!empty($result)) {
foreach ($result as &$survey) {
$survey['organizerLink'] = Yii::app()->getController()->createUrl(
'admin/survey',
[
'sa' => 'organize',
'surveyid' => $survey['sid'],
]
);
}
$aDelete['groupOrderDuplicates'] = $result;
}
unset($survey); // &$survey escapes scope (lol php).
$aDelete['groupOrderDuplicates'] = $this->checkGroupOrderDuplicates();

/**********************************************************************/
/* CHECK CPDB SURVEY_LINKS TABLE FOR REDUNDENT Survey participants tableS */
Expand All @@ -872,6 +850,36 @@ protected function _checkintegrity()
return $aDelete;
}

/**
* Check group order duplicates.
* @return array Result.
*/
protected function checkGroupOrderDuplicates()
{
$sQuery = "
SELECT
sid,
COUNT(DISTINCT group_order) AS group_order,
COUNT(gid) AS gid
FROM
lime_groups
GROUP BY sid
HAVING group_order != gid";
$result = Yii::app()->db->createCommand($sQuery)->queryAll();
if (!empty($result)) {
foreach ($result as &$survey) {
$survey['organizerLink'] = Yii::app()->getController()->createUrl(
'admin/survey',
[
'sa' => 'organize',
'surveyid' => $survey['sid'],
]
);
}
}
return $result;
}

/**
* Renders template(s) wrapped in header and footer
*
Expand Down

0 comments on commit 4bb18c0

Please sign in to comment.