73 lines
2.3 KiB
PHP

<?php
class Controller_api_houroverride extends Crunchbutton_Controller_RestAccount {
public function init() {
// if (!c::admin()->permission()->check(['global','rules'])) {
// return ;
// }
$id_restaurant_hour_override = $this->request()[ 'id_restaurant_hour_override' ];
if( $id_restaurant_hour_override ){
$hour = Crunchbutton_Restaurant_Hour_Override::o( $id_restaurant_hour_override );
$id_restaurant = $hour->restaurant()->id_restaurant;
} else {
$id_restaurant = $this->request()[ 'id_restaurant' ];
}
if( !$id_restaurant ){
return;
}
if (!c::admin()->permission()->check(['global', 'restaurants-all', 'restaurants-crud','restaurant-'.$id_restaurant.'-all','restaurant-'.$id_restaurant.'-edit'])) {
return;
}
switch ( $this->method() ) {
case 'post':
switch ( c::getPagePiece(2) ) {
case 'remove':
$hour = Crunchbutton_Restaurant_Hour_Override::o( $id_restaurant_hour_override );
$hour->delete();
echo json_encode( [ 'success' => 'success' ] );
exit;
break;
case 'add':
$hour = new Crunchbutton_Restaurant_Hour_Override();
$hour->id_restaurant = $this->request()[ 'id_restaurant' ];
$date_start = $this->request()[ 'date_start' ];
$date_start = explode( '/' , $date_start );
$date_start_hour = ( $this->request()[ 'date_start_hour' ] ) ? $this->request()[ 'date_start_hour' ] : '00:00';
$date_start = $date_start[ 2 ] . '/' . $date_start[ 0 ] . '/' . $date_start[ 1 ] . ' ' . $date_start_hour . ':00';
$date_end = $this->request()[ 'date_end' ];
$date_end = explode( '/' , $date_end );
$date_end_hour = ( $this->request()[ 'date_end_hour' ] ) ? $this->request()[ 'date_end_hour' ] : '00:00';
$date_end = $date_end[ 2 ] . '/' . $date_end[ 0 ] . '/' . $date_end[ 1 ] . ' ' . $date_end_hour . ':00';
$hour->date_start = $date_start;
$hour->date_end = $date_end;
$hour->type = $this->request()[ 'type' ];
$hour->notes = $this->request()[ 'notes' ];
$hour->id_admin = c::admin()->id_admin;
$hour->save();
if( $hour->id_restaurant_hour_override ){
echo json_encode( [ 'success' => 'success' ] );
} else {
echo json_encode( [ 'error' => 'error' ] );
}
exit;
break;
}
break;
}
}
}