Skip to content

Commit

Permalink
Dev: move QuestionAttributesSettings to an helper
Browse files Browse the repository at this point in the history
Dev: add /ls/helper to namespace (think we need it elsewhere)
Dev: now, we load only attribute we need (not whole question type attribute)
Dev: in fact : we load all existing attribute, but take only needed for $questionAttributesSettings[type]
  • Loading branch information
Shnoulle committed Jul 29, 2016
1 parent 1acdcf9 commit 12c56b9
Show file tree
Hide file tree
Showing 8 changed files with 1,448 additions and 1,469 deletions.
9 changes: 2 additions & 7 deletions application/controllers/admin/database.php
Expand Up @@ -658,7 +658,7 @@ function index($sa = null)
}
}
} else {
$validAttributes=QuestionAttribute::getQuestionAttributesSettings(Yii::app()->request->getPost('type'));
$validAttributes=\ls\helpers\questionHelper::getQuestionAttributesSettings(Yii::app()->request->getPost('type'));
$aLanguages=array_merge(array(Survey::model()->findByPk($iSurveyID)->language),Survey::model()->findByPk($iSurveyID)->additionalLanguages);

foreach ($validAttributes as $validAttribute)
Expand Down Expand Up @@ -775,19 +775,14 @@ function index($sa = null)

$criteria = new CDbCriteria;
$criteria->compare('qid',$iQuestionID);
$validAttributes=QuestionAttribute::getQuestionAttributesSettings($sQuestionType);
$validAttributes=\ls\helpers\questionHelper::getQuestionAttributesSettings($sQuestionType);
foreach ($validAttributes as $validAttribute)
{
$criteria->compare('attribute', '<>'.$validAttribute['name']);
}
QuestionAttribute::model()->deleteAll($criteria);
$aLanguages=array_merge(array(Survey::model()->findByPk($iSurveyID)->language),Survey::model()->findByPk($iSurveyID)->additionalLanguages);


//now save all valid attributes
// eg: other_replace_text ; other_replace_text_en
$validAttributes=$qattributes[$sQuestionType];

foreach ($validAttributes as $validAttribute)
{
if ($validAttribute['i18n'])
Expand Down
5 changes: 3 additions & 2 deletions application/controllers/admin/questions.php
Expand Up @@ -1361,7 +1361,7 @@ public function index($sa, $surveyid, $gid, $qid=null)
* Since is moved via ajax call only : it's not needed, when we have time : readd it for no-js solution
*/
//~ if (!$adding)
//~ $qattributes = Question::getQuestionAttributesSettings($aqresult->type); //(or Question::getAdvancedSettingsWithValues )
//~ $qattributes = \ls\helpers\questionHelper::getQuestionAttributesSettings(($aqresult->type); //(or Question::getAdvancedSettingsWithValues )
//~ else
//~ $qattributes = array();

Expand Down Expand Up @@ -1721,14 +1721,15 @@ public function ajaxReloadPositionWidget($gid, $classes='')
*/
public function ajaxquestionattributes()
{

$surveyid = (int) Yii::app()->request->getParam('sid',0);
$qid = (int) Yii::app()->request->getParam('qid',0);
$type = Yii::app()->request->getParam('question_type');
$thissurvey = getSurveyInfo($surveyid);
if(!$thissurvey) die();
$aLanguages = array_merge(array(Survey::model()->findByPk($surveyid)->language), Survey::model()->findByPk($surveyid)->additionalLanguages);

$aAttributesWithValues = Question::model()->getAdvancedSettingsWithValues($qid, $type, $surveyid);

uasort($aAttributesWithValues, 'categorySort');

$aAttributesPrepared = array();
Expand Down
11 changes: 6 additions & 5 deletions application/helpers/admin/import_helper.php
Expand Up @@ -220,7 +220,7 @@ function XMLImportGroup($sFullFilePath, $iNewSID)
{


$aAllAttributes=QuestionAttribute::getAttributesDefinitions();
$aAllAttributes=\ls\helpers\questionHelper::getAttributesDefinitions();

foreach ($xml->question_attributes->rows->row as $row)
{
Expand Down Expand Up @@ -518,7 +518,7 @@ function XMLImportQuestion($sFullFilePath, $iNewSID, $newgid)
{


$aAllAttributes=QuestionAttribute::getAttributesDefinitions();
$aAllAttributes=\ls\helpers\questionHelper::getAttributesDefinitions();
foreach ($xml->question_attributes->rows->row as $row)
{
$insertdata=array();
Expand Down Expand Up @@ -1266,7 +1266,7 @@ function XMLImportSurvey($sFullFilePath,$sXMLdata=NULL,$sNewSurveyName=NULL,$iDe
// Import questionattributes -------------------------------------------------
if(isset($xml->question_attributes))
{
$aAllAttributes=QuestionAttribute::getAttributesDefinitions();
$aAllAttributes=\ls\helpers\questionHelper::getAttributesDefinitions();
foreach ($xml->question_attributes->rows->row as $row)
{
$insertdata=array();
Expand Down Expand Up @@ -2074,7 +2074,7 @@ function TSVImportSurvey($sFullFilePath)
$handle = fopen($sFullFilePath, 'r');
$bom = fread($handle, 2);
rewind($handle);
$aAttributeList = QuestionAttribute::getQuestionAttributesSettings();
$aAttributeList = array(); //QuestionAttribute::getQuestionAttributesSettings();

// Excel tends to save CSV as UTF-16, which PHP does not properly detect
if($bom === chr(0xff).chr(0xfe) || $bom === chr(0xfe).chr(0xff)){
Expand Down Expand Up @@ -2358,7 +2358,8 @@ function TSVImportSurvey($sFullFilePath)
$insertdata = array();
$insertdata['qid'] = $qid;
// check if attribute is a i18n attribute. If yes, set language, else set language to null in attribute table
if (isset($aAttributeList[$qtype][$key]['i18n']) && $aAttributeList[$qtype][$key]['i18n']==1)
$aAttributeList[$qtype]=\ls\helpers\questionHelper::getQuestionAttributesSettings($qtype);
if ($aAttributeList[$qtype][$key]['i18n'])
{
$insertdata['language'] = (isset($row['language']) ? $row['language'] : $baselang);
}
Expand Down
2 changes: 1 addition & 1 deletion application/helpers/expressions/em_manager_helper.php
Expand Up @@ -9704,7 +9704,7 @@ static public function &TSVSurveyExport($sid)
);

// Advanced question attributes : @todo get used question attribute by question in survey ?
$aQuestionAttributes=array_keys(QuestionAttribute::getAttributesDefinitions());
$aQuestionAttributes=array_keys(\ls\helpers\questionHelper::getAttributesDefinitions());
sort($aQuestionAttributes);
$fields=array_merge($aBaseFields,$aQuestionAttributes);

Expand Down

0 comments on commit 12c56b9

Please sign in to comment.