Browse Source

added helpers

Josh 4 years ago
parent
commit
0de95a4692

+ 89 - 0
app/Helpers/helpers.php

@@ -42,6 +42,40 @@ if(!function_exists('friendly_date_time_short')) {
     }
     }
 }
 }
 
 
+if(!function_exists('friendly_date_time_short_with_tz')) {
+    function friendly_date_time_short_with_tz($value, $includeTime = true, $tz='UTC', $default = '-') {
+        if(!$value || empty($value)) return $default;
+        try {
+
+            $realTimezone = resolve_timezone($tz);
+            $date = new DateTime($value, new DateTimeZone('UTC'));
+            
+            $date->setTimezone(new DateTimeZone($realTimezone));
+            
+            return $date->format("m/d/y" . ($includeTime ? ", h:iA" : ""));
+
+        }
+        catch (Exception $e) {
+            return $e->getMessage();
+        }
+    }
+}
+
+
+if(!function_exists('unfriendly_date')) {
+    function unfriendly_date($value) {
+        if(!$value || empty($value)) return '';
+        try {
+            $result = strtotime($value);
+            $result = date("Y-m-d", $result);
+            return $result;
+        }
+        catch (Exception $e) {
+            return $value;
+        }
+    }
+}
+
 if(!function_exists('friendly_time')) {
 if(!function_exists('friendly_time')) {
     function friendly_time($value, $default = '-') {
     function friendly_time($value, $default = '-') {
         if(!$value || empty($value)) return $default;
         if(!$value || empty($value)) return $default;
@@ -56,6 +90,61 @@ if(!function_exists('friendly_time')) {
     }
     }
 }
 }
 
 
+if(!function_exists('military_time')) {
+    function military_time($value,  $tz='UTC', $default = '-') {
+        
+        if(!$value || empty($value)) return $default;
+        try {
+            $realTimezone = resolve_timezone($tz);
+            $date = new DateTime($value, new DateTimeZone('UTC'));  
+            $date->setTimezone(new DateTimeZone($realTimezone));          
+            return $date->format("H:i");
+        }
+        catch (Exception $e) {
+            return $value;
+        }
+    }
+}
+
+if(!function_exists('resolve_timezone')) {
+    function resolve_timezone($value) {
+        try {
+            switch ($value) {
+                case 'ALASKA': {
+                    return 'US/Alaska';
+                }
+                case 'CENTRAL': {
+                    return 'US/Central';
+                }
+                case 'EASTERN': {
+                    return 'US/Eastern';
+                }
+                case 'HAWAII': {
+                    return 'US/Hawaii';
+                }
+                case 'MOUNTAIN': {
+                    return 'US/Mountain';
+                }
+                case 'PACIFIC': {
+                    return 'US/Pacific';
+                }
+                case 'PUERTO_RICO': {
+                    return 'America/Puerto_Rico';
+                }
+                case 'UTC': {
+                    return 'UTC';
+                }
+                }
+        }
+        catch (Exception $e) {
+            return $value;
+        }
+    }
+}
+
+// $date = new DateTime('2000-01-01', new DateTimeZone('Pacific/Nauru'));
+// echo $date->format('Y-m-d H:i:sP') . "\n";
+
 if(!function_exists('friendly_month')) {
 if(!function_exists('friendly_month')) {
     function friendly_month($value) {
     function friendly_month($value) {
         if(!$value || empty($value)) return "-";
         if(!$value || empty($value)) return "-";

+ 28 - 3
app/Http/Controllers/PracticeManagementController.php

@@ -141,9 +141,34 @@ class PracticeManagementController extends Controller
     {
     {
         $performer = $this->performer();
         $performer = $this->performer();
         $pro = $performer->pro;
         $pro = $performer->pro;
-        $generalAvailabilities = ProGeneralAvailability::where('pro_id', $pro->id)->where('is_cancelled', false)->orderBy('created_at', 'asc')->get();
-        $specificAvailabilities = ProGeneralAvailability::where('pro_id', $pro->id)->where('is_cancelled', false)->orderBy('created_at', 'asc')->get();
-        $specificUnavailabilities = ProSpecificUnavailability::where('pro_id', $pro->id)->where('is_cancelled', false)->orderBy('created_at', 'asc')->get();
+        $generalAvailabilitiesList = ProGeneralAvailability::where('pro_id', $pro->id)->where('is_cancelled', false)->orderBy('created_at', 'asc')->get();
+        $generalAvailabilities = [];
+        foreach($generalAvailabilitiesList as $ga){
+            if($ga->day_of_week == 'MONDAY'){
+                $generalAvailabilities['MONDAY'] = $ga;
+            }
+            if($ga->day_of_week == 'TUESDAY'){
+                $generalAvailabilities['TUESDAY'] = $ga;
+            }
+            if($ga->day_of_week == 'WEDNESDAY'){
+                $generalAvailabilities['WEDNESDAY'] = $ga;
+            }
+            if($ga->day_of_week == 'THURSDAY'){
+                $generalAvailabilities['THURSDAY'] = $ga;
+            }
+            if($ga->day_of_week == 'FRIDAY'){
+                $generalAvailabilities['FRIDAY'] = $ga;
+            }
+            if($ga->day_of_week == 'SATURDAY'){
+                $generalAvailabilities['SATURDAY'] = $ga;
+            }
+            if($ga->day_of_week == 'SUNDAY'){
+                $generalAvailabilities['SUNDAY'] = $ga;
+            }
+        }
+        
+        $specificAvailabilities = ProSpecificUnavailability::where('pro_id', $pro->id)->where('is_cancelled', false)->orderBy('start_time')->get();
+        $specificUnavailabilities = ProSpecificUnavailability::where('pro_id', $pro->id)->where('is_cancelled', false)->orderBy('start_time', 'asc')->get();
 
 
         return view('app.practice-management.my-availability', compact('generalAvailabilities', 'specificAvailabilities', 'specificUnavailabilities'));
         return view('app.practice-management.my-availability', compact('generalAvailabilities', 'specificAvailabilities', 'specificUnavailabilities'));
     }
     }

+ 126 - 66
resources/views/app/practice-management/my-availability.blade.php

@@ -55,7 +55,7 @@
                                     @foreach($daysOfWeek as $dayOfWeek)
                                     @foreach($daysOfWeek as $dayOfWeek)
                                     <option value="{{$dayOfWeek}}">{{$dayOfWeek}}</option>
                                     <option value="{{$dayOfWeek}}">{{$dayOfWeek}}</option>
                                     @endforeach
                                     @endforeach
-                                </select>        
+                                </select>
                             </div>
                             </div>
                             <div class="form-group">
                             <div class="form-group">
                                 <label for="" class="control-label">Start Time </label>
                                 <label for="" class="control-label">Start Time </label>
@@ -82,36 +82,39 @@
                         </tr>
                         </tr>
                     </thead>
                     </thead>
                     <tbody>
                     <tbody>
-                        @foreach($generalAvailabilities as $ga)
+                        @foreach($daysOfWeek as $dow)
                         <tr>
                         <tr>
-                            <td>{{$ga->day_of_week}}</td>
-                            <td>{{$ga->start_time}}</td>
-                            <td>{{$ga->end_time}}</td>
-                            <td></td>
-                        </tr>
-                        @endforeach
-                    </tbody>
-                </table>
-            </div>
-
-            <div class="card mb-2">
-                <div class="card-header">
-                    Specific Availability
-                </div>
-                <table class="table table-sm table-striped">
-                    <thead>
-                        <tr>
-                            <th>Start Time</th>
-                            <th>End Time</th>
-                            <th></th>
-                        </tr>
-                    </thead>
-                    <tbody>
-                        @foreach($specificAvailabilities as $ga)
-                        <tr>
-                            <td>{{$ga->start_time}}</td>
-                            <td>{{$ga->end_time}}</td>
-                            <td></td>
+                            <td>{{$dow}}</td>
+                            <td>{{isset($generalAvailabilities[$dow]) ? $generalAvailabilities[$dow]->start_time : ''}}</td>
+                            <td>{{isset($generalAvailabilities[$dow]) ? $generalAvailabilities[$dow]->end_time : ''}}</td>
+                            <td>
+                                @if(isset($generalAvailabilities[$dow]))
+                                <div moe wide class="mr-2">
+                                    <a start show>
+                                        update
+                                    </a>
+                                    <form url="/api/proGeneralAvailability/update">
+                                        <input type="hidden" name="uid" value="{{$generalAvailabilities[$dow]->uid}}">
+                                        <input type="hidden" name="timezone" value="EASTERN">
+                                        <div class="form-group">
+                                            {{$generalAvailabilities[$dow]->day_of_week}}
+                                        </div>
+                                        <div class="form-group">
+                                            <label for="" class="control-label">Start Time </label>
+                                            <input class="form-control" type="time" name="startTime" value="{{military_time($generalAvailabilities[$dow]->start_time)}}">
+                                        </div>
+                                        <div class="form-group">
+                                            <label for="" class="control-label">End Time </label>
+                                            <input class="form-control" type="time" name="endTime" value="{{military_time($generalAvailabilities[$dow]->end_time)}}">
+                                        </div>
+                                        <div class="form-group m-0">
+                                            <button submit class="btn btn-primary btn-sm mr-2">Submit</button>
+                                            <button cancel class="btn btn-default border btn-sm mr-2">Cancel</button>
+                                        </div>
+                                    </form>
+                                </div>
+                                @endif
+                            </td>
                         </tr>
                         </tr>
                         @endforeach
                         @endforeach
                     </tbody>
                     </tbody>
@@ -119,40 +122,10 @@
             </div>
             </div>
 
 
             <div class="card mb-2">
             <div class="card mb-2">
-                <div class="card-header">
-                    Specific Unavailability
-                </div>
-                <table class="table table-sm table-striped">
-                    <thead>
-                        <tr>
-                            <th>Start Time</th>
-                            <th>End Time</th>
-                            <th>Title</th>
-                            <th></th>
-                        </tr>
-                    </thead>
-                    <tbody>
-                        @foreach($specificUnavailabilities as $su)
-                        <tr>
-                            <td>{{$su->start_time}}</td>
-                            <td>{{$su->end_time}}</td>
-                            <td>{{$su->title}}</td>
-                            <td></td>
-                        </tr>
-                        @endforeach
-                    </tbody>
-                </table>
-            </div>
-        </div>
-        <div class="col-md-6">
-            <div class="card">
-
-                <div class="card-header px-3 py-2 d-flex align-items-center">
-                    <strong class="">
-                        <i class="fas fa-user-injured"></i>
-                        My Availability
-                    </strong>
-                    <span class="mx-2 text-secondary">|</span>
+                <div class="card-header d-flex">
+                    <div class="mr-2">
+                        Specific Availability
+                    </div>
                     <div moe wide class="mr-2">
                     <div moe wide class="mr-2">
                         <a start show>
                         <a start show>
                             Add Specific Availability
                             Add Specific Availability
@@ -185,8 +158,32 @@
                             </div>
                             </div>
                         </form>
                         </form>
                     </div>
                     </div>
+                </div>
+                <table class="table table-sm table-striped">
+                    <thead>
+                        <tr>
+                            <th>Start Time</th>
+                            <th>End Time</th>
+                            <th></th>
+                        </tr>
+                    </thead>
+                    <tbody>
+                        @foreach($specificAvailabilities as $ga)
+                        <tr>
+                            <td>{{friendly_date_time_short($ga->start_time)}}</td>
+                            <td>{{friendly_date_time_short($ga->end_time)}}</td>
+                            <td></td>
+                        </tr>
+                        @endforeach
+                    </tbody>
+                </table>
+            </div>
 
 
-                    <span class="mx-2 text-secondary">|</span>
+            <div class="card mb-2">
+                <div class="card-header d-flex">
+                    <div class="mr-2">
+                        Specific Unavailability
+                    </div>
                     <div moe wide class="mr-2">
                     <div moe wide class="mr-2">
                         <a start show>
                         <a start show>
                             Add Specific Unvailability
                             Add Specific Unvailability
@@ -220,8 +217,71 @@
                         </form>
                         </form>
                     </div>
                     </div>
                 </div>
                 </div>
+                <table class="table table-sm table-striped">
+                    <thead>
+                        <tr>
+                            <th>Start Time</th>
+                            <th>End Time</th>
+                            <th>Title</th>
+                            <th></th>
+                        </tr>
+                    </thead>
+                    <tbody>
+                        @foreach($specificUnavailabilities as $su)
+                        <tr>
+                            <td>{{friendly_date_time_short_with_tz($su->start_time, $su->timezone)}}</td>
+                            <td>{{friendly_date_time_short_with_tz($su->end_time, $su->timezone)}}</td>
+                            <td>{{$su->title}}</td>
+                            <td>
+                                <div moe wide class="mr-2">
+                                    <a start show>
+                                        update
+                                    </a>
+                                    <form url="/api/proSpecificUnavailability/update">
+                                        <input type="hidden" name="uid" value="{{$su->uid}}">
+                                        <input type="hidden" name="timezone" value="EASTERN">
+                                        <div class="mb-2">
+                                            <input type="text" class="form-control form-control-sm" name="title" value="{{$su->title}}">
+                                        </div>
+                                        <div class="mb-2">
+                                            <label for="" class="control-label">Start Date </label>
+                                            <input class="form-control" type="date" name="startDate" value="{{unfriendly_date($su->start_time)}}">
+                                        </div>
+                                        <div class="mb-2">
+                                            <label for="" class="control-label">Start Time </label>
+                                            <input class="form-control" type="time" name="startTime" value="{{military_time($su->start_time, $su->timezone)}}">
+                                        </div>
+                                        <div class="mb-2">
+                                            <label for="" class="control-label">End Date </label>
+                                            <input class="form-control" type="date" name="endDate" value="{{unfriendly_date($su->end_time)}}">
+                                        </div>
+                                        <div class="mb-2">
+                                            <label for="" class="control-label">End Time </label>
+                                            <input class="form-control" type="time" name="endTime" value="{{military_time($su->end_time, $su->timezone)}}">
+                                        </div>
+                                        <div class="form-group m-0">
+                                            <button submit class="btn btn-primary btn-sm mr-2">Submit</button>
+                                            <button cancel class="btn btn-default border btn-sm mr-2">Cancel</button>
+                                        </div>
+                                    </form>
+                                </div>
+                            </td>
+                        </tr>
+                        @endforeach
+                    </tbody>
+                </table>
+            </div>
+        </div>
+        <div class="col-md-6">
+            <div class="card">
+                <div class="card-header px-3 py-2 d-flex align-items-center">
+                    <strong class="">
+                        <i class="fas fa-user-injured"></i>
+                        My Availability
+                    </strong>
+                </div>
                 <div class="card-body p-0">
                 <div class="card-body p-0">
-                    <div id="pro-availability-calendar"></div>
+                    <div id="pro-availability-calendar" class="mx-2"></div>
                 </div>
                 </div>
             </div>
             </div>
         </div>
         </div>