diff --git a/application/controllers/admin/participantsaction.php b/application/controllers/admin/participantsaction.php index 8801d4e6397..85e42d19c61 100644 --- a/application/controllers/admin/participantsaction.php +++ b/application/controllers/admin/participantsaction.php @@ -1039,7 +1039,7 @@ function subval_sort($a, $subkey, $order) $page = Yii::app()->request->getPost('page'); $limit = Yii::app()->request->getPost('rows'); - $limit = isset($limit) ? $limit : 50; //Stop division by zero errors + $limit = isset($limit) ? $limit : 50; //Stop division by zero errors $attid = ParticipantAttributeNames::model()->getVisibleAttributes(); $participantfields = array('participant_id', 'can_edit', 'firstname', 'lastname', 'email', 'blacklisted', 'survey', 'language', 'owner_uid'); @@ -1051,35 +1051,27 @@ function subval_sort($a, $subkey, $order) //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 + $sortablearray=array(); + foreach ($records as $key => $row) + { $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++; } $indexsort = array_search(Yii::app()->request->getPost('sidx'), $participantfields); - if(!empty($sortablearray)) { + if(!empty($sortablearray)) { $sortedarray = subval_sort($sortablearray, $indexsort, Yii::app()->request->getPost('sord')); $i = 0; $count = count($sortedarray[0]); diff --git a/application/models/Participants.php b/application/models/Participants.php index fc80f6cd986..8a4060aaff8 100644 --- a/application/models/Participants.php +++ b/application/models/Participants.php @@ -205,11 +205,28 @@ 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)