Skip to content

Commit

Permalink
Dev: added surveygroup frontending
Browse files Browse the repository at this point in the history
Surveygroup edition and adjustments on Frontend
  • Loading branch information
lacrioque committed Aug 15, 2017
1 parent a6b9fe0 commit f82d8f8
Show file tree
Hide file tree
Showing 21 changed files with 317 additions and 155 deletions.
2 changes: 1 addition & 1 deletion application/config/version.php
Expand Up @@ -14,7 +14,7 @@

$config['versionnumber'] = '3.0.0-beta.2'; //The current version of this branch
$config['masterversion'] = '2.67.2'; //The current masters version merged into this branch
$config['dbversionnumber'] = 310;
$config['dbversionnumber'] = 311;
$config['buildnumber'] = '';
$config['updatable'] = true;
$config['assetsversionnumber'] = '2902';
Expand Down
14 changes: 11 additions & 3 deletions application/controllers/admin/SurveysGroupsController.php
Expand Up @@ -45,7 +45,7 @@ public function create()
if(isset($_POST['SurveysGroups']))
{
$model->attributes=$_POST['SurveysGroups'];
$model->name = sanitize_paranoid_string($_POST['SurveysGroups']['title']);
$model->name = sanitize_paranoid_string($model->name);
$model->created_by = $model->owner_uid = Yii::app()->user->id;
if($model->save())
$this->getController()->redirect(array('admin/survey/sa/listsurveys '));
Expand All @@ -71,13 +71,21 @@ public function update($id)
{
$model->attributes=$_POST['SurveysGroups'];
if($model->save())
$this->getController()->redirect(array('admin/survey/sa/listsurveys '));
$this->getController()->redirect($this->getController()->createUrl('admin/survey/sa/listsurveys').'#surveygroups');
}
$aData['model'] = $model;
$oSurveySearch = new Survey('search');
$oSurveySearch->gsid = $model->gsid;

$aData['oSurveySearch'] = $oSurveySearch;

$oTemplateOptions = Template::getTemplateConfiguration(null, null, $model->gsid);
$oTemplateOptions->bUseMagicInherit = false;
$oTemplateOptionsReplacement = TemplateConfiguration::model()->findByPk($oTemplateOptions->id);
$templateOptionPage = $oTemplateOptionsReplacement->optionPage;

$aData['templateOptionsModel'] = $oTemplateOptions;
$aData['templateOptionPage'] = $templateOptionPage;

$this->_renderWrappedTemplate('surveysgroups', 'update', $aData);
}

Expand Down
24 changes: 24 additions & 0 deletions application/controllers/admin/templateoptions.php
Expand Up @@ -138,6 +138,30 @@ public function updatesurvey($sid)
$this->_updateCommon($model, $sid);
}

/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id the ID of the model to be updated
*/
public function updatesurveygroup($gsid)
{
if (! Permission::model()->hasGlobalPermission('templates', 'update')){
Yii::app()->setFlashMessage(gT('Access denied!'),'error');
$this->getController()->redirect(Yii::app()->getController()->createUrl("/admin/surveysgroups/sa/update/",['id'=>$gsid]));
}

$model = Template::getTemplateConfiguration(null, null, $gsid);
$model->bUseMagicInherit = false;

if(isset($_POST['TemplateConfiguration'])){
$model->attributes=$_POST['TemplateConfiguration'];
if($model->save())
$this->getController()->redirect(Yii::app()->getController()->createUrl("/admin/surveysgroups/sa/update/",['id'=>$gsid]));
}

$this->_updateCommon($model, $sid);
}

/**
* Lists all models.
*/
Expand Down
4 changes: 2 additions & 2 deletions application/core/plugins/QuickMenu/QuickMenu.php
Expand Up @@ -103,7 +103,7 @@ class QuickMenu extends \ls\pluginmanager\PluginBase
),
'statistics' => array(
'type' => 'checkbox',
'label' => 'Statistics&nbsp;<span class="fa fa-stats"></span>',
'label' => 'Statistics&nbsp;<span class="fa fa-bar-chart"></span>',
'default' => '0',
'help' => 'Needed permission: Statistics - View'
),
Expand Down Expand Up @@ -324,7 +324,7 @@ private function initialiseButtons(array $data)
'name' => 'statistics',
'href' => Yii::app()->getController()->createUrl("admin/statistics/sa/index/surveyid/$surveyId"),
'tooltip' => gT('Statistics'),
'iconClass' => 'fa fa-stats navbar-brand',
'iconClass' => 'fa fa-bar-chart navbar-brand',
'showOnlyWhenSurveyIsActivated' => true,
'neededPermission' => array('statistics', 'read')
)),
Expand Down
2 changes: 1 addition & 1 deletion application/extensions/bootstrap/helpers/TbHtml.php
Expand Up @@ -466,7 +466,7 @@ class TbHtml extends CHtml // required in order to access the protected methods
const ICON_SOUND_STEREO = 'fa-sound-stereo';
const ICON_STAR = 'fa-star';
const ICON_STAR_EMPTY = 'fa-star-empty';
const ICON_STATS = 'fa-stats';
const ICON_STATS = 'fa-bar-chart';
const ICON_STEP_BACKWARD = 'fa-step-backward';
const ICON_STEP_FORWARD = 'fa-step-forward';
const ICON_STOP = 'fa-stop';
Expand Down
10 changes: 10 additions & 0 deletions application/helpers/update/updatedb_helper.php
Expand Up @@ -376,6 +376,16 @@ function db_upgrade_all($iOldDBVersion, $bSilent=false) {
$oTransaction->commit();
}

/*
* Add template settings to survey groups
*/
if ($iOldDBVersion < 311) {
$oTransaction = $oDB->beginTransaction();
addColumn('{{surveys_groups}}','template', "string(128) DEFAULT 'default'");
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>311),"stg_name='DBVersion'");
$oTransaction->commit();
}


}
catch(Exception $e)
Expand Down
2 changes: 1 addition & 1 deletion application/models/Survey.php
Expand Up @@ -1320,7 +1320,7 @@ public function getbuttons()
}

if(Permission::model()->hasSurveyPermission($this->sid, 'statistics', 'read') && $this->active=='Y' ) {
$button .= '<a class="btn btn-default" href="'.$sStatUrl.'" role="button" data-toggle="tooltip" title="'.gT('Statistics').'"><span class="fa fa-stats text-success" ></span><span class="sr-only">'.gT('Statistics').'</span></a>';
$button .= '<a class="btn btn-default" href="'.$sStatUrl.'" role="button" data-toggle="tooltip" title="'.gT('Statistics').'"><span class="fa fa-bar-chart text-success" ></span><span class="sr-only">'.gT('Statistics').'</span></a>';
}

if (Permission::model()->hasSurveyPermission($this->sid, 'survey', 'create')) {
Expand Down
2 changes: 1 addition & 1 deletion application/models/Surveymenu.php
Expand Up @@ -109,7 +109,7 @@ public function getSurveyIdOptions (){
}

public function getNextOrderPosition(){
$oSurveymenus = Surveymenu::model()->findAll();
$oSurveymenus = Surveymenu::model()->findAll('parent_id=:parent_id',array('parent_id'=>0));
return count($oSurveymenus);
}

Expand Down
110 changes: 108 additions & 2 deletions application/models/SurveysGroups.php
Expand Up @@ -76,6 +76,90 @@ public function attributeLabels()
);
}

public function getColumns(){
return array(

array(
'id'=>'gsid',
'class'=>'CCheckBoxColumn',
'selectableRows' => '100',
),

array(
'header' => gT('Survey Group ID'),
'name' => 'gsid',
'type' => 'raw',
'value'=>'CHtml::link($data->gsid, Yii::app()->createUrl("admin/surveysgroups/sa/update/",array("id"=>$data->gsid)))',
'headerHtmlOptions'=>array('class' => 'hidden-xs'),
'htmlOptions' => array('class' => 'hidden-xs has-link'),
),

array(
'header' => gT('Name'),
'name' => 'name',
'type' => 'raw',
'value'=>'CHtml::link($data->name, Yii::app()->createUrl("admin/surveysgroups/sa/update/",array("id"=>$data->gsid)))',
'headerHtmlOptions'=>array('class' => 'hidden-xs'),
'htmlOptions' => array('class' => 'has-link'),
),

array(
'header' => gT('Title'),
'name' => 'title',
'type' => 'raw',
'value'=>'CHtml::link($data->title, Yii::app()->createUrl("admin/surveysgroups/sa/update/",array("id"=>$data->gsid)))',
'headerHtmlOptions'=>array('class' => 'hidden-xs'),
'htmlOptions' => array('class' => 'has-link'),
),

array(
'header' => gT('Description'),
'name' => 'description',
'type' => 'raw',
'value'=>'CHtml::link($data->description, Yii::app()->createUrl("admin/surveysgroups/sa/update/",array("id"=>$data->gsid)))',
'headerHtmlOptions'=>array('class' => 'hidden-xs'),
'htmlOptions' => array('class' => 'hidden-xs has-link'),
),

array(
'header' => gT('Parent Group'),
'name' => 'parent',
'type' => 'raw',
'value'=>'CHtml::link( $data->parentTitle, Yii::app()->createUrl("admin/surveysgroups/sa/update/",array("id"=>$data->gsid)))',
'headerHtmlOptions'=>array('class' => 'hidden-xs'),
'htmlOptions' => array('class' => 'hidden-xs has-link'),
),

array(
'header' => gT('Owner'),
'name' => 'owner',
'value'=>'$data->owner->users_name',
'headerHtmlOptions'=>array('class' => 'hidden-xs'),
'htmlOptions' => array('class' => 'hidden-xs has-link'),
),

array(
'header' => gT('Order'),
'name' => 'order',
'type' => 'raw',
'value'=>'CHtml::link($data->order, Yii::app()->createUrl("admin/surveysgroups/sa/update/",array("id"=>$data->gsid)))',
'headerHtmlOptions'=>array('class' => 'hidden-xs'),
'htmlOptions' => array('class' => 'hidden-xs has-link'),
),


array(
'header' => gT('Actions'),
'name' => 'order',
'type' => 'raw',
'value'=> '$data->buttons',
'headerHtmlOptions'=>array('class' => 'hidden-xs'),
'htmlOptions' => array('class' => 'hidden-xs has-link'),
),

);
}

/**
* Retrieves a list of models based on the current search/filter conditions.
*
Expand Down Expand Up @@ -132,10 +216,14 @@ public function getHasSurveys()
public function getButtons()
{
$sDeleteUrl = App()->createUrl("admin/surveysgroups/sa/delete", array("id"=>$this->gsid));
$sEditUrl = App()->createUrl("admin/surveysgroups/sa/update", array("id"=>$this->gsid));
$button = '';

if (! $this->gsid !== 1){
$button .= '<a class="btn btn-default" href="'.$sEditUrl.'" role="button" data-toggle="tooltip" title="'.gT('Edit survey group').'"><i class="fa fa-edit" ></i><span class="sr-only">'.gT('Edit survey group').'</span></a>';
}
if (! $this->hasSurveys){
$button .= '<a class="btn btn-default" href="'.$sDeleteUrl.'" role="button" data-toggle="tooltip" title="'.gT('Delete survey group').'"><span class="fa fa-trash text-danger " ></span><span class="sr-only">'.gT('Delete survey group').'</span></a>';
$button .= '<a class="btn btn-default" href="'.$sDeleteUrl.'" role="button" data-toggle="tooltip" title="'.gT('Delete survey group').'"><i class="fa fa-trash text-danger " ></i><span class="sr-only">'.gT('Delete survey group').'</span></a>';
}

return $button;
Expand All @@ -144,7 +232,7 @@ public function getButtons()
public static function getSurveyGroupsList()
{
$aSurveyList = [];
$oSurveyGroups = self::model()->findAll();
$oSurveyGroups = self::model()->findAll('parent_id=:parent_id',array('parent_id'=>0));

foreach( $oSurveyGroups as $oSurveyGroup){
$aSurveyList[$oSurveyGroup->gsid] = $oSurveyGroup->title;
Expand All @@ -153,6 +241,24 @@ public static function getSurveyGroupsList()
return $aSurveyList;
}

public function getNextOrderPosition(){
$oSurveysGroups = SurveysGroups::model()->findAll();
return count($oSurveysGroups);
}

public function getParentGroupOptions (){
$oSurveysGroups = SurveysGroups::model()->findAll();
$options = [
'' => gT('No parent menu')
];
foreach($oSurveysGroups as $oSurveysGroup){
//$options[] = "<option value='".$oSurveymenu->id."'>".$oSurveymenu->title."</option>";
$options[''.($oSurveysGroup->gsid).''] = '('.$oSurveysGroup->name.') '.$oSurveysGroup->title;
}
//return join('\n',$options);
return $options;
}

/**
* Returns the static model of the specified AR class.
* Please note that you should have this exact method in all your CActiveRecord descendants!
Expand Down
2 changes: 1 addition & 1 deletion application/models/TemplateConfiguration.php
Expand Up @@ -502,7 +502,7 @@ protected function setOptionInheritance()

foreach($oOptions as $sKey => $sOption){
if ($sOption == 'inherit'){
$aParentOptions = (array) json_decode($this->getParentConfiguration('options'));
$aParentOptions = (array) json_decode($this->options);
$oOptions->$sKey = $aParentOptions[$sKey];
}
}
Expand Down
2 changes: 1 addition & 1 deletion application/views/admin/export/statistics_user_view.php
Expand Up @@ -13,7 +13,7 @@
<div class="row">
<div class="col-sm-12">
<h3>
<span class="fa fa-stats"></span> &nbsp;&nbsp;&nbsp;
<span class="fa fa-bar-chart"></span> &nbsp;&nbsp;&nbsp;
<?php eT("Statistics"); ?>
</h3>
</div>
Expand Down
2 changes: 1 addition & 1 deletion application/views/admin/export/statistics_view.php
Expand Up @@ -11,7 +11,7 @@

<div id='statisticsview' class='side-body <?php echo getSideBodyClass(false); ?>'>
<h3>
<span class="fa fa-stats"></span> &nbsp;&nbsp;&nbsp;
<span class="fa fa-bar-chart"></span> &nbsp;&nbsp;&nbsp;
<?php eT("Statistics"); ?>
</h3>

Expand Down
6 changes: 3 additions & 3 deletions application/views/admin/responses/browsemenubar_view.php
Expand Up @@ -50,7 +50,7 @@
<?php if (Permission::model()->hasSurveyPermission($surveyid, 'statistics', 'read')): ?>
<!-- Get statistics from these responses -->
<a class="btn btn-default" href='<?php echo $this->createUrl("admin/statistics/sa/index/surveyid/$surveyid"); ?>' role="button">
<span class="fa fa-stats text-success"></span>
<span class="fa fa-bar-chart text-success"></span>
<?php eT("Statistics"); ?>
</a>

Expand Down Expand Up @@ -177,12 +177,12 @@
<?php if(isset($menu['stats'])):?>
<?php if (isset($menu['expertstats']) && $menu['expertstats'] = true):?>
<a class="btn btn-info" href="<?php echo App()->createUrl('/admin/statistics/sa/index/surveyid/'.$surveyid); ?>" role="" id="">
<span class="fa fa-stats"></span>
<span class="fa fa-bar-chart"></span>
<?php eT("Expert mode"); ?>
</a>
<?php else: ?>
<a class="btn btn-info" href="<?php echo App()->createUrl('/admin/statistics/sa/simpleStatistics/surveyid/'.$surveyid); ?>" role="" id="">
<span class="fa fa-stats"></span>
<span class="fa fa-bar-chart"></span>
<?php eT("Simple mode"); ?>
</a>
<a class="btn btn-success" href="#" role="button" id="save-button">
Expand Down
16 changes: 2 additions & 14 deletions application/views/admin/super/fullpagebar_view.php
Expand Up @@ -7,21 +7,9 @@
<!-- Full page menu bar -->
<div class='menubar' id="fullpagebar">
<div class='row container-fluid'>

<!-- Left Actions -->
<div class="col-md-8">
<!-- Create a new survey -->
<?php if (isset($fullpagebar['button']['newsurvey']) && Permission::model()->hasGlobalPermission('surveys','create')):?>
<a class="btn btn-default" href="<?php echo $this->createUrl("admin/survey/sa/newsurvey"); ?>" role="button">
<span class="icon-add text-success"></span>
<?php eT("Create a new survey");?>
</a>
<a class="btn btn-default" href="<?php echo $this->createUrl("admin/surveysgroups/sa/create"); ?>" role="button">
<span class="icon-add text-success"></span>
<?php eT("Create a new survey group");?>
</a>
<?php endif;?>
<div class="col-md-6 text-left">
</div>


<!-- Right actions -->
<div class="col-md-4 text-right">
Expand Down

0 comments on commit f82d8f8

Please sign in to comment.