-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* #114 - batch students import * Update resources/js/Pages/Dashboard/Student/Import.vue Co-authored-by: Ewelina Skrzypacz <56546832+EwelinaSkrzypacz@users.noreply.github.com> --------- Co-authored-by: Ewelina Skrzypacz <56546832+EwelinaSkrzypacz@users.noreply.github.com>
- Loading branch information
1 parent
2f713a2
commit a2dec55
Showing
10 changed files
with
629 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Actions; | ||
|
||
use App\Models\Student; | ||
|
||
class WuStudentsImport | ||
{ | ||
protected array $students = []; | ||
|
||
public function import(string $content): array | ||
{ | ||
$previousLine = null; | ||
|
||
foreach (explode("\n", $content) as $line) { | ||
if (str_starts_with($line, "nr albumu:")) { | ||
$names = explode(" ", $previousLine); | ||
|
||
$this->students[] = new Student([ | ||
"first_name" => $names[1] ?? "", | ||
"surname" => $names[0] ?? "", | ||
"index_number" => str_replace("nr albumu:", "", $line), | ||
]); | ||
} | ||
|
||
$previousLine = $line; | ||
} | ||
|
||
return $this->students; | ||
} | ||
|
||
public function save(): void | ||
{ | ||
/** @var Student $student */ | ||
foreach ($this->students as $student) { | ||
if (Student::query()->where("index_number", $student->index_number)->count() === 0) { | ||
$student->save(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<script setup> | ||
import DashboardLayout from '@/Layouts/DashboardLayout.vue' | ||
import Section from '@/Shared/Components/Section.vue' | ||
import SubmitButton from '@/Shared/Components/Buttons/SubmitButton.vue' | ||
import FormGroup from '@/Shared/Forms/FormGroup.vue' | ||
import FormLabel from '@/Shared/Forms/FormLabel.vue' | ||
import { useForm } from '@inertiajs/inertia-vue3' | ||
import FormError from '@/Shared/Forms/FormError.vue' | ||
import ManagementHeader from '@/Shared/Components/ManagementHeader.vue' | ||
import ManagementHeaderItem from '@/Shared/Components/ManagementHeaderItem.vue' | ||
const form = useForm({ | ||
content: '', | ||
}) | ||
function importStudents() { | ||
form.post('/dashboard/students/import') | ||
} | ||
</script> | ||
|
||
<template> | ||
<DashboardLayout> | ||
<div class="flex flex-col gap-8"> | ||
<ManagementHeader> | ||
<template #header> | ||
Zarządzanie studentami (masowo) | ||
</template> | ||
<template #statistics> | ||
<ManagementHeaderItem> | ||
Formularz dodawania nowych studentów | ||
</ManagementHeaderItem> | ||
</template> | ||
</ManagementHeader> | ||
|
||
<form class="grid grid-cols-2" @submit.prevent="importStudents"> | ||
<Section> | ||
<div class="flex flex-col justify-between gap-4"> | ||
<FormGroup> | ||
<FormLabel for="content"> | ||
Źródło strony z WU | ||
<span class="text-gray-500">(uczelnia -> protokoły -> edytuj)</span> | ||
</FormLabel> | ||
<textarea v-model="form.content" class="block h-[320px] w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 sm:text-sm sm:leading-6" /> | ||
<FormError :error="form.errors.content" /> | ||
</FormGroup> | ||
<div class="mt-4 flex justify-end"> | ||
<SubmitButton> | ||
Importuj | ||
</SubmitButton> | ||
</div> | ||
</div> | ||
</Section> | ||
</form> | ||
</div> | ||
</DashboardLayout> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.