Update params on get promocodes (CVS)
GET /api/v1/summits/{id}/promo-codes/csv expand: new values owner_name,owner_email,sponsor_name columns: new param posible values $allowed_columns = [ "id", "created", "last_edited", "code", "redeemed", "email_sent", "source", "summit_id", "creator_id", "class_name", "type", "speaker_id", "owner_name", "owner_email", "sponsor_name" ]; Change-Id: Ie51041077b277eb73f97df09c817573692aee043
This commit is contained in:
parent
86d1615a8f
commit
1539d2cd51
@ -210,7 +210,23 @@ final class OAuth2SummitPromoCodesApiController extends OAuth2ProtectedControlle
|
|||||||
*/
|
*/
|
||||||
public function getAllBySummitCSV($summit_id){
|
public function getAllBySummitCSV($summit_id){
|
||||||
$values = Input::all();
|
$values = Input::all();
|
||||||
$rules = [
|
$rules = [];
|
||||||
|
$allowed_columns = [
|
||||||
|
"id",
|
||||||
|
"created",
|
||||||
|
"last_edited",
|
||||||
|
"code",
|
||||||
|
"redeemed",
|
||||||
|
"email_sent",
|
||||||
|
"source",
|
||||||
|
"summit_id",
|
||||||
|
"creator_id",
|
||||||
|
"class_name",
|
||||||
|
"type",
|
||||||
|
"speaker_id",
|
||||||
|
"owner_name",
|
||||||
|
"owner_email",
|
||||||
|
"sponsor_name"
|
||||||
];
|
];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -281,10 +297,19 @@ final class OAuth2SummitPromoCodesApiController extends OAuth2ProtectedControlle
|
|||||||
'code',
|
'code',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
$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)));
|
||||||
|
}
|
||||||
|
|
||||||
$data = $this->promo_code_repository->getBySummit($summit, new PagingInfo($page, $per_page), $filter, $order);
|
$data = $this->promo_code_repository->getBySummit($summit, new PagingInfo($page, $per_page), $filter, $order);
|
||||||
$filename = "promocodes-" . date('Ymd');
|
$filename = "promocodes-" . date('Ymd');
|
||||||
$list = $data->toArray();
|
$list = $data->toArray(Input::get("expand", ""));
|
||||||
|
|
||||||
return $this->export
|
return $this->export
|
||||||
(
|
(
|
||||||
'csv',
|
'csv',
|
||||||
@ -295,9 +320,9 @@ final class OAuth2SummitPromoCodesApiController extends OAuth2ProtectedControlle
|
|||||||
'last_edited' => new EpochCellFormatter,
|
'last_edited' => new EpochCellFormatter,
|
||||||
'redeemed' => new BooleanCellFormatter,
|
'redeemed' => new BooleanCellFormatter,
|
||||||
'email_sent' => new BooleanCellFormatter,
|
'email_sent' => new BooleanCellFormatter,
|
||||||
]
|
],
|
||||||
|
$columns
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (ValidationException $ex1)
|
catch (ValidationException $ex1)
|
||||||
{
|
{
|
||||||
|
@ -127,10 +127,11 @@ abstract class JsonController extends Controller
|
|||||||
* @param string $filename
|
* @param string $filename
|
||||||
* @param array $items
|
* @param array $items
|
||||||
* @param array $formatters
|
* @param array $formatters
|
||||||
|
* @param array $columns
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
protected function export($format, $filename, array $items, array $formatters = []){
|
protected function export($format, $filename, array $items, array $formatters = [], array $columns = []){
|
||||||
if($format == 'csv') return $this->csv($filename, $items, $formatters);
|
if($format == 'csv') return $this->csv($filename, $items, $formatters, ",", 'application/vnd.ms-excel', $columns);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -139,9 +140,10 @@ abstract class JsonController extends Controller
|
|||||||
* @param array $formatters
|
* @param array $formatters
|
||||||
* @param string $field_separator
|
* @param string $field_separator
|
||||||
* @param string $mime_type
|
* @param string $mime_type
|
||||||
|
* @param array $columns
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
private function csv($filename, array $items, array $formatters = [], $field_separator = ",", $mime_type = 'application/vnd.ms-excel'){
|
private function csv($filename, array $items, array $formatters = [], $field_separator = ",", $mime_type = 'application/vnd.ms-excel', array $columns = []){
|
||||||
$headers = [
|
$headers = [
|
||||||
'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0',
|
'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0',
|
||||||
'Content-type' => $mime_type,
|
'Content-type' => $mime_type,
|
||||||
@ -151,6 +153,6 @@ abstract class JsonController extends Controller
|
|||||||
'Pragma' => 'public',
|
'Pragma' => 'public',
|
||||||
];
|
];
|
||||||
|
|
||||||
return Response::make(CSVExporter::getInstance()->export($items, $field_separator, [] , $formatters), 200, $headers);
|
return Response::make(CSVExporter::getInstance()->export($items, $field_separator, $columns, $formatters), 200, $headers);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -60,6 +60,18 @@ class MemberSummitRegistrationPromoCodeSerializer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'owner_name': {
|
||||||
|
if($code->hasOwner()){
|
||||||
|
$values['owner_name'] = $code->getOwner()->getFullName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'owner_email': {
|
||||||
|
if($code->hasOwner()){
|
||||||
|
$values['owner_email'] = $code->getOwner()->getEmail();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,6 +56,18 @@ final class SpeakerSummitRegistrationPromoCodeSerializer
|
|||||||
)->serialize($expand);
|
)->serialize($expand);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case 'owner_name': {
|
||||||
|
if($code->hasSpeaker()){
|
||||||
|
$values['owner_name'] = $code->getSpeaker()->getFullName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'owner_email': {
|
||||||
|
if($code->hasSpeaker()){
|
||||||
|
$values['owner_email'] = $code->getSpeaker()->getEmail();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,10 @@ extends MemberSummitRegistrationPromoCodeSerializer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'sponsor_name':{
|
||||||
|
$values['sponsor_name'] = $code->getSponsor()->getName();
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,9 +82,11 @@ final class OAuth2PromoCodesApiTest extends ProtectedApiTest
|
|||||||
public function testGetPromoCodesByClassNameSpeakerSummitRegistrationPromoCodeCSV(){
|
public function testGetPromoCodesByClassNameSpeakerSummitRegistrationPromoCodeCSV(){
|
||||||
$params = [
|
$params = [
|
||||||
|
|
||||||
'id' => 23,
|
'id' => 25,
|
||||||
'filter' => 'class_name=='.\models\summit\SpeakerSummitRegistrationPromoCode::ClassName,
|
//'filter' => 'class_name=='.\models\summit\SpeakerSummitRegistrationPromoCode::ClassName,
|
||||||
'order' => '+code'
|
'order' => '+code',
|
||||||
|
'columns' => 'code,type,owner_name,owner_email,sponsor_name,redeemed,email_sent',
|
||||||
|
'expand' => 'owner_name,owner_email,sponsor_name',
|
||||||
];
|
];
|
||||||
|
|
||||||
$headers = [
|
$headers = [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user