diff --git a/application/controllers/SurveysController.php b/application/controllers/SurveysController.php index c5166939559..4caa5d566a9 100644 --- a/application/controllers/SurveysController.php +++ b/application/controllers/SurveysController.php @@ -30,10 +30,22 @@ public function actionPublicList($lang = null) App()->bootstrap->registerAllScripts(); } - $this->render('publicSurveyList', array( - 'publicSurveys' => Survey::model()->active()->open()->public()->with('languagesettings')->findAll(), - 'futureSurveys' => Survey::model()->active()->registration()->public()->with('languagesettings')->findAll(), - )); + $aData = array( + 'publicSurveys' => Survey::model()->active()->open()->public()->with('languagesettings')->findAll(), + 'futureSurveys' => Survey::model()->active()->registration()->public()->with('languagesettings')->findAll(), + ); + $htmlOut = $this->render('publicSurveyList', $aData,true ); + + $event = new PluginEvent('beforeSurveysStartpageRender', $this); + $event->set('aData', $aData); + App()->getPluginManager()->dispatchEvent($event); + + if(!empty($event->get('result'))) + { + $htmlFromEvent = $event->get('result'); + $htmlOut = $htmlFromEvent['html']; + } + echo $htmlOut; } } ?> diff --git a/application/core/plugins/extendedStartPage/extendedStartPage.php b/application/core/plugins/extendedStartPage/extendedStartPage.php new file mode 100644 index 00000000000..592c1702b31 --- /dev/null +++ b/application/core/plugins/extendedStartPage/extendedStartPage.php @@ -0,0 +1,28 @@ +subscribe('beforeSurveysStartpageRender'); + } + + public function beforeSurveysStartpageRender(){ + $event = $this->getEvent(); + $aData = $event->get('aData'); + + $html = $this->renderPartial('publicSurveyList_extended',$aData,true,true ); + $event->append('result',array('html'=>$html)); + } + +} \ No newline at end of file diff --git a/application/core/plugins/extendedStartPage/views/publicSurveyList_extended.php b/application/core/plugins/extendedStartPage/views/publicSurveyList_extended.php new file mode 100644 index 00000000000..37d1d034f81 --- /dev/null +++ b/application/core/plugins/extendedStartPage/views/publicSurveyList_extended.php @@ -0,0 +1,208 @@ +"; + $list .= "
"; + $divideToggle = true; + + foreach($publicSurveys as $survey) + { + $outputSurveys++; + //echo "IKI :";var_dump( $survey->localizedTitle); + $divider = ($divideToggle ? " vertical-divider right " : ""); + if ($survey->publicstatistics == "Y") + { + $statistics = "
"; + $statistics .= CHtml::link(''. gT('View statistics') .'', + array('statistics_user/action', 'surveyid' => $survey->sid,'language' => App()->language), + array( + 'class'=>'view-stats btn btn-success btn-block', + 'title'=>gT('View statistics'), + 'data-toggle'=>'tooltip', + ) + ); + $statistics .= "
"; + $list .= "
"; + } + else + { + $statistics = ""; + $list .= "
"; + } + + $tooltips = ""; + if($survey->allowregister == "Y") + { + $tooltips .= " "; + } + else + { + if($survey->hasTokens($survey->sid)) + { + $tooltips .= " "; + } + } + + if($survey->usecaptcha == "Y" || $survey->usecaptcha == "A") + { + $tooltips .= " "; + } + if($survey->anonymized == "Y") + { + $tooltips .= " "; + } + if($survey->allowsave == "Y") + { + $tooltips .= " "; + } + if($survey->allowprev == "Y") + { + $tooltips .= " "; + } + $tooltips .= "  ".$survey->calculateEstimatedTime()." ".gt("Minutes"); + + $content = $survey->localizedTitle; + $content .= "" + ." " + .""; + + $list .= CHtml::link( + $content, + array( + 'survey/index', + 'sid' => $survey->sid, + 'lang' => App()->language, + 'encode' => false + ), + array( + 'class' => 'surveytitle btn btn-primary btn-block', + 'data-html' => true, + 'data-toggle' => 'tooltip', + 'title' => $tooltips + ) + ); + $list .= "
"; + $list .= $statistics; + $divideToggle = !$divideToggle; + } + + $list .= "
"; + $list .= "
"; + + if (!empty($futureSurveys)) + { + $list .= "
". gT("Following survey(s) are not yet active but you can register for them.")."
"; + $list .= "
"; + $list .= "
"; + foreach($futureSurveys as $survey) + { + $outputSurveys++; + $list .= CHtml::openTag('div', array('class'=>'col-xs-12')); + $list .= CHtml::link($survey->localizedTitle, array('survey/index', 'sid' => $survey->sid, 'lang' => App()->language), array('class' => 'surveytitle')); + $list .= CHtml::closeTag('div'); + $list .= CHtml::tag('div', array( + 'data-regformsurvey' => $survey->sid, + 'class' => 'col-xs-12' + )); + } + } + + + $legendForSurvey_button = ""; + $legendForSurvey = "" + . ""; + + //@TODO: Create Global configuration for showSurveyInfo + $showSurveyInformation = false; + + + $listheading="
+
+

+ ".gT("The following surveys are available:")." + ".$legendForSurvey_button." +

+ ".$legendForSurvey." +
"; + if( $outputSurveys==0) + { + $list=CHtml::openTag('div',array('class'=>'col-xs-12')).gT("No available surveys").CHtml::closeTag('div'); + } + $data['surveylist'] = array( + "nosid"=> "", + "contact"=> sprintf(gT("Please contact %s ( %s ) for further assistance."), + Yii::app()->getConfig("siteadminname"), + encodeEmail(Yii::app()->getConfig("siteadminemail")) + ), + "listheading"=> $listheading, + "list"=> $list, + ); + + $oTemplate = Template::model()->getInstance("default"); + + $data['templatedir'] = Template::getTemplatePath(Yii::app()->getConfig("defaulttemplate")); + $data['templateurl'] = Template::getTemplateURL(Yii::app()->getConfig("defaulttemplate"))."/"; + $data['templatename'] = $oTemplate->name; + $data['sitename'] = Yii::app()->getConfig("sitename"); + $data['languagechanger'] = makeLanguageChanger(App()->language); + + //A nice exit + sendCacheHeaders(); + doHeader(); + // Javascript Var + $aLSJavascriptVar=array(); + $aLSJavascriptVar['bFixNumAuto']=(int)(bool)Yii::app()->getConfig('bFixNumAuto',1); + $aLSJavascriptVar['bNumRealValue']=(int)(bool)Yii::app()->getConfig('bNumRealValue',0); + if(isset($thissurvey['surveyls_numberformat'])) + { + $radix=getRadixPointData($thissurvey['surveyls_numberformat']); + } + else + { + $aLangData=getLanguageData(); + $radix=getRadixPointData($aLangData[ Yii::app()->getConfig('defaultlang')]['radixpoint']);// or App()->language . defaultlang ensure it's same for each language ? + } + $aLSJavascriptVar['sLEMradix']=$radix['separator']; + $sLSJavascriptVar="LSvar=".json_encode($aLSJavascriptVar); + App()->clientScript->registerScript('sLSJavascriptVar',$sLSJavascriptVar,CClientScript::POS_HEAD); + App()->clientScript->registerScript('setJsVar',"setJsVar();",CClientScript::POS_BEGIN);// Ensure all js var is set before rendering the page (User can click before $.ready) + App()->getClientScript()->registerPackage('jqueryui'); + App()->getClientScript()->registerPackage('jquery-touch-punch'); + App()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts')."survey_runtime.js"); + useFirebug(); + + echo templatereplace(file_get_contents($oTemplate->viewPath."/startpage.pstpl"),array(),$data,'survey['.__LINE__.']'); + echo templatereplace(file_get_contents($oTemplate->viewPath."/surveylist.pstpl"),array(),$data,'survey['.__LINE__.']'); + echo templatereplace(file_get_contents($oTemplate->viewPath."/endpage.pstpl"),array(),$data,'survey['.__LINE__.']'); + doFooter(); +?> diff --git a/application/models/Survey.php b/application/models/Survey.php index 22e4ac04ba1..cebd156ca7f 100644 --- a/application/models/Survey.php +++ b/application/models/Survey.php @@ -1109,4 +1109,29 @@ public static function transcribeCaptchaOptions() { return 'N'; } + /** + * Method to make an approximation on how long a survey will last + * Approx is 3 questions each minute. + * @return int + */ + public function calculateEstimatedTime () + { + //@TODO make the time_per_question variable user configureable + $time_per_question = 0.5; + $criteria = new CDbCriteria(); + $criteria->addCondition('sid = ' . $this->sid); + $criteria->addCondition('parent_qid = 0'); + $criteria->addCondition('language = \'' . $this->language . '\''); + $baseQuestions = Question::model()->count($criteria); + // Note: An array questions with one sub question is fetched as 1 base question + 1 sub question + $criteria = new CDbCriteria(); + $criteria->addCondition('sid = ' . $this->sid); + $criteria->addCondition('parent_qid != 0'); + $criteria->addCondition('language = \'' . $this->language . '\''); + $subQuestions = Question::model()->count($criteria); + // Subquestions are worth less "time" than base questions + $subQuestions = intval(($subQuestions - $baseQuestions) / 2); + $subQuestions = $subQuestions < 0 ? 0 : $subQuestions; + return ceil(($subQuestions + $baseQuestions)*$time_per_question); + } } diff --git a/application/views/surveys/publicSurveyList.php b/application/views/surveys/publicSurveyList.php index e6da517e2ef..cf5c7f5700d 100644 --- a/application/views/surveys/publicSurveyList.php +++ b/application/views/surveys/publicSurveyList.php @@ -1,43 +1,84 @@ '; + $outputSurveys = 0; + $list = "
"; + $list .= "
"; + $divideToggle = true; + foreach($publicSurveys as $survey) { - //echo "IKI :";var_dump( $survey->localizedTitle); - $list .= CHtml::openTag('li'); - $list .= CHtml::link($survey->localizedTitle, array('survey/index', 'sid' => $survey->sid, 'lang' => App()->language), array('class' => 'surveytitle btn btn-primary')); + $outputSurveys++; + //echo "IKI :";var_dump( $survey->localizedTitle); + $divider = ($divideToggle ? " vertical-divider right " : ""); if ($survey->publicstatistics == "Y") { - $list .= CHtml::link(''. gT('View statistics') .'', + $statistics = "
"; + $statistics .= CHtml::link(''. gT('View statistics') .'', array('statistics_user/action', 'surveyid' => $survey->sid,'language' => App()->language), array( - 'class'=>'view-stats btn btn-success', + 'class'=>'view-stats btn btn-success btn-block', 'title'=>gT('View statistics'), 'data-toggle'=>'tooltip', ) ); + $statistics .= "
"; + $list .= "
"; + } + else + { + $statistics = ""; + $list .= "
"; } - $list .= CHtml::closeTag('li'); + //@TODO Make $allowTooltips a global configuration setting + $allowTooltips = "Y"; + $content = $survey->localizedTitle; + $list .= CHtml::link( + $content, + array( + 'survey/index', + 'sid' => $survey->sid, + 'lang' => App()->language, + 'encode' => false + ), + array( + 'class' => 'surveytitle btn btn-primary btn-block' + ) + ); + $list .= "
"; + $list .= $statistics; + $divideToggle = !$divideToggle; } - $list .= ""; + + $list .= "
"; + $list .= "
"; + if (!empty($futureSurveys)) { $list .= "
". gT("Following survey(s) are not yet active but you can register for them.")."
"; - $list .= '
    '; + $list .= "
    "; + $list .= "
    "; foreach($futureSurveys as $survey) { - $list .= CHtml::openTag('li'); + $outputSurveys++; + $list .= CHtml::openTag('div', array('class'=>'col-xs-12')); $list .= CHtml::link($survey->localizedTitle, array('survey/index', 'sid' => $survey->sid, 'lang' => App()->language), array('class' => 'surveytitle')); - $list .= CHtml::closeTag('li'); + $list .= CHtml::closeTag('div'); $list .= CHtml::tag('div', array( 'data-regformsurvey' => $survey->sid, - + 'class' => 'col-xs-12' )); } } - if(empty($list)) + + $listheading="
    +
    +

    + ".gT("The following surveys are available:")." +

    +
    "; + if( $outputSurveys==0) { - $list=CHtml::openTag('li',array('class'=>'surveytitle')).gT("No available surveys").CHtml::closeTag('li'); + $list=CHtml::openTag('div',array('class'=>'col-xs-12')).gT("No available surveys").CHtml::closeTag('div'); } $data['surveylist'] = array( "nosid"=> "", @@ -45,7 +86,7 @@ Yii::app()->getConfig("siteadminname"), encodeEmail(Yii::app()->getConfig("siteadminemail")) ), - "listheading"=> gT("The following surveys are available:"), + "listheading"=> $listheading, "list"=> $list, ); diff --git a/templates/default/css/template.css b/templates/default/css/template.css index d2afb331c58..a3eb11234cd 100644 --- a/templates/default/css/template.css +++ b/templates/default/css/template.css @@ -986,4 +986,72 @@ div.yes-no .btn-group label { .privacy-header{ font-weight: bold; font-style: italic; +} + +/*** Divider for Bootstrap ***/ + +.horizontal-divider.top{ + border-top: 3px solid #323232; +} +.horizontal-divider.bottom{ + border-bottom: 3px solid #323232; +} + +.vertical-divider.left { + border-left: 3px solid #323232; +} +.vertical-divider.right { + border-right: 3px solid #323232; +} +@media (max-width: 800px){ + .vertical-divider.left { + border: none; + } + .vertical-divider.right { + border: none; + } +} +/*** Small helper classes, that are not shipped with bootstrap but fit in well***/ +.ls-custom-padding{ + padding: 1px; +} +.ls-custom-padding.two{ + padding: 2px; +} +.ls-custom-padding.three{ + padding: 3px; +} +.ls-custom-padding.four{ + padding: 4px; +} +.ls-custom-padding.five{ + padding: 5px; +} +.ls-custom-padding.fifteen{ + padding: 15px; +} +.ls-custom-padding.eighteen{ + padding: 18px; +} + +.ls-custom-margin{ + margin: 1px; +} +.ls-custom-margin.two{ + margin: 2px; +} +.ls-custom-margin.three{ + margin: 3px; +} +.ls-custom-margin.four{ + margin: 4px; +} +.ls-custom-margin.five{ + margin: 5px; +} +.ls-custom-margin.fifteen{ + margin: 15px; +} +.ls-custom-margin.eighteen{ + margin: 18px; } \ No newline at end of file