Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Http\Controllers;
- use App\ChildrenPresent;
- use App\WorkingDays;
- use DateTime;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Support\Facades\Response;
- class PresenceController extends Controller
- {
- public function presence(Request $request)
- {
- $publishDates = ChildrenPresent::where('CHILDREN_ID', Auth::user()->CHILDREN_ID)
- //->where('YYYYMM', date('Ym', $request->input('to') / 1000))
- ->get();
- $output = [];
- $record = count($publishDates );
- if ($record >= 1) {
- foreach ($publishDates as $publishDate ) {
- $year = substr($publishDate ->YYYYMM, 0, 4);
- $month = substr($publishDate ->YYYYMM, -2, 2);
- $thework = WorkingDays::where('MM', $month)
- ->where('YYYY', $year)
- ->where('GARDEN_ID', $publishDate ->GARDEN_ID)
- ->get();
- foreach ($thework as $work) {
- $workdays = str_split($work->DAY_STATUS);
- }
- $days = str_split($publishDate ->DAY_STATUS);
- }
- $status = array(
- '0' => 'Непопълнен ден',
- '1' => 'Присъства',
- '2' => 'Отсъства по болест',
- '3' => 'Карантина',
- '4' => 'Отсъства по домашни причини',
- '5' => 'Отпуск',
- '6' => 'Служебно отсъствие',
- '7' => 'Неизвинено отсъствие'
- );
- $color = array(
- '0' => '#E0EBF8',
- '1' => '#b9f6ca',
- '2' => '#fce4ec',
- '3' => '#ffab91',
- '4' => '#b3e5fc',
- '5' => '#ede7f6',
- '6' => '#efebe9',
- '7' => '#ffecb3'
- );
- $i = 0;
- foreach ($workdays as $item) {
- $today = $i + 1;
- setlocale(LC_TIME, 'bg.UTF-8');
- if (strtotime($today . '-' . substr($publishDate ->YYYYMM, -2) . '-' .
- substr($publishDate ->YYYYMM, 0, -2)) < strtotime(date('d-m-Y'))) {
- if ($item == 1) {
- $day_by_day[$i] = array(
- 'today' => $today . '.' . $month . '.' . $year,
- 'status' => $status[$days[$i]]
- );
- $output[] = array(
- 'id' => $publishDate->YYYYMM . $i,
- 'title' => $day_by_day[$i]['status'],
- 'color' => $color[$days[$i]],
- 'start' => date("Y-m-d H:i:s", strtotime($day_by_day[$i]['today'])),
- 'end' => date("Y-m-d H:i:s", strtotime($day_by_day[$i]['today'] . "+1 day" . "-1 second"))
- );
- }
- }
- $i = $i + 1;
- }
- return response()->json($output);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement