Горизонтальный календарь - правильный путь - PullRequest
0 голосов
/ 09 февраля 2020

Я собираюсь по горизонтальному календарю, чтобы управлять сменами на работе. Но это также должно работать для бронирований, если я получу хорошее решение для этого.

У меня есть полу-рабочее решение, но я прошу лучшего (правильный способ сделать это). Потому что у меня есть fl aws ... Например, если день имеет двойную смену (бронирование), календарь добавляет день. Так что это ужасно.

Я собираюсь что-то вроде этого:

desired results

Мой запрос:

$sql = "SELECT
            schedule.*,
            CONCAT(users.userFirst,' ',users.userLast) AS fullName
        FROM
            schedule
            LEFT JOIN users ON schedule.userId = users.userId";

Данные:

    array(8) {
      ["John Johnsson"]=>
      array(1) {
        [0]=>
        array(13) {
          ["schedId"]=>
          string(2) "25"
          ["userId"]=>
          string(2) "10"
          ["createdBy"]=>
          string(1) "3"
          ["startDate"]=>
          string(10) "2020-02-06"
          ["startTime"]=>
          string(8) "08:00:00"
          ["endDate"]=>
          string(10) "2020-02-06"
          ["endTime"]=>
          string(8) "16:00:00"
          ["schedTitle"]=>
          string(13) "08:00 - 16:00"
          ["schedDesc"]=>
          string(6) "Awesome description"
          ["schedColor"]=>
          string(7) "#e9e6e1"
          ["lastUpdated"]=>
          string(19) "2020-02-06 12:52:54"
          ["fullName"]=>
          string(16) "John Johnsson"
        }
      }
      ["Eve Wolley"]=>
      array(2) {
        [0]=>
        array(13) {
          ["schedId"]=>
          string(2) "15"
          ["userId"]=>
          string(2) "11"
          ["createdBy"]=>
          string(1) "3"
          ["startDate"]=>
          string(10) "2020-02-01"
          ["startTime"]=>
          string(8) "08:00:00"
          ["endDate"]=>
          string(10) "2020-02-01"
          ["endTime"]=>
          string(8) "20:00:00"
          ["schedTitle"]=>
          string(13) "08:00 - 20:00"
          ["schedDesc"]=>
          string(27) "Awesome description"
          ["schedColor"]=>
          string(7) "#e9e6e1"
          ["lastUpdated"]=>
          string(19) "2020-02-06 11:32:18"
          ["fullName"]=>
          string(20) "Eve Wolley"
        }
        [1]=>
        array(13) {
          ["schedId"]=>
          string(2) "22"
          ["userId"]=>
          string(2) "11"
          ["createdBy"]=>
          string(1) "3"
          ["startDate"]=>
          string(10) "2020-02-02"
          ["startTime"]=>
          string(8) "08:00:00"
          ["endDate"]=>
          string(10) "2020-02-02"
          ["endTime"]=>
          string(8) "20:00:00"
          ["schedTitle"]=>
          string(13) "08:00 - 20:00"
          ["schedDesc"]=>
          string(15) "Awesome description"
          ["schedColor"]=>
          string(7) "#e9e6e1"
          ["lastUpdated"]=>
          string(19) "2020-02-06 11:55:30"
          ["fullName"]=>
          string(20) "Eve Wolley"
        }
      }
      ["Mitchell Finley"]=>
      array(2) {
        [0]=>
        array(13) {
          ["schedId"]=>
          string(2) "14"
          ["userId"]=>
          string(2) "13"
          ["createdBy"]=>
          string(1) "3"
          ["startDate"]=>
          string(10) "2020-02-01"
          ["startTime"]=>
          string(8) "20:00:00"
          ["endDate"]=>
          string(10) "2020-02-01"
          ["endTime"]=>
          string(8) "08:00:00"
          ["schedTitle"]=>
          string(13) "20:00 - 08:00"
          ["schedDesc"]=>
          string(34) "Awesome description"
          ["schedColor"]=>
          string(7) "#e9e6e1"
          ["lastUpdated"]=>
          string(19) "2020-02-06 11:31:35"
          ["fullName"]=>
          string(17) "Mitchell Finley"
        }
        [1]=>
        array(13) {
          ["schedId"]=>
          string(2) "21"
          ["userId"]=>
          string(2) "13"
          ["createdBy"]=>
          string(1) "3"
          ["startDate"]=>
          string(10) "2020-02-02"
          ["startTime"]=>
          string(8) "20:00:00"
          ["endDate"]=>
          string(10) "2020-02-02"
          ["endTime"]=>
          string(8) "08:00:00"
          ["schedTitle"]=>
          string(13) "20:00 - 08:00"
          ["schedDesc"]=>
          string(34) "Awesome description"
          ["schedColor"]=>
          string(7) "#e9e6e1"
          ["lastUpdated"]=>
          string(19) "2020-02-06 11:51:44"
          ["fullName"]=>
          string(17) "Mitchell Finley"
        }
      }
      ["Alisa Bullock"]=>
      array(1) {
        [0]=>
        array(13) {
          ["schedId"]=>
          string(2) "33"
          ["userId"]=>
          string(2) "14"
          ["createdBy"]=>
          string(1) "3"
          ["startDate"]=>
          string(10) "2020-02-06"
          ["startTime"]=>
          string(8) "08:00:00"
          ["endDate"]=>
          string(10) "2020-02-06"
          ["endTime"]=>
          string(8) "16:00:00"
          ["schedTitle"]=>
          string(13) "08:00 - 16:00"
          ["schedDesc"]=>
          string(0) "Awesome description"
          ["schedColor"]=>
          string(7) "#e9e6e1"
          ["lastUpdated"]=>
          string(19) "2020-02-06 12:57:54"
          ["fullName"]=>
          string(22) "Alisa Bullock"
        }
      }
      ["Kirandeep Burks"]=>
      array(1) {
        [0]=>
        array(13) {
          ["schedId"]=>
          string(2) "30"
          ["userId"]=>
          string(2) "15"
          ["createdBy"]=>
          string(1) "3"
          ["startDate"]=>
          string(10) "2020-02-06"
          ["startTime"]=>
          string(8) "16:00:00"
          ["endDate"]=>
          string(10) "2020-02-06"
          ["endTime"]=>
          string(8) "00:00:00"
          ["schedTitle"]=>
          string(13) "16:00 - 00:00"
          ["schedDesc"]=>
          string(19) "Awesome description"
          ["schedColor"]=>
          string(7) "#e9e6e1"
          ["lastUpdated"]=>
          string(19) "2020-02-06 12:55:41"
          ["fullName"]=>
          string(18) "Kirandeep Burks"
        }
      }
      ["Maegan Mclaughlin"]=>
      array(4) {
        [0]=>
        array(13) {
          ["schedId"]=>
          string(1) "3"
          ["userId"]=>
          string(2) "16"
          ["createdBy"]=>
          string(1) "3"
          ["startDate"]=>
          string(10) "2020-01-17"
          ["startTime"]=>
          string(8) "09:00:00"
          ["endDate"]=>
          string(10) "2020-01-17"
          ["endTime"]=>
          string(8) "14:00:00"
          ["schedTitle"]=>
          string(13) "09:00 - 14:00"
          ["schedDesc"]=>
          string(11) "Awesome description"
          ["schedColor"]=>
          string(7) "#e9e6e1"
          ["lastUpdated"]=>
          string(19) "2020-02-06 11:18:16"
          ["fullName"]=>
          string(18) "Maegan Mclaughlin"
        }
        [1]=>
        array(13) {
          ["schedId"]=>
          string(1) "4"
          ["userId"]=>
          string(2) "16"
          ["createdBy"]=>
          string(1) "3"
          ["startDate"]=>
          string(10) "2020-01-16"
          ["startTime"]=>
          string(8) "09:00:00"
          ["endDate"]=>
          string(10) "2020-01-16"
          ["endTime"]=>
          string(8) "14:00:00"
          ["schedTitle"]=>
          string(13) "09:00 - 14:00"
          ["schedDesc"]=>
          string(8) "Awesome description"
          ["schedColor"]=>
          string(7) "#e9e6e1"
          ["lastUpdated"]=>
          string(19) "2020-02-06 11:19:39"
          ["fullName"]=>
          string(18) "Maegan Mclaughlin"
        }
        [2]=>
        array(13) {
          ["schedId"]=>
          string(2) "16"
          ["userId"]=>
          string(2) "16"
          ["createdBy"]=>
          string(1) "3"
          ["startDate"]=>
          string(10) "2020-02-01"
          ["startTime"]=>
          string(8) "08:00:00"
          ["endDate"]=>
          string(10) "2020-02-01"
          ["endTime"]=>
          string(8) "16:00:00"
          ["schedTitle"]=>
          string(13) "08:00 - 16:00"
          ["schedDesc"]=>
          string(4) "Awesome description"
          ["schedColor"]=>
          string(7) "#e9e6e1"
          ["lastUpdated"]=>
          string(19) "2020-02-06 11:47:38"
          ["fullName"]=>
          string(18) "Maegan Mclaughlin"
        }
      }
      ["Margo Rennie"]=>
      array(1) {
        [0]=>
        array(13) {
          ["schedId"]=>
          string(2) "29"
          ["userId"]=>
          string(2) "19"
          ["createdBy"]=>
          string(1) "3"
          ["startDate"]=>
          string(10) "2020-02-06"
          ["startTime"]=>
          string(8) "08:00:00"
          ["endDate"]=>
          string(10) "2020-02-06"
          ["endTime"]=>
          string(8) "16:00:00"
          ["schedTitle"]=>
          string(13) "08:00 - 16:00"
          ["schedDesc"]=>
          string(8) "Awesome description"
          ["schedColor"]=>
          string(7) "#e9e6e1"
          ["lastUpdated"]=>
          string(19) "2020-02-06 12:55:12"
          ["fullName"]=>
          string(22) "Margo Rennie"
        }
      }
      ["Naya Thomas"]=>
      array(3) {
        [0]=>
        array(13) {
          ["schedId"]=>
          string(2) "13"
          ["userId"]=>
          string(2) "21"
          ["createdBy"]=>
          string(1) "3"
          ["startDate"]=>
          string(10) "2020-02-01"
          ["startTime"]=>
          string(8) "16:00:00"
          ["endDate"]=>
          string(10) "2020-02-01"
          ["endTime"]=>
          string(8) "00:00:00"
          ["schedTitle"]=>
          string(13) "16:00 - 00:00"
          ["schedDesc"]=>
          string(13) "Awesome description"
          ["schedColor"]=>
          string(7) "#e9e6e1"
          ["lastUpdated"]=>
          string(19) "2020-02-06 11:30:21"
          ["fullName"]=>
          string(24) "Naya Thomas"
        }
        [1]=>
        array(13) {
          ["schedId"]=>
          string(2) "20"
          ["userId"]=>
          string(2) "21"
          ["createdBy"]=>
          string(1) "3"
          ["startDate"]=>
          string(10) "2020-02-02"
          ["startTime"]=>
          string(8) "16:00:00"
          ["endDate"]=>
          string(10) "2020-02-02"
          ["endTime"]=>
          string(8) "00:00:00"
          ["schedTitle"]=>
          string(13) "16:00 - 00:00"
          ["schedDesc"]=>
          string(1) "Awesome description"
          ["schedColor"]=>
          string(7) "#e9e6e1"
          ["lastUpdated"]=>
          string(19) "2020-02-06 11:50:52"
          ["fullName"]=>
          string(24) "Naya Thomas"
        }
        [2]=>
        array(13) {
          ["schedId"]=>
          string(2) "31"
          ["userId"]=>
          string(2) "21"
          ["createdBy"]=>
          string(1) "3"
          ["startDate"]=>
          string(10) "2020-02-06"
          ["startTime"]=>
          string(8) "20:00:00"
          ["endDate"]=>
          string(10) "2020-02-06"
          ["endTime"]=>
          string(8) "08:00:00"
          ["schedTitle"]=>
          string(13) "20:00 - 08:00"
          ["schedDesc"]=>
          string(34) "Awesome description"
          ["schedColor"]=>
          string(7) "#e9e6e1"
          ["lastUpdated"]=>
          string(19) "2020-02-06 12:56:32"
          ["fullName"]=>
          string(24) "Naya Thomas"
        }
      }
    }


А теперь для ужасной части, я представляю:

<?php
    $numberOfDaysInCurrentMonth = date('t');
    $alldata_in_while_loop = array();
    while($row = $result->fetch_assoc()) {
        $alldata_in_while_loop[$row['fullName']][] = $row;
    } // ending while loop
?>
<div class="justsomerow">
    <div class="the-container">
        <table id="multivaktaplan" class="display" cellspacing="0" width="100%">
            <thead>
                <tr>
                    <th class="userNameHeader">Name</th>
                    <th class="userIDcolumn">UserID</th>
                    <?php for ($s = 1; $s < ($numberOfDaysInCurrentMonth+1); $s++) { ?><th class="daysinheader"><?php echo $s; ?></th><?php } ?>
                </tr>
                <tr class="weekdaynamesrow"><td></th><td></th><?php for ($s = 1; $s < ($numberOfDaysInCurrentMonth+1); $s++) { ?><th class="daysinheader"><?php echo utf8_encode(strftime('%a', strtotime('2020-02-'.$s))); ?></th><?php } ?></tr>
            </thead>
            <tbody>
<?php
    foreach ($alldata_in_while_loop as $userKey => $userRow) {
        echo "<tr class=\"msgLink\">";
            echo "<td class=\"userName\">".$userRow[0]['fullName']."</td>";
            echo "<td class=\"userIDtd\">".$userRow[0]['userId']."</td>"; 
            foreach (range(1,$numberOfDaysInCurrentMonth) as $day) {
                if ($day <= 9) {
                    $a_with_zero = '0'.$day;
                } else {
                    $a_with_zero = $day;
                }

                foreach ($userRow as $sadfdfdd => $row) {
                    if ('2020-02-'.$a_with_zero == $row['startDate']) {
                        echo "<td class=\"timeparent has-value\" schedId=\"".$row["schedId"]."\"><span class=\"windowtime\">XX</span>";
                        echo "</td>";
                        $dont_echo_next_day = "dont";
                    }

                }
                if ($dont_echo_next_day == 'dont') {
                    $dont_echo_next_day = '';
                } else {
                    echo "<td class=\"timeparent no-value\"><span class=\"windowtime\"></span>";
                    echo "</td>";
                }
            }
        echo "</tr>";
    }
?>
            </tbody>
        </table>
    </div>
</div>

Хотя этот код работает нормально. Он выведет таблицу, как я показываю на картинке. Но если у человека более двух смен (бронирований) в один и тот же день, он выдаст дополнительный день <td></td> для этого человека. Я хочу, чтобы обе брони в один и тот же день были в одном и том же <td></td>

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...