Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
Conflicts:
	application/views/admin/survey/Question/answerOptions_view.php
  • Loading branch information
olleharstedt committed May 29, 2018
2 parents 91fc8ae + 1f5bb13 commit 45e6143
Show file tree
Hide file tree
Showing 25 changed files with 775 additions and 801 deletions.
6 changes: 4 additions & 2 deletions application/config/internal.php
Expand Up @@ -266,7 +266,8 @@
'getLanguageNameFromCode' => 'getLanguageNameFromCode',
'checkconditionFunction' => 'checkconditionFunction',
'doRender' => 'doRender',
'flattenText' => 'flattenText'
'flattenText' => 'flattenText',
'getEditor' => 'getEditor'
),
'filters' => array(
'jencode' => 'CJSON::encode',
Expand Down Expand Up @@ -367,7 +368,8 @@
'checkconditionFunction',
'doRender',
'flattenText',
'range'
'range',
'getEditor'
),
),
),
Expand Down
2 changes: 0 additions & 2 deletions application/controllers/admin/questiongroups.php
Expand Up @@ -415,8 +415,6 @@ public function updateOrder($surveyid)
$oQuestion->save(true);
}, $oQuestions);
}

Question::updateSortOrder($aQuestiongroup['gid'], $surveyid);
}

return Yii::app()->getController()->renderPartial(
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/admin/questions.php
Expand Up @@ -953,7 +953,7 @@ public function getSubquestionRow($surveyid, $gid, $qid, $codes, $language, $fir
}

$html = '<!-- Inserted Row -->';
$html .= $this->getController()->renderPartial('/admin/survey/Question/subquestionsAndAnswers/'.$view, $aData, true, false);
$html .= App()->twigRenderer->renderAnswerOptions('/admin/survey/Question/subquestionsAndAnswers/'.$view, $aData);
$html .= '<!-- end of Inserted Row -->';
return $html;
}
Expand Down
55 changes: 55 additions & 0 deletions application/core/LSETwigViewRenderer.php
Expand Up @@ -179,6 +179,61 @@ public function renderQuestion($sView, $aData)
}
}

/**
* This method is used to render question's subquestions and answer options pages .
* It first checks if the question use a template (set in display attributes)
* If it is the case, it will use the views of that template, else, it will render the core view.
*
* @param string $sView the view (layout) to render
* @param array $aData the datas needed for the view rendering
*
* @return string the generated html
*/
public function renderAnswerOptions($sView, $aData)
{
$this->_twig = parent::getTwig(); // Twig object
$loader = $this->_twig->getLoader(); // Twig Template loader
$requiredView = Yii::getPathOfAlias('application.views').$sView; // By default, the required view is the core view
$loader->setPaths(App()->getBasePath().'/views/'); // Core views path

$oQuestionTemplate = QuestionTemplate::getInstance(); // Question template instance has been created at top of qanda_helper::retrieveAnswers()

// currently, question's subquestions and answer options pages are rendered only from core
$sTemplateFolderName = null;

// Check if question use a custom template and that it provides its own twig view
if ($sTemplateFolderName) {
$bTemplateHasThisView = $oQuestionTemplate->checkIfTemplateHasView($sView); // A template can change only one of the view of the question type. So other views should be rendered by core.

if ($bTemplateHasThisView) {
$sQTemplatePath = $oQuestionTemplate->getTemplatePath(); // Question template views path
$loader->setPaths($sQTemplatePath); // Loader path
$requiredView = $sQTemplatePath.ltrim($sView, '/'); // Complete path of the view
}
}

// We check if the file is a twig file or a php file
// This allow us to twig the view one by one, from PHP to twig.
// The check will be removed when 100% of the views will have been twig
if (file_exists($requiredView.'.twig')) {
// We're not using the Yii Theming system, so we don't use parent::renderFile
// current controller properties will be accessible as {{ this.property }}

// aData and surveyInfo variables are accessible from question type twig files
$aData['aData'] = $aData;
$sBaseLanguage = Survey::model()->findByPk($_SESSION['LEMsid'])->language;
$aData['surveyInfo'] = getSurveyInfo($_SESSION['LEMsid'], $sBaseLanguage);
$aData['this'] = Yii::app()->getController();

$aData['question_template_attribute'] = null;

$template = $this->_twig->loadTemplate($sView.'.twig')->render($aData);
return $template;
} else {
return Yii::app()->getController()->renderPartial($sView, $aData, true);
}
}

/**
* This method is called from Template Editor.
* It returns the HTML string needed for the tmp file using the template twig file.
Expand Down
2 changes: 1 addition & 1 deletion application/views/admin/responses/browsemenubar_view.php
Expand Up @@ -57,7 +57,7 @@
<!-- Get time statistics from these responses -->
<?php if ($thissurvey['savetimings'] == "Y"):?>
<a class="btn btn-default" href='<?php echo $this->createUrl("admin/responses/sa/time/surveyid/$surveyid"); ?>' role="button">
<span class="fa fa-time text-success"></span>
<span class="fa fa-clock-o text-success"></span>
<?php eT("Timing statistics"); ?>
</a>
<?php endif;?>
Expand Down
232 changes: 232 additions & 0 deletions application/views/admin/survey/Question/answerOptionsEdit_view.twig
@@ -0,0 +1,232 @@

<input type='hidden' name='sid' value='{{ surveyid }}' />
<input type='hidden' name='gid' value='{{ gid }}' />
<input type='hidden' name='qid' value='{{ qid }}' />

{% if viewType=='subQuestions' %}
<input type='hidden' id='action' name='action' value='updatesubquestions' />
{% elseif viewType=='answerOptions' %}
<input type='hidden' name='action' value='updateansweroptions' />
{% endif %}

<input type='hidden' name='sortorder' value='' />
<input type='hidden' id='deletedqids' name='deletedqids' value='' />

{% set first=true %}

<!-- Tabs -->
<ul class="nav nav-tabs">
{% for i, anslang in anslangs %}
<li role="presentation" {% if i==0 %}class="active"{% endif %}>
<a data-toggle="tab" href='#tabpage_{{ anslang }}'>
{{ base_language[i] }}
</a>
</li>
{% endfor %}
</ul>
{% set sortorderids='' %}
{% set codeids='' %}
{% set scale_id = 0 %}

<!-- Tab content -->
<div class="tab-content">
{% for i, anslang in anslangs %}
<div id='tabpage_{{ anslang }}' class='tab-page tab-pane fade in {% if i==0 %}active{% endif %}'>
{% for scale_id in range(0,scalecount-1) %}
{% set result = results[anslang][scale_id] %}
{% set anscount = result|length %}
{# TODO : check the rendering of XSCALES / Y SCALES #}

{# For subQuestions #}
{% if viewType=='subQuestions' %}
{% set position=0 %}
{% if scalecount>1 %}
{% if scale_id==0 %}
<div class='header ui-widget-header'>
{{ gT("Y-Scale") }}
</div>
{% else %}
<div class='header ui-widget-header'>
{{ gT("X-Scale") }}
</div>
{% endif %}
{% endif %}

{# For answers #}
{% elseif viewType=='answerOptions' %}
{% set position=1 %}
{% if scalecount>1 %}
<div class='header ui-widget-header' style='margin-top:5px;'>
{{ sprintf(gT("Answer scale %s"),scale_id+1) }}
</div>
{% endif %}
{% endif %}

<!-- Answers/Subquestions Table -->
<table class='answertable table table-responsive' id='{{ tableId[anslang][scale_id] }}' data-scaleid='{{ scale_id }}'>

<!-- Headers -->
<thead>
<tr>
<th class="col-md-1">
{% if first and activated != 'Y' %}
{{ gT("Position") }}
{% else %}
&nbsp;
{% endif %}
</th>
<th class='col-md-1'>{{ gT("Code") }}</th>

<!-- subQuestions headers -->
{% if viewType=='subQuestions' %}
<th>
{{ gT("Subquestion") }}
</th>
{% if first %}
<th id='rel-eq-th' class='col-md-1'>
{{ gT("Relevance equation") }}
</th>
<th class="col-md-1">
{{ gT("Action") }}
</th>
{% endif %}

<!-- answer Options header-->
{% elseif viewType=='answerOptions' %}
{% if assessmentvisible %}
<th class='col-md-1'>
{{ gT("Assessment value") }}
</th>
{% else %}
<th style='display:none;'>
&nbsp;
</th>
{% endif %}

<th class='col-md-8'>
{{ gT("Answer option") }}
</th>

<th class='col-md-1'>
{% if first %}
{{ gT("Actions") }}
{% endif %}
</th>
{% endif %}
</tr>
</thead>

<!-- Body -->
<tbody id="rowcontainer">
{% for row in result %}
<!-- Line tag -->
{% if viewType=='subQuestions' %}
{% include '/admin/survey/Question/subquestionsAndAnswers/_subquestion.twig' with {
'position' : position,
'scale_id' : scale_id,
'activated' : activated,
'first' : first,
'surveyid' : surveyid,
'gid' : gid,
'qid' : row.qid,
'language' : row.language,
'title' : row.title,
'question' : row.question,
'relevance' : row.relevance,
'oldCode' : true,
} %}

{% elseif viewType=='answerOptions' %}
{% include '/admin/survey/Question/subquestionsAndAnswers/_answer_option.twig' with {
'position' : position,
'first' : first,
'assessmentvisible' : assessmentvisible,
'scale_id' : scale_id,
'title' : row.code,
'surveyid' : surveyid,
'gid' : gid,
'qid' : qid,
'language' : row.language,
'assessment_value' : row.assessment_value,
'sortorder' : row.sortorder,
'answer' : row.answer,
'oldCode' : true,
} %}

{% endif %}

{% set position = position + 1 %}

{% endfor %}
</tbody>
</table>

<div class="action-buttons">
{% if viewType=='subQuestions' %}
{% if activated == 'Y' %}
{% set disabled = 'disabled="disabled"' %}
{% else %}
{% set disabled = '' %}
{% endif %}
{% elseif viewType=='answerOptions' %}
{% if first %}
<input type='hidden' id='answercount_{{ scale_id }}' name='answercount_{{ scale_id }}' value='{{ anscount }}' />
{% set disabled="" %}
{% endif %}
<br/>
{% endif %}

<button {{ disabled }} id='btnlsbrowser_{{ anslang }}_{{ scale_id }}' data-scale-id="{{ scale_id }}" class='btnlsbrowser btn btn-default' type='button' data-toggle="modal" data-target="#labelsetbrowserModal">
{{ gT('Predefined label sets...') }}
</button>

<button {{ disabled }} id='btnquickadd_{{ anslang }}_{{ scale_id }}' data-scale-id="{{ scale_id }}" class='btn btn-default btnquickadd' type='button' data-toggle="modal" data-target="#quickaddModal" data-scale-id="{{ scale_id }}">
{{ gT('Quick add...') }}
</button>


{% if has_permissions %}
<button class='bthsaveaslabel btn btn-default' id='bthsaveaslabel_{{ scale_id }}' type='button' data-toggle="modal" data-target="#saveaslabelModal">
{{ gT('Save as label set') }}
</button>
{% endif %}

</div>
{% set position=sprintf("%05d", position) %}
{% endfor %}
</div>
{% set first=false %}
{% endfor %}

<!-- Modals -->
{% include 'admin/survey/Question/question_subviews/_modals.twig' %}

<p>
<input type='submit' class="hidden" id='saveallbtn_{{ anslang }}' name='method' value='{{ gT("Save changes") }}' />
<!-- For javascript -->
<input
type="hidden"
id="add-input-javascript-datas"
data-url="{{ createUrl('/admin/questions/sa/getSubquestionRowForAllLanguages/') }}"
data-quickurl="{{ createUrl(
'/admin/questions/',
({
'sa' : 'getSubquestionRowQuickAdd',
'surveyid' : surveyid,
'gid' : gid
})
) }}"
data-assessmentvisible="{% if assessmentvisible|length and assessmentvisible==true%}1{% else %}0{% endif %}"
data-errormessage="An error occured while processing the ajax request."
data-surveyid="{{ surveyid }}"
data-languages='{{ json_encode(all_languages) }}'
data-gid="{{ gid }}"
data-qid="{{ qid }}"
data-scale-id="{{ scale_id }}" {# -1 : because it's incremented via < #}
/>
</p>

</div>
<input type='hidden' id='bFullPOST' name='bFullPOST' value='1' />


0 comments on commit 45e6143

Please sign in to comment.