Skip to content

Commit

Permalink
Dev: Move some code around (CPDB export)
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Dec 2, 2016
1 parent 5dbcf0f commit 2799d05
Showing 1 changed file with 37 additions and 29 deletions.
66 changes: 37 additions & 29 deletions application/controllers/admin/participantsaction.php
Expand Up @@ -225,6 +225,15 @@ private function csvExportFilter(CDataProvider $dataProvider, array $attributeId
$output = array();
$output[0] = $fields;

foreach ($attributeIds as $attributeId) {
if ($attributeId == 0) {
continue;
}
$fields[] = 'a'.$attributeId;
$attributename = ParticipantAttributeName::model()->getAttributeNames($attributeId);
$output[0][] = $attributename[0]['attribute_name'];
}

$fieldNeededKeys = array_fill_keys($fields, '');
$fieldKeys = array_flip($fields);

Expand Down Expand Up @@ -1114,45 +1123,44 @@ public function exporttocsv()
{
$this->checkPermission('export');

$filteredOrSelected = Yii::app()->request->getPost('filteredOrSelected');

if (Yii::app()->request->getPost('searchcondition','') !== '') // if there is a search condition then only the participants that match the search criteria are counted
{
$condition = explode("%7C%7C", Yii::app()->request->getPost('searchcondition',''));
$search = Participant::model()->getParticipantsSearchMultipleCondition($condition);
}
else
{
$search = null;
}

$chosenParticipants = Yii::app()->request->getPost('selectedParticipant');
$chosenParticipantsArray = explode(',',$chosenParticipants);
$searchSelected = new CDbCriteria;
if(!empty($chosenParticipants)) {
$searchSelected->addInCondition("p.participant_id",$chosenParticipantsArray);
}
else {
$searchSelected = null;
}

if($search) {
$search->mergeWith($searchSelected);
}
else {
$search = $searchSelected;
}
$useGridViewFilter = Yii::app()->request->getPost('filteredOrSelected') == 'filtered';

$aAttributes = explode('+', Yii::app()->request->getPost('attributes', ''));

if ($filteredOrSelected == 'filtered') {
if ($useGridViewFilter) {
$p = new Participant();
$p->setAttributes(Yii::app()->request->getPost('Participant'));
$dataProvider = $p->search();
$dataProvider->setPagination(false);
$this->csvExportFilter($dataProvider, $aAttributes);
}
else {
// if there is a search condition then only the participants that match the search criteria are counted
if (Yii::app()->request->getPost('searchcondition','') !== '') {
$condition = explode("%7C%7C", Yii::app()->request->getPost('searchcondition',''));
$search = Participant::model()->getParticipantsSearchMultipleCondition($condition);
}
else {
$search = null;
}

$chosenParticipants = Yii::app()->request->getPost('selectedParticipant');
$chosenParticipantsArray = explode(',',$chosenParticipants);
$searchSelected = new CDbCriteria;
if(!empty($chosenParticipants)) {
$searchSelected->addInCondition("p.participant_id",$chosenParticipantsArray);
}
else {
$searchSelected = null;
}

if($search) {
$search->mergeWith($searchSelected);
}
else {
$search = $searchSelected;
}

$this->csvExport($search, $aAttributes);
}
}
Expand Down

0 comments on commit 2799d05

Please sign in to comment.