Let Drivers See Shifts Easily #2967

This commit is contained in:
Daniel Camargo 2014-04-11 10:44:08 -03:00
parent 05278a947d
commit 40e5cc64d0
6 changed files with 194 additions and 44 deletions

View File

@ -1,9 +1,8 @@
<?php
class Controller_home extends Crunchbutton_Controller_Account {
public function init() {
public function init() {
c::view()->layout( 'layout/html' );
if( c::db()->escape( c::getPagePiece( 0 ) ) ){
@ -24,29 +23,65 @@ class Controller_home extends Crunchbutton_Controller_Account {
public function miniRouter(){
c::view()->menu = true;
switch ( c::getPagePiece( 0 ) ) {
case 'shifts':
c::view()->actual = 'list-shift';
$this->showShifts();
case 'shifts-list':
switch ( c::getPagePiece( 1 ) ) {
case 'all':
$this->showAllShifts();
break;
case 'mine':
default:
$this->showMineShifts();
break;
}
break;
case 'orders-list':
default:
$this->showList();
switch ( c::getPagePiece( 1 ) ) {
case 'all':
$this->showAllOrders();
break;
case 'mine':
default:
$this->showMineOrders();
break;
}
break;
}
}
public function showShifts(){
c::view()->shifts = Crunchbutton_Community_Shift::nextShiftsByAdmin( c::admin()->id_admin );
c::view()->display( 'shifts/index' );
public function showAllShifts(){
c::view()->actual = 'shifts-all';
$communities = c::admin()->communitiesHeDeliveriesFor();
$list = [];
foreach( $communities as $community ){
$list[] = $community->id_community;
}
c::view()->shifts = Crunchbutton_Community_Shift::nextShiftsByCommunities( $list );
c::view()->display( 'shifts/all' );
}
public function showList(){
public function showMineShifts(){
c::view()->actual = 'shifts-mine';
c::view()->shifts = Crunchbutton_Community_Shift::nextShiftsByAdmin( c::admin()->id_admin );
c::view()->display( 'shifts/mine' );
}
$justMineOrders = ( c::db()->escape( c::getPagePiece( 0 ) ) == 'mine' );
public function showAllOrders(){
c::view()->actual = 'orders-all';
c::view()->orders = $this->getOrdersList( true );
c::view()->display( 'orders/index' );
}
$hours = c::getPagePiece( 1 ) ? c::getPagePiece( 1 ) : 12;
public function showMineOrders(){
c::view()->actual = 'orders-mine';
c::view()->orders = $this->getOrdersList();
c::view()->display( 'orders/index' );
}
public function getOrdersList( $all = false ){
$orders = Order::deliveryOrders( $hours, ( c::db()->escape( c::getPagePiece( 0 ) ) == 'all' ) );
$hours = 120;
$orders = Order::deliveryOrders( $hours, $all );
$list = [];
foreach ( $orders as $order ) {
@ -70,17 +105,7 @@ 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;
c::view()->display( 'home/index' );
return $list;
}
}

View File

@ -57,10 +57,21 @@ class Crunchbutton_Community_Shift extends Cana_Table {
$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';
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 nextShiftsByCommunities( $communities ){
if( count( $communities ) > 0 ){
$now = new DateTime( 'now', new DateTimeZone( c::config()->timezone ) );
$query = 'SELECT cs.* FROM community_shift cs
WHERE cs.id_community IN( ' . join( ',', $communities ) . ' ) 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 );
}
return false;
}
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' );

View File

@ -430,12 +430,27 @@ input[type="submit"]::-moz-focus-inner, input[type="button"]::-moz-focus-inner,
.warning{
color: red;
font-style: italic;
color: #c09853;
font-family: 'Open Sans', HelveticaNeue, Helvetica, Arial;
font-size: 1.2em;
line-height: 1.4em;
margin-bottom:1.1em;
margin-top:1.1em;
border: 1px solid #f1d276;
background-color: #f7e6b4;
background-image: -webkit-gradient(linear, left top, left bottom, from(rgb(249, 236, 196)), to(rgb(246, 225, 165)));
background-image: -webkit-linear-gradient(top, rgb(249, 236, 196), rgb(246, 225, 165));
background-image: -moz-linear-gradient(top, rgb(249, 236, 196), rgb(246, 225, 165));
background-image: -o-linear-gradient(top, rgb(249, 236, 196), rgb(246, 225, 165));
background-image: -ms-linear-gradient(top, rgb(249, 236, 196), rgb(246, 225, 165));
background-image: linear-gradient(top, rgb(249, 236, 196), rgb(246, 225, 165));
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,StartColorStr='#f9ecc4', EndColorStr='#f6e1a5');
-webkit-border-radius: .4em;
-moz-border-radius: .4em;
border-radius: .4em;
padding: .5em;
text-shadow: rgba(255, 255, 255, 0.498039) 0px 1px 0px;
box-shadow: rgb(249, 237, 201) 0px 1px 2px 0px inset, rgb(223, 223, 223) 0px 1px 1px 0px;
}
.order-list-item a{
color: #FFF;
@ -526,11 +541,14 @@ input[type="submit"]::-moz-focus-inner, input[type="button"]::-moz-focus-inner,
.pickedup .order-list-action .button{ color:#505050; }
.menu-bar{
font-size: 1.8em;
font-size: 1.7em;
}
.shifts-list-item{
background: #6d6d6d;
}
.shifts-list-item.mine{
background: #00957f;
}
.shifts-list-item-date{
font-size: 1.7em;
}
@ -547,9 +565,43 @@ input[type="submit"]::-moz-focus-inner, input[type="button"]::-moz-focus-inner,
text-align: right;
}
.menu-bar a.actual{
color: #000;
color: #666;
text-decoration: none;
}
.menu-bar ul{
list-style-type: none;
margin: 0;
padding: 0;
}
.menu-bar li{
display: inline-block;
margin: 0 0.2em;
padding: 0;
}
.menu-bar li.title{
margin-left: 0;
}
.menu-bar li.title.shifts{
margin-left: 1em;
}
.shifts-list-item .drivers{
margin: 0;
margin-top: 1em;
padding: 0;
list-style-type: none;
}
.shifts-list-item .drivers li{
font-size: 1.3em;
line-height: 1.5em;
}
.shifts-list-item .drivers li.no-drivers{
font-size: 1em;
opacity: .7;
font-style: italic;
}
.shifts-list-item a{
color: #FFF;
}
</style>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="/assets/js/fastclick.js"></script>
@ -558,24 +610,29 @@ input[type="submit"]::-moz-focus-inner, input[type="button"]::-moz-focus-inner,
<div class="loader-wrap">
<div class="loader-frame"><div class="loader">&nbsp;</div></div>
</div>
<?php if( $this->menu ) {
$orders = $this->orders;
$showAll = !$this->justMineOrders;
$hours = $this->hours;
?>
<?php if( $this->menu ) { ?>
<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>
&nbsp;|&nbsp;
<a class="<?php if( $this->actual == 'list-mine' ){ echo 'actual'; } ?>" href="/mine/<?php echo $hours; ?>">mine</a>
&nbsp;|&nbsp;
<a class="<?php if( $this->actual == 'list-shift' ){ echo 'actual'; } ?>" href="/shifts/">my next shifts</a>
<ul>
<li class="title"><b>Orders</b></li>
<li>
<a class="<?php if( $this->actual == 'orders-all' ){ echo 'actual'; } ?>" href="/orders-list/all">all</a>
</li>
<li>
<a class="<?php if( $this->actual == 'orders-mine' ){ echo 'actual'; } ?>" href="/orders-list/mine/">mine</a>
</li>
<li class="title shifts"><b>Shifts</b></li>
<li>
<a class="<?php if( $this->actual == 'shifts-all' ){ echo 'actual'; } ?>" href="/shifts-list/all">all</a>
</li>
<li>
<a class="<?php if( $this->actual == 'shifts-mine' ){ echo 'actual'; } ?>" href="/shifts-list/mine">mine</a>
</li>
</ul>
<div class="divider"></div>
</div>
</div>
<?php } ?>
<?php echo $this->content; ?>
</body>
<script>

View File

@ -6,7 +6,7 @@ $hours = $this->hours;
<div class="content">
<div class="wrap">
<div class="warning">
In order to receive payment for orders that you deliver, you MUST confirm all orders that you've delivered. <br/> Check back here at the of the night to make sure YOUR orders are confirmed and delivered!
In order to receive payment for orders that you deliver, you <strong>MUST</strong> confirm all orders that you've delivered. <br/> Check back here at the of the night to make sure YOUR orders are confirmed and delivered!
</div>
<?php
if( count( $orders ) > 0 ){

View File

@ -0,0 +1,57 @@
<?php
$shifts = $this->shifts;
$id_admin = c::admin()->id_admin;
?>
<div class="content">
<div class="wrap">
<?php
if( $shifts->count() > 0 ){
foreach( $shifts as $shift ) {
$drivers = $shift->getDrivers();
$mine = false;
foreach ( $drivers as $driver ) {
if( $driver->id_admin == $id_admin ){
$mine = true;
}
}
?>
<div class="shifts-list-item <?php if( $mine ){ echo 'mine'; } else { echo 'false'; } ?>">
<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( 'D, M jS' ); ?>
</div>
<div class="shifts-list-item-hour">
<?php echo $shift->startEndToString(); ?> (<?php echo $shift->timezoneAbbr(); ?>)
</div>
</div>
<ul class="drivers">
<?php
if ( $drivers->count() ) {
foreach ( $drivers as $driver ) {
?>
<li <?php if( $driver->id_admin == $id_admin ){ echo 'class="you"'; } ?>>
<?php echo $driver->name; ?> - <?php echo $driver->phone(); ?>
</li>
<?php
}
} else {
?>
<li class="no-drivers">No drivers</li>
<?php
}
?>
</ul>
<div class="divider"></div>
</div>
<?php
}
} else { ?>
<div class="no-orders">
No shifts
</div>
<?php } ?>
</div>
</div>

View File

@ -6,7 +6,7 @@ $shifts = $this->shifts;
<?php
if( $shifts->count() > 0 ){
foreach( $shifts as $shift ) { ?>
<div class="shifts-list-item">
<div class="shifts-list-item mine">
<div class="shifts-list-item-community">
<?php echo $shift->community()->name; ?>
</div>