Let Drivers See Shifts Easily #2967
This commit is contained in:
parent
439ade818b
commit
95095b5435
14
include/controllers/default/cockpit/api/drivers/shifts.php
Normal file
14
include/controllers/default/cockpit/api/drivers/shifts.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
class Controller_api_drivers_shifts extends Crunchbutton_Controller_RestAccount {
|
||||
|
||||
public function init() {
|
||||
$id_admin = c::admin()->id_admin;
|
||||
$shifts = Crunchbutton_Community_Shift::nextShiftsByAdmin( $id_admin );
|
||||
$data = [];
|
||||
foreach( $shifts as $shift ){
|
||||
$data[] = $shift->export();
|
||||
}
|
||||
echo json_encode( $data );
|
||||
}
|
||||
}
|
||||
@ -14,13 +14,32 @@ class Controller_home extends Crunchbutton_Controller_Account {
|
||||
c::view()->display('order/index');
|
||||
exit();
|
||||
} else {
|
||||
$this->showList();
|
||||
$this->miniRouter();
|
||||
}
|
||||
} else {
|
||||
$this->showList();
|
||||
$this->miniRouter();
|
||||
}
|
||||
}
|
||||
|
||||
public function miniRouter(){
|
||||
c::view()->menu = true;
|
||||
switch ( c::getPagePiece( 0 ) ) {
|
||||
case 'shifts':
|
||||
c::view()->actual = 'list-shift';
|
||||
$this->showShifts();
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->showList();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function showShifts(){
|
||||
c::view()->shifts = Crunchbutton_Community_Shift::nextShiftsByAdmin( c::admin()->id_admin );
|
||||
c::view()->display( 'shifts/index' );
|
||||
}
|
||||
|
||||
public function showList(){
|
||||
|
||||
$justMineOrders = ( c::db()->escape( c::getPagePiece( 0 ) ) == 'mine' );
|
||||
@ -51,6 +70,13 @@ class Controller_home extends Crunchbutton_Controller_Account {
|
||||
return ( $a->lastStatus[ 'order' ] > $b->lastStatus[ 'order' ] );
|
||||
} );
|
||||
|
||||
|
||||
if( $justMineOrders ){
|
||||
c::view()->actual = 'list-mine';
|
||||
} else {
|
||||
c::view()->actual = 'list-all';
|
||||
}
|
||||
|
||||
c::view()->justMineOrders = $justMineOrders;
|
||||
c::view()->hours = $hours;
|
||||
c::view()->orders = $list;
|
||||
|
||||
@ -29,6 +29,38 @@ class Crunchbutton_Community_Shift extends Cana_Table {
|
||||
WHERE o.id_order = ' . $id_order . ' AND cs.date_start <= "' . $now->format( 'Y-m-d H:i:s' ) . '" AND cs.date_end >= "' . $now->format( 'Y-m-d H:i:s' ) . '" AND cs.active = 1 ');
|
||||
}
|
||||
|
||||
public function export(){
|
||||
$out = [];
|
||||
|
||||
$out[ 'community' ] = array( 'id_community' => $this->id_community, 'name' => $this->community()->name );
|
||||
|
||||
$out[ 'period' ] = array( 'toString' => $this->startEndToString(),
|
||||
'day_start' => $this->dateStart()->format( 'M jS Y' ),
|
||||
'day_end' => $this->dateEnd()->format( 'M jS Y' ),
|
||||
'date_start' => $this->dateStart()->format( 'Y-m-d H:i:s' ),
|
||||
'date_end' => $this->dateEnd()->format( 'Y-m-d H:i:s' ),
|
||||
'timezone' => $this->timezone(),
|
||||
'timezone_abbr' => $this->timezoneAbbr() );
|
||||
|
||||
$out[ 'period_pst' ] = array( 'toString' => $this->startEndToString( c::config()->timezone ),
|
||||
'day_start' => $this->dateStart( c::config()->timezone )->format( 'M jS Y' ),
|
||||
'day_end' => $this->dateEnd( c::config()->timezone )->format( 'M jS Y' ),
|
||||
'date_start' => $this->dateStart( c::config()->timezone )->format( 'Y-m-d H:i:s' ),
|
||||
'date_end' => $this->dateEnd( c::config()->timezone )->format( 'Y-m-d H:i:s' ),
|
||||
'timezone' => c::config()->timezone,
|
||||
'timezone_abbr' => 'PST' );
|
||||
return $out;
|
||||
}
|
||||
|
||||
public function nextShiftsByAdmin( $id_admin ){
|
||||
$now = new DateTime( 'now', new DateTimeZone( c::config()->timezone ) );
|
||||
$query = 'SELECT cs.* FROM admin_shift_assign ass
|
||||
INNER JOIN community_shift cs ON cs.id_community_shift = ass.id_community_shift
|
||||
WHERE ass.id_admin = "' . $id_admin . '" AND
|
||||
DATE_FORMAT( cs.date_start, "%Y-%m-%d" ) >= "' . $now->format( 'Y-m-d' ) . '" ORDER BY cs.date_start ASC LIMIT 20';
|
||||
return Crunchbutton_Community_Shift::q( $query );
|
||||
}
|
||||
|
||||
public function shiftsByDay( $date ){
|
||||
Crunchbutton_Community_Shift::createRecurringEvent( $date );
|
||||
return Crunchbutton_Community_Shift::q( 'SELECT cs.* FROM community_shift cs INNER JOIN community c ON c.id_community = cs.id_community WHERE DATE_FORMAT( cs.date_start, "%Y-%m-%d" ) = "' . $date . '" ORDER BY c.name, cs.date_start ASC' );
|
||||
|
||||
@ -3,19 +3,6 @@ $orders = $this->orders;
|
||||
$showAll = !$this->justMineOrders;
|
||||
$hours = $this->hours;
|
||||
?>
|
||||
<div class="control">
|
||||
<div class="wrap order-status-init menu-bar">
|
||||
<b>Show: </b>
|
||||
<?php if( $showAll ) { ?>
|
||||
<strong>all</strong> | <a href="/mine/<?php echo $hours; ?>">mine</a>
|
||||
<?php } else { ?>
|
||||
<a href="/list/<?php echo $hours; ?>">all</a> | <strong>mine</strong>
|
||||
<?php } ?>
|
||||
|
||||
<div class="divider"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
<div class="wrap">
|
||||
<div class="warning">
|
||||
|
||||
@ -445,7 +445,7 @@ input[type="submit"]::-moz-focus-inner, input[type="button"]::-moz-focus-inner,
|
||||
font-size: 1.8em;
|
||||
padding: 1em;
|
||||
}
|
||||
.order-list-item{
|
||||
.order-list-item, .shifts-list-item{
|
||||
color: #FFF;
|
||||
font-size: 1.1em;
|
||||
padding:0.5em;
|
||||
@ -528,16 +528,54 @@ input[type="submit"]::-moz-focus-inner, input[type="button"]::-moz-focus-inner,
|
||||
.menu-bar{
|
||||
font-size: 1.8em;
|
||||
}
|
||||
|
||||
.shifts-list-item{
|
||||
background: #6d6d6d;
|
||||
}
|
||||
.shifts-list-item-date{
|
||||
font-size: 1.7em;
|
||||
}
|
||||
.shifts-list-item-day{
|
||||
opacity: 0.7;
|
||||
}
|
||||
.shifts-list-item-hour{
|
||||
font-size: 1.2em;
|
||||
}
|
||||
.shifts-list-item-community{
|
||||
font-size: 1.7em;
|
||||
opacity: 0.5;
|
||||
float: right;
|
||||
text-align: right;
|
||||
}
|
||||
.menu-bar a.actual{
|
||||
color: #000;
|
||||
text-decoration: none;
|
||||
}
|
||||
</style>
|
||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
|
||||
<script src="/assets/js/fastclick.js"></script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div class="loader-wrap">
|
||||
<div class="loader-frame"><div class="loader"> </div></div>
|
||||
</div>
|
||||
<?php if( $this->menu ) {
|
||||
$orders = $this->orders;
|
||||
$showAll = !$this->justMineOrders;
|
||||
$hours = $this->hours;
|
||||
?>
|
||||
<div class="control">
|
||||
<div class="wrap order-status-init menu-bar">
|
||||
<b>Show: </b>
|
||||
<a class="<?php if( $this->actual == 'list-all' ){ echo 'actual'; } ?>" href="/list/<?php echo $hours; ?>">all</a>
|
||||
|
|
||||
<a class="<?php if( $this->actual == 'list-mine' ){ echo 'actual'; } ?>" href="/mine/<?php echo $hours; ?>">mine</a>
|
||||
|
|
||||
<a class="<?php if( $this->actual == 'list-shift' ){ echo 'actual'; } ?>" href="/shifts/">my next shifts</a>
|
||||
<div class="divider"></div>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php echo $this->content; ?>
|
||||
</body>
|
||||
<script>
|
||||
|
||||
31
include/views/default/quick/shifts/index.phtml
Normal file
31
include/views/default/quick/shifts/index.phtml
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
$shifts = $this->shifts;
|
||||
?>
|
||||
<div class="content">
|
||||
<div class="wrap">
|
||||
<?php
|
||||
if( $shifts->count() > 0 ){
|
||||
foreach( $shifts as $shift ) { ?>
|
||||
<div class="shifts-list-item">
|
||||
<div class="shifts-list-item-community">
|
||||
<?php echo $shift->community()->name; ?>
|
||||
</div>
|
||||
<div class="shifts-list-item-date">
|
||||
<div class="shifts-list-item-day">
|
||||
<?php echo $shift->dateStart()->format( 'M jS Y' ); ?>
|
||||
</div>
|
||||
<div class="shifts-list-item-hour">
|
||||
<?php echo $shift->startEndToString(); ?> (<?php echo $shift->timezoneAbbr(); ?>)
|
||||
</div>
|
||||
</div>
|
||||
<div class="divider"></div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
} else { ?>
|
||||
<div class="no-orders">
|
||||
No shifts
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
Loading…
x
Reference in New Issue
Block a user