Andrew před 1 měsícem
rodič
revize
25a3bdc9a3

+ 21
- 12
app/Http/Controllers/Api/EsgController.php Zobrazit soubor

16
  */
16
  */
17
 class EsgController extends Controller
17
 class EsgController extends Controller
18
 {
18
 {
19
-    public function __construct(
20
-    )
19
+    public function __construct()
21
     {
20
     {
22
     }
21
     }
23
 
22
 
28
         $yearList = EsgHistory::select("selected_year", \DB::raw("concat(selected_year, '年') as lable"))->distinct()->orderBy("selected_year", "desc")->pluck('lable', 'selected_year');
27
         $yearList = EsgHistory::select("selected_year", \DB::raw("concat(selected_year, '年') as lable"))->distinct()->orderBy("selected_year", "desc")->pluck('lable', 'selected_year');
29
         $result = [];
28
         $result = [];
30
         $result["yearList"] = $yearList;
29
         $result["yearList"] = $yearList;
31
-        foreach($data as $item){
30
+        foreach ($data as $item) {
32
             $result["list"][$item->selected_year][] = [
31
             $result["list"][$item->selected_year][] = [
33
                 "operateMonth " => $item->selected_year . "." . str_pad($item->selected_month, 2, "0", STR_PAD_LEFT),
32
                 "operateMonth " => $item->selected_year . "." . str_pad($item->selected_month, 2, "0", STR_PAD_LEFT),
34
                 "title" => $item->getTranslation("title", $locale),
33
                 "title" => $item->getTranslation("title", $locale),
41
     public function uploadFiles($locale = "tw")
40
     public function uploadFiles($locale = "tw")
42
     {
41
     {
43
         $locale = $locale == "tw" ? "zh_TW" : $locale;
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
         $request_ordering = $request->ordering ?? "desc";
53
         $request_ordering = $request->ordering ?? "desc";
45
         $fileList = UploadFile::where("type", 1)
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
         return Response::ok($fileList);
64
         return Response::ok($fileList);
56
     }
65
     }
57
 }
66
 }

+ 11
- 3
app/Http/Controllers/Api/ProjectController.php Zobrazit soubor

133
         return Response::ok($result);
133
         return Response::ok($result);
134
     }
134
     }
135
 
135
 
136
-    public function badges($locale = 'tw')
137
-    {
136
+    public function badges($locale = 'tw') {
138
         $locale = $locale == 'tw' ? 'zh_TW' : $locale;
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
         $projects = Project::where('badge_type', 2)->get();
148
         $projects = Project::where('badge_type', 2)->get();
141
         $result = [];
149
         $result = [];
142
 
150
 
147
                 $badges[] = [
155
                 $badges[] = [
148
                     'imgUrl' => $badge->imgUrlLink,
156
                     'imgUrl' => $badge->imgUrlLink,
149
                     'name' => $badge->getTranslation('title', $locale),
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
             $result[] = [
161
             $result[] = [

+ 18
- 9
app/Models/Project.php Zobrazit soubor

77
     public function firstListImgUrl(): Attribute
77
     public function firstListImgUrl(): Attribute
78
     {
78
     {
79
         return Attribute::make(
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
     public function imgList(): Attribute
84
     public function imgList(): Attribute
85
     {
85
     {
86
         $imgList = [];
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
             foreach ($this->img_url as $img) {
88
             foreach ($this->img_url as $img) {
89
                 $imgList[] = Storage::url($img);
89
                 $imgList[] = Storage::url($img);
90
             }
90
             }
91
         }
91
         }
92
 
92
 
93
         return Attribute::make(
93
         return Attribute::make(
94
-            get: fn ($value) => $imgList,
94
+            get: fn($value) => $imgList,
95
         );
95
         );
96
     }
96
     }
97
 
97
 
98
     public function thumbnailUrl(): Attribute
98
     public function thumbnailUrl(): Attribute
99
     {
99
     {
100
         return Attribute::make(
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
     public function firstMobileImgUrl(): Attribute
105
     public function firstMobileImgUrl(): Attribute
106
     {
106
     {
107
         return Attribute::make(
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
     public function mobileImgList(): Attribute
112
     public function mobileImgList(): Attribute
113
     {
113
     {
114
         $imgList = [];
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
             foreach ($this->mobile_img_url as $img) {
116
             foreach ($this->mobile_img_url as $img) {
117
                 $imgList[] = Storage::url($img);
117
                 $imgList[] = Storage::url($img);
118
             }
118
             }
119
         }
119
         }
120
 
120
 
121
         return Attribute::make(
121
         return Attribute::make(
122
-            get: fn ($value) => $imgList,
122
+            get: fn($value) => $imgList,
123
         );
123
         );
124
     }
124
     }
125
 
125
 
131
                 $badges[] = [
131
                 $badges[] = [
132
                     'imgUrl' => $badge->imgUrlLink,
132
                     'imgUrl' => $badge->imgUrlLink,
133
                     'name' => $badge->getTranslation('title', $locale),
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
 
141
 
142
     public function getBadgesByType($locale, $badgeType): array
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
         $badges = [];
153
         $badges = [];
145
         switch ($badgeType) {
154
         switch ($badgeType) {
146
             case '1':
155
             case '1':
159
                     $badges[] = [
168
                     $badges[] = [
160
                         'imgUrl' => $badge->imgUrlLink,
169
                         'imgUrl' => $badge->imgUrlLink,
161
                         'name' => $badge->getTranslation('title', $locale),
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
                 break;
174
                 break;