Andrew 1 month ago
parent
commit
25a3bdc9a3

+ 21
- 12
app/Http/Controllers/Api/EsgController.php View File

@@ -16,8 +16,7 @@ use Illuminate\Support\Facades\Log;
16 16
  */
17 17
 class EsgController extends Controller
18 18
 {
19
-    public function __construct(
20
-    )
19
+    public function __construct()
21 20
     {
22 21
     }
23 22
 
@@ -28,7 +27,7 @@ class EsgController extends Controller
28 27
         $yearList = EsgHistory::select("selected_year", \DB::raw("concat(selected_year, '年') as lable"))->distinct()->orderBy("selected_year", "desc")->pluck('lable', 'selected_year');
29 28
         $result = [];
30 29
         $result["yearList"] = $yearList;
31
-        foreach($data as $item){
30
+        foreach ($data as $item) {
32 31
             $result["list"][$item->selected_year][] = [
33 32
                 "operateMonth " => $item->selected_year . "." . str_pad($item->selected_month, 2, "0", STR_PAD_LEFT),
34 33
                 "title" => $item->getTranslation("title", $locale),
@@ -41,17 +40,27 @@ class EsgController extends Controller
41 40
     public function uploadFiles($locale = "tw")
42 41
     {
43 42
         $locale = $locale == "tw" ? "zh_TW" : $locale;
43
+
44
+        // 定義「取得時間」的翻譯
45
+        $awardDateLabels = [
46
+            'zh_TW' => '取得時間',
47
+            'en' => 'Awarded',
48
+        ];
49
+
50
+        // 取得對應的標籤,如果找不到則使用預設值
51
+        $awardDateLabel = $awardDateLabels[$locale] ?? $awardDateLabels['zh_TW'];
52
+
44 53
         $request_ordering = $request->ordering ?? "desc";
45 54
         $fileList = UploadFile::where("type", 1)
46
-                                        ->select("title", "upload_link", "award_date")
47
-                                        ->orderBy("award_date", $request_ordering)
48
-                                        ->orderBy("order", $request_ordering)->get()->map(function ($record) {
49
-            return [
50
-                "title" => $record->title,
51
-                "uploadLink" => $record->upload_file_link,
52
-                "awardDate" => "獲頒日期 : " . date("Y/m/d", strtotime($record->award_date))
53
-            ];
54
-        });
55
+            ->select("title", "upload_link", "award_date")
56
+            ->orderBy("award_date", $request_ordering)
57
+            ->orderBy("order", $request_ordering)->get()->map(function ($record) use ($awardDateLabel, $locale) {
58
+                return [
59
+                    "title" => $record->getTranslation("title", $locale),
60
+                    "uploadLink" => $record->upload_file_link,
61
+                    "awardDate" => $awardDateLabel . " : " . date("Y/m/d", strtotime($record->award_date))
62
+                ];
63
+            });
55 64
         return Response::ok($fileList);
56 65
     }
57 66
 }

+ 11
- 3
app/Http/Controllers/Api/ProjectController.php View File

@@ -133,10 +133,18 @@ class ProjectController extends Controller
133 133
         return Response::ok($result);
134 134
     }
135 135
 
136
-    public function badges($locale = 'tw')
137
-    {
136
+    public function badges($locale = 'tw') {
138 137
         $locale = $locale == 'tw' ? 'zh_TW' : $locale;
139 138
 
139
+        // 定義「取得時間」的翻譯
140
+        $awardDateLabels = [
141
+            'zh_TW' => '取得時間',
142
+            'en' => 'Awarded',
143
+        ];
144
+
145
+        // 取得對應的標籤,如果找不到則使用預設值
146
+        $awardDateLabel = $awardDateLabels[$locale] ?? $awardDateLabels['zh_TW'];
147
+
140 148
         $projects = Project::where('badge_type', 2)->get();
141 149
         $result = [];
142 150
 
@@ -147,7 +155,7 @@ class ProjectController extends Controller
147 155
                 $badges[] = [
148 156
                     'imgUrl' => $badge->imgUrlLink,
149 157
                     'name' => $badge->getTranslation('title', $locale),
150
-                    'rewardYear' => '取得時間 : '.date('Y.m', strtotime($badge->pivot->award_date)),
158
+                    'rewardYear' => $awardDateLabel . ' : ' . date('Y.m', strtotime($badge->pivot->award_date)),
151 159
                 ];
152 160
             }
153 161
             $result[] = [

+ 18
- 9
app/Models/Project.php View File

@@ -77,49 +77,49 @@ class Project extends Model
77 77
     public function firstListImgUrl(): Attribute
78 78
     {
79 79
         return Attribute::make(
80
-            get: fn ($value) => ! empty($this->img_url) ? Storage::url($this->img_url[0]) : null,
80
+            get: fn($value) => !empty($this->img_url) ? Storage::url($this->img_url[0]) : null,
81 81
         );
82 82
     }
83 83
 
84 84
     public function imgList(): Attribute
85 85
     {
86 86
         $imgList = [];
87
-        if (! is_null($this->img_url) && count($this->img_url) > 0) {
87
+        if (!is_null($this->img_url) && count($this->img_url) > 0) {
88 88
             foreach ($this->img_url as $img) {
89 89
                 $imgList[] = Storage::url($img);
90 90
             }
91 91
         }
92 92
 
93 93
         return Attribute::make(
94
-            get: fn ($value) => $imgList,
94
+            get: fn($value) => $imgList,
95 95
         );
96 96
     }
97 97
 
98 98
     public function thumbnailUrl(): Attribute
99 99
     {
100 100
         return Attribute::make(
101
-            get: fn ($value) => ! empty($this->thumbnail) ? Storage::url($this->thumbnail) : null,
101
+            get: fn($value) => !empty($this->thumbnail) ? Storage::url($this->thumbnail) : null,
102 102
         );
103 103
     }
104 104
 
105 105
     public function firstMobileImgUrl(): Attribute
106 106
     {
107 107
         return Attribute::make(
108
-            get: fn ($value) => ! empty($this->mobile_img_url) ? Storage::url($this->mobile_img_url[0]) : null,
108
+            get: fn($value) => !empty($this->mobile_img_url) ? Storage::url($this->mobile_img_url[0]) : null,
109 109
         );
110 110
     }
111 111
 
112 112
     public function mobileImgList(): Attribute
113 113
     {
114 114
         $imgList = [];
115
-        if (! is_null($this->mobile_img_url) && count($this->mobile_img_url) > 0) {
115
+        if (!is_null($this->mobile_img_url) && count($this->mobile_img_url) > 0) {
116 116
             foreach ($this->mobile_img_url as $img) {
117 117
                 $imgList[] = Storage::url($img);
118 118
             }
119 119
         }
120 120
 
121 121
         return Attribute::make(
122
-            get: fn ($value) => $imgList,
122
+            get: fn($value) => $imgList,
123 123
         );
124 124
     }
125 125
 
@@ -131,7 +131,7 @@ class Project extends Model
131 131
                 $badges[] = [
132 132
                     'imgUrl' => $badge->imgUrlLink,
133 133
                     'name' => $badge->getTranslation('title', $locale),
134
-                    'awardDate' => '取得時間 : '.date('Y.m', strtotime($badge->pivot->award_date)),
134
+                    'awardDate' => '取得時間 : ' . date('Y.m', strtotime($badge->pivot->award_date)),
135 135
                 ];
136 136
             }
137 137
         }
@@ -141,6 +141,15 @@ class Project extends Model
141 141
 
142 142
     public function getBadgesByType($locale, $badgeType): array
143 143
     {
144
+        // 定義「取得時間」的翻譯
145
+        $awardDateLabels = [
146
+            'zh_TW' => '取得時間',
147
+            'en' => 'Awarded',
148
+        ];
149
+
150
+        // 取得對應的標籤,如果找不到則使用預設值
151
+        $awardDateLabel = $awardDateLabels[$locale] ?? $awardDateLabels['zh_TW'];
152
+
144 153
         $badges = [];
145 154
         switch ($badgeType) {
146 155
             case '1':
@@ -159,7 +168,7 @@ class Project extends Model
159 168
                     $badges[] = [
160 169
                         'imgUrl' => $badge->imgUrlLink,
161 170
                         'name' => $badge->getTranslation('title', $locale),
162
-                        'awardDate' => '取得時間 : '.date('Y.m', strtotime($badge->pivot->award_date)),
171
+                        'awardDate' => $awardDateLabel . ' : ' . date('Y.m', strtotime($badge->pivot->award_date)),
163 172
                     ];
164 173
                 }
165 174
                 break;