]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[ERP-195] refactor month names and week names out to DateHelper
authorAlexander Smirnov <fredeom@mail.ru>
Wed, 25 Sep 2024 15:27:47 +0000 (18:27 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Wed, 25 Sep 2024 15:27:47 +0000 (18:27 +0300)
erp24/controllers/ProductionCalendarController.php
erp24/helpers/DateHelper.php
erp24/views/production-calendar/index.php

index 4ae56d0f813dbac9af1e615948d7626c21331033..ed9efd6dc6ee07b37f4767b1fe744b5e4781a44a 100644 (file)
@@ -62,9 +62,6 @@ class ProductionCalendarController extends Controller
             Yii::$app->session->setFlash('success', 'Календарь успешно загружен.');
         }
 
-        $months = ['Январь',' Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'];
-        $daysInWeek = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'];
-
         $workDaysMap = ArrayHelper::map(ProductionCalendar::find()->where(['between', 'date', '2024-01-01', '2024-12-31'])->all(), 'date', 'work');
 
         if (!$viewYear) {
@@ -92,6 +89,6 @@ class ProductionCalendarController extends Controller
         }
 
         return $this->render('index',
-            compact('months', 'daysInWeek', 'workDaysMap', 'viewYear', 'years', 'workDaysInMonthCountMap'));
+            compact('workDaysMap', 'viewYear', 'years', 'workDaysInMonthCountMap'));
     }
 }
\ No newline at end of file
index e6c618eafef41e81f66c588213b69abe0df3b805..3e5428b320051ccfb9d0d5e8190f51a4675e014c 100644 (file)
@@ -7,6 +7,8 @@ use yii_app\services\CabinetService;
 
 class DateHelper
 {
+    const MONTH_NAMES = ['Январь',' Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'];
+    const DAYS_IN_WEEK_NAMES_SHORT = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'];
 
     public static int $hourStartSmen = 8;
     public static int $hourEndSmen = 20;
index 4efedeeaf5b7da68ab4afe325122b5b2baa6907e..0628a2ecd86bcd0b4ff1672e3357b3a6b2c5ceda 100644 (file)
@@ -3,8 +3,8 @@
 use yii\helpers\Html;
 use yii\widgets\ActiveForm;
 
-/** @var $months array */
-/** @var $daysInWeek array */
+use yii_app\helpers\DateHelper;
+
 /** @var $workDaysMap array */
 /** @var $years array */
 /** @var $viewYear string */
@@ -35,14 +35,14 @@ $this->registerCssFile('/css/production-calendar/style.css');
 
 
     <div class="pcal-month-container" style="max-width: 1230px;">
-        <?php foreach ($months as $monthIndex => $month): ?>
+        <?php foreach (DateHelper::MONTH_NAMES as $monthIndex => $month): ?>
             <div class="pcal-month w-20" style="max-width: 250px;">
                 <div class="pcal-month-name"><?= $month; ?></div>
                 <div class="pcal-days">
                     <table>
                         <tbody>
                             <tr>
-                                <?php foreach ($daysInWeek as $dayName): ?>
+                                <?php foreach (DateHelper::DAYS_IN_WEEK_NAMES_SHORT as $dayName): ?>
                                     <td class="pcal-day-of-week1"><?= $dayName; ?></td>
                                 <?php endforeach; ?>
                             </tr>
@@ -51,7 +51,7 @@ $this->registerCssFile('/css/production-calendar/style.css');
                             <?php $numMonth =  date('t', strtotime(date($viewYear . "-" . $padMonth . "-01"))); ?>
                             <?php foreach (range(1, 6) as $weekNum): ?>
                                 <tr>
-                                    <?php foreach ($daysInWeek as $dayIndexInWeek => $dayName): ?>
+                                    <?php foreach (DateHelper::DAYS_IN_WEEK_NAMES_SHORT as $dayIndexInWeek => $dayName): ?>
                                         <?php $num++; ?>
                                         <?php $date = $viewYear . '-' . $padMonth . '-' . ($num < 10 ? '0' . $num : $num); ?>
                                         <td class="text-center pcal-day <?= ($workDaysMap[$date] ?? -1) == 0 ? 'pcal-day-holiday' : ''?>">