diff --git a/app/Http/Controllers/MyBaseController.php b/app/Http/Controllers/MyBaseController.php index 64e5a29d..07f53b2e 100644 --- a/app/Http/Controllers/MyBaseController.php +++ b/app/Http/Controllers/MyBaseController.php @@ -28,6 +28,7 @@ class MyBaseController extends Controller 'is_confirmed' => Auth::user()->is_confirmed, ], 'DateTimeFormat' => config('attendize.default_date_picker_format'), + 'DateSeparator' => config('attendize.default_date_picker_seperator'), 'GenericErrorMessage' => trans("Controllers.whoops"), ]); /* diff --git a/app/Models/Event.php b/app/Models/Event.php index 7357097c..154986ef 100644 --- a/app/Models/Event.php +++ b/app/Models/Event.php @@ -16,18 +16,22 @@ class Event extends MyBaseModel /** * The validation rules. * - * @var array $rules + * @return array $rules */ - protected $rules = [ - 'title' => ['required'], - 'description' => ['required'], - 'location_venue_name' => ['required_without:venue_name_full'], - 'venue_name_full' => ['required_without:location_venue_name'], - 'start_date' => ['required|date'], - 'end_date' => ['required|date'], - 'organiser_name' => ['required_without:organiser_id'], - 'event_image' => ['mimes:jpeg,jpg,png', 'max:3000'], - ]; + public function rules() + { + $format = config('attendize.default_datetime_format'); + return [ + 'title' => 'required', + 'description' => 'required', + 'location_venue_name' => 'required_without:venue_name_full', + 'venue_name_full' => 'required_without:location_venue_name', + 'start_date' => 'required|date_format:"'.$format.'"', + 'end_date' => 'required|date_format:"'.$format.'"', + 'organiser_name' => 'required_without:organiser_id', + 'event_image' => 'mimes:jpeg,jpg,png|max:3000', + ]; + } /** * The validation error messages. @@ -200,7 +204,8 @@ class Event extends MyBaseModel */ public function setStartDateAttribute($date) { - $this->attributes['start_date'] = Carbon::parse($date); + $format = config('attendize.default_datetime_format'); + $this->attributes['start_date'] = Carbon::createFromFormat($format, $date); } /** @@ -219,7 +224,8 @@ class Event extends MyBaseModel */ public function setEndDateAttribute($date) { - $this->attributes['end_date'] = Carbon::parse($date); + $format = config('attendize.default_datetime_format'); + $this->attributes['end_date'] = Carbon::createFromFormat($format, $date); } /** diff --git a/app/Models/MyBaseModel.php b/app/Models/MyBaseModel.php index 090e3c16..b9d61292 100644 --- a/app/Models/MyBaseModel.php +++ b/app/Models/MyBaseModel.php @@ -86,7 +86,8 @@ class MyBaseModel extends \Illuminate\Database\Eloquent\Model */ public function validate($data) { - $v = Validator::make($data, $this->rules, $this->messages, $this->attributes); + $rules = $this->rules ? is_array($rules = $this->rules) : $rules = $this->rules(); + $v = Validator::make($data, $rules, $this->messages, $this->attributes); if ($v->fails()) { $this->errors = $v->messages(); diff --git a/app/Models/Ticket.php b/app/Models/Ticket.php index 7e4e2dbb..717fb226 100644 --- a/app/Models/Ticket.php +++ b/app/Models/Ticket.php @@ -15,16 +15,21 @@ class Ticket extends MyBaseModel /** * The rules to validate the model. * - * @var array $rules + * @return array $rules */ - public $rules = [ - 'title' => ['required'], - 'price' => ['required', 'numeric', 'min:0'], - 'description' => [], - 'start_sale_date' => ['date'], - 'end_sale_date' => ['date', 'after:start_sale_date'], - 'quantity_available' => ['integer', 'min:0'], - ]; + public function rules() + { + $format = config('attendize.default_datetime_format'); + return [ + 'title' => 'required', + 'price' => 'required|numeric|min:0', + 'description' => '', + 'start_sale_date' => 'date_format:"'.$format.'"', + 'end_sale_date' => 'date_format:"'.$format.'"|after:start_sale_date', + 'quantity_available' => 'integer|min:0', + ]; + } + /** * The validation error messages. * @@ -84,7 +89,10 @@ class Ticket extends MyBaseModel if (!$date) { $this->attributes['start_sale_date'] = Carbon::now(); } else { - $this->attributes['start_sale_date'] = Carbon::parse($date); + $this->attributes['start_sale_date'] = Carbon::createFromFormat( + config('attendize.default_datetime_format'), + $date + ); } } @@ -98,7 +106,10 @@ class Ticket extends MyBaseModel if (!$date) { $this->attributes['end_sale_date'] = null; } else { - $this->attributes['end_sale_date'] = Carbon::parse($date); + $this->attributes['end_sale_date'] = Carbon::createFromFormat( + config('attendize.default_datetime_format'), + $date + ); } } diff --git a/public/assets/javascript/app.js b/public/assets/javascript/app.js index 79b6db79..319be822 100644 --- a/public/assets/javascript/app.js +++ b/public/assets/javascript/app.js @@ -12,7 +12,8 @@ $(function () { var $div = $("
", {id: "DatePicker"}); $("body").append($div); $div.DateTimePicker({ - dateTimeFormat: Attendize.DateTimeFormat + dateTimeFormat: Attendize.DateTimeFormat, + dateSeparator: Attendize.DateSeparator }); }); @@ -505,7 +506,7 @@ function toggleSubmitDisabled($submitButton) { } /** - * + * * @returns {{}} */ $.fn.serializeObject = function() diff --git a/resources/views/ManageOrganiser/Partials/EventCreateAndEditJS.blade.php b/resources/views/ManageOrganiser/Partials/EventCreateAndEditJS.blade.php index 126bdfa9..9a8d036a 100644 --- a/resources/views/ManageOrganiser/Partials/EventCreateAndEditJS.blade.php +++ b/resources/views/ManageOrganiser/Partials/EventCreateAndEditJS.blade.php @@ -28,7 +28,8 @@ var $div = $("
", {id: "DatePicker"}); $("body").append($div); $div.DateTimePicker({ - dateTimeFormat: window.Attendize.DateTimeFormat + dateTimeFormat: window.Attendize.DateTimeFormat, + dateSeparator: window.Attendize.DateSeparator }); }); @@ -52,4 +53,4 @@ .in-form-link { display: block; padding: 5px;margin-bottom: 5px;padding-left: 0; } - \ No newline at end of file + diff --git a/resources/views/Public/ViewEvent/Partials/EventHeaderSection.blade.php b/resources/views/Public/ViewEvent/Partials/EventHeaderSection.blade.php index ae282e08..f8ea7f36 100644 --- a/resources/views/Public/ViewEvent/Partials/EventHeaderSection.blade.php +++ b/resources/views/Public/ViewEvent/Partials/EventHeaderSection.blade.php @@ -1,13 +1,13 @@ @if(!$event->is_live)
- @if(!$event->is_live) + @if(!$event->is_live) {{ @trans("ManageEvent.event_not_live") }} {{ @trans("ManageEvent.publish_it") }} - @endif + @endif
@endif @@ -32,7 +32,7 @@ - - @if($event->start_date->diffInHours($event->end_date) <= 12) + @if($event->start_date->diffInDays($event->end_date) == 0) {{ $event->end_date->format('H:i') }} @else {{ $event->endDateFormatted() }}