Skip to content

Commit

Permalink
Fixed issue #6567: Performance issue
Browse files Browse the repository at this point in the history
Dev This commit changes the way attributes are extracted for superadmins only
  • Loading branch information
aniesshsethh committed Oct 30, 2012
1 parent 5b710ca commit b8a1073
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
24 changes: 8 additions & 16 deletions application/controllers/admin/participantsaction.php
Expand Up @@ -988,31 +988,23 @@ function getParticipants_json()
//If super admin all the participants will be visible
if (Yii::app()->session['USER_RIGHT_SUPERADMIN'])
{
$records = Participants::model()->getParticipants($page, $limit);
$records = Participants::model()->getParticipants($page, $limit,$attid);

$aData = new stdClass;
$aData->page = $page;
$aData->records = Participants::model()->count();
$aData->total = ceil($aData->records / $limit);
$i = 0;
$sortablearray=array();
foreach ($records as $key => $row)
{
$username = User::model()->getName($row['owner_uid']); //for conversion of uid to human readable names
{
$surveycount = Participants::model()->getSurveyCount($row['participant_id']);
$sortablearray[$i] = array($row['participant_id'], "true", $row['firstname'], $row['lastname'], $row['email'], $row['blacklisted'], $surveycount, $row['language'], $username[0]['full_name']); // since it's the admin he has access to all editing on the participants inspite of what can_edit option is

foreach ($attid as $iAttributeId)
$sortablearray[$i] = array($row['participant_id'], "true", $row['firstname'], $row['lastname'], $row['email'], $row['blacklisted'], $surveycount, $row['language'], $row['ownername']); // since it's the admin he has access to all editing on the participants inspite of what can_edit option is
unset($row['participant_id'], $row['firstname'], $row['lastname'], $row['email'], $row['blacklisted'], $row['language'],$row['ownername'],$row['owner_uid']);
foreach($row as $key=>$attvalue)
{
$answer = ParticipantAttributeNames::model()->getAttributeValue($row['participant_id'], $iAttributeId['attribute_id']);
if (isset($answer['value']))
{
array_push($sortablearray[$i], $answer['value']);
}
else
{
array_push($sortablearray[$i], "");
}
}
array_push($sortablearray[$i], $attvalue);
}
$i++;
}

Expand Down
22 changes: 19 additions & 3 deletions application/models/Participants.php
Expand Up @@ -205,11 +205,27 @@ function getParticipantsSharedCount($userid)
return count(Yii::app()->db->createCommand()->select('{{participants}}.*, {{participant_shares}}.*')->from('{{participants}}')->join('{{participant_shares}}', '{{participant_shares}}.participant_id = {{participants}}.participant_id')->where('owner_uid = :userid')->bindParam(":userid", $userid, PDO::PARAM_INT)->queryAll());
}

function getParticipants($page, $limit)
function getParticipants($page, $limit,$attid)
{
$start = $limit * $page - $limit;
$data = Yii::app()->db->createCommand()->select('*')->from('{{participants}}')->limit($limit, $start)->queryAll();
return $data;
$selectValue = array();
$joinValue = array();
array_push($selectValue,"p.*");
array_push($selectValue,"luser.full_name as ownername");
array_push($joinValue,"left join lime_users luser ON luser.uid=p.owner_uid");
foreach($attid as $key=>$attid)
{
$attid = $attid['attribute_id'];
array_push($selectValue,"attribute".$attid.".value as a".$attid);
array_push($joinValue,"LEFT JOIN {{participant_attribute}} attribute".$attid." ON attribute".$attid.".participant_id=p.participant_id AND attribute".$attid.".attribute_id=".$attid);
}
$data = Yii::app()->db->createCommand()
->select($selectValue)
->from('{{participants}} p')
->limit($limit, $start);
$data->setJoin($joinValue);
$allData = $data->queryAll();
return $allData;
}

function getSurveyCount($participant_id)
Expand Down

0 comments on commit b8a1073

Please sign in to comment.