Skip to content

Commit

Permalink
Fixed issue #06515 - Central Participant Database on deleint particip…
Browse files Browse the repository at this point in the history
…ant not all data is erased
  • Loading branch information
jcleeland committed Aug 23, 2012
1 parent 35683ee commit 812cb7c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
6 changes: 3 additions & 3 deletions application/controllers/admin/participantsaction.php
Expand Up @@ -359,8 +359,8 @@ function delParticipant()
{
$selectoption = Yii::app()->request->getPost('selectedoption');
$iParticipantId = Yii::app()->request->getPost('participant_id');
//echo $selectoption." -- ".$iParticipantId."<br />";
//die();

//echo $selectoption." -- ".$iParticipantId."<br />"; die();

// Deletes from participants only
if ($selectoption == 'po')
Expand All @@ -373,7 +373,7 @@ function delParticipant()
Participants::model()->deleteParticipantToken($iParticipantId);
}
// Deletes from central , token and assosiated responses as well
else
elseif ($selectoption == 'ptta')
{
Participants::model()->deleteParticipantTokenAnswer($iParticipantId);
}
Expand Down
46 changes: 34 additions & 12 deletions application/models/Participants.php
Expand Up @@ -245,23 +245,26 @@ function deleteParticipantToken($rows)
/* This function deletes the participant from the participants table,
the participant from any tokens table they're in (using the survey_links table to find them)
and then all the participants attributes. */

$rowid = explode(",", $rows);
foreach ($rowid as $row)
{
$tokens = Yii::app()->db->createCommand()->select('*')->from('{{survey_links}}')->where('participant_id = "' . $row .'"')->queryAll();

foreach ($tokens as $key => $value)
{
if (Yii::app()->db->schema->getTable('tokens_' . intval($value['survey_id'])))
$tokentable='{{tokens_'.intval($value['survey_id']).'}}';

if (Yii::app()->db->schema->getTable($tokentable))
{
Yii::app()->db->createCommand()->delete(Tokens::model()->tableName(), array('in', 'participant_id', $row));
Yii::app()->db->createCommand()
->delete('{{tokens_' . intval($value['survey_id']) . '}}', 'participant_id = "' . $row . '"'); // Deletes matching token table entries
//Yii::app()->db->createCommand()->delete(Tokens::model()->tableName(), array('in', 'participant_id', $row));
}
}

Yii::app()->db->createCommand()->delete(Participants::model()->tableName(), array('in', 'participant_id', $row));
Yii::app()->db->createCommand()->delete(Survey_links::model()->tableName(), array('in', 'participant_id', $row));
Yii::app()->db->createCommand()->delete(Participant_attribute::model()->tableName(), array('in', 'participant_id', $row));

}
}

Expand All @@ -275,24 +278,43 @@ function deleteParticipantTokenAnswer($rows)
foreach ($rowid as $row)
{
//ORIGINAL LINE: $tokens = Yii::app()->db->createCommand()->select('*')->from('{{survey_links}}')->where('participant_id = "' . $row . '"')->queryAll();
$tokens = Yii::app()->db->createCommand()->select('*')->from('{{survey_links}}')->where('participant_id = :row')->bindParam(":row", $row, PDO::PARAM_INT)->queryAll();
$tokens = Yii::app()->db->createCommand()
->select('*')
->from('{{survey_links}}')
->where('participant_id = :row')
->bindParam(":row", $row, PDO::PARAM_INT)
->queryAll();

foreach ($tokens as $key => $value)
{
if (Yii::app()->db->schema->getTable('tokens_' . Yii::app()->db->quoteValue($value['survey_id'])))
$tokentable='{{tokens_'.intval($value['survey_id']).'}}';
if (Yii::app()->db->schema->getTable($tokentable))
{
$tokenid = Yii::app()->db->createCommand()->select('token')->from('{{tokens_' . intval($value['survey_id']) . '}}')->where('participant_id = "' . $value['participant_id'] . '"')->queryAll();
$tokenid = Yii::app()->db->createCommand()
->select('token')
->from('{{tokens_' . intval($value['survey_id']) . '}}')
->where('participant_id = "' . $value['participant_id'] . '"')
->queryAll();
$token = $tokenid[0];
if (Yii::app()->db->schema->getTable('survey_' . intval($value['survey_id'])))
$surveytable='{{survey_'.intval($value['survey_id']).'}}';
if ($datas=Yii::app()->db->schema->getTable($surveytable))
{
if (!empty($token['token']))
if (!empty($token['token']) && isset($datas->columns['token'])) //Make sure we have a token value, and that tokens are used to link to the survey
{
$gettoken = Yii::app()->db->createCommand()->select('*')->from('{{survey_' . intval($value['survey_id']) . '}}')->where('token = :token')->bindParam(":token", $token['token'], PDO::PARAM_STR)->queryAll();
$gettoken = Yii::app()->db->createCommand()
->select('*')
->from('{{survey_' . intval($value['survey_id']) . '}}')
->where('token = :token')
->bindParam(":token", $token['token'], PDO::PARAM_STR)
->queryAll();
$gettoken = $gettoken[0];
Yii::app()->db->createCommand()->delete('{{survey_' . intval($value['survey_id']) . '}}', 'token = :token')->bindParam(":token", $gettoken['token'], PDO::PARAM_STR); // Deletes matching responses from surveys
Yii::app()->db->createCommand()
->delete('{{survey_' . intval($value['survey_id']) . '}}', 'token = :token')
->bindParam(":token", $gettoken['token'], PDO::PARAM_STR); // Deletes matching responses from surveys
}
}
Yii::app()->db->createCommand()->delete('{{tokens_' . intval($value['survey_id']) . '}}', 'participant_id = "' . $value['participant_id'] . '"'); // Deletes matching token table entries
Yii::app()->db->createCommand()
->delete('{{tokens_' . intval($value['survey_id']) . '}}', 'participant_id = "' . $value['participant_id'] . '"'); // Deletes matching token table entries
}
}
Yii::app()->db->createCommand()->delete(Participants::model()->tableName(), array('in', 'participant_id', $row));
Expand Down

0 comments on commit 812cb7c

Please sign in to comment.