Skip to content

Commit

Permalink
Dev Fixed importing
Browse files Browse the repository at this point in the history
  • Loading branch information
SamMousa committed Aug 24, 2015
1 parent 3041b5c commit 6985f33
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 32 deletions.
11 changes: 3 additions & 8 deletions application/config/internal.php
Expand Up @@ -84,20 +84,15 @@
'class' => 'CLogRouter',
'routes' => array(
'vardump' => [
'class' => 'CWebLogRoute',
'class' => CWebLogRoute::class,
'levels'=>'error, warning, trace, info',
'except' => [
'system.CModule'
],
'enabled' => true
],
'trace' => array(
'class' => 'CWebLogRoute', // you can include more levels separated by commas... trace is shown on debug only
'levels' => 'trace', // you can include more separated by commas
'enabled' => YII_DEBUG
),
],
'profile' => [
'class' => 'CProfileLogRoute',
'class' => CProfileLogRoute::class,
'enabled' => YII_DEBUG
]
)
Expand Down
5 changes: 2 additions & 3 deletions application/entry.php
Expand Up @@ -28,14 +28,13 @@
}

if (version_compare(PHP_VERSION, '5.5.0', '<'))
die('This version of LimeSurvey requires PHP version 5.4.0 or later! Your version: '.PHP_VERSION);
die('This version of LimeSurvey requires PHP version 5.5.0 or later! Your version: '.PHP_VERSION);


class_exists('Yii');
Yii::$enableIncludePath = false;
$config = require_once(__DIR__ . '/config/internal' . EXT);
$config['loader'] = $loader;
unset($loader);
//var_dump($config['components']['themeManager']); die();

Yii::createApplication('WebApplication', $config)->run();
Yii::createApplication(WebApplication::class, $config)->run();
10 changes: 5 additions & 5 deletions application/helpers/export_helper.php
Expand Up @@ -631,7 +631,7 @@ function buildXMLFromQuery($xmlwriter, $Query, $tagname='', $excludes = array())
/**
* from export_structure_xml.php
*/
function surveyGetXMLStructure($iSurveyID, $xmlwriter, $exclude=array())
function surveyGetXMLStructure($iSurveyID, $xmlwriter, $exclude = [])
{
$sdump = "";
if (!isset($exclude['answers']))
Expand Down Expand Up @@ -760,11 +760,11 @@ function surveyGetXMLData($iSurveyID, $exclude = array())
$xml->writeElement('LimeSurveyDocType','Survey');
$xml->writeElement('DBVersion',\SettingGlobal::get("DBVersion"));
$xml->startElement('languages');
$surveylanguages=Survey::model()->findByPk($iSurveyID)->additionalLanguages;
$surveylanguages[]=Survey::model()->findByPk($iSurveyID)->language;
foreach ($surveylanguages as $surveylanguage)
$languages = Survey::model()->findByPk($iSurveyID)->allLanguages;

foreach ($languages as $language)
{
$xml->writeElement('language',$surveylanguage);
$xml->writeElement('language', $language);
}
$xml->endElement();
surveyGetXMLStructure($iSurveyID, $xml,$exclude);
Expand Down
33 changes: 23 additions & 10 deletions application/helpers/import/BaseElementXmlImport.php
Expand Up @@ -27,7 +27,7 @@ protected function constructTree($data) {
// Recursion create cleaner code at the cost of some speed (since the $data array is iterated a lot).
foreach($data['groups']['rows'] as $group) {
// Only handle the base language.
if ($group['language'] == $result['language']) {
if (!isset($group['language']) || $group['language'] == $result['language']) {
$result['groups'][] = $this->constructGroup($group, $result['language'], $data);
}
}
Expand Down Expand Up @@ -78,6 +78,7 @@ protected function constructQuestion($question, $language, $data)
$questions = isset($data['subquestions']) ? array_merge($data['subquestions']['rows'], $data['questions']['rows']) : $data['questions']['rows'];
foreach ($questions as $translatedQuestion) {
if ($translatedQuestion['qid'] == $question['qid']
&& isset($translatedQuestion['language'])
&& $translatedQuestion['language'] != $language
) {
$question['translations'][] = $translatedQuestion;
Expand All @@ -86,16 +87,19 @@ protected function constructQuestion($question, $language, $data)

// Add subquestions
foreach (isset($data['subquestions']) ? $data['subquestions']['rows'] : [] as $subQuestion) {
if ($subQuestion['parent_qid'] == $question['qid'] && $subQuestion['language'] == $language) {
if ($subQuestion['parent_qid'] == $question['qid'] && (!isset($subQuestion['language']) || $subQuestion['language'] == $language)) {
$question['subquestions'][] = $this->constructQuestion($subQuestion, $language, $data);
}
}

// Add answers
foreach ($data['answers']['rows'] as $answer) {
if ($answer['qid'] == $question['qid']
&& $answer['language'] == $language) {
$question['answers'][] = $this->constructAnswer($answer, $language, $data);
if (isset($data['answers'])) {
foreach ($data['answers']['rows'] as $answer) {
if ($answer['qid'] == $question['qid']
&& $answer['language'] == $language
) {
$question['answers'][] = $this->constructAnswer($answer, $language, $data);
}
}
}

Expand All @@ -112,7 +116,6 @@ protected function constructQuestion($question, $language, $data)
$question[$attribute['attribute']] = $attribute['value'];
}
}

return $question;
}

Expand All @@ -128,17 +131,27 @@ protected function constructQuestion($question, $language, $data)
protected function constructGroup($group, $language, $data) {
// Add translations.
foreach($data['groups']['rows'] as $translatedGroup) {
if ($translatedGroup['gid'] == $group['gid']
&& $translatedGroup['language'] != $language) {

if (isset($translatedGroup['gid'],$group['gid'], $translatedGroup['language'])
&& $translatedGroup['gid'] == $group['gid']
&& $translatedGroup['language'] != $language
) {
$group['translations'][] = $translatedGroup;
} elseif (
isset($translatedGroup['id'],$group['id'], $translatedGroup['language'])
&& $translatedGroup['id'] == $group['id']
&& $translatedGroup['language'] != $language
) {
$group['translations'][] = $translatedGroup;
}

}


// Add questions.
foreach($data['questions']['rows'] as $question) {
// Only handle the base language.
if ($question['gid'] == $group['gid'] && $question['language'] == $language) {
if ($question['gid'] == (isset($group['gid']) ? $group['gid'] : $group['id']) && (!isset($question['language']) || $question['language'] == $language)) {

$group['questions'][] = $this->constructQuestion($question, $language, $data);
}
Expand Down
5 changes: 4 additions & 1 deletion application/helpers/import/importers/Import178.php
Expand Up @@ -65,7 +65,8 @@ protected function importTranslation(TranslatableBehavior $translatable, array $
}
protected function prepareGroup(array $data, \Survey $survey) {
// Translate gid.
$data['id'] = $data['gid'];

$data['id'] = isset($data['gid']) ? $data['gid'] : $data['id'];
$data['sid'] = $survey->primaryKey;
unset($data['gid']);
unset($data['language']);
Expand All @@ -92,6 +93,7 @@ protected function importGroup(array $data, \Survey $survey, array &$questionMap
$result = $result && $this->importTranslation($group->translatable, $translation, $group->primaryKey);
}
foreach($questions as $question) {
\Yii::trace('importQuestion');
$result = $result && $this->importQuestion($question, $group, $questionMap);
}

Expand Down Expand Up @@ -128,6 +130,7 @@ protected function importSurvey($data) {
foreach ($surveyTranslations as $surveyTranslation) {
$result = $result && $this->importSurveyTranslation($surveyTranslation, $survey);
}

foreach ($groups as $group) {
$result = $result && $this->importGroup($group, $survey, $questionMap);
}
Expand Down
16 changes: 16 additions & 0 deletions application/helpers/import/importers/Import182.php
@@ -0,0 +1,16 @@
<?php
/**
* Created by PhpStorm.
* User: sam
* Date: 6/18/15
* Time: 1:45 PM
*/

namespace ls\import\importers;


use ls\import\BaseImport;

class Import182 extends Import181{

}
10 changes: 5 additions & 5 deletions application/models/Question.php
Expand Up @@ -22,7 +22,7 @@
* @property-read Translation[] $translations Relation added by translatable behavior
* @property-read bool $hasSubQuestions
* @property-read bool $hasAnswers
* @property-read string $type
* @property string $type
* @property QuestionGroup $group;
* @property string $title
* @property boolean $other
Expand Down Expand Up @@ -382,14 +382,14 @@ public function rules()
'message' => gT('Subquestion codes may only contain alphanumeric characters.'),
'on' => ['updatesub', 'insertsub']
];
$aRules[] = ['title', 'unique', 'caseSensitive'=>true,
$aRules[] = ['title', CUniqueValidator::class, 'caseSensitive'=>true,
'criteria'=>[
'condition' => 'sid=:sid AND parent_qid=:parent_qid and scale_id=:scale_id',
// Use a deferred value since $this->sid might be set after validators are created.
'params' => [
':sid' => new DeferredValue(function() { return $this->sid; }),
':parent_qid' => new DeferredValue(function() { return $this->parent_qid; }),
':scale_id' => new DeferredValue(function() { return $this->scale_id; })
':sid' => new DeferredValue(function() { return $this->sid; }, 'sid'),
':parent_qid' => new DeferredValue(function() { return $this->parent_qid; }, 'parent_qid'),
':scale_id' => new DeferredValue(function() { return $this->scale_id; }, 'scale_id')
]
],
'message' => gT('Question codes must be unique.'),
Expand Down

0 comments on commit 6985f33

Please sign in to comment.