Fixed Members CSV
Change-Id: I99556606077283bb423897420310c5863bf6ecbf
This commit is contained in:
parent
79341d36ab
commit
dd7c6b5ff1
@ -11,6 +11,8 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
use App\Http\Utils\CurrentAffiliationsCellFormatter;
|
||||
use App\Http\Utils\EpochCellFormatter;
|
||||
use App\Http\Utils\PagingConstants;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
@ -548,6 +550,29 @@ final class OAuth2SummitMembersApiController extends OAuth2ProtectedController
|
||||
public function getAllBySummitCSV($summit_id){
|
||||
$values = Input::all();
|
||||
|
||||
$allowed_columns = [
|
||||
"id",
|
||||
"created",
|
||||
"last_edited",
|
||||
"first_name",
|
||||
"last_name",
|
||||
"email",
|
||||
"country",
|
||||
"gender",
|
||||
"github_user",
|
||||
"bio",
|
||||
"linked_in",
|
||||
"irc",
|
||||
"twitter",
|
||||
"state",
|
||||
"country",
|
||||
"active",
|
||||
"email_verified",
|
||||
"pic",
|
||||
"affiliations",
|
||||
"groups"
|
||||
];
|
||||
|
||||
$rules = [
|
||||
];
|
||||
|
||||
@ -635,7 +660,18 @@ final class OAuth2SummitMembersApiController extends OAuth2ProtectedController
|
||||
$relations = Request::input('relations', '');
|
||||
$relations = !empty($relations) ? explode(',', $relations) : [];
|
||||
|
||||
$list = $data->toArray
|
||||
$columns_param = Input::get("columns", "");
|
||||
$columns = [];
|
||||
if(!empty($columns_param))
|
||||
$columns = explode(',', $columns_param);
|
||||
$diff = array_diff($columns, $allowed_columns);
|
||||
if(count($diff) > 0){
|
||||
throw new ValidationException(sprintf("columns %s are not allowed!", implode(",", $diff)));
|
||||
}
|
||||
if(empty($columns))
|
||||
$columns = $allowed_columns;
|
||||
|
||||
$list = $data->toArray
|
||||
(
|
||||
Request::input('expand', ''),
|
||||
$fields,
|
||||
@ -650,9 +686,11 @@ final class OAuth2SummitMembersApiController extends OAuth2ProtectedController
|
||||
$filename,
|
||||
$list['data'],
|
||||
[
|
||||
'created' => new EpochCellFormatter(),
|
||||
'last_edited' => new EpochCellFormatter(),
|
||||
]
|
||||
'created' => new EpochCellFormatter(),
|
||||
'last_edited' => new EpochCellFormatter(),
|
||||
'affiliations' => new CurrentAffiliationsCellFormatter(),
|
||||
],
|
||||
$columns
|
||||
);
|
||||
}
|
||||
catch (EntityNotFoundException $ex1) {
|
||||
|
@ -65,6 +65,7 @@ final class CSVExporter
|
||||
$val = isset($row[$key])? $row[$key] : '';
|
||||
if(isset($formatters[$key]))
|
||||
$val = $formatters[$key]->format($val);
|
||||
if(is_array($val)) $val = '';
|
||||
$values[] = $val;
|
||||
}
|
||||
$output .= implode($field_separator, $values) . PHP_EOL;;
|
||||
@ -75,7 +76,7 @@ final class CSVExporter
|
||||
function cleanData(&$str)
|
||||
{
|
||||
if (is_null($str)) {$str = ''; return;};
|
||||
if (is_array($str)) {$str = ''; return;};
|
||||
if (is_array($str)) {return;};
|
||||
$str = preg_replace("/\t/", "\\t", $str);
|
||||
$str = preg_replace("/\r?\n/", "\\n", $str);
|
||||
$str = preg_replace("/,/", "-", $str);
|
||||
|
40
app/Http/Utils/CSV/CurrentAffiliationsCellFormatter.php
Normal file
40
app/Http/Utils/CSV/CurrentAffiliationsCellFormatter.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php namespace App\Http\Utils;
|
||||
/**
|
||||
* Copyright 2019 OpenStack Foundation
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
/**
|
||||
* Class CurrentAffiliationsCellFormatter
|
||||
* @package App\Http\Utils
|
||||
*/
|
||||
final class CurrentAffiliationsCellFormatter implements ICellFormatter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param string $val
|
||||
* @return string
|
||||
*/
|
||||
public function format($val)
|
||||
{
|
||||
$res = "";
|
||||
foreach ($val as $affiliation){
|
||||
if(!isset($affiliation['is_current'])) continue;
|
||||
if(boolval($affiliation['is_current']) == false) continue;
|
||||
if(!isset($affiliation['organization'])) continue;
|
||||
$organization = $affiliation['organization'];
|
||||
if(!empty($res))
|
||||
$res .= '|';
|
||||
$res .= $organization['name'];
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
}
|
@ -1349,7 +1349,8 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
|
||||
|
||||
'expand' => 'attendee,speaker,feedback,groups,presentations',
|
||||
'id' => $summit_id,
|
||||
'filter' => 'schedule_event_id==23828'
|
||||
'filter' => 'schedule_event_id==24015',
|
||||
'columns' => 'id,first_name,last_name,email,affiliations',
|
||||
];
|
||||
|
||||
$headers = ["HTTP_Authorization" => " Bearer " . $this->access_token];
|
||||
|
Loading…
x
Reference in New Issue
Block a user