Skip to content

Commit

Permalink
Dev: Some whitespace fixes in SurveyActivator
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Mar 11, 2020
1 parent 738652e commit 6e694ee
Showing 1 changed file with 23 additions and 33 deletions.
56 changes: 23 additions & 33 deletions application/models/SurveyActivator.php
@@ -1,30 +1,34 @@
<?php


class SurveyActivator
{
/** @var Survey */
protected $survey;

/** @var array */
protected $tableDefinition = [];

/** @var array */
protected $timingsTableDefinition = [];

/** @var array */
protected $fieldMap;

/** @var string */
protected $collation;

/** @var PluginEvent */
protected $event;

/** @var string */
protected $error;

/** @var bool */
protected $createSurveyDir = false;


/** @var boolean */
public $isSimulation;


/**
* @param Survey $survey
*/
Expand All @@ -39,7 +43,6 @@ public function __construct($survey)
*/
public function activate()
{

$this->event = new PluginEvent('beforeSurveyActivate');
$this->event->set('surveyId', $this->survey->primaryKey);
$this->event->set('simulate', $this->isSimulation);
Expand Down Expand Up @@ -70,10 +73,10 @@ public function activate()
}

Yii::app()->db->createCommand()->update(
Survey::model()->tableName(),
['active'=>'Y'], 'sid=:sid',
[':sid'=>$this->survey->primaryKey]
);
Survey::model()->tableName(),
['active'=>'Y'], 'sid=:sid',
[':sid'=>$this->survey->primaryKey]
);

$aResult = array(
'status' => 'OK',
Expand All @@ -86,8 +89,6 @@ public function activate()
return $aResult;
}



/**
* For each question, create the appropriate field(s)
* @return void
Expand All @@ -96,7 +97,7 @@ protected function prepareTableDefinition()
{
$sFieldMap = $this->fieldMap;

foreach ($sFieldMap as $j=>$aRow) {
foreach ($sFieldMap as $aRow) {
switch ($aRow['type']) {
case 'seed':
$aTableDefinition[$aRow['fieldname']] = "string(31)";
Expand Down Expand Up @@ -211,7 +212,6 @@ protected function prepareTableDefinition()
}
}
$this->tableDefinition = $aTableDefinition;

}

/**
Expand All @@ -222,14 +222,12 @@ protected function prepareTimingsTable()
$timingsfieldmap = createTimingsFieldMap($this->survey->primaryKey, "full", false, false, $this->survey->language);
$aTimingTableDefinition = array();
$aTimingTableDefinition['id'] = $this->tableDefinition['id'];
foreach ($timingsfieldmap as $field=>$fielddata) {
foreach ($timingsfieldmap as $field => $fielddata) {
$aTimingTableDefinition[$field] = 'FLOAT';
}
$this->timingsTableDefinition = $aTimingTableDefinition;
}



/**
* @return void
*/
Expand All @@ -245,7 +243,6 @@ protected function prepareCollation()
}
}


/**
* @return void
*/
Expand All @@ -262,10 +259,8 @@ protected function prepareSimulateQuery()
$arrSim[] = array($type);
$this->tableDefinition = $arrSim;
}

}


/**
* @return void
*/
Expand All @@ -280,7 +275,6 @@ protected function prepareResponsesTable()
$this->prepareSimulateQuery();
}


/**
* @return boolean
* @throws CDbException
Expand All @@ -292,7 +286,8 @@ protected function createParticipantsTable()
Yii::app()->loadHelper("database");
try {
Yii::app()->db->createCommand()->createTable($sTableName, $this->tableDefinition);
Yii::app()->db->schema->getTable($sTableName, true); // Refresh schema cache just in case the table existed in the past
// Refresh schema cache just in case the table existed in the past
Yii::app()->db->schema->getTable($sTableName, true);
} catch (Exception $e) {
if (App()->getConfig('debug')) {
$this->error = $e->getMessage();
Expand All @@ -302,18 +297,16 @@ protected function createParticipantsTable()
return false;
}
try {
if (isset($aTableDefinition['token'])) {
if (isset($this->tableDefinition['token'])) {
Yii::app()->db->createCommand()->createIndex("idx_survey_token_{$this->survey->primaryKey}_".rand(1, 50000), $sTableName, 'token');
}
} catch (\Exception $e) {
}

$this->createParticipantsTableKeys();
return true;

}


/**
* @return boolean
*/
Expand All @@ -325,11 +318,10 @@ protected function showEventMessages()
if ($success === false) {
Yii::app()->user->setFlash('error', $message);
return false;
} else if (!empty($message)) {
} elseif (!empty($message)) {
Yii::app()->user->setFlash('info', $message);
}
return true;

}

/**
Expand Down Expand Up @@ -364,7 +356,6 @@ protected function createParticipantsTableKeys()
@Yii::app()->db->createCommand($sQuery)->execute();
}
}

}

/**
Expand All @@ -377,16 +368,15 @@ protected function createTimingsTable()
$sTableName = $this->survey->timingsTableName;
try {
Yii::app()->db->createCommand()->createTable($sTableName, $this->timingsTableDefinition);
Yii::app()->db->schema->getTable($sTableName, true); // Refresh schema cache just in case the table existed in the past
// Refresh schema cache just in case the table existed in the past
Yii::app()->db->schema->getTable($sTableName, true);
} catch (\Exception $e) {
throw $e;
}

}
return true;
}


/**
* @return bool
*/
Expand All @@ -404,21 +394,21 @@ protected function createSurveyDirectory()
}
}
return true;

}

/**
* Set the default_storage_engine for mysql DB
* @param string $dbEngine
*/
private function setMySQLDefaultEngine($dbEngine) {
private function setMySQLDefaultEngine($dbEngine)
{
/* empty dbEngine : out */
if(empty($dbEngine)) {
if (empty($dbEngine)) {
return;
}
$db = Yii::app()->db;
/* not DB : out */
if(empty($db)) {
if (empty($db)) {
return;
}
/* not mysql : out */
Expand Down

0 comments on commit 6e694ee

Please sign in to comment.