Skip to content

Commit

Permalink
Dev More fixes for label set localisation change
Browse files Browse the repository at this point in the history
  • Loading branch information
c-schmitz committed Jan 10, 2018
1 parent 34f9873 commit 1dbf195
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 31 deletions.
4 changes: 2 additions & 2 deletions application/controllers/admin/export.php
Expand Up @@ -782,13 +782,13 @@ public function dumplabel()
buildXMLFromQuery($xml, $lsquery, 'labelsets');

// Labels
$lquery = "SELECT lid, code, sortorder, assessment_value FROM {{labels}} WHERE lid=".implode(' or lid=', $lids);
$lquery = "SELECT id, lid, code, sortorder, assessment_value FROM {{labels}} WHERE lid=".implode(' or lid=', $lids);
buildXMLFromQuery($xml, $lquery, 'labels');

// Labels localization
$lquery = "SELECT ls.id, label_id, title, language FROM {{label_l10ns}} ls
join {{labels}} l on l.id=label_id WHERE lid=".implode(' or lid=', $lids);
buildXMLFromQuery($xml, $lquery, 'labels');
buildXMLFromQuery($xml, $lquery, 'label_l10ns');

$xml->endElement(); // close columns
$xml->endDocument();
Expand Down
4 changes: 2 additions & 2 deletions application/controllers/admin/labels.php
Expand Up @@ -366,8 +366,8 @@ public function process()
*/
public function delete()
{
$lid = (int)App()->request->getPost('lid');

$lid = returnglobal('lid');
// @todo This needs to be a POST, interface needs to be changed
if (Permission::model()->hasGlobalPermission('labelsets', 'delete')) {
Yii::app()->loadHelper('admin/label');

Expand Down
51 changes: 39 additions & 12 deletions application/helpers/admin/import_helper.php
Expand Up @@ -924,6 +924,7 @@ function XMLImportLabelsets($sFullFilePath, $options)
if ($xml->LimeSurveyDocType != 'Label set') {
safeDie('This is not a valid LimeSurvey label set structure XML file.');
}
$iDBVersion = (int) $xml->DBVersion;
$aLSIDReplacements = $results = [];
$results['labelsets'] = 0;
$results['labels'] = 0;
Expand Down Expand Up @@ -957,29 +958,55 @@ function XMLImportLabelsets($sFullFilePath, $options)
$insertdata[(string) $key] = (string) $value;
}
$insertdata['lid'] = $aLSIDReplacements[$insertdata['lid']];
$insertdataLS['title'] =$insertdata['title'];
$insertdataLS['language'] =$insertdata['language'];
unset ($insertdata['title']);
if ($iDBVersion < 350) {
$insertdataLS['title'] =$insertdata['title'];
$insertdataLS['language'] =$insertdata['language'];
unset ($insertdata['title']);
unset ($insertdata['language']);
} else {
$iOldLabelID=$insertdata['id'];
}
unset ($insertdata['id']);
unset ($insertdata['language']);

$findLabel = Label::model()->findByAttributes($insertdata);
if (empty($findLabel)) {
if ($iDBVersion < 350) {
$findLabel = Label::model()->findByAttributes($insertdata);
if (empty($findLabel)) {
$arLabel= new Label();
$arLabel->setAttributes($insertdata);
$arLabel->save();
$insertdataLS['label_id']=$arLabel->id;
} else {
$insertdataLS['label_id'] = $findLabel->id;
}
$arLabelL10n = new LabelL10n();
$arLabelL10n->setAttributes($insertdataLS);
$arLabelL10n->save();
} else {
$arLabel= new Label();
$arLabel->setAttributes($insertdata);
$arLabel->save();
$insertdataLS['label_id']=$arLabel->id;
} else {
$insertdataLS['label_id'] = $findLabel->id;
$aLIDReplacements[$iOldLabelID]=$arLabel->id;
}
$arLabelL10n = new LabelL10n();
$arLabelL10n->setAttributes($insertdataLS);
$arLabelL10n->save();

$results['labels']++;
}
}

// Import label_l10ns table ===================================================================================
if (isset($xml->label_l10ns->rows->row)) {
foreach ($xml->label_l10ns->rows->row as $row) {
$insertdata = [];
foreach ($row as $key=>$value) {
$insertdata[(string) $key] = (string) $value;
}
$insertdata['label_id'] = $aLIDReplacements[$insertdata['label_id']];
$arLabelL10n = new LabelL10n();
$arLabelL10n->setAttributes($insertdata);
$arLabelL10n->save();

}
}

//CHECK FOR DUPLICATE LABELSETS

if ($options['checkforduplicates']=='on') {
Expand Down
29 changes: 16 additions & 13 deletions application/helpers/admin/label_helper.php
Expand Up @@ -61,17 +61,23 @@ function updateset($lid)
}

// If languages are removed, delete labels for these languages
$criteria = new CDbCriteria;
$criteria->addColumnCondition(array('lid' => $lid));
$langcriteria = new CDbCriteria();
foreach ($dellangidsarray as $dellangid) {
$langcriteria->addColumnCondition(array('language' => $dellangid), 'OR');
}
$criteria->mergeWith($langcriteria);

if (!empty($dellangidsarray)) {
Label::model()->deleteAll($criteria);
$criteria = new CDbCriteria;
$criteria->addColumnCondition(array('lid' => $lid));
$langcriteria = new CDbCriteria();
foreach ($dellangidsarray as $sDeleteLanguage) {
$langcriteria->addColumnCondition(array('labelL10ns.language' => $sDeleteLanguage), 'OR');
}
$criteria->mergeWith($langcriteria);
debugbreak();
$aLabels=Label::model()->with('labelL10ns')->together()->findAll($criteria);
foreach ($aLabels as $aLabel) {
foreach ($aLabel->labelL10ns as $aLabelL10ns){
$aLabelL10ns->delete();
}
}
}


// Update the label set itself
$labelset->label_name = $postlabel_name;
Expand Down Expand Up @@ -134,10 +140,7 @@ function modlabelsetanswers($lid)
{
// if {}
}
$query = "DELETE FROM {{labels}} WHERE lid = '$lid'";

Yii::app()->db->createCommand($query)->execute();

debugbreak();
foreach ($data['codelist'] as $index=>$codeid) {

$codeObj = $data->$codeid;
Expand Down
3 changes: 1 addition & 2 deletions installer/create-database.php
Expand Up @@ -152,8 +152,7 @@ function createDatabase($oDB){
));
$oDB->createCommand()->createIndex('{{idx1_labels}}', '{{labels}}', 'code', false);
$oDB->createCommand()->createIndex('{{idx2_labels}}', '{{labels}}', 'sortorder', false);
$oDB->createCommand()->createIndex('{{idx3_labels}}', '{{labels}}', 'language', false);
$oDB->createCommand()->createIndex('{{idx4_labels}}', '{{labels}}', ['lid','sortorder','language'], false);
$oDB->createCommand()->createIndex('{{idx4_labels}}', '{{labels}}', ['lid','sortorder'], false);

// label_l10ns
$oDB->createCommand()->createTable('{{label_l10ns}}', array(
Expand Down

0 comments on commit 1dbf195

Please sign in to comment.