Skip to content

Commit

Permalink
Dev: twigged registration
Browse files Browse the repository at this point in the history
  • Loading branch information
lacrioque committed Aug 7, 2017
1 parent a2426ec commit 508bfee
Show file tree
Hide file tree
Showing 13 changed files with 248 additions and 52 deletions.
99 changes: 50 additions & 49 deletions application/controllers/RegisterController.php
Expand Up @@ -73,7 +73,7 @@ public function actionAJAXRegisterForm($surveyid)
$data['startdate'] = $oSurvey->startdate;
$data['enddate'] = $oSurvey->expires;
$data['thissurvey'] = getSurveyInfo($iSurveyId , $oSurvey->language);
echo self::getRegisterForm($iSurveyId);
echo self::ajaxGetRegisterForm($iSurveyId);
Yii::app()->end();
}

Expand Down Expand Up @@ -177,7 +177,7 @@ public function getRegisterErrors($iSurveyId){

public function getRegisterForm($iSurveyId)
{
$aSurveyInfo=getSurveyInfo($iSurveyId,App()->language);
$oSurvey=Survey::model()->findByPk($iSurveyId);

// Event to replace register form
$event = new PluginEvent('beforeRegisterForm');
Expand All @@ -195,36 +195,36 @@ public function getRegisterForm($iSurveyId)
}
$aFieldValue=$this->getFieldValue($iSurveyId);
$aRegisterAttributes=$this->getExtraAttributeInfo($iSurveyId);

$aData['iSurveyId'] = $iSurveyId;
$aData['sLanguage'] = App()->language;
$aData['sFirstName'] = $aFieldValue['sFirstName'];
$aData['sLastName'] = $aFieldValue['sLastName'];
$aData['sEmail'] = $aFieldValue['sEmail'];
$aData['aAttribute'] = $aFieldValue['aAttribute'];
$aData['aExtraAttributes']=$aRegisterAttributes;
$aData['bCaptcha'] = function_exists("ImageCreate") && isCaptchaEnabled('registrationscreen', $aSurveyInfo['usecaptcha']);
$aReplacement['REGISTERFORM'] = CHtml::form(App()->createUrl('register/index',array('sid'=>$iSurveyId)),'post',array('id'=>'limesurvey', 'role' => 'form', 'class' => 'ls-form'));
$aReplacement['REGISTERFORM'].= $this->renderPartial('/survey/frontpage/registerForm/form',$aData,true);
$aReplacement['REGISTERFORM'].= CHtml::endForm();
$aData['bCaptcha'] = function_exists("ImageCreate") && isCaptchaEnabled('registrationscreen', $oSurvey->usecaptcha);
$aData['sRegisterFormUrl'] = App()->createUrl('register/index',array('sid'=>$iSurveyId));

$aData['formAdditions'] = 'Blablablabla';
if(!empty($registerFormEvent)){
$aReplacement['REGISTERFORM'].= $registerFormEvent['formAppend'];
$aData['formAdditions'] = $registerFormEvent['formAppend'];
}

if(is_array($this->aRegisterErrors))
{
$aReplacement['REGISTERERROR']=$this->renderPartial("/survey/frontpage/registerForm/error",array('aErrors'=>$this->aRegisterErrors),true);
$aData['aErrors'] = $this->aRegisterErrors;
}
else
{
$aReplacement['REGISTERERROR']='';
$aData['aErrors'] = array();
}
$aReplacement['REGISTERMESSAGE1']=$this->renderPartial("/survey/frontpage/registerForm/heading",array(),true);
$aReplacement['REGISTERMESSAGE2']=$this->renderPartial("/survey/frontpage/registerForm/message",array('sStartDate'=>$this->getStartDate($iSurveyId)),true);
$aData['thissurvey'] = $aSurveyInfo;
Yii::app()->setConfig('surveyID',$iSurveyId);//Needed for languagechanger
// $aData['languagechanger'] = frontend_helper::makeLanguageChangerSurvey(App()->language);
$oTemplate = Template::model()->getInstance(null, $iSurveyId);
return templatereplace(file_get_contents($oTemplate->pstplPath . "/register.pstpl"),$aReplacement,$aData);

$aData['sStartDate'] = $this->getStartDate($iSurveyId ,true);

$aData['thissurvey'] = $oSurvey->attributes;

return $aData;
}

/**
Expand Down Expand Up @@ -476,38 +476,39 @@ private function display($iSurveyId)
$this->aReplacementData['sMessage']=$this->sMessage;

$oTemplate = Template::model()->getInstance('', $iSurveyId);
Yii::app()->clientScript->registerPackage( 'survey-template' );

$this->sTemplate=$oTemplate->sTemplateName;
if(!$this->sMessage){
// $this->aGlobalData['languagechanger']=frontend_helper::makeLanguageChangerSurvey($sLanguage); // Only show language changer shown the form is shown, not after submission
$this->aReplacementData['content']=self::getRegisterForm($iSurveyId);
}else{
// Must use message.pstpl
$this->aReplacementData['content']=templatereplace(file_get_contents($oTemplate->pstplPath . "/message.pstpl"),
array(
'MESSAGEID'=>'register-message',
'ERROR'=>'',
'MESSAGE'=>$this->sMessage,
)
,$this->aGlobalData
);

}
// Test if we come from index or from register
if(empty(App()->clientScript->scripts)){
/* This surely can be moved to layout , but remove iot from surveyController before */
$oTemplate = Template::model()->getInstance('', $iSurveyId);
Yii::app()->clientScript->registerPackage( 'survey-template' );
App()->getClientScript()->registerPackage('jqueryui');
App()->getClientScript()->registerPackage('jquery-touch-punch');
App()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts')."survey_runtime.js");
useFirebug();
$this->layout='survey';
$this->render('/survey/system/display',$this->aReplacementData);
}else{
// Survey/index need renderPartial
echo $this->render('/survey/system/display',$this->aReplacementData, true, true);
}
//Yii::app()->clientScript->registerPackage( 'survey-template' );

// $this->sTemplate=$oTemplate->sTemplateName;
// if(!$this->sMessage){
// // $this->aGlobalData['languagechanger']=frontend_helper::makeLanguageChangerSurvey($sLanguage); // Only show language changer shown the form is shown, not after submission
// }else{
// // Must use message.pstpl
// $this->aReplacementData['content']=templatereplace(file_get_contents($oTemplate->pstplPath . "/message.pstpl"),
// array(
// 'MESSAGEID'=>'register-message',
// 'ERROR'=>'',
// 'MESSAGE'=>$this->sMessage,
// )
// ,$this->aGlobalData
// );

// }

$aData['aSurveyInfo'] = self::getRegisterForm($iSurveyId);
Yii::app()->twigRenderer->renderTemplateFromFile('layout_register.twig',$aData, false);

// // Test if we come from index or from register
// if(empty(App()->clientScript->scripts)){
// /* This surely can be moved to layout , but remove iot from surveyController before */
// $oTemplate = Template::model()->getInstance('', $iSurveyId);
// Yii::app()->clientScript->registerPackage( 'survey-template' );
// App()->getClientScript()->registerPackage('jqueryui');
// App()->getClientScript()->registerPackage('jquery-touch-punch');
// App()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts')."survey_runtime.js");

// }else{
// // Survey/index need renderPartial
// Yii::app()->twigRenderer->renderTemplateFromFile('layout_register.twig',$aData, false);
// }
}
}
1 change: 1 addition & 0 deletions application/core/plugins/SocialMediaRegistration
Submodule SocialMediaRegistration added at 1ed34f
19 changes: 19 additions & 0 deletions application/models/Surveymenu.php
Expand Up @@ -63,6 +63,25 @@ public function relations()
);
}


public static function staticAddMenu($menuArray)
{
$oSurveymenu = new Surveymenu();
$oSurveymenu->parent_id = $menuArray['parent_id'];
$oSurveymenu->title = $menuArray['title'];
$oSurveymenu->position = $menuArray['position'];
$oSurveymenu->description = $menuArray['description'];

$oSurveymenu->changed_at = date('Y-m-d H:i:s');
$oSurveymenu->changed_by = Yii::app()->user->getId();
$oSurveymenu->created_at = date('Y-m-d H:i:s');
$oSurveymenu->created_by = Yii::app()->user->getId();

$oSurveymenu->save();
return $oSurveymenu->getPrimaryKey();
}


public function getMenuIdOptions (){
$oSurveymenus = Surveymenu::model()->findAll();
$options = [
Expand Down
33 changes: 33 additions & 0 deletions application/models/SurveymenuEntries.php
Expand Up @@ -73,6 +73,39 @@ public function relations()
);
}

public static function staticAddMenuEntry($menuEntryArray)
{
$oSurveymenuEntries = new SurveymenuEntries();


$oSurveymenuEntries->name = $menuEntryArray['name'];
$oSurveymenuEntries->title = $menuEntryArray['title'];
$oSurveymenuEntries->menu_title = $menuEntryArray['menu_title'];
$oSurveymenuEntries->menu_description = $menuEntryArray['menu_description'];
$oSurveymenuEntries->menu_icon = $menuEntryArray['menu_icon'];
$oSurveymenuEntries->menu_icon_type = $menuEntryArray['menu_icon_type'];
$oSurveymenuEntries->menu_link = $menuEntryArray['menu_link'];

//set data
$oMenuEntryData = new SurveymenuEntryData();
$oMenuEntryData->linkExternal = $menuEntryArray['linkExternal'];
$oMenuEntryData->isActive = $menuEntryArray['hideOnSurveyState'] == 'active' ? true : ($menuEntryArray['hideOnSurveyState'] == 'inactive' ? false : null);

if($menuEntryArray['manualParams'] != '')
$oMenuEntryData->linkData = json_parse($menuEntryArray['manualParams']);

$oSurveymenuEntries->data = $oMenuEntryData->createOptionJson($menuEntryArray['addSurveyId'], $menuEntryArray['addQuestionGroupId'], $menuEntryArray['addQuestionId']);

$oSurveymenuEntries->changed_at = date('Y-m-d H:i:s');
$oSurveymenuEntries->changed_by = Yii::app()->user->getId();
$oSurveymenuEntries->created_at = date('Y-m-d H:i:s');
$oSurveymenuEntries->created_by = Yii::app()->user->getId();

$oSurveymenuEntries->save();
return $oSurveymenuEntries->getPrimaryKey();
}


public static function reorderMenu($menuId){
$criteriaItems = new CDbCriteria();
$criteriaItems->addCondition(['menu_id = :menu_id']);
Expand Down
30 changes: 29 additions & 1 deletion application/models/SurveymenuEntryData.php
Expand Up @@ -26,6 +26,33 @@ public function apply($menuEntry, $surveyid){
}
$this->_parseLink();
}

public function createOptionJson($addSurveyID=false, $addQuestionGroupId=false, $addQuestionId=false){

$dataArray = array();
if($addSurveyID)
$dataArray['surveyid'] = ['survey', 'sid'];
if($addQuestionGroupId)
$dataArray['gid'] = ['questiongroup', 'gid'];
if($addQuestionId)
$dataArray['qid'] = ['question', 'qid'];


$baseArray = array(
'link' => array(
'external' => $this->linkExternal,
'pjaxed' => $this->pjaxed,
'data' => $dataArray
)
);

if($this->isActive === true || $this->isActive === false)
$baseArray['isActive'] = $this->isActive;

$baseArray = array_merge($baseArray, $this->linkData);

return json_encode(array('render' => $baseArray));
}

public function linkCreator(){
$returnLink = Yii::app()->getController()->createUrl($this->link, $this->linkData);
Expand All @@ -47,6 +74,7 @@ private function _parseDataAttribute(){
}
}


private function _parseLink(){

if(empty($this->menuEntry->menu_link)){
Expand Down Expand Up @@ -105,4 +133,4 @@ private function _getValueForLinkData($getDataPair)

}

?>
?>
3 changes: 2 additions & 1 deletion application/models/Template.php
Expand Up @@ -216,7 +216,6 @@ public static function getTemplateConfiguration($sTemplateName=null, $iSurveyId=
if (!is_a($oTemplateConfigurationModel, 'TemplateConfiguration')){
$sTemplateName = SurveysGroups::model()->findByPk($iSurveyGroupId)->template;
$oTemplateConfigurationModel = TemplateConfiguration::model()->find('templates_name=:templates_name AND sid IS NULL AND gsid IS NULL', array(':templates_name'=>$sTemplateName));
$oTemplateConfigurationModel->setToInherit();
}
}

Expand All @@ -242,6 +241,7 @@ public static function getTemplateConfiguration($sTemplateName=null, $iSurveyId=
$oTemplateConfigurationModel->isNewRecord = true;
$oTemplateConfigurationModel->gsid = $iSurveyGroupId;
$oTemplateConfigurationModel->setToInherit();
$oTemplateConfigurationModel->setThisTemplate();
$oTemplateConfigurationModel->save();
return $oTemplateConfigurationModel;
}
Expand All @@ -252,6 +252,7 @@ public static function getTemplateConfiguration($sTemplateName=null, $iSurveyId=
$oTemplateConfigurationModel->isNewRecord = true;
$oTemplateConfigurationModel->sid = $iSurveyId;
$oTemplateConfigurationModel->setToInherit();
$oTemplateConfigurationModel->setThisTemplate();
$oTemplateConfigurationModel->save();
return $oTemplateConfigurationModel;
}
Expand Down
2 changes: 1 addition & 1 deletion templates/default/scripts/template.js
Expand Up @@ -73,7 +73,7 @@ $(document).on('ready pjax:complete',function()
}

$(function () {
$('[data-toggle="tooltip"]').tooltip()
//$('[data-toggle="tooltip"]').tooltip()
})
});
/**
Expand Down
29 changes: 29 additions & 0 deletions templates/default/views/layout_register.twig
@@ -0,0 +1,29 @@
{# Call the global layout #}
{% extends "./layout_global.twig" %}

{# Replace the content block #}
{% block content %}

{# render the layout_global content block #}
{{ parent() }}

<div class="container">
{# This will display the script and the hidden inputs needed for Expression Manager #}
{{ aSurveyInfo.EM.ScriptsAndHiddenInputs }}

<div class="row">
<div class='jumbotron'>
{{ include('./subviews/registration/register_head.twig') }}
<div class="container clearfix">
{{ include('./subviews/registration/register_message.twig') }}
</div>
</div>
</div>
{{ include('./subviews/registration/register_error.twig') }}
<div class="register-form row">
{{ include('./subviews/registration/register_form.twig') }}
</div>
</div>
<input type='hidden' class='hidemenubutton'/>

{% endblock %}
@@ -0,0 +1,9 @@
{% if aSurveyInfo.errors is not empty %}
<ul class='alert alert-danger list-unstyled' role='alert'>
{% for error in aSurveyInfo.errors %}
<!-- Error Html warnings -->
<li>{{ error }}</li>
<br/>
{% endfor %}
</ul>
{% endif %}
65 changes: 65 additions & 0 deletions templates/default/views/subviews/registration/register_form.twig
@@ -0,0 +1,65 @@

{{ C.Html.form(aSurveyInfo.sRegisterFormUrl,'post',({'id' : 'limesurvey', 'role' : 'form', 'class' : 'form'})) }}

<input type="hidden" name="lang" value="{{aSurveyInfo.sLanguage}}" id="register_lang" />
<div class='col-md-8 col-md-offset-2'>
<div class='form-group row'>
<label for='register_firstname' class='control-label '>{{ gT("First name:") }}</label>
<div class="">
{{ C.Html.textField('register_firstname', aSurveyInfo.sFirstName, ({'id' : 'register_firstname','class' : 'form-control'})) }}
</div>
</div>

<div class='form-group row'>
<label for='register_lastname' class='control-label '>{{ gT("Last name:") }}</label>
<div class="">
{{ C.Html.textField('register_lastname', aSurveyInfo.sLastName, ({'id' : 'register_lastname', 'class' : 'form-control'})) }}
</div>
</div>
<div class='form-group row'>
<label for='register_email' class='control-label'> {{ gT("Email address:") }} {{ include('./subviews/required.twig') }}</label>
<div class="">
{{ C.Html.textField('register_email', aSurveyInfo.sEmail, ({'id' : 'register_email','class' : 'form-control input-sm','required' : true})) }}
</div>
</div>
{% for key, aExtraAttribute in aSurveyInfo.aExtraAttributes %}
<div class='form-group row'>
{% set registerKey = "register_" ~ key %}
<label for="{{ registerKey }}" class='control-label '> {{ aExtraAttribute.caption }} {% if aExtraAttribute.mandatory == 'Y' %}{{ include('./subviews/required.twig') }}{% endif %}</label>
<div class="">
{{ C.Html.textField(registerKey, aAttribute[key],({'id' : "register_{$key}",'class' : 'form-control input-sm'})) }}
</div>
</div>
{% endfor %}
{% if aSurveyInfo.bCaptcha %}
<div class='form-group row captcha-item'>
<label class='control-label ' for='loadsecurity'>{{ gT("Please enter the letters you see:") }} {{ include('./subviews/required.twig') }}</label>
<div class=''>
<div class='input-group'>
<div class='control-label captcha-widget' >
{{ renderCaptcha }}
</div>
<input class='form-control' type='text' size='15' maxlength='15' id='loadsecurity' name='loadsecurity' value='' alt='' required>
</div>
</div>
</div>
{% endif %}

<div class='row' aria-hidden='true'>
{{ gT('Fields marked with an asterisk are mandatory.')}}
</div>

<div class='form-group row'>
<div class=' col-md-offset-7'>
{% set continue = gT("Continue",'unescaped') %}
<button type='submit' id='savebutton' name="savesubmit" class='btn btn-default' value='save'>
{{ continue }}
</button>
</div>
</div>
<div class="row">
{{ aSurveyInfo.formAdditions | raw }}
</div>
</div>

{{ C.Html.endForm }}

0 comments on commit 508bfee

Please sign in to comment.