diff --git a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitMembersApiController.php b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitMembersApiController.php index c9a04424..6465f7b4 100644 --- a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitMembersApiController.php +++ b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitMembersApiController.php @@ -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) { diff --git a/app/Http/Utils/CSV/CSVExporter.php b/app/Http/Utils/CSV/CSVExporter.php index 3089a063..0e373e82 100644 --- a/app/Http/Utils/CSV/CSVExporter.php +++ b/app/Http/Utils/CSV/CSVExporter.php @@ -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); diff --git a/app/Http/Utils/CSV/CurrentAffiliationsCellFormatter.php b/app/Http/Utils/CSV/CurrentAffiliationsCellFormatter.php new file mode 100644 index 00000000..5bf536de --- /dev/null +++ b/app/Http/Utils/CSV/CurrentAffiliationsCellFormatter.php @@ -0,0 +1,40 @@ + '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];