Skip to content

Commit

Permalink
Dev Put in basics for question attributes localization
Browse files Browse the repository at this point in the history
Dev ToDo: Editing & survey runtime

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_ci@10963 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
c-schmitz committed Sep 11, 2011
1 parent 9c41422 commit dbbfaeb
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 121 deletions.
30 changes: 26 additions & 4 deletions application/helpers/common_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3279,15 +3279,21 @@ function getQuestionAttributes($qid, $type='')
}
$setattributes=array();
$qid=sanitize_int($qid);
$fields = array('attribute', 'value');
$fields = array('attribute', 'value', 'language');
$condition = "qid = $qid";
$CI->load->model('question_attributes_model');
//$query = "SELECT attribute, value FROM ".db_table_name('question_attributes')." WHERE qid=$qid";
$result = $CI->question_attributes_model->getSomeRecords($fields,$condition) or safe_die("Error finding question attributes"); //Checked)
$setattributes=array();
foreach ($result->result_array() as $row)
{
$setattributes[$row['attribute']]=$row['value'];
if (is_empty($row['language']))
{
$setattributes[$row['attribute']]=$row['value'];
}
else{
$setattributes[$row['attribute']][$row['language']]=$row['value'];
}
}
//echo "<pre>";print_r($qid_attributes);echo "</pre>";
$qid_attributes=array_merge($defaultattributes,$setattributes);
Expand All @@ -3301,14 +3307,19 @@ function getQuestionAttributes($qid, $type='')
* @author: lemeur
* @param $questionAttributeArray
* @param $attributeName
* @param $language string Optional: The language if the particualr attributes is localizable
* @return string
*/
function getQuestionAttributeValue($questionAttributeArray, $attributeName)
function getQuestionAttributeValue($questionAttributeArray, $attributeName, $language='')
{
if (isset($questionAttributeArray[$attributeName]))
if ($language=='' && isset($questionAttributeArray[$attributeName]))
{
return $questionAttributeArray[$attributeName];
}
elseif ($language!='' && isset($questionAttributeArray[$attributeName][$language]))
{
return $questionAttributeArray[$attributeName][$language];
}
else
{
return '';
Expand Down Expand Up @@ -3445,6 +3456,7 @@ function questionAttributes($returnByName=false)
'category'=>$clang->gT('Display'),
'sortorder'=>112,
'inputtype'=>'text',
'i18n'=>true,
"help"=>$clang->gT('Prefix|Suffix for dropdown lists'),
"caption"=>$clang->gT('Dropdown prefix/suffix'));

Expand All @@ -3461,6 +3473,7 @@ function questionAttributes($returnByName=false)
'category'=>$clang->gT('Display'),
'sortorder'=>110,
'inputtype'=>'text',
'i18n'=>true,
"help"=>$clang->gT('Enter a header text for the first scale'),
"caption"=>$clang->gT('Header for first scale'));

Expand All @@ -3469,6 +3482,7 @@ function questionAttributes($returnByName=false)
'category'=>$clang->gT('Display'),
'sortorder'=>111,
'inputtype'=>'text',
'i18n'=>true,
"help"=>$clang->gT('Enter a header text for the second scale'),
"caption"=>$clang->gT('Header for second scale'));

Expand Down Expand Up @@ -3844,6 +3858,7 @@ function questionAttributes($returnByName=false)
'category'=>$clang->gT('Display'),
'sortorder'=>100,
'inputtype'=>'text',
'i18n'=>true,
"help"=>$clang->gT("Replaces the label of the 'Other:' answer option with a custom text"),
"caption"=>$clang->gT("Label for 'Other:' option"));

Expand All @@ -3863,6 +3878,7 @@ function questionAttributes($returnByName=false)
'category'=>$clang->gT('Display'),
'sortorder'=>10,
'inputtype'=>'text',
'i18n'=>true,
"help"=>$clang->gT('Add a prefix to the answer field'),
"caption"=>$clang->gT('Answer prefix'));

Expand Down Expand Up @@ -4002,6 +4018,7 @@ function questionAttributes($returnByName=false)
'category'=>$clang->gT('Display'),
'sortorder'=>11,
'inputtype'=>'text',
'i18n'=>true,
"help"=>$clang->gT('Add a suffix to the answer field'),
"caption"=>$clang->gT('Answer suffix'));

Expand Down Expand Up @@ -4083,6 +4100,7 @@ function questionAttributes($returnByName=false)
'category'=>$clang->gT('Timer'),
'sortorder'=>98,
"inputtype"=>"textarea",
'i18n'=>true,
"help"=>$clang->gT("The text message that displays in the countdown timer during the countdown"),
"caption"=>$clang->gT("Time limit countdown message"));

Expand All @@ -4107,6 +4125,7 @@ function questionAttributes($returnByName=false)
'category'=>$clang->gT('Timer'),
'sortorder'=>104,
"inputtype"=>"textarea",
'i18n'=>true,
"help"=>$clang->gT("The message to display when the time limit has expired (a default message will display if this setting is left blank)"),
"caption"=>$clang->gT("Time limit expiry message"));

Expand All @@ -4123,6 +4142,7 @@ function questionAttributes($returnByName=false)
'category'=>$clang->gT('Timer'),
'sortorder'=>108,
"inputtype"=>"integer",
'i18n'=>true,
"help"=>$clang->gT("Display a 'time limit warning' when there are this many seconds remaining in the countdown (warning will not display if left blank)"),
"caption"=>$clang->gT("1st time limit warning message timer"));

Expand All @@ -4139,6 +4159,7 @@ function questionAttributes($returnByName=false)
'category'=>$clang->gT('Timer'),
'sortorder'=>112,
"inputtype"=>"textarea",
'i18n'=>true,
"help"=>$clang->gT("The message to display as a 'time limit warning' (a default warning will display if this is left blank)"),
"caption"=>$clang->gT("1st time limit warning message"));

Expand Down Expand Up @@ -4171,6 +4192,7 @@ function questionAttributes($returnByName=false)
'category'=>$clang->gT('Timer'),
'sortorder'=>120,
"inputtype"=>"textarea",
'i18n'=>true,
"help"=>$clang->gT("The 2nd message to display as a 'time limit warning' (a default warning will display if this is left blank)"),
"caption"=>$clang->gT("2nd time limit warning message"));

Expand Down
3 changes: 3 additions & 0 deletions application/helpers/update/upgrade-mssql_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,9 @@ function db_upgrade($oldversion) {
PRIMARY KEY ([participant_id],[token_id],[survey_id])
);");echo $modifyoutput; flush();ob_flush();
modify_database("", "ALTER TABLE [prefix_users] ADD [participant_panel] int NOT NULL default '1'"); echo $modifyoutput; flush();ob_flush();
// Add language field to question_attributes table
modify_database("","ALTER TABLE [prefix_question_attributes] ADD [language] varchar(20)"); echo $modifyoutput; flush();ob_flush();

modify_database("", "UPDATE [prefix_settings_global] SET stg_value='148' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
}
echo '<br /><br />'.sprintf($clang->gT('Database update finished (%s)'),date('Y-m-d H:i:s')).'<br />';
Expand Down
83 changes: 43 additions & 40 deletions application/helpers/update/upgrade-mssqlnative_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function db_upgrade($oldversion) {
/// older versions to match current functionality
global $modifyoutput, $dbprefix, $clang;
if ($oldversion < 111) {

// Language upgrades from version 110 to 111 since the language names did change

$oldnewlanguages=array('german_informal'=>'german-informal',
Expand Down Expand Up @@ -385,7 +385,7 @@ function db_upgrade($oldversion) {
created DATETIME NOT NULL ,
modified DATETIME NOT NULL ,
sessdata varchar(max),
CONSTRAINT pk_sessions_sesskey PRIMARY KEY ( [sesskey] ))"); echo $modifyoutput; flush();ob_flush();
CONSTRAINT pk_sessions_sesskey PRIMARY KEY ( [sesskey] ))"); echo $modifyoutput; flush();ob_flush();
modify_database("", "create index [idx_expiry] on [prefix_sessions] ([expiry])"); echo $modifyoutput;
modify_database("", "create index [idx_expireref] on [prefix_sessions] ([expireref])"); echo $modifyoutput;
modify_database("", "UPDATE [prefix_settings_global] SET stg_value='143' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
Expand Down Expand Up @@ -417,41 +417,41 @@ function db_upgrade($oldversion) {
modify_database("", "ALTER TABLE [prefix_surveys] ADD nokeyboard CHAR(1) NULL default 'N'"); echo $modifyoutput; flush();ob_flush();
modify_database("", "ALTER TABLE [prefix_surveys] ADD alloweditaftercompletion CHAR(1) NULL default 'N'"); echo $modifyoutput; flush();ob_flush();
modify_database("", "CREATE TABLE [prefix_survey_permissions] (
[sid] INT NOT NULL,
[uid] INT NOT NULL,
[permission] VARCHAR(20) NOT NULL,
[create_p] TINYINT NOT NULL default '0',
[read_p] TINYINT NOT NULL default '0',
[update_p] TINYINT NOT NULL default '0',
[delete_p] TINYINT NOT NULL default '0',
[import_p] TINYINT NOT NULL default '0',
[export_p] TINYINT NOT NULL default '0',
[sid] INT NOT NULL,
[uid] INT NOT NULL,
[permission] VARCHAR(20) NOT NULL,
[create_p] TINYINT NOT NULL default '0',
[read_p] TINYINT NOT NULL default '0',
[update_p] TINYINT NOT NULL default '0',
[delete_p] TINYINT NOT NULL default '0',
[import_p] TINYINT NOT NULL default '0',
[export_p] TINYINT NOT NULL default '0',
PRIMARY KEY ([sid], [uid],[permission])
);"); echo $modifyoutput; flush();ob_flush();
upgrade_surveypermissions_table145();
modify_database("", "DROP TABLE [prefix_surveys_rights]"); echo $modifyoutput; flush();ob_flush();

// Add new fields for email templates
modify_database("", "ALTER TABLE prefix_surveys_languagesettings ADD
email_admin_notification_subj VARCHAR(255) NULL,
email_admin_notification varchar(max) NULL,
email_admin_responses_subj VARCHAR(255) NULL,
modify_database("", "ALTER TABLE prefix_surveys_languagesettings ADD
email_admin_notification_subj VARCHAR(255) NULL,
email_admin_notification varchar(max) NULL,
email_admin_responses_subj VARCHAR(255) NULL,
email_admin_responses varchar(max) NULL");

//Add index to questions table to speed up subquestions
modify_database("", "create index [parent_qid_idx] on [prefix_questions] ([parent_qid])"); echo $modifyoutput; flush();ob_flush();

modify_database("", "ALTER TABLE prefix_surveys ADD emailnotificationto text DEFAULT NULL"); echo $modifyoutput; flush();ob_flush();
upgrade_survey_table145();
upgrade_survey_table145();
mssql_drop_constraint('notification','surveys');
modify_database("", "ALTER TABLE [prefix_surveys] DROP COLUMN [notification]"); echo $modifyoutput; flush();ob_flush();

// modify length of method in conditions
modify_database("","ALTER TABLE [prefix_conditions] ALTER COLUMN [method] CHAR(5) NOT NULL"); echo $modifyoutput; flush();ob_flush();

//Add index to questions table to speed up subquestions
modify_database("", "create index [parent_qid] on [prefix_questions] ([parent_qid])"); echo $modifyoutput; flush();ob_flush();

modify_database("","UPDATE prefix_surveys set [private]='N' where [private] is NULL;"); echo $modifyoutput; flush();ob_flush();

modify_database("","EXEC sp_rename 'prefix_surveys.private','anonymized'"); echo $modifyoutput; flush();ob_flush();
Expand All @@ -465,7 +465,7 @@ function db_upgrade($oldversion) {
[number_attempts] int NOT NULL );"); echo $modifyoutput; flush();ob_flush();

modify_database("", "ALTER TABLE [prefix_surveys_languagesettings] ADD [surveyls_numberformat] INT default 0 NOT NULL"); echo $modifyoutput; flush();ob_flush();

upgrade_token_tables145();
modify_database("", "UPDATE [prefix_settings_global] SET stg_value='145' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();

Expand All @@ -479,10 +479,10 @@ function db_upgrade($oldversion) {

if ($oldversion < 147)
{
modify_database("", "ALTER TABLE [prefix_users] ADD templateeditormode VARCHAR( 7 ) NOT NULL default 'default'"); echo $modifyoutput; flush();ob_flush();
modify_database("", "ALTER TABLE [prefix_users] ADD questionselectormode VARCHAR( 7 ) NOT NULL default 'default'"); echo $modifyoutput; flush();ob_flush();
modify_database("", "ALTER TABLE [prefix_users] ADD templateeditormode VARCHAR( 7 ) NOT NULL default 'default'"); echo $modifyoutput; flush();ob_flush();
modify_database("", "ALTER TABLE [prefix_users] ADD questionselectormode VARCHAR( 7 ) NOT NULL default 'default'"); echo $modifyoutput; flush();ob_flush();
modify_database("", "UPDATE [prefix_settings_global] SET stg_value='147' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
}
}
if ($oldversion < 148)
{
modify_database("","CREATE TABLE [prefix_participants] (
Expand Down Expand Up @@ -533,9 +533,12 @@ function db_upgrade($oldversion) {
[date_created] datetime,
PRIMARY KEY ([participant_id],[token_id],[survey_id])
); ");echo $modifyoutput; flush();ob_flush();
modify_database("","ALTER TABLE [prefix_users] ADD [participant_panel] int(1) DEFAULT '1'"); echo $modifyoutput; flush();ob_flush();
modify_database("", "UPDATE [prefix_settings_global] SET stg_value='148' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();

modify_database("","ALTER TABLE [prefix_users] ADD [participant_panel] int(1) DEFAULT '1'"); echo $modifyoutput; flush();ob_flush();
// Add language field to question_attributes table
modify_database("","ALTER TABLE [prefix_question_attributes] ADD [language] varchar(20)"); echo $modifyoutput; flush();ob_flush();

modify_database("", "UPDATE [prefix_settings_global] SET stg_value='148' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();

}
echo '<br /><br />'.sprintf($clang->gT('Database update finished (%s)'),date('Y-m-d H:i:s')).'<br />';
return true;
Expand Down Expand Up @@ -697,7 +700,7 @@ function upgrade_question_attributes142()
$record['value']=implode(';',$attributevalues);
$record['attribute']='exclude_all_other';
$record['qid']=$questionid;
$connect->AutoExecute("{$dbprefix}question_attributes", $record, 'INSERT');
$connect->AutoExecute("{$dbprefix}question_attributes", $record, 'INSERT');
}
}

Expand All @@ -719,20 +722,20 @@ function upgrade_tables143()
}

// Convert answers to subquestions

$answerquery = "select a.*, q.sid, q.gid, q.type from {$dbprefix}answers a,{$dbprefix}questions q where a.qid=q.qid and a.language=q.language and q.type in ('1','A','B','C','E','F','H','K',';',':','M','P','Q')";
$answerresult = db_execute_assoc($answerquery);
if (!$answerresult) {return "Database Error";}
else
{
while ( $row = $answerresult->FetchRow() )
{

$insertarray=array();
if (isset($aQIDReplacements[$row['qid'].'_'.$row['code']]))
{
$insertarray['qid']=$aQIDReplacements[$row['qid'].'_'.$row['code']];
db_switchIDInsert('questions',true);
db_switchIDInsert('questions',true);
}
$insertarray['sid']=$row['sid'];
$insertarray['gid']=$row['gid'];
Expand All @@ -747,13 +750,13 @@ function upgrade_tables143()
modify_database("",$query); echo $modifyoutput; flush();ob_flush();
if (!isset($insertarray['qid']))
{
$aQIDReplacements[$row['qid'].'_'.$row['code']]=$connect->Insert_ID("{$dbprefix}questions","qid");
$aQIDReplacements[$row['qid'].'_'.$row['code']]=$connect->Insert_ID("{$dbprefix}questions","qid");
$iSaveSQID=$aQIDReplacements[$row['qid'].'_'.$row['code']];
}
else
{
$iSaveSQID=$insertarray['qid'];
db_switchIDInsert('questions',false);
db_switchIDInsert('questions',false);
}
if (($row['type']=='M' || $row['type']=='P') && $row['default_value']=='Y')
{
Expand Down Expand Up @@ -812,8 +815,8 @@ function upgrade_tables143()
if (isset($aQIDReplacements[$row['qid'].'_'.$lrow['code'].'_1']))
{
$insertarray['qid']=$aQIDReplacements[$row['qid'].'_'.$lrow['code'].'_1'];
db_switchIDInsert('questions',true);
db_switchIDInsert('questions',true);

}
$insertarray['sid']=$row['sid'];
$insertarray['gid']=$row['gid'];
Expand All @@ -829,10 +832,10 @@ function upgrade_tables143()
modify_database("",$query); echo $modifyoutput; flush();ob_flush();
if (isset($insertarray['qid']))
{
$aQIDReplacements[$row['qid'].'_'.$lrow['code'].'_1']=$connect->Insert_ID("{$dbprefix}questions","qid");
db_switchIDInsert('questions',false);
$aQIDReplacements[$row['qid'].'_'.$lrow['code'].'_1']=$connect->Insert_ID("{$dbprefix}questions","qid");
db_switchIDInsert('questions',false);

}
}
}
}
}
Expand All @@ -842,7 +845,7 @@ function upgrade_tables143()
modify_database("",$updatequery); echo $modifyoutput; flush();ob_flush();
$updatequery = "update {$dbprefix}questions set type='L' where type='Z'";
modify_database("",$updatequery); echo $modifyoutput; flush();ob_flush();

// Now move all non-standard templates to the /upload dir
global $usertemplaterootdir, $standardtemplates,$standardtemplaterootdir;

Expand All @@ -860,7 +863,7 @@ function upgrade_tables143()
}
}
closedir($handle);
}
}

}

Expand Down

0 comments on commit dbbfaeb

Please sign in to comment.