Skip to content

Commit

Permalink
Dev: survey list improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Mar 16, 2016
1 parent 47eb86e commit 9d623e1
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 74 deletions.
2 changes: 0 additions & 2 deletions application/controllers/admin/surveyadmin.php
Expand Up @@ -81,9 +81,7 @@ public function listsurveys()
}

$aData['fullpagebar']['button']['newsurvey'] = true;

$this->_renderWrappedTemplate('survey', 'listSurveys_view', $aData);

}


Expand Down
1 change: 0 additions & 1 deletion application/core/Survey_Common_Action.php
Expand Up @@ -991,7 +991,6 @@ function _surveysummary($aData)

$sumcount3 = Question::model()->countByAttributes($condition); //Checked
$condition = array('sid' => $iSurveyID, 'language' => $baselang);

$sumcount2 = QuestionGroup::model()->countByAttributes($condition); //Checked

//SURVEY SUMMARY
Expand Down
117 changes: 87 additions & 30 deletions application/models/Survey.php
Expand Up @@ -46,12 +46,12 @@ public function init()
$this->attachEventHandler("onAfterFind", array($this,'fixSurveyAttribute'));
}

/* Your model attribute labels */
/* Add virtual survey attribute labels for gridView*/
public function attributeLabels() {
return [
return array(
/* Your other attribute labels */
'running' => gT('survey', 'running')
];
'running' => gT('running')
);
}

/**
Expand Down Expand Up @@ -418,12 +418,17 @@ public function hasTokens($iSurveyID) {
return $tokens[$iSurveyID];
}

public function getHasTokens() {
public function getHasTokens()
{
$hasTokens = $this->hasTokens($this->sid) ;
if($hasTokens)
{
return gT('Yes');
}
else
{
return gT('No');
}
}


Expand Down Expand Up @@ -633,26 +638,45 @@ public function getRunning()
// If the survey is not active, no date test is needed
if($this->active == 'N')
{
$running = gT('No');
$running = '<a href="'.App()->createUrl('/admin/survey/sa/view/surveyid/'.$this->sid).'" class="survey-state" data-toggle="tooltip" title="'.gT('Inactive').'"><span class="fa fa-stop text-warning"></span></a>';
}
// If it's active, then we check if not expired
elseif ($this->expires != '')
elseif ($this->expires != '' || $this->startdate != '')
{
// Time adjust
$now = date("Y-m-d H:i:s", strtotime(Yii::app()->getConfig('timeadjust'), strtotime(date("Y-m-d H:i:s"))) );// dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i:s", Yii::app()->getConfig('timeadjust'));
$expire = date("Y-m-d H:i:s", strtotime(Yii::app()->getConfig('timeadjust'), strtotime($this->expires)) );
$sNow = date("Y-m-d H:i:s", strtotime(Yii::app()->getConfig('timeadjust'), strtotime(date("Y-m-d H:i:s"))) );
$sStop = ($this->expires != '')?date("Y-m-d H:i:s", strtotime(Yii::app()->getConfig('timeadjust'), strtotime($this->expires)) ):$sNow;
$sStart = ($this->startdate != '')?date("Y-m-d H:i:s", strtotime(Yii::app()->getConfig('timeadjust'), strtotime($this->startdate)) ):$sNow;

// Time comparaison
$oNow = new DateTime($sNow);
$oStop = new DateTime($sStop);
$oStart = new DateTime($sStart);

$date1 = new DateTime($now);
$date2 = new DateTime($expire);
$bExpired = ($oStop < $oNow);
$bWillRun = ($oStart > $oNow);

$running = ($date2 < $date1)?'<span class="text-warning">'.gT('Expired').'</span>':gT('Yes');
// Icon generaton (for CGridView)
$sIconRunning = '<a href="'.App()->createUrl('/admin/survey/sa/view/surveyid/'.$this->sid).'" class="survey-state" data-toggle="tooltip" title="'.gT('Expire').': '.$sStop.'"><span class="fa fa-clock-o text-success"></span></a>';
$sIconExpired = '<a href="'.App()->createUrl('/admin/survey/sa/view/surveyid/'.$this->sid).'" class="survey-state" data-toggle="tooltip" title="'.gT('Expired').': '.$sStop.'"><span class="fa fa fa-step-forward text-warning"></span></a>';
$sIconFuture = '<a href="'.App()->createUrl('/admin/survey/sa/view/surveyid/'.$this->sid).'" class="survey-state" data-toggle="tooltip" title="'.gT('Start').': '.$sStart.'"><span class="fa fa-clock-o text-warning"></span></a>';

//return $expires;
// Icon parsing
if ( $bExpired || $bWillRun )
{
// Expire prior to will start
$running = ($bExpired)?$sIconExpired:$sIconFuture;
}
else
{
$running = $sIconRunning;
}
}
// If it's active, and don't have expire date, it's running
// If it's active, and doesn't have expire date, it's running
else
{
$running = gT('Yes');
$running = '<a href="'.App()->createUrl('/admin/survey/sa/view/surveyid/'.$this->sid).'" class="survey-state" data-toggle="tooltip" title="'.gT('Active').'"><span class="fa fa-play text-success"></span></a>';
//$running = '<div class="survey-state"><span class="fa fa-play text-success"></span></div>';
}

return $running;
Expand Down Expand Up @@ -761,15 +785,40 @@ public function getCountTotalAnswers()

public function getbuttons()
{
$url = Yii::app()->createUrl("/admin/survey/sa/view/surveyid/");
$url .= '/'.$this->sid;
$button = '<a class="btn btn-default" href="'.$url.'" role="button"><span class="glyphicon glyphicon-pencil" ></span></a>';
$sSummaryUrl = App()->createUrl("/admin/survey/sa/view/surveyid/".$this->sid);
$sEditUrl = App()->createUrl("/admin/survey/sa/editlocalsettings/surveyid/".$this->sid);
$sDeleteUrl = App()->createUrl("/admin/survey/sa/delete/surveyid/".$this->sid);
$sStatUrl = App()->createUrl("/admin/statistics/sa/simpleStatistics/surveyid/".$this->sid);
$sAddGroup = App()->createUrl("/admin/questiongroups/sa/add/surveyid/".$this->sid);;
$sAddquestion = App()->createUrl("/admin/questions/sa/newquestion/surveyid/".$this->sid);;

$button = '<a class="btn btn-default " href="'.$sSummaryUrl.'" role="button" data-toggle="tooltip" title="'.gT('Survey summary').'"><span class="glyphicon glyphicon-list-alt" ></span></a>';
$button .= '<a class="btn btn-default" href="'.$sEditUrl.'" role="button" data-toggle="tooltip" title="'.gT('General settings & texts').'"><span class="glyphicon glyphicon-pencil" ></span></a>';
$button .= '<a class="btn btn-default" href="'.$sDeleteUrl.'" role="button" data-toggle="tooltip" title="'.gT('Delete').'"><span class="text-danger glyphicon glyphicon-trash" ></span></a>';

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="glyphicon glyphicon-stats text-success" ></span></a>';
}

if($this->active!='Y')
{
$groupCount = QuestionGroup::model()->countByAttributes(array('sid' => $this->sid, 'language' => $this->language)); //Checked
if($groupCount > 0)
{
$button .= '<a class="btn btn-default" href="'.$sAddquestion.'" role="button" data-toggle="tooltip" title="'.gT('Add new question').'"><span class="icon-add text-success" ></span></a>';
}
else
{
$button .= '<a class="btn btn-default" href="'.$sAddGroup.'" role="button" data-toggle="tooltip" title="'.gT('Add new group').'"><span class="icon-add text-success" ></span></a>';
}
}

$previewUrl = Yii::app()->createUrl("survey/index/sid/");
$previewUrl .= '/'.$this->sid;

//$button = '<a class="btn btn-default open-preview" aria-data-url="'.$previewUrl.'" aria-data-language="'.$this->language.'" href="# role="button" ><span class="glyphicon glyphicon-eye-open" ></span></a> ';
$button = '<a class="btn btn-default" href="'.$url.'" role="button"><span class="glyphicon glyphicon-pencil" ></span></a>';

return $button;
}

Expand Down Expand Up @@ -810,14 +859,6 @@ public function search()
);

$criteria = new CDbCriteria;

// Answers
$criteria->select = array(
'*',
$this->getCountFullAnswers() . " as full_answers_account",
$this->getCountPartialAnswers() . " as partial_answers_account",
);

$criteria->join = 'LEFT JOIN {{surveys_languagesettings}} AS surveys_languagesettings ON ( surveys_languagesettings.surveyls_language = t.language AND t.sid = surveys_languagesettings.surveyls_survey_id )';
$criteria->join .= 'LEFT JOIN {{users}} AS users ON ( users.uid = t.owner_id )';

Expand All @@ -828,19 +869,35 @@ public function search()
$criteria->condition = 'permissions.read_p=1';
$criteria->params=(array(':userid'=>Yii::app()->user->id ));
}

// Search filter
$criteria2 = new CDbCriteria;
$sid_reference = (Yii::app()->db->getDriverName() == 'pgsql' ?' t.sid::varchar' : 't.sid');
$criteria2->compare($sid_reference, $this->searched_value, true, 'OR');
$criteria2->compare('surveys_languagesettings.surveyls_title', $this->searched_value, true, 'OR');
$criteria2->compare('t.admin', $this->searched_value, true, 'OR');



// Active filter
if(isset($this->active))
{
$criteria->addCondition("t.active='$this->active'");
if($this->active == 'N' || $this->active == "Y")
{
$criteria->addCondition("t.active='$this->active'");
}
else
{
// Time adjust
$sNow = date("Y-m-d H:i:s", strtotime(Yii::app()->getConfig('timeadjust'), strtotime(date("Y-m-d H:i:s"))) );

if($this->active == "E")
{
$criteria->addCondition("t.expires <'$sNow'");
}
if($this->active == "S")
{
$criteria->addCondition("t.startdate >'$sNow'");
}
}
}

$criteria->mergeWith($criteria2, 'AND');
Expand Down
64 changes: 31 additions & 33 deletions application/views/admin/survey/deleteSurvey_view.php
@@ -1,38 +1,36 @@
<div class="side-body">
<div class="row">
<div class="col-lg-12 content-right">
<br/>
<div class="row">
<div class="col-lg-12 content-right">
<br/>

<div class="jumbotron message-box">
<h2><?php eT("Delete survey"); ?></h2>
<p class="lead"><?php eT("Warning"); ?></p>
<p>
<strong><?php eT("You are about to delete this survey"); ?> (<?php echo $surveyid; ?>)</strong><br /><br />
<?php eT("This process will delete this survey, and all related groups, questions answers and conditions."); ?><br /><br />
<?php eT("It will also delete any resources/files that have been uploaded for this survey."); ?><br /><br />
<?php eT("We recommend that before you delete this survey you export the entire survey from the main administration screen."); ?>

<?php if(tableExists("{{survey_{$surveyid}}}")):?>
<span class="text-warning"><?php eT("This survey is active and a responses table exists. If you delete this survey, these responses (and files) will be deleted. We recommend that you export the responses before deleting this survey."); ?></span><br /><br />
<?php endif; ?>


<?php if (tableExists("{{tokens_{$surveyid}}}")): ?>
<span class="text-warning"><?php eT("This survey has an associated tokens table. If you delete this survey this tokens table will be deleted. We recommend that you export or backup these tokens before deleting this survey."); ?><br /><br />
<?php endif; ?>

</p>
<p>
<?php echo CHtml::beginForm($this->createUrl("admin/survey/sa/delete/surveyid/{$surveyid}"), 'post');?>
<input type='hidden' name='delete' value='yes'>
<input type='submit' class="btn btn-lg btn-warning" value='<?php eT("Delete survey"); ?>'>
<input type='button' class="btn btn-lg btn-default" value='<?php eT("Cancel"); ?>' onclick="window.open('<?php echo $this->createUrl("admin/survey/sa/view/surveyid/$surveyid"); ?>', '_top')" />
<?php echo CHtml::endForm(); ?>
</p>
</div>
<div class="jumbotron message-box">
<h2><?php eT("Delete survey"); ?></h2>
<p class="lead"><?php eT("Warning"); ?></p>
<p>
<strong><?php eT("You are about to delete this survey"); ?> (<?php echo $surveyid; ?>)</strong><br /><br />
<?php eT("This process will delete this survey, and all related groups, questions answers and conditions."); ?><br /><br />
<?php eT("It will also delete any resources/files that have been uploaded for this survey."); ?><br /><br />
<?php eT("We recommend that before you delete this survey you export the entire survey from the main administration screen."); ?>

<?php if(tableExists("{{survey_{$surveyid}}}")):?>
<span class="text-warning"><?php eT("This survey is active and a responses table exists. If you delete this survey, these responses (and files) will be deleted. We recommend that you export the responses before deleting this survey."); ?></span><br /><br />
<?php endif; ?>

</div>
</div>
</div>

<?php if (tableExists("{{tokens_{$surveyid}}}")): ?>
<span class="text-warning"><?php eT("This survey has an associated tokens table. If you delete this survey this tokens table will be deleted. We recommend that you export or backup these tokens before deleting this survey."); ?><br /><br />
<?php endif; ?>

</p>
<p>
<?php echo CHtml::beginForm($this->createUrl("admin/survey/sa/delete/surveyid/{$surveyid}"), 'post');?>
<input type='hidden' name='delete' value='yes'>
<input type='submit' class="btn btn-lg btn-warning" value='<?php eT("Delete survey"); ?>'>
<input type='button' class="btn btn-lg btn-default" value='<?php eT("Cancel"); ?>' onclick="window.open('<?php echo Yii::app()->request->getUrlReferrer( Yii::app()->createUrl("admin/survey/sa/view/surveyid/$surveyid") , array() ); ?>', '_top')" />
<?php echo CHtml::endForm(); ?>
</p>
</div>

</div>
</div>
</div>
19 changes: 11 additions & 8 deletions application/views/admin/survey/listSurveys_view.php
Expand Up @@ -33,9 +33,11 @@
<div class="form-group">
<?php echo $form->label($model, 'active', array('label'=>gT('Active:'),'class'=>'control-label')); ?>
<select name="active" class="form-control">
<option value="" <?php if( $model->active!="Y" && $model->active!="N" ){echo "selected";}?>><?php eT('(Any state)');?></option>
<option value="" <?php if( $model->active==""){echo "selected";}?>><?php eT('(Any state)');?></option>
<option value="Y" <?php if( $model->active=="Y"){echo "selected";}?>><?php eT('Yes');?></option>
<option value="N" <?php if( $model->active=="N"){echo "selected";}?>><?php eT('No');?></option>
<option value="E" <?php if( $model->active=="E"){echo "selected";}?>><?php eT('Expired');?></option>
<option value="S" <?php if( $model->active=="S"){echo "selected";}?>><?php eT('Futur');?></option>
</select>
</div>
<?php echo CHtml::submitButton(gT('Search','unescaped'), array('class'=>'btn btn-success')); ?>
Expand Down Expand Up @@ -71,6 +73,14 @@
'htmlOptions' => array('class' => 'hidden-xs'),
),

array(
'header' => gT('Active'),
'name' => 'running',
'value'=>'$data->running',
'type'=>'raw',
'htmlOptions' => array('class' => 'hidden-xs'),
),

array(
'header' => gT('Title'),
'name' => 'title',
Expand Down Expand Up @@ -99,13 +109,6 @@
'htmlOptions' => array('class' => 'hidden-xs'),
),

array(
'header' => gT('Running'),
'name' => 'running',
'value'=>'$data->running',
'type'=>'raw',
'htmlOptions' => array('class' => 'hidden-xs'),
),

array(
'header' => gT('Partial'),
Expand Down

0 comments on commit 9d623e1

Please sign in to comment.