Skip to content

Commit

Permalink
WIP QE-945
Browse files Browse the repository at this point in the history
  • Loading branch information
ptelu committed May 15, 2024
1 parent 6bcb5c2 commit 316655e
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions application/models/services/ResponseArchiveService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace LimeSurvey\Models\Services;

use CDbSchema;
use PluginDynamic;
use Survey;
use Permission;
Expand Down Expand Up @@ -30,35 +31,55 @@ public function __construct(
$this->modelQuestionGroup = $modelQuestionGroup;
}

public function searchGroup()
/**
* Searches if questions exist in the latest archived response table
* @param $surveyId
* @param $questionIds
* @return bool if questions with this group exist
*/
public function searchQuestions($surveyId, $questionIds): bool
{
foreach ($questionIds as $question) {
$this->searchQuestion($surveyId, $question->id);
}

return false;
}

/**
* Searches if a question exists in the latest archived response table
* @param int $surveyId
* @param int $questionId
* @param int $questionCode The question code (Q) of the SGQA code (survey, group, question, answer)
* @return bool
* @throws \CDbException
*/
public function searchQuestion(int $surveyId, int $questionId): bool
public function searchQuestion(int $surveyId, int $questionCode): bool
{
$sourceTable = PluginDynamic::model($_POST['table']);
if ($sourceTable === null) {
return false;
}
$sourceSchema = $sourceTable->getTableSchema();
$archivedTableName = App()->getDb()->tablePrefix . 'old_survey_' . $surveyId;
$archivedResponseTable = App()->getDb()->getSchema()->getTable($archivedTableName);
$archivedReponseTableSchema = PluginDynamic::model($archivedResponseTable)->getTableSchema();

$pattern = '/(\d+)X(\d+)X(\d+.*)/';
foreach ($sourceSchema->getColumnNames() as $name) {
foreach ($archivedReponseTableSchema->getColumnNames() as $name) {
// The following columns are not questions
if (in_array($name, array('id', 'submitdate', 'lastpage', 'startlanguage', 'seed', 'startdate', 'datestamp')
)) {
continue;
}
$matches = array();
if (preg_match($pattern, (string) $name, $matches)) {
if (preg_match($pattern, (string)$name, $matches)) {
// Column name is SIDXGIDXQID
$archiveQid = $matches[3];
if ($archiveQid === $questionId) {
if ($archiveQuestionCode=== $questionCode) {
return true;
}
}
}
return false;
}

public function searchQuestionWithTypeCoercion(int $surveyId, int $questionId): bool
{
return false;
}
}

0 comments on commit 316655e

Please sign in to comment.