diff --git a/application/controllers/admin/questiongroup.php b/application/controllers/admin/questiongroup.php index c56ab9bc619..14d59931324 100644 --- a/application/controllers/admin/questiongroup.php +++ b/application/controllers/admin/questiongroup.php @@ -43,6 +43,8 @@ public function run($sa) $this->route('update', array('gid')); elseif ($sa == 'import') $this->route('import', array()); + elseif ($sa == 'organize') + $this->route('organize', array('surveyid')); } /** @@ -501,52 +503,56 @@ function update($gid) */ function organize($iSurveyID) { - $iSurveyID= (int)$iSurveyID; - $this->load->model('groups_model'); - $this->load->model('questions_model'); + $iSurveyID = (int) $iSurveyID; - if ($this->input->post('orgdata') && bHasSurveyPermission($iSurveyID,'surveycontent','update')) + if (!empty($_POST['orgdata']) && bHasSurveyPermission($iSurveyID,'surveycontent','update')) { - $AOrgData=array(); - parse_str($this->input->post('orgdata'),$AOrgData); - $grouporder=0; + $AOrgData = array(); + parse_str($_POST['orgdata'], $AOrgData); + $grouporder = 0; foreach($AOrgData['list'] as $ID=>$parent) { if ($parent=='root' && $ID[0]=='g'){ - $this->groups_model->update(array('group_order'=>$grouporder),array('gid'=>(int)substr($ID,1))); + Groups::model()->update(array('group_order'=>$grouporder), 'gid='.(int)substr($ID,1)); $grouporder++; } elseif ($ID[0]=='q') { if (!isset($questionorder[(int)substr($parent,1)])) $questionorder[(int)substr($parent,1)]=0; - $this->questions_model->update(array('question_order'=>$questionorder[(int)substr($parent,1)],'gid'=>(int)substr($parent,1)),array('qid'=>(int)substr($ID,1))); - $this->questions_model->update(array('gid'=>(int)substr($parent,1)),array('parent_qid'=>(int)substr($ID,1))); + Questions::model()->update(array('question_order'=>$questionorder[(int)substr($parent,1)],'gid'=>(int)substr($parent,1)), 'qid='.(int)substr($ID,1)); + Questions::model()->update(array('gid'=>(int)substr($parent,1)), 'parent_qid='.(int)substr($ID,1)); $questionorder[(int)substr($parent,1)]++; } } - $this->session->set_userdata('flashmessage', $this->limesurvey_lang->gT("The new question group/question order was successfully saved.")); - redirect('admin/survey/view/'.$iSurveyID); + Yii::app()->session['flashmessage'] = Yii::app()->lang->gT("The new question group/question order was successfully saved."); + $this->getController()->redirect($this->getController()->createUrl('admin/survey/sa/view/surveyid/'.$iSurveyID)); } // Prepare data for the view - $sBaseLanguage=GetBaseLanguageFromSurveyID($iSurveyID); - self::_js_admin_includes(base_url().'scripts/jquery/jquery.ui.nestedSortable.js'); - self::_js_admin_includes(base_url().'scripts/admin/organize.js'); + $sBaseLanguage = GetBaseLanguageFromSurveyID($iSurveyID); + + Yii::import('application.helpers.expressions.em_manager_helper', true); + Yii::import('application.helpers.replacements_helper', true); LimeExpressionManager::StartProcessingPage(false,true,false); - $aGrouplist=$this->groups_model->getGroups($iSurveyID); - $initializedReplacementFields=false; - foreach($aGrouplist as $iGID=>$aGroup) + + $aGrouplist = Groups::model()->getGroups($iSurveyID); + $initializedReplacementFields = false; + + foreach($aGrouplist as $iGID => $aGroup) { LimeExpressionManager::StartProcessingGroup($aGroup['gid'],false,$iSurveyID); if (!$initializedReplacementFields) { templatereplace("{SITENAME}"); // Hack to ensure the EM sets values of LimeReplacementFields $initializedReplacementFields = true; } - $oQuestionData=$this->questions_model->getQuestions($iSurveyID,$aGroup['gid'],$sBaseLanguage); - $qs = array(); + + $oQuestionData=Questions::model()->getQuestions($iSurveyID,$aGroup['gid'],$sBaseLanguage); + + $qs = array(); $junk=array(); - foreach ($oQuestionData->result_array() as $q) { + + foreach ($oQuestionData->readAll() as $q) { $relevance = (trim($q['relevance'])=='') ? 1 : $q['relevance']; $question = '[{' . $relevance . '}] ' . $q['question']; LimeExpressionManager::ProcessString($question,$q['qid'],$junk,false,1,1); @@ -557,17 +563,29 @@ function organize($iSurveyID) $aGrouplist[$iGID]['questions']=$qs; } LimeExpressionManager::FinishProcessingPage(); - $aViewData['aGroupsAndQuestions']=$aGrouplist; - $aViewData['clang']=$this->limesurvey_lang; - $aViewData['surveyid']=$iSurveyID; - $css_admin_includes[] = $this->config->item('styleurl')."admin/default/superfish.css"; - $this->config->set_item("css_admin_includes", $css_admin_includes); - self::_getAdminHeader(); - self::_showadminmenu(); - self::_surveybar($iSurveyID); - $this->load->view('admin/survey/organizeGroupsAndQuestions_view',$aViewData); - self::_loadEndScripts(); - self::_getAdminFooter("http://docs.limesurvey.org", $this->limesurvey_lang->gT("LimeSurvey online manual")); + + $aViewData['aGroupsAndQuestions'] = $aGrouplist; + $aViewData['clang'] = Yii::app()->lang; + $aViewData['surveyid'] = $iSurveyID; + + $js_admin_includes = Yii::app()->getConfig("js_admin_includes"); + $js_admin_includes[] = Yii::app()->getConfig('generalscripts').'jquery/jquery.ui.nestedSortable.js'; + $js_admin_includes[] = Yii::app()->getConfig('generalscripts').'admin/organize.js'; + Yii::app()->setConfig("js_admin_includes", $js_admin_includes); + + $css_admin_includes = Yii::app()->getConfig("css_admin_includes"); + $css_admin_includes[] = Yii::app()->getConfig('styleurl')."admin/default/superfish.css"; + Yii::app()->setConfig("css_admin_includes", $css_admin_includes); + + $this->controller->_getAdminHeader(); + $this->controller->_showadminmenu(); + $this->_surveybar($iSurveyID); + + $this->getController()->render('/admin/survey/organizeGroupsAndQuestions_view',$aViewData); + + $this->controller->_loadEndScripts(); + $this->controller->_getAdminFooter("http://docs.limesurvey.org", Yii::app()->lang->gT("LimeSurvey online manual")); + } diff --git a/application/helpers/expressions/em_manager_helper.php b/application/helpers/expressions/em_manager_helper.php index 8a78c14e384..c2b2281ac10 100644 --- a/application/helpers/expressions/em_manager_helper.php +++ b/application/helpers/expressions/em_manager_helper.php @@ -1876,7 +1876,7 @@ static function FinishProcessingPage() foreach($LEM->runtimeTimings as $unit) { $totalTime += $unit[1]; } - log_message('debug','Total time attributable to EM = ' . $totalTime); +// log_message('debug','Total time attributable to EM = ' . $totalTime); // log_message('debug',print_r($LEM->runtimeTimings,true)); // LimeExpressionManager::ShowStackTrace(); diff --git a/application/models/Groups.php b/application/models/Groups.php index f6adc1937b4..d7a02bd9427 100644 --- a/application/models/Groups.php +++ b/application/models/Groups.php @@ -49,7 +49,7 @@ public function primaryKey() { return 'gid'; } - + function updateGroupOrder($sid,$lang,$position=0) { $data=Yii::app()->db->createCommand()->select('gid')->where(array('and','sid='.$sid,'language="'.$lang.'"'))->order('group_order, group_name ASC')->from('{{groups}}')->query(); @@ -58,16 +58,16 @@ function updateGroupOrder($sid,$lang,$position=0) { Yii::app()->db->createCommand()->update($this->tableName(),array('group_order' => $position),'gid='.$row['gid']); $position++; -} + } } - + function update($data, $condition=FALSE) { return Yii::app()->db->createCommand()->update('{{groups}}', $data, $condition); } - + public function insertRecords($data) { $group = new self; @@ -75,5 +75,16 @@ public function insertRecords($data) $group->$k = $v; return $group->save(); } + + function getGroups($surveyid) { + $language = GetBaseLanguageFromSurveyID($surveyid); + return Yii::app()->db->createCommand() + ->select(array('gid', 'group_name')) + ->from($this->tableName()) + ->where(array('and', 'sid='.$surveyid, 'language=:language')) + ->order('group_order asc') + ->bindParam(":language", $language, PDO::PARAM_STR) + ->query()->readAll(); + } } ?> diff --git a/application/models/Questions.php b/application/models/Questions.php index c294aa903f2..b63e6c3ab37 100644 --- a/application/models/Questions.php +++ b/application/models/Questions.php @@ -50,6 +50,13 @@ public function primaryKey() return 'qid'; } + function update($data, $condition=FALSE) + { + + return Yii::app()->db->createCommand()->update($this->tableName(), $data, $condition); + + } + /** * This function returns an array of the advanced attributes for the particular question including their values set in the database * @@ -105,7 +112,18 @@ public function getAdvancedSettingsWithValues($iQuestionID, $sQuestionType , $iS } return $aAttributeNames; } - + + function getQuestions($sid,$gid,$language) + { + return Yii::app()->db->createCommand() + ->select() + ->where(array('and', 'sid='.$sid, 'gid='.$gid, 'language=:language', 'parent_qid=0')) + ->order('question_order asc') + ->from($this->tableName()) + ->bindParam(":language", $language, PDO::PARAM_STR) + ->query(); + } + function insertRecords($data) { $questions = new self; diff --git a/application/views/admin/survey/organizeGroupsAndQuestions_view.php b/application/views/admin/survey/organizeGroupsAndQuestions_view.php index 95a5df16249..7e8f0ef5cf8 100644 --- a/application/views/admin/survey/organizeGroupsAndQuestions_view.php +++ b/application/views/admin/survey/organizeGroupsAndQuestions_view.php @@ -15,7 +15,7 @@ -
  • '>
    '>:
  • +
  • '>
    '>:
  • @@ -25,7 +25,7 @@ }?> -

    +

    diff --git a/application/views/admin/survey/surveybar_view.php b/application/views/admin/survey/surveybar_view.php index a75c0bd3ea3..2cc5cae9e6d 100644 --- a/application/views/admin/survey/surveybar_view.php +++ b/application/views/admin/survey/surveybar_view.php @@ -210,7 +210,7 @@ else { ?>
  • - "> + "> /organize.png' alt='gT("Reorder question groups / questions"); ?>' name='Organize' width="40" height="40"/>