Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
Conflicts:
	application/config/version.php
	application/models/Question.php
	application/views/admin/survey/Question/editQuestion_view.php
  • Loading branch information
olleharstedt committed Jun 19, 2018
2 parents 33649f5 + 0ace024 commit a4ec6d9
Show file tree
Hide file tree
Showing 72 changed files with 1,869 additions and 798 deletions.
11 changes: 11 additions & 0 deletions application/config/questiontypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,15 @@
'emoji'
]
),
/* array-numeric question */
'question-array-numeric'=>array(
'devBaseUrl' => 'assets/packages/questions/arraynumeric/',
'basePath' => 'core.questions.arraynumeric',
'position' => CClientScript::POS_BEGIN,
'css'=> array(
),
'js'=>array(
'scripts/array-totalsum'.$minVersion.'.js',
),
),
);
2 changes: 1 addition & 1 deletion application/config/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
$config['dbversionnumber'] = 403;
$config['buildnumber'] = '';
$config['updatable'] = true;
$config['assetsversionnumber'] = '30039';
$config['assetsversionnumber'] = '30041';
return $config;
59 changes: 33 additions & 26 deletions application/controllers/admin/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -1313,32 +1313,39 @@ private function actionInsertCopyQuestion($iSurveyID)
if (Yii::app()->request->getPost('action') == 'copyquestion') {
/** @var Question $oOldQuestion */
$oldQID = returnGlobal('oldqid');
if ($oldQID) {
$oOldQuestion = Question::model()->findByPk(
array(
'qid' => $oldQID,
'language' => $survey->language
)
);
}
if (returnGlobal('copysubquestions') == 1 && isset($oOldQuestion)) {
$aSQIDMappings = [];
foreach ($oOldQuestion->subquestions as $qr1) {
$arQuestion = new Question();
$arQuestion->attributes = $qr1->attributes;
$arQuestion->parent_qid = $this->iQuestionID;
$oldqid = '';
if (isset($aSQIDMappings[$qr1->qid])) {
$arQuestion->qid = $aSQIDMappings[$qr1->qid];
} else {
$oldqid = $qr1->qid;
$arQuestion->qid = null;
}

$arQuestion->gid = $this->iQuestionGroupID;
if ($arQuestion->save()) {
$aSQIDMappings[$oldqid] = $arQuestion->gid;
}

if (returnGlobal('copysubquestions') == 1) {
$aSubquestionIds = array();
if ($oldQID) {
// get all survey languages
$aLanguages = array_merge(array(Survey::model()->findByPk($iSurveyID)->language), Survey::model()->findByPk($iSurveyID)->additionalLanguages);
foreach ($aLanguages as $sLanguageIndex => $sLanguage) {
// create a Question model for each language
$oOldQuestion = Question::model()->findByPk(
array(
'qid' => $oldQID,
'language' => $sLanguage
)
);

// subquestions
foreach ($oOldQuestion->subquestions as $sSubquestionIndex => $qr1) {
$aInsertData = $qr1->attributes;
if ($sLanguageIndex == 0){ // main language
$aInsertData['qid'] = null;
} else { // additional languages
$aInsertData['qid'] = $aSubquestionIds[$sSubquestionIndex]; // get qid from array
}

$aInsertData['parent_qid'] = $this->iQuestionID;
if (Question::model()->insertRecords($aInsertData)){
if ($sLanguageIndex == 0){ // main language
$aSubquestionIds[$sSubquestionIndex] = Yii::app()->db->getLastInsertID(); // save qid into the array
}
}
}
}

}
}
if (returnGlobal('copyanswers') == 1) {
Expand Down
14 changes: 6 additions & 8 deletions application/controllers/admin/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ private function _exportPrintableHtmls($iSurveyID, $readFile = true)
$tempdir = Yii::app()->getConfig("tempdir");
$zipdir = $this->_tempdir($tempdir);

$fn = "printable_survey_".CHtml::encode($oSurvey->currentLanguageSettings->surveyls_title)."_{$oSurvey->primaryKey}.zip";
$fn = "printable_survey_".preg_replace('([^\w\s\d\-_~,;\[\]\(\).])','',$oSurvey->currentLanguageSettings->surveyls_title)."_{$oSurvey->primaryKey}.zip";
$zipfile = "$tempdir/".$fn;

Yii::app()->loadLibrary('admin.pclzip');
Expand All @@ -1249,13 +1249,14 @@ private function _exportPrintableHtmls($iSurveyID, $readFile = true)
Yii::app()->language = $siteLanguage;

$this->_addHeaders($fn, "application/zip", 0);
if ($readFile) {
// if ($readFile) {
header('Content-Transfer-Encoding: binary');
header("Content-disposition: attachment; filename=\"".$fn."\"");
readfile($zipfile);
unlink($zipfile);
}
return $zipfile;
Yii::app()->end();
// }
//return $zipfile;

}

Expand All @@ -1272,10 +1273,7 @@ private function _exportPrintableHtml($oSurvey, $language, $tempdir)
{
$printableSurvey = new printablesurvey();

ob_start(); //Start output buffer
$printableSurvey->index($oSurvey->primaryKey, $language);
$response = ob_get_contents(); //Grab output
ob_end_clean(); //Discard output buffer
$response = $printableSurvey->index($oSurvey->primaryKey, $language, true);

$file = "$tempdir/questionnaire_{$oSurvey->getPrimaryKey()}_{$language}.html";

Expand Down
9 changes: 5 additions & 4 deletions application/controllers/admin/printablesurvey.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class printablesurvey extends Survey_Common_Action
* Show printable survey
* @param string $lang
*/
function index($surveyid, $lang = null)
function index($surveyid, $lang = null, $bReturn = false)
{
$surveyid = sanitize_int($surveyid);
$oSurvey = Survey::model()->findByPk($surveyid);
Expand Down Expand Up @@ -1265,7 +1265,7 @@ function index($surveyid, $lang = null)
// Previous version of PHP needs two regular expressions to do the same thing and thus will run a bit slower.
$server_is_newer = version_compare(PHP_VERSION, '5.1.0', '>');
$rounds = 0;
Yii::app()->twigRenderer->renderTemplateFromFile('layout_print.twig', ['aSurveyInfo' => $aSurveyInfo, 'print' => $printarray], false);
return Yii::app()->twigRenderer->renderTemplateFromFile('layout_print.twig', ['aSurveyInfo' => $aSurveyInfo, 'print' => $printarray], $bReturn);
// die(print_r(['aSurveyInfo' => $aSurveyInfo, 'print' => $printarray], true));
// echo self::_populate_template($oTemplate, 'survey', ['aSurveyInfo' => $aSurveyInfo, 'print' => $printarray]);
}// End print
Expand Down Expand Up @@ -1387,16 +1387,17 @@ private function getColumnWidth($answerBaseWidth, $labelBaseWidth)
if (intval($labelBaseWidth) < 1 || intval($labelBaseWidth) > 12) {
$labelBaseWidth = null;
}

if (!$answerBaseWidth && !$labelBaseWidth) {
$sInputContainerWidth = 8;
$sLabelWidth = 4;
} else {
if ($answerBaseWidth) {
$sInputContainerWidth = $answerBaseWidth;
} elseif ($attributeLabelWidth == 12) {
} elseif ($labelBaseWidth == 12) {
$sInputContainerWidth = 12;
} else {
$sInputContainerWidth = 12 - $attributeLabelWidth;
$sInputContainerWidth = 12 - $labelBaseWidth;
}
if ($labelBaseWidth) {
$sLabelWidth = $labelBaseWidth;
Expand Down
16 changes: 8 additions & 8 deletions application/controllers/survey/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public function action()
}

$this->_loadRequiredHelpersAndLibraries();

$param = $this->_getParameters(func_get_args(), $_POST);
$surveyid = $param['sid'];
$thisstep = $param['thisstep'];
Expand Down Expand Up @@ -91,6 +90,11 @@ public function action()
SetSurveyLanguage($surveyid, $sDisplayLanguage);
}

/* Launch beforeSurveyPage before all renderExitMessage */
$beforeSurveyPageEvent = new PluginEvent('beforeSurveyPage');
$beforeSurveyPageEvent->set('surveyId', $surveyid);
App()->getPluginManager()->dispatchEvent($beforeSurveyPageEvent);

if ($this->_isClientTokenDifferentFromSessionToken($clienttoken, $surveyid)) {
$sReloadUrl = $this->getController()->createUrl("/survey/index/sid/{$surveyid}", array('token'=>$clienttoken, 'lang'=>App()->language, 'newtest'=>'Y'));
$aErrors = array(gT('Token mismatch'));
Expand Down Expand Up @@ -267,13 +271,9 @@ public function action()

//GET BASIC INFORMATION ABOUT THIS SURVEY
$thissurvey = getSurveyInfo($surveyid, $_SESSION['survey_'.$surveyid]['s_lang']);

$event = new PluginEvent('beforeSurveyPage');
$event->set('surveyId', $surveyid);
App()->getPluginManager()->dispatchEvent($event);

if (!is_null($event->get('template'))) {
$thissurvey['templatedir'] = $event->get('template');
/* Unsure it still work, and surely better in afterFindSurvey */
if (!is_null($beforeSurveyPageEvent->get('template'))) {
$thissurvey['templatedir'] = $beforeSurveyPageEvent->get('template');
}

//SEE IF SURVEY USES TOKENS
Expand Down
2 changes: 1 addition & 1 deletion application/core/plugins/ExportR/RSyntaxWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function close()
$str .= '),labels=c(';

foreach ($answers as $answer) {
$str .= '"'.addslashes($answer['value']).'", ';
$str .= '"'.addslashes(!empty($answer['value'])?$answer['value']:$answer['code']).'", ';
}

$str = mb_substr($str, 0, -2);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

class PreviewModalWidget extends CWidget {

//The name the widget will be rendered to, please make sure it is unique!
public $widgetsJsName = "";
//The title the widgets modal will have
public $modalTitle = "Select please";
//If using the grouped view this should be the key to get the group title
public $groupTitleKey = "title";
//If using the grouped view this should be the key of the grouped items array key
public $groupItemsKey = "items";
//Display this with the items key in debug mode
public $debugKeyCheck = "Key: ";
//The title of the preview window
public $previewWindowTitle = "Preview";

//Either a group or an items array must be given
public $groupStructureArray = [];
public $itemsArray = [];

//There should be a value set
public $value = null;
//This may be the value also, but oftentimes you'd want this to be an easy to read title
public $currentSelected = "";

//This is the option array that gets fed into the javascript.
public $optionArray = [];


//These are pretty standard and may not need to be changed
public $closeButton = "Close";
public $selectButton = "Select";

//RenderType should either be modal, simple, group-simple or group-modal
public $renderType;

public $debug = false;

public function run() {
//clean up the widgets name to be js friendly
$this->widgetsJsName = preg_replace('/[^a-zA-Z0-9_-]/','',$this->widgetsJsName);
$this->registerScripts();
}


public function getModal($return=false){
if(preg_match("/modal/",$this->renderType)){
return $this->render($this->view, null, $return);
}
echo "";
return;
}

public function getButtonOrSelect($return=false){
if(preg_match("/modal/",$this->renderType)){
return $this->render("open_modal_button", null, $return);
}

return $this->render($this->view, null, $return);
}

public function getView(){

switch( $this->renderType ) {
case 'simple' : return 'simple_select';
case 'group-simple' : return 'simple_grouped_select';
case 'group-modal' : return 'grouped_select_modal';
case 'modal' : //fallthrough
default: return 'select_modal';
}
}

private function registerScripts(){
$oClientScript = App()->getClientScript();
$basePath = dirname(__FILE__) . '/assets/';

//publish Assets
$sStyleFile = App()->getAssetManager()->publish($basePath.'previewModalWidget.dist.css');
$sScriptFile = App()->getAssetManager()->publish($basePath.'previewModalWidget.dist.js');
//register Assets
$oClientScript->registerCssFile($sStyleFile);
$oClientScript->registerScriptFile($sScriptFile, CClientScript::POS_BEGIN);
$oClientScript->registerScript('WIDGETSCRIPT--'.$this->widgetsJsName, '
var runner_'.$this->widgetsJsName.' = new PreviewModalScript("'.$this->widgetsJsName.'",'
.json_encode(array_merge($this->optionArray, [
'value' => $this->value,
'debugString' => $this->debugKeyCheck,
'debug' => $this->debug,
'viewType' => $this->view
]))
.');
runner_'.$this->widgetsJsName.'.bind();',
LSYii_ClientScript::POS_POSTSCRIPT);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
babel previewModalWidget.src.js --out-file previewModalWidget.dist.js
node-sass --output-style compressed previewModalWidget.src.scss > previewModalWidget.dist.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.previewModalWidget .currentImageContainer{width:100%}.previewModalWidget .currentImageContainer img{max-width:100%}

0 comments on commit a4ec6d9

Please sign in to comment.