Andrew před 2 měsíci
rodič
revize
b20ce81054

+ 15
- 8
app/Filament/Resources/ProjectResource/Pages/CreateProject.php Zobrazit soubor

4
 
4
 
5
 use App\Filament\Resources\ProjectResource;
5
 use App\Filament\Resources\ProjectResource;
6
 use App\Models\Project;
6
 use App\Models\Project;
7
-use Filament\Actions;
8
 use Filament\Resources\Pages\CreateRecord;
7
 use Filament\Resources\Pages\CreateRecord;
9
 
8
 
10
 class CreateProject extends CreateRecord
9
 class CreateProject extends CreateRecord
11
 {
10
 {
12
     protected static string $resource = ProjectResource::class;
11
     protected static string $resource = ProjectResource::class;
13
 
12
 
13
+    protected array $badgesTargetData = [];
14
+
15
+    protected array $badgesAwardData = [];
16
+
14
     protected function getRedirectUrl(): string
17
     protected function getRedirectUrl(): string
15
     {
18
     {
16
         return $this->getResource()::getUrl('index');
19
         return $this->getResource()::getUrl('index');
28
             $this->badgesAwardData = $data['badgesAward'];
31
             $this->badgesAwardData = $data['badgesAward'];
29
             unset($data['badgesAward']);
32
             unset($data['badgesAward']);
30
         }
33
         }
34
+
31
         return $data;
35
         return $data;
32
     }
36
     }
33
 
37
 
34
     protected function afterCreate(): void
38
     protected function afterCreate(): void
35
     {
39
     {
36
         $syncData = [];
40
         $syncData = [];
37
-        if (!empty($this->badgesTargetData)) {
38
-            foreach ($this->badgesTargetData as $item) {
39
-                $syncData[$item['badge_id'] . '_1'] = [
41
+        if (! empty($this->badgesTargetData)) {
42
+            foreach ($this->badgesTargetData as $index => $item) {
43
+                $syncData[$item['badge_id'].'_1'] = [
40
                     'badge_id' => $item['badge_id'],
44
                     'badge_id' => $item['badge_id'],
41
                     'award_type' => 1,
45
                     'award_type' => 1,
42
                     'award_date' => null,
46
                     'award_date' => null,
47
+                    'sort_order' => $index,
43
                 ];
48
                 ];
44
             }
49
             }
45
         }
50
         }
46
 
51
 
47
-        if (!empty($this->badgesAwardData)) {
48
-            foreach ($this->badgesAwardData as $item) {
49
-                $syncData[$item['badge_id'] . '_2'] = [
52
+        if (! empty($this->badgesAwardData)) {
53
+            foreach ($this->badgesAwardData as $index => $item) {
54
+                $syncData[$item['badge_id'].'_2'] = [
50
                     'badge_id' => $item['badge_id'],
55
                     'badge_id' => $item['badge_id'],
51
                     'award_type' => 2,
56
                     'award_type' => 2,
52
-                    'award_date' => $item['award_date'] . "-01",
57
+                    'award_date' => $item['award_date'].'-01',
58
+                    'sort_order' => $index,
53
                 ];
59
                 ];
54
             }
60
             }
55
         }
61
         }
61
                 'badgeable_type' => Project::class,
67
                 'badgeable_type' => Project::class,
62
                 'award_type' => $data['award_type'],
68
                 'award_type' => $data['award_type'],
63
                 'award_date' => $data['award_date'],
69
                 'award_date' => $data['award_date'],
70
+                'sort_order' => $data['sort_order'],
64
                 'created_at' => now(),
71
                 'created_at' => now(),
65
                 'updated_at' => now(),
72
                 'updated_at' => now(),
66
             ]);
73
             ]);

+ 27
- 17
app/Filament/Resources/ProjectResource/Pages/EditProject.php Zobrazit soubor

4
 
4
 
5
 use App\Filament\Resources\ProjectResource;
5
 use App\Filament\Resources\ProjectResource;
6
 use App\Models\Project;
6
 use App\Models\Project;
7
-use Filament\Actions;
8
 use Filament\Resources\Pages\EditRecord;
7
 use Filament\Resources\Pages\EditRecord;
9
 
8
 
10
 class EditProject extends EditRecord
9
 class EditProject extends EditRecord
11
 {
10
 {
12
     protected static string $resource = ProjectResource::class;
11
     protected static string $resource = ProjectResource::class;
13
 
12
 
13
+    protected array $badgesTargetData = [];
14
+
15
+    protected array $badgesAwardData = [];
16
+
14
     protected function getRedirectUrl(): string
17
     protected function getRedirectUrl(): string
15
     {
18
     {
16
         return $this->getResource()::getUrl('index');
19
         return $this->getResource()::getUrl('index');
24
             ->where('badgeable_id', $project->id)
27
             ->where('badgeable_id', $project->id)
25
             ->where('badgeable_type', Project::class)
28
             ->where('badgeable_type', Project::class)
26
             ->where('award_type', 1)
29
             ->where('award_type', 1)
30
+            ->orderBy('sort_order')
27
             ->get()
31
             ->get()
28
             ->map(fn ($item) => [
32
             ->map(fn ($item) => [
29
                 'badge_id' => $item->badge_id,
33
                 'badge_id' => $item->badge_id,
31
             ])->toArray();
35
             ])->toArray();
32
 
36
 
33
         $data['badgesAward'] = \DB::table('badgeables')
37
         $data['badgesAward'] = \DB::table('badgeables')
34
-        ->where('badgeable_id', $project->id)
35
-        ->where('badgeable_type', Project::class)
36
-        ->where('award_type', 2)
37
-        ->get()
38
-        ->map(fn ($item) => [
39
-            'badge_id' => $item->badge_id,
40
-            'award_date' => $item->award_date,
41
-            'award_type' => $item->award_type,
42
-        ])->toArray();
38
+            ->where('badgeable_id', $project->id)
39
+            ->where('badgeable_type', Project::class)
40
+            ->where('award_type', 2)
41
+            ->orderBy('sort_order')
42
+            ->get()
43
+            ->map(fn ($item) => [
44
+                'badge_id' => $item->badge_id,
45
+                'award_date' => $item->award_date,
46
+                'award_type' => $item->award_type,
47
+            ])->toArray();
48
+
43
         return $data;
49
         return $data;
44
     }
50
     }
45
 
51
 
55
             $this->badgesAwardData = $data['badgesAward'];
61
             $this->badgesAwardData = $data['badgesAward'];
56
             unset($data['badgesAward']);
62
             unset($data['badgesAward']);
57
         }
63
         }
64
+
58
         return $data;
65
         return $data;
59
     }
66
     }
60
 
67
 
67
             ->where('badgeable_type', Project::class)
74
             ->where('badgeable_type', Project::class)
68
             ->delete();
75
             ->delete();
69
 
76
 
70
-        if (!empty($this->badgesTargetData)) {
71
-            foreach ($this->badgesTargetData as $item) {
72
-                $syncData[$item['badge_id'] . '_1'] = [
77
+        if (! empty($this->badgesTargetData)) {
78
+            foreach ($this->badgesTargetData as $index => $item) {
79
+                $syncData[$item['badge_id'].'_1'] = [
73
                     'badge_id' => $item['badge_id'],
80
                     'badge_id' => $item['badge_id'],
74
                     'award_type' => 1,
81
                     'award_type' => 1,
75
                     'award_date' => null,
82
                     'award_date' => null,
83
+                    'sort_order' => $index,
76
                 ];
84
                 ];
77
             }
85
             }
78
         }
86
         }
79
 
87
 
80
-        if (!empty($this->badgesAwardData)) {
81
-            foreach ($this->badgesAwardData as $item) {
82
-                $syncData[$item['badge_id'] . '_2'] = [
88
+        if (! empty($this->badgesAwardData)) {
89
+            foreach ($this->badgesAwardData as $index => $item) {
90
+                $syncData[$item['badge_id'].'_2'] = [
83
                     'badge_id' => $item['badge_id'],
91
                     'badge_id' => $item['badge_id'],
84
                     'award_type' => 2,
92
                     'award_type' => 2,
85
-                    'award_date' => $item['award_date'] . "-01",
93
+                    'award_date' => $item['award_date'].'-01',
94
+                    'sort_order' => $index,
86
                 ];
95
                 ];
87
             }
96
             }
88
         }
97
         }
94
                 'badgeable_type' => Project::class,
103
                 'badgeable_type' => Project::class,
95
                 'award_type' => $data['award_type'],
104
                 'award_type' => $data['award_type'],
96
                 'award_date' => $data['award_date'],
105
                 'award_date' => $data['award_date'],
106
+                'sort_order' => $data['sort_order'],
97
                 'created_at' => now(),
107
                 'created_at' => now(),
98
                 'updated_at' => now(),
108
                 'updated_at' => now(),
99
             ]);
109
             ]);