Skip to content

Commit

Permalink
Dev: NON_FUNCTIONING! Started to implement settings as xml configurat…
Browse files Browse the repository at this point in the history
…ion files
  • Loading branch information
lacrioque committed Jun 27, 2017
1 parent dc84b9b commit 263338b
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 82 deletions.
4 changes: 2 additions & 2 deletions .gitignore
@@ -1,6 +1,8 @@

# Never include config.php
/application/config/config.php
# ignore CAssetManager for debugging
/framework/web/CAssetManager.php

# upload directory : whole except the index.html and readme.txt
/upload/*
Expand Down Expand Up @@ -76,5 +78,3 @@ launch.json
!/plugins/Demo/
!/plugins/AuditLog/
enabletests


144 changes: 115 additions & 29 deletions application/controllers/admin/surveyadmin.php
Expand Up @@ -416,6 +416,7 @@ public function view($iSurveyID, $gid = null, $qid = null)
$aData['showLastQuestion'] = false;
}
$aData['templateapiversion'] = Template::model()->getTemplateConfiguration(null,$iSurveyID)->getApiVersion();

$this->_renderWrappedTemplate('survey', array(), $aData);
}

Expand Down Expand Up @@ -480,6 +481,7 @@ public function getAjaxQuestionGroupArray($surveyid){
);
}


/**
* Ajaxified get MenuItems with containing questions
*
Expand All @@ -489,40 +491,15 @@ public function getAjaxMenuArray($surveyid){
$iSurveyID = sanitize_int($surveyid);
$survey = Survey::model()->findByPk($iSurveyID);
$baselang = $survey->language;
$setting_entry = 'last_question_'.Yii::app()->user->getId().'_'.$iSurveyID;
$lastquestion = getGlobalSetting($setting_entry);
$setting_entry = 'last_question_'.Yii::app()->user->getId().'_'.$iSurveyID.'_gid';
$lastquestiongroup = getGlobalSetting($setting_entry);
$aGroups = QuestionGroup::model()->findAllByAttributes(array('sid' => $iSurveyID, "language" => $baselang), array('order'=>'group_order ASC'));
$aGroupViewable = array();
if(count($aGroups))
{
foreach($aGroups as $group)
{
$curGroup = $group->attributes;
$group->aQuestions = Question::model()->findAllByAttributes(array("sid"=>$iSurveyID, "gid"=>$group['gid'],"language"=>$baselang), array('order'=>'question_order ASC'));
$curGroup['questions'] = array();
foreach($group->aQuestions as $question)
{
if(is_object($question))
{
$curQuestion = $question->attributes;
$curQuestion['name_short'] = viewHelper::flatEllipsizeText($question->question,true,60,'[...]',0.5);
$curGroup['questions'][] = $curQuestion;
}

}
$aGroupViewable[] = $curGroup;
}
}
//$menu_items = $this->_collectMenuItems($currentMenu);

return Yii::app()->getController()->renderPartial(
'/admin/super/_renderJson',
array(
'data' => array(
'menuEntries' => [
[
'active' => true,
'active' => false,
'icon' => 'fa fa-list',
'name' => gT('Overview'),
'link' => $this->getController()->createUrl("admin/survey/sa/view", ['surveyid' => $surveyid])
Expand All @@ -531,13 +508,13 @@ public function getAjaxMenuArray($surveyid){
'active' => false,
'icon' => 'fa fa-cogs',
'name' => gT('General Settings'),
'link' => $this->getController()->createUrl("admin/survey/sa/editlocalsettings",['surveyid' => $surveyid])
'link' => $this->getController()->createUrl("admin/survey/sa/surveygeneralsettings",['surveyid' => $surveyid])
],
[
'active' => false,
'icon' => 'fa fa-language',
'name' => gT('Language'),
'link' => '#stillToCome'
'link' => $this->getController()->createUrl("admin/survey/sa/editlanguagesettings",['surveyid' => $surveyid])
],
],
'settings' => array(
Expand Down Expand Up @@ -947,6 +924,114 @@ public function editSurvey_json()
}
}
}

/**
* Edit surveytexts and general settings
*/

public function surveygeneralsettings($iSurveyID){
$aViewUrls = $aData = $activePanels = array();

$pageTitle=gT("Edit survey text elements and settings");
if (Permission::model()->hasSurveyPermission($iSurveyID, 'surveylocale', 'read') && !Permission::model()->hasSurveyPermission($iSurveyID, 'surveysettings', 'read'))
{
$pageTitle=gT("Edit survey text elements");
}
elseif (!Permission::model()->hasSurveyPermission($iSurveyID, 'surveylocale', 'read') && Permission::model()->hasSurveyPermission($iSurveyID, 'surveysettings', 'read'))
{
$pageTitle=gT("Edit survey settings");
}

$aData['surveyid'] = $iSurveyID = sanitize_int($iSurveyID);
if (!(Permission::model()->hasSurveyPermission($iSurveyID, 'surveylocale', 'read') || Permission::model()->hasSurveyPermission($iSurveyID, 'surveysettings', 'read')))
{
Yii::app()->setFlashMessage(gT("You do not have permission to access this page."),'error');
$this->getController()->redirect(array('admin/survey','sa'=>'view','surveyid'=>$iSurveyID));
Yii::app()->end();
}

$this->_registerScriptFiles();
if (Permission::model()->hasSurveyPermission($iSurveyID, 'surveylocale', 'update'))
{
Yii::app()->session['FileManagerContext'] = "edit:survey:{$iSurveyID}";
}

//This method creates the text edition and the general settings
$aData['panels'] = [];

$grplangs = Survey::model()->findByPk($iSurveyID)->additionalLanguages;
$baselang = Survey::model()->findByPk($iSurveyID)->language;
array_unshift($grplangs, $baselang);

Yii::app()->loadHelper("admin/htmleditor");

$aData['scripts'] = PrepareEditorScript(false, $this->getController());
$aTabTitles = $aTabContents= array();

foreach ($grplangs as $i => $sLang)
{
// this one is created to get the right default texts fo each language
Yii::app()->loadHelper('database');
Yii::app()->loadHelper('surveytranslator');

$esrow = SurveyLanguageSetting::model()->findByPk(array('surveyls_survey_id' => $iSurveyID, 'surveyls_language' => $sLang))->getAttributes();
$aTabTitles[$sLang] = getLanguageNameFromCode($esrow['surveyls_language'], false);

if ($esrow['surveyls_language'] == Survey::model()->findByPk($iSurveyID)->language)
{
$aTabTitles[$sLang] .= ' (' . gT("Base language") . ')';
}

$aData['esrow'] = $esrow;
$aData['action'] = "surveygeneralsettings";
$aData['dateformatdetails'] = getDateFormatData(Yii::app()->session['dateformat']);
$aTabContents[$sLang] = $this->getController()->renderPartial('/admin/survey/editLocalSettings_view', $aData, true);
}

$aData['aTabContents'] = $aTabContents;
$aData['aTabTitles'] = $aTabTitles;

$esrow = self::_fetchSurveyInfo('editsurvey', $iSurveyID);
$aData['esrow'] = $esrow;
$aData['has_permissions'] = Permission::model()->hasSurveyPermission($iSurveyID, 'surveylocale', 'update');
$aData['surveyls_language'] = $esrow["surveyls_language"];


$generalEditArray = $this->_generalTabEditSurvey($iSurveyID, $esrow);


$oResult = Question::model()->getQuestionsWithSubQuestions($iSurveyID, $esrow['language'], "({{questions}}.type = 'T' OR {{questions}}.type = 'Q' OR {{questions}}.type = 'T' OR {{questions}}.type = 'S')");

//$aData['questions'] = $oResult;
$aData['display']['menu_bars']['surveysummary'] = "surveygeneralsettings";
$tempData = $aData;

$aData['settings_data'] = $tempData;


$aData['sidemenu']['state'] = false;


$surveyinfo = Survey::model()->findByPk($iSurveyID)->surveyinfo;
$aData['title_bar']['title'] = $surveyinfo['surveyls_title']." (".gT("ID").":".$iSurveyID.")";
$aData['surveybar']['savebutton']['form'] = 'globalsetting';
$aData['surveybar']['savebutton']['useformid'] = 'true';
if (Permission::model()->hasSurveyPermission($iSurveyID, 'surveysettings', 'update') || Permission::model()->hasSurveyPermission($iSurveyID, 'surveylocale', 'update'))
{
$aData['surveybar']['saveandclosebutton']['form'] = true;
}
else
{
unset($aData['surveybar']['savebutton']['form']);
}

$aData['surveybar']['closebutton']['url'] = 'admin/survey/sa/view/surveyid/'.$iSurveyID; // Close button

$aViewUrls[] = 'editLocalSettings_main_view';
$this->_renderWrappedTemplate('survey', $aViewUrls, $aData);

}

/**
* Load editing of local settings of a survey screen.
*
Expand Down Expand Up @@ -1980,6 +2065,7 @@ private function _createSampleQuestion($iSurveyID, $iGroupID)
*/
protected function _renderWrappedTemplate($sAction = 'survey', $aViewUrls = array(), $aData = array())
{
$isPjax = Yii::app()->request->getQuery('pjax',false);
parent::_renderWrappedTemplate($sAction, $aViewUrls, $aData);
}

Expand Down
1 change: 1 addition & 0 deletions application/core/Survey_Common_Action.php
Expand Up @@ -218,6 +218,7 @@ protected function route($sa, array $get_vars)
return call_user_func_array(array($this, $sa), $func_args);
}


/**
* Renders template(s) wrapped in header and footer
*
Expand Down
45 changes: 9 additions & 36 deletions application/views/admin/survey/editLocalSettings_main_view.php
Expand Up @@ -10,56 +10,29 @@
</script>

<?php
extract($settings_data);
$count = 0;
if(isset($scripts))
echo $scripts;
$data = array('aTabTitles'=>$aTabTitles, 'aTabContents'=>$aTabContents, 'has_permissions'=>$has_permissions, 'surveyid'=>$surveyid,'surveyls_language'=>$surveyls_language);
?>

<div id='edit-survey-text-element' class='side-body <?php echo getSideBodyClass(false); ?>'>
<div class="row">
<?php
// Decide in the right title of the dialog depending on permissions
$sTitle=gT("Edit survey text elements and settings");
if (Permission::model()->hasSurveyPermission($iSurveyID, 'surveylocale', 'read') && !Permission::model()->hasSurveyPermission($iSurveyID, 'surveysettings', 'read'))
{
$sTitle=gT("Edit survey text elements");
}
elseif (!Permission::model()->hasSurveyPermission($iSurveyID, 'surveylocale', 'read') && Permission::model()->hasSurveyPermission($iSurveyID, 'surveysettings', 'read'))
{
$sTitle=gT("Edit survey settings");
}
$this->renderPartial('/admin/survey/breadcrumb', array('oSurvey'=>$oSurvey, 'active'=>$sTitle)); ?>
<h3 class="pagetitle"><?php echo $sTitle; ?></h3>
<h3 class="pagetitle"><?php echo $pageTitle; ?></h3>

<!-- Edition container -->

<!-- Form -->
<div class="col-xs-12">
<?php echo CHtml::form(array("admin/database/index/updatesurveylocalesettings"), 'post', array('id'=>'globalsetting','name'=>'globalsetting','class'=>'form-horizontal form30')); ?>
<div class="row">
<?php echo CHtml::form(array("admin/database/index/".$panel['action']), 'post', array('id'=>$panel['name'],'name'=>$panel['name'],'class'=>'form-horizontal form30')); ?>

<!-- text edition -->
<?php
if (Permission::model()->hasSurveyPermission($iSurveyID, 'surveylocale', 'read'))
{?>
<div class="col-sm-12 col-md-7 content-right">
<?php $this->renderPartial('/admin/survey/subview/tab_edit_view',$data); ?>
<div class="row">
<?php if (Permission::model()->hasSurveyPermission($iSurveyID, $panel['permission'], $panel['permissionGrade'])):?>
<div class="<?=$panel['classes']?>">
<?php $this->renderPartial($panel['template'],$panel['data']); ?>
</div>
<?php
}
?>

<!-- settings -->
<div class="col-sm-12 col-md-5" id="accordion-container" style="background-color: #fff;">
<?php
if (Permission::model()->hasSurveyPermission($iSurveyID, 'surveysettings', 'read'))
{
$this->renderPartial('/admin/survey/subview/accordion/_accordion_container', array('data'=>$settings_data));
}
?>
</div>
<?php endif; ?>
</div>

<!--
Expand All @@ -69,13 +42,13 @@
Now, the "import ressources" is outside the global form, in a modal ( subview/import_ressources_modal.php)
So the globalsetting form needs its own submit button
-->
<input type="hidden" name="action" value="updatesurveylocalesettings" />
<input type="hidden" name="action" value="<?=$panel['action']?>" />
<input type="hidden" name="sid" value="<?php echo $surveyid; ?>" />
<input type="hidden" name="language" value="<?php echo $surveyls_language; ?>" />
<input type='submit' class="hide" id="globalsetting_submit" />
</form>
</div>

<?php $this->renderPartial('/admin/survey/subview/import_ressources_modal', $settings_data); ?>
<?php //$this->renderPartial('/admin/survey/subview/import_ressources_modal', $settings_data); ?>
</div>
</div>
31 changes: 31 additions & 0 deletions application/views/admin/survey/settings/generalsettings.xml
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This is a config file for a menu entry in the survey settings.
All Entries in the surveysettings will need to have xml-files
This Entries can either point to a general template file, or to a newly created user template
-->
<config core="true">
<name>generalsettings</name>
<title>Edit survey settings</title>
<menu>
<title>General settings</title>
<description>General survey settings</description>
<classes></classes>
<icon type="fontawesome">fa-gears</icon>
</menu>
<version>1.0.0</version>
<action>updatesurveylocalesettings</action>
<!-- This is currently necessary, though the generation of the admin pages is not finished at all -->
<template>/admin/survey/editLocalSettings_main_view</template>
<!-- Hopefully we will have time to recreate the genearion of the admin pages through a.e. TWIG -->
<partial>/admin/survey/subview/accordion/_generaloptions_panel</partial>
<language></language>
<permission>surveysettings</permission>
<permissionGrade>read</permissionGrade>
<classes>col-sm-12 col-md-5</classes>
<!-- Hopefully we can define some standardized methods to fill the data soon.
For now we will define a method in surveyadmin
<data></data>
-->
<getdatamethod>_generalTabEditSurvey</getdatamethod>
</config>
33 changes: 33 additions & 0 deletions application/views/admin/survey/settings/surveytexts.xml
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This is a config file for a menu entry in the survey settings.
All Entries in the surveysettings will need to have xml-files
This Entries can either point to a general template file, or to a newly created user template
-->
<config core="true">
<name>generalsettings</name>
<title>Edit survey text elements</title>
<menu>
<title>General settings</title>
<description>Survey texts</description>
<classes></classes>
<icon type="fontawesome">fa-file-text-o</icon>
</menu>
<version>1.0.0</version>
<action>surveygeneralsettings</action>
<!-- This is currently necessary, though the generation of the admin pages is not finished at all -->
<template>/admin/survey/editLocalSettings_main_view</template>
<!-- Hopefully we will have time to recreate the geneartion of the admin pages through a.e. TWIG -->
<partial>/admin/survey/subview/tab_edit_view</partial>
<language>
<partial>/admin/survey/editLocalSettings_view</partial>
</language>
<permission>surveylocale</permission>
<permissionGrade>read</permissionGrade>
<classes>col-sm-12 col-md-7 content-right</classes>
<!-- Hopefully we can define some standardized methods to fill the data soon.
For now we will define a method in surveyadmin
<data></data>
-->
<getdatamethod>_generalTabEditSurvey</getdatamethod>
</config>

0 comments on commit 263338b

Please sign in to comment.