diff --git a/db/migrate/000176_community_shift.sql b/db/migrate/000176_community_shift.sql deleted file mode 100644 index a7d11a05d..000000000 --- a/db/migrate/000176_community_shift.sql +++ /dev/null @@ -1,9 +0,0 @@ -CREATE TABLE `community_shift` ( - `id_community_shift` int(11) unsigned NOT NULL AUTO_INCREMENT, - `id_community` int(11) unsigned DEFAULT NULL, - `date_start` datetime DEFAULT NULL, - `date_end` datetime DEFAULT NULL, - PRIMARY KEY (`id_community_shift`), - KEY `community_shift_ibfk_1` (`id_community`), - CONSTRAINT `community_shift_ibfk_1` FOREIGN KEY (`id_community`) REFERENCES `community` (`id_community`) ON DELETE SET NULL ON UPDATE SET NULL -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; \ No newline at end of file diff --git a/db/migrate/000176_shift_stuff.sql b/db/migrate/000176_shift_stuff.sql new file mode 100644 index 000000000..af5b24a4f --- /dev/null +++ b/db/migrate/000176_shift_stuff.sql @@ -0,0 +1,34 @@ +CREATE TABLE `community_shift` ( + `id_community_shift` int(11) unsigned NOT NULL AUTO_INCREMENT, + `id_community` int(11) unsigned DEFAULT NULL, + `date_start` datetime DEFAULT NULL, + `date_end` datetime DEFAULT NULL, + PRIMARY KEY (`id_community_shift`), + KEY `community_shift_ibfk_1` (`id_community`), + CONSTRAINT `community_shift_ibfk_1` FOREIGN KEY (`id_community`) REFERENCES `community` (`id_community`) ON DELETE SET NULL ON UPDATE SET NULL +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; + +CREATE TABLE `admin_shift_preference` ( + `id_admin_shift_preference` int(11) unsigned NOT NULL AUTO_INCREMENT, + `id_community_shift` int(11) unsigned DEFAULT NULL, + `id_admin` int(11) unsigned DEFAULT NULL, + `ranking` TINYINT( 2 ) NOT NULL DEFAULT '0', + PRIMARY KEY (`id_admin_shift_preference`), + KEY `admin_shift_preference_ibfk_1` (`id_community_shift`), + KEY `admin_shift_preference_ibfk_2` (`id_admin`), + CONSTRAINT `admin_shift_preference_ibfk_1` FOREIGN KEY (`id_community_shift`) REFERENCES `community_shift` (`id_community_shift`) ON DELETE SET NULL ON UPDATE SET NULL, + CONSTRAINT `admin_shift_preference_ibfk_2` FOREIGN KEY (`id_admin`) REFERENCES `admin` (`id_admin`) ON DELETE SET NULL ON UPDATE SET NULL +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; + +CREATE TABLE `admin_shift_status` ( + `id_admin_shift_status` int(11) unsigned NOT NULL AUTO_INCREMENT, + `id_admin` int(11) unsigned DEFAULT NULL, + `year` int(4) unsigned DEFAULT NULL, + `week` int(2) unsigned DEFAULT NULL, + `completed` TINYINT( 1 ) NOT NULL DEFAULT '0', + `shifts` TINYINT( 2 ) NOT NULL DEFAULT '0', + `date` datetime DEFAULT NULL, + PRIMARY KEY (`id_admin_shift_status`), + KEY `admin_shift_status_ibfk_1` (`id_admin`), + CONSTRAINT `admin_shift_status_ibfk_2` FOREIGN KEY (`id_admin`) REFERENCES `admin` (`id_admin`) ON DELETE SET NULL ON UPDATE SET NULL +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; \ No newline at end of file diff --git a/db/migrate/000177_admin_shift_preference.sql b/db/migrate/000177_admin_shift_preference.sql deleted file mode 100644 index f5942ce2e..000000000 --- a/db/migrate/000177_admin_shift_preference.sql +++ /dev/null @@ -1,10 +0,0 @@ -CREATE TABLE `admin_shift_preference` ( - `id_admin_shift_preference` int(11) unsigned NOT NULL AUTO_INCREMENT, - `id_community_shift` int(11) unsigned DEFAULT NULL, - `id_admin` int(11) unsigned DEFAULT NULL, - `ranking` TINYINT( 2 ) NOT NULL DEFAULT '0', - PRIMARY KEY (`id_admin_shift_preference`), - KEY `admin_shift_preference_ibfk_1` (`id_community_shift`), - CONSTRAINT `admin_shift_preference_ibfk_1` FOREIGN KEY (`id_community_shift`) REFERENCES `community_shift` (`id_community_shift`) ON DELETE SET NULL ON UPDATE SET NULL, - CONSTRAINT `admin_shift_preference_ibfk_2` FOREIGN KEY (`id_admin`) REFERENCES `admin` (`id_admin`) ON DELETE SET NULL ON UPDATE SET NULL -) ENGINE=InnoDB AUTO_INCREMENT=70 DEFAULT CHARSET=utf8; \ No newline at end of file diff --git a/include/controllers/default/cockpit/api/drivers/shift.php b/include/controllers/default/cockpit/api/drivers/shift.php index 7e09c609c..c2c84356d 100644 --- a/include/controllers/default/cockpit/api/drivers/shift.php +++ b/include/controllers/default/cockpit/api/drivers/shift.php @@ -24,9 +24,18 @@ class Controller_api_drivers_shift extends Crunchbutton_Controller_RestAccount { $allItems = $this->request()[ 'allItems' ]; $wantWorkItems = $this->request()[ 'wantWorkItems' ]; $dontWantWorkItems = $this->request()[ 'dontWantWorkItems' ]; + $completed = $this->request()[ 'completed' ]; + $shifts = $this->request()[ 'shifts' ]; + if( count( $allItems ) > 0 ){ $id_admin = c::admin()->id_admin; + + $status = Crunchbutton_Admin_Shift_Status::currentStatus( $id_admin ); + $status->completed = $completed; + $status->shifts = $shifts; + $status->date = date('Y-m-d H:i:s'); + $status->save(); // remove all items if( count( $allItems ) > 0 ){ diff --git a/include/controllers/default/cockpit/drivers/shift.php b/include/controllers/default/cockpit/drivers/shift.php index 3aaef74d7..895a3f640 100644 --- a/include/controllers/default/cockpit/drivers/shift.php +++ b/include/controllers/default/cockpit/drivers/shift.php @@ -54,7 +54,9 @@ class Controller_drivers_shift extends Crunchbutton_Controller_Account { $days[] = new DateTime( $firstDay->format( 'Y-m-d' ), new DateTimeZone( c::config()->timezone ) ); $firstDay->modify( '+ 1 day' ); } - c::view()->days = $days; + + c::view()->status = Crunchbutton_Admin_Shift_Status::currentStatus( $admin->id_admin ); + c::view()->days = $days; c::view()->from = new DateTime( $days[ 0 ]->format( 'Y-m-d' ), new DateTimeZone( c::config()->timezone ) ); c::view()->to = new DateTime( $days[ 6 ]->format( 'Y-m-d' ), new DateTimeZone( c::config()->timezone ) ); c::view()->communities = $admin->communitiesHeDeliveriesFor(); diff --git a/include/library/Crunchbutton/Admin/Shift/Status.php b/include/library/Crunchbutton/Admin/Shift/Status.php new file mode 100644 index 000000000..b7fe9e139 --- /dev/null +++ b/include/library/Crunchbutton/Admin/Shift/Status.php @@ -0,0 +1,33 @@ +table('admin_shift_status') + ->idVar('id_admin_shift_status') + ->load($id); + } + + public function currentStatus( $id_admin ){ + $year = date( 'Y' ); + $week = date( 'W' ); + $date = new DateTime( date( 'Y-m-d', strtotime( $year . 'W' . $week . 1 ) ), new DateTimeZone( c::config()->timezone ) ); + $date->modify( '+ 1 week' ); + return Crunchbutton_Admin_Shift_Status::getByAdminWeekYear( $id_admin, $date->format( 'W' ), $date->format( 'Y' ) ); + } + + public function getByAdminWeekYear( $id_admin, $week, $year ){ + $status = Crunchbutton_Admin_Shift_Status::q( 'SELECT * FROM admin_shift_status WHERE id_admin = ' . $id_admin . ' AND year = ' . $year . ' AND week = ' . $week ); + if( !$status->id_admin_shift_status ){ + $status = new Crunchbutton_Admin_Shift_Status(); + $status->id_admin = $id_admin; + $status->week = $week; + $status->year = $year; + $status->date = date('Y-m-d H:i:s'); + $status->save(); + } + return $status; + } + +} \ No newline at end of file diff --git a/include/views/default/cockpit/drivers/shift/schedule/driver.phtml b/include/views/default/cockpit/drivers/shift/schedule/driver.phtml index 555a4ebbd..89732260d 100644 --- a/include/views/default/cockpit/drivers/shift/schedule/driver.phtml +++ b/include/views/default/cockpit/drivers/shift/schedule/driver.phtml @@ -11,7 +11,7 @@