Skip to content

Commit

Permalink
Port the functionality 'Questiongroup/question organizer' to the Yii …
Browse files Browse the repository at this point in the history
…PHP framework - GCI Task #7114263 by student gautamgupta

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_yii@11556 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
GautamGupta committed Dec 1, 2011
1 parent 7b04b28 commit 4e24692
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 41 deletions.
82 changes: 50 additions & 32 deletions application/controllers/admin/questiongroup.php
Expand Up @@ -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'));
}

/**
Expand Down Expand Up @@ -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);
Expand All @@ -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"));

}


Expand Down
2 changes: 1 addition & 1 deletion application/helpers/expressions/em_manager_helper.php
Expand Up @@ -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();

Expand Down
19 changes: 15 additions & 4 deletions application/models/Groups.php
Expand Up @@ -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();
Expand All @@ -58,22 +58,33 @@ 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;
foreach ($data as $k => $v)
$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();
}
}
?>
20 changes: 19 additions & 1 deletion application/models/Questions.php
Expand Up @@ -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
*
Expand Down Expand Up @@ -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;
Expand Down
Expand Up @@ -15,7 +15,7 @@
<?php
foreach($aGroupAndQuestions['questions'] as $aQuestion)
{?>
<li id='list_q<?php echo $aQuestion['qid'];?>'><div><b><a href='<?php echo site_url('admin/question/editquestion/'.$surveyid.'/'.$aQuestion['gid'].'/'.$aQuestion['qid']);?>'><?php echo $aQuestion['title'];?></a></b>: <?php echo FlattenText($aQuestion['question'],true);?></div></li>
<li id='list_q<?php echo $aQuestion['qid'];?>'><div><b><a href='<?php echo Yii::app()->createUrl('admin/question/editquestion/'.$surveyid.'/'.$aQuestion['gid'].'/'.$aQuestion['qid']);?>'><?php echo $aQuestion['title'];?></a></b>: <?php echo FlattenText($aQuestion['question'],true);?></div></li>

<?php }?>
</ol>
Expand All @@ -25,7 +25,7 @@
}?>
</ol>
</div>
<form id='frmOrganize' action="<?php echo site_url('admin/questiongroup/organize/'.$surveyid);?>" method="post"><p>
<form id='frmOrganize' action="<?php echo Yii::app()->createUrl('admin/questiongroup/sa/organize/surveyid/'.$surveyid);?>" method="post"><p>
<input type='hidden' id='orgdata' name='orgdata' value='' />
<button id='btnSave'><?php echo $clang->eT('Save'); ?></button></p>
</form>
2 changes: 1 addition & 1 deletion application/views/admin/survey/surveybar_view.php
Expand Up @@ -210,7 +210,7 @@
else
{ ?><li>

<a href="<?php echo $this->createUrl("admin/questiongroup/organize/$surveyid"); ?>">
<a href="<?php echo $this->createUrl("admin/questiongroup/sa/organize/surveyid/$surveyid"); ?>">
<img src='<?php echo Yii::app()->getConfig('imageurl'); ?>/organize.png' alt='<?php echo $clang->gT("Reorder question groups / questions"); ?>' name='Organize' width="40" height="40"/></a></li>
<?php }
} ?>
Expand Down

0 comments on commit 4e24692

Please sign in to comment.