Fixed used where exported answers data was inaccurate (closes #13)

This commit is contained in:
Dave Earley 2016-08-11 13:19:59 +01:00
parent 9e4d4a4520
commit 6d9433a45c
2 changed files with 70 additions and 45 deletions

View File

@ -64,7 +64,7 @@ class EventSurveyController extends MyBaseController
*
* @access public
* @param StoreEventQuestionRequest $request
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\JsonResponse
*/
public function postCreateEventQuestion(StoreEventQuestionRequest $request, $event_id)
{
@ -133,12 +133,12 @@ class EventSurveyController extends MyBaseController
/**
* Edits a question
* Edit a question
*
* @param Request $request
* @param $event_id
* @param $question_id
* @return mixed
* @return \Illuminate\Http\JsonResponse
*/
public function postEditEventQuestion(Request $request, $event_id, $question_id)
{
@ -173,9 +173,8 @@ class EventSurveyController extends MyBaseController
}
}
// Get tickets.
$ticket_ids = (array) $request->get('tickets');
$ticket_ids = (array)$request->get('tickets');
$question->tickets()->sync($ticket_ids);
@ -194,7 +193,7 @@ class EventSurveyController extends MyBaseController
*
* @param Request $request
* @param $event_id
* @return mixed
* @return \Illuminate\Http\JsonResponse
*/
public function postDeleteEventQuestion(Request $request, $event_id)
{
@ -250,16 +249,14 @@ class EventSurveyController extends MyBaseController
/**
* Export answers
* Export answers to xls, csv etc.
*
* @todo This doesn't work :-|
* @param Request $request
* @param $event_id
* @param string $export_as
*/
public function showExportAnswers(Request $request, $event_id, $export_as = 'xlsx')
{
Excel::create('answers-as-of-' . date('d-m-Y-g.i.a'), function ($excel) use ($event_id) {
$excel->setTitle('Survey Answers');
@ -272,26 +269,7 @@ class EventSurveyController extends MyBaseController
$event = Event::scope()->findOrFail($event_id);
$rows[] = array_merge([
'Order Ref',
'Attendee Name',
'Attendee Email',
'Attendee Ticket'
], $event->questions->lists('title')->toArray());
$attendees = $event->attendees()->has('answers')->get();
foreach ($attendees as $attendee) {
$rows[] = array_merge([
$attendee->order->order_reference,
$attendee->full_name,
$attendee->email,
$attendee->ticket->title
], $attendee->answers->lists('answer_text')->toArray());
}
$sheet->fromArray($rows);
$sheet->fromArray($event->survey_answers, null, 'A1', false, false);
// Set gray background on first row
$sheet->row(1, function ($row) {
@ -299,13 +277,18 @@ class EventSurveyController extends MyBaseController
});
});
})->export($export_as);
}
/**
* Toggle the enabled status of question
*
* @param Request $request
* @param $event_id
* @param $question_id
* @return \Illuminate\Http\JsonResponse
*/
public function postEnableQuestion(Request $request, $event_id, $question_id)
{
$question = Question::scope()->find($question_id);
$question->is_enabled = ($question->is_enabled == 1) ? 0 : 1;
@ -330,7 +313,7 @@ class EventSurveyController extends MyBaseController
* Updates the sort order of event questions
*
* @param Request $request
* @return mixed
* @return \Illuminate\Http\JsonResponse
*/
public function postUpdateQuestionsOrder(Request $request)
{

View File

@ -10,7 +10,7 @@ use URL;
class Event extends MyBaseModel
{
use SoftDeletes;
/**
* The validation rules.
*
@ -221,6 +221,48 @@ class Event extends MyBaseModel
return $this->currency->code;
}
/**
* Return an array of attendees and answers they gave to questions at checkout
*
* @return array
*/
public function getSurveyAnswersAttribute()
{
$rows[] = array_merge([
'Order Ref',
'Attendee Name',
'Attendee Email',
'Attendee Ticket'
], $this->questions->lists('title')->toArray());
$attendees = $this->attendees()->has('answers')->get();
foreach ($attendees as $attendee) {
$answers = [];
foreach ($this->questions as $question) {
if (in_array($question->id, $attendee->answers->lists('question_id')->toArray())) {
$answers[] = $attendee->answers->where('question_id', $question->id)->first()->answer_text;
} else {
$answers[] = null;
}
}
$rows[] = array_merge([
$attendee->order->order_reference,
$attendee->full_name,
$attendee->email,
$attendee->ticket->title
], $answers);
}
return $rows;
}
/**
* Get the embed html code.
*
@ -229,7 +271,7 @@ class Event extends MyBaseModel
public function getEmbedHtmlCodeAttribute()
{
return "<!--Attendize.com Ticketing Embed Code-->
<iframe style='overflow:hidden; min-height: 350px;' frameBorder='0' seamless='seamless' width='100%' height='100%' src='".$this->embed_url."' vspace='0' hspace='0' scrolling='auto' allowtransparency='true'></iframe>
<iframe style='overflow:hidden; min-height: 350px;' frameBorder='0' seamless='seamless' width='100%' height='100%' src='" . $this->embed_url . "' vspace='0' hspace='0' scrolling='auto' allowtransparency='true'></iframe>
<!--/Attendize.com Ticketing Embed Code-->";
}
@ -239,13 +281,13 @@ class Event extends MyBaseModel
*/
public function getMapAddressAttribute()
{
$string = $this->venue.','
.$this->location_street_number.','
.$this->location_address_line_1.','
.$this->location_address_line_2.','
.$this->location_state.','
.$this->location_post_code.','
.$this->location_country;
$string = $this->venue . ','
. $this->location_street_number . ','
. $this->location_address_line_1 . ','
. $this->location_address_line_2 . ','
. $this->location_state . ','
. $this->location_post_code . ','
. $this->location_country;
return urlencode($string);
}
@ -257,7 +299,7 @@ class Event extends MyBaseModel
*/
public function getBgImageUrlAttribute()
{
return URL::to('/').'/'.$this->bg_image_path;
return URL::to('/') . '/' . $this->bg_image_path;
}
/**
@ -267,7 +309,7 @@ class Event extends MyBaseModel
*/
public function getEventUrlAttribute()
{
return URL::to('/').'/e/'.$this->id.'/'.Str::slug($this->title);
return URL::to('/') . '/e/' . $this->id . '/' . Str::slug($this->title);
}
/**
@ -279,7 +321,7 @@ class Event extends MyBaseModel
{
return $this->sales_volume + $this->organiser_fees_volume;
}
/**
* The attributes that should be mutated to dates.
*