Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed issue #9961: LS3 - Add response to series: loops back to respon…
…se table
  • Loading branch information
SamMousa committed Oct 21, 2015
1 parent bf2fa60 commit 3d28334
Show file tree
Hide file tree
Showing 49 changed files with 430 additions and 953 deletions.
13 changes: 1 addition & 12 deletions protected/components/SurveySession.php
Expand Up @@ -50,7 +50,6 @@ class SurveySession extends \CComponent
protected $_maxStep = 0;
protected $_templateDir;
protected $_postKey;
protected $_finished = false;
/**
* This is used to decide if we should display errors.
* It gets reset when changing the step.
Expand Down Expand Up @@ -88,24 +87,14 @@ public function getResponseId()

public function getIsFinished()
{
return $this->_finished;
}

public function setIsFinished($value)
{
$this->_finished = $value;
return $this->response->getIsFinished();
}

public function getToken()
{
return $this->_response->getToken();
}

public function setToken($value)
{
$this->_token = $value;
}

public function getLanguage()
{
return $this->_language;
Expand Down
3 changes: 2 additions & 1 deletion protected/components/SurveySessionManager.php
Expand Up @@ -92,7 +92,8 @@ public function newSession($surveyId, \ls\interfaces\iResponse $response)

foreach ($this->sessions as $session) {
if ($session->getSurveyId() == $surveyId && $session->getResponseId() == $response->getId()) {
throw new \Exception("Duplicate session detected.");
$this->_current = $session;
return $this->current;
}
}
// Doesn't really need to be random
Expand Down
63 changes: 31 additions & 32 deletions protected/controllers/Controller.php
Expand Up @@ -21,52 +21,52 @@ abstract class Controller extends \CController
* @var Array of active menus, keys are the menu names, values will be passed to the view.
*/
public $menus = [];

/**
* This array contains the survey / group / question id used by the menu widget.
* @var array
*/
public $navData = [];
/**
* Basic initialiser to the base controller class
*
* @access public
* @param string $id
* @param CWebModule $module
* @return void
*/
public function __construct($id, $module = null)
{
parent::__construct($id, $module);
/**
* Basic initialiser to the base controller class
*
* @access public
* @param string $id
* @param CWebModule $module
* @return void
*/
public function __construct($id, $module = null)
{
parent::__construct($id, $module);

Yii::app()->session->init();
$this->_init();
}
$this->_init();
}

public function accessRules() {
return array_merge([
['allow', 'roles' => ['superadmin']],
['deny']
], parent::accessRules());
}

protected function _init()
{
enforceSSLMode();// This really should be at the top but for it to utilise \ls\models\SettingGlobal::get() it has to be here

//SET LOCAL TIME
$timeadjust = Yii::app()->getConfig("timeadjust");
if (substr($timeadjust,0,1)!='-' && substr($timeadjust,0,1)!='+') {$timeadjust='+'.$timeadjust;}
if (strpos($timeadjust,'hours')===false && strpos($timeadjust,'minutes')===false && strpos($timeadjust,'days')===false)
{
Yii::app()->setConfig("timeadjust",$timeadjust.' hours');
}


protected function _init()
{
enforceSSLMode();// This really should be at the top but for it to utilise \ls\models\SettingGlobal::get() it has to be here


//SET LOCAL TIME
$timeadjust = Yii::app()->getConfig("timeadjust");
if (substr($timeadjust,0,1)!='-' && substr($timeadjust,0,1)!='+') {$timeadjust='+'.$timeadjust;}
if (strpos($timeadjust,'hours')===false && strpos($timeadjust,'minutes')===false && strpos($timeadjust,'days')===false)
{
Yii::app()->setConfig("timeadjust",$timeadjust.' hours');
}

Yii::app()->setConfig('adminimageurl', Yii::app()->getConfig('styleurl').Yii::app()->getConfig('admintheme').'/images/');
Yii::app()->setConfig('adminstyleurl', Yii::app()->getConfig('styleurl').Yii::app()->getConfig('admintheme').'/');
}
}

/**
* Base implementation for load model.
Expand All @@ -88,7 +88,7 @@ public function loadModel($id) {
} else {
throw new \Exception("Override loadModel when using a non standard class.");
}

}

public function getActionParams()
Expand Down Expand Up @@ -130,7 +130,6 @@ protected function createActionFromMap($actionMap, $actionID, $requestActionID,
{
$result = parent::createActionFromMap($actionMap, $actionID, $requestActionID, $config);
if (!isset($result)) {

$class = __NAMESPACE__ . "\\{$this->id}\\" . ucfirst($actionID);
if (class_exists($class)) {
$result = Yii::createComponent(['class' => $class], $this, $requestActionID);
Expand Down
23 changes: 18 additions & 5 deletions protected/controllers/ResponsesController.php
Expand Up @@ -129,7 +129,7 @@ public function actionView($id, $surveyId)

/**
* This function appends a new response to the series of the response id given.
* If the current seriwe hees_id is set to null it's initialized to 0.
* If the current series_id is set to null it's initialized to 0.
*
* @param int $surveyId
* @param string $id
Expand All @@ -139,13 +139,26 @@ public function actionAppend($surveyId, $id, $copy = false)
{
$response = \ls\models\Response::model($surveyId)->findByPk($id);
$newResponse = $response->append($copy);
$newResponse->markAsUnFinished();
$newResponse->save();
$this->redirect(['responses/index', 'id' => $surveyId]);

$this->redirect(['responses/update', 'id' => $newResponse->getId(), 'surveyId' => $surveyId]);
}


public function actionUpdate($id, $surveyId) {
$_SESSION['survey_'.$surveyId]['srid'] = $id;
$this->redirect(['survey/index', 'sid' => $surveyId]);
public function actionUpdate($id, $surveyId)
{
/** @var \ls\models\Survey $survey */
$survey = Survey::model()->findByPk($surveyId);
$this->layout = 'showsurvey';
if (!$survey->isActive) {
throw new \CHttpException(412, gT("The survey is not active."));
} elseif ($survey->bool_usetokens
&& null === $response = \ls\models\Response::model($surveyId)->findByPk($id)
) {
throw new \CHttpException(404, gT("Response not found."));
}

$this->redirect(['surveys/run', 'SSM' => App()->surveySessionManager->newSession($survey->primaryKey, $response)->getId()]);
}
}
84 changes: 0 additions & 84 deletions protected/controllers/SurveyController.php

This file was deleted.

14 changes: 7 additions & 7 deletions protected/controllers/SurveysController.php
Expand Up @@ -34,10 +34,11 @@ public function actionOrganize($surveyId)
}


public function actionUpdate($id) {
public function actionUpdate($id)
{
$survey = $this->loadModel($id, 'groups.questions');

if (App()->request->isPostRequest && isset($survey)) {
if (App()->request->isPutRequest) {
$survey->setAttributes(App()->request->getParam(\CHtml::modelName($survey)));
if ($survey->save(true)) {
App()->user->setFlash('success', gT("Survey settings updated."));
Expand All @@ -51,7 +52,8 @@ public function actionUpdate($id) {
eP('render');
}

public function actionActivate($id) {
public function actionActivate($id)
{
$this->layout = 'survey';
$survey = $this->loadModel($id);
if (App()->request->isPostRequest) {
Expand Down Expand Up @@ -150,9 +152,6 @@ public function actionStart($id, $token = null, array $pre = [])
$response->save();

$session = App()->surveySessionManager->newSession($survey->primaryKey, $response);
if (isset($token)) {
$session->setToken($token);
}

$this->redirect(['survey/index', 'SSM' => $session->getId()]);
} else {
Expand Down Expand Up @@ -363,7 +362,8 @@ public function actionScript($id) {
echo $result;
}

public function actionPreview($id) {
public function actionPreview($id)
{
$survey = $this->loadModel($id);
$dummy = new \ls\models\DummyResponse($survey);
$session = App()->surveySessionManager->newSession($survey->primaryKey, $dummy);
Expand Down
19 changes: 19 additions & 0 deletions protected/controllers/surveys/Completed.php
@@ -0,0 +1,19 @@
<?php
namespace ls\controllers\surveys;

use ls\models\Survey;

class Completed extends \Action
{
/**
* Renders the completed page.
*/
public function run()
{
$session = App()->surveySessionManager->current;
if ($session->isFinished) {
echo "Good job you are done with the survey!";
}
}

}

0 comments on commit 3d28334

Please sign in to comment.