/
SurveysController.php
87 lines (69 loc) · 3.85 KB
/
SurveysController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
* This class will handle survey creation and manipulation.
*/
class SurveysController extends LSYii_Controller
{
/* All this part is for PUBLIC view : maybe move to LSYii_Controller ? */
/* @var string : Default layout when using render : leave at bare actually : just send content */
public $layout= 'public';
/* @var string the template name to be used when using layout */
public $sTemplate= 'default';
/* @var string[] Replacement data when use templatereplace function in layout, @see templatereplace $replacements */
public $aReplacementData= array();
/* @var array Global data when use templatereplace function in layout, @see templatereplace $redata */
public $aGlobalData= array();
public $defaultAction = 'publicList';
public function actionPublicList($lang = null)
{
if (!empty($lang)){
// Control is a real language , in restrictToLanguages ?
App()->setLanguage($lang);
}else{
App()->setLanguage(App()->getConfig('defaultlang'));
}
$oTemplate = Template::model()->getInstance(Yii::app()->getConfig("defaulttemplate"));
$oTemplate->registerAssets();
$this->sTemplate = $oTemplate->name;
//Yii::app()->clientScript->registerPackage( 'survey-template' );
//Yii::app()->clientScript->registerPackage( 'survey-template-'.$oTemplate->sTemplateName );
//var_dump('survey-template-'.$oTemplate->sTemplateName);
$aData = array(
'publicSurveys' => Survey::model()->active()->open()->public()->with('languagesettings')->findAll(),
'futureSurveys' => Survey::model()->active()->registration()->public()->with('languagesettings')->findAll(),
'oTemplate' => $oTemplate,
'sSiteName' => Yii::app()->getConfig('sitename'),
'sSiteAdminName' => Yii::app()->getConfig("siteadminname"),
'sSiteAdminEmail' => Yii::app()->getConfig("siteadminemail"),
'bShowClearAll' => false,
);
$aData['alanguageChanger']['show'] = false;
$alanguageChangerDatas = getLanguageChangerDatasPublicList(App()->language);
if ($alanguageChangerDatas){
$aData['alanguageChanger']['show'] = true;
$aData['alanguageChanger']['datas'] = $alanguageChangerDatas;
}
Yii::app()->clientScript->registerScriptFile(Yii::app()->getConfig("generalscripts").'nojs.js',CClientScript::POS_HEAD);
$sTemplateViewPath = $oTemplate->viewPath;
Yii::app()->twigRenderer->setForcedPath($sTemplateViewPath);
Yii::app()->twigRenderer->renderTemplateFromString( file_get_contents($sTemplateViewPath."layout_survey_list.twig"), array('aSurveyInfo'=>$aData), false);
}
/**
* System error : only 404 error are managed here (2016-11-29)
* SurveysController is the default controller set in internal
* @see http://www.yiiframework.com/doc/guide/1.1/en/topics.error#handling-errors-using-an-action
*/
public function actionError()
{
$oTemplate = Template::model()->getInstance(Yii::app()->getConfig("defaulttemplate"));
$this->sTemplate = $oTemplate->name;
$error = Yii::app()->errorHandler->error;
if ($error){
App()->setConfig('sitename',"Not found");
$this->render('/system/error'.$error['code'], array('error'=>$error,'admin'=>encodeEmail(Yii::app()->getConfig("siteadminemail"))));
}else{
throw new CHttpException(404, 'Page not found.');
}
}
}
?>