Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app/Http/Controllers/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function show(LanguagePack $languagePack)
}

return view('languagepack.export', [
'completedSteps' => ['lang_info', 'tiles', 'wordlist', 'keyboard', 'syllables', 'resources', 'game_settings', 'games', 'export'],
'completedSteps' => ['lang_info', 'tiles', 'wordlist', 'keyboard', 'syllables', 'resources', 'game_settings', 'games', 'notes', 'export'],
'languagePack' => $languagePack,
'errors' => $groupedErrors,
'exportWarningMessage' => $exportWarningMessage,
Expand Down
98 changes: 98 additions & 0 deletions src/app/Http/Controllers/NotesController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php

namespace App\Http\Controllers;

use App\Models\LanguagePack;
use App\Models\Note;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Validator;

class NotesController extends BaseItemController
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->route = 'notes';
$this->model = new Note();
$this->fileKeyname = 'note';

parent::__construct();
}

/**
* Edit the language pack setup.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function edit(LanguagePack $languagePack)
{
$items = Note::where('languagepackid', $languagePack->id)
->orderBy('id')
->paginate(config('pagination.default'));

return view('languagepack.notes', [
'completedSteps' => ['lang_info', 'tiles', 'wordlist', 'keyboard', 'syllables', 'resources', 'game_settings', 'games', 'notes'],
'languagePack' => $languagePack,
'items' => $items,
'pagination' => $items->links(),
]);
}

public function store(LanguagePack $languagePack, Request $request)
{
$validator = Validator::make($request->all(), [
'text' => 'required|string',
]);

if ($validator->fails()) {
return Redirect::back()->withErrors($validator)->withInput();
}

Note::create([
'languagepackid' => $languagePack->id,
'text' => $request->input('text'),
]);

$totalPages = (int) ceil(Note::where('languagepackid', $languagePack->id)->count() / config('pagination.default'));

return redirect("languagepack/notes/{$languagePack->id}?page={$totalPages}");
}

public function update(LanguagePack $languagePack, Request $request)
{
$validator = Validator::make($request->all(), [
'items.*.id' => 'required|integer',
'items.*.text' => 'required|string',
]);

if ($validator->fails()) {
return Redirect::back()->withErrors($validator)->withInput();
}

foreach ($request->input('items', []) as $item) {
Note::where('id', $item['id'])
->where('languagepackid', $languagePack->id)
->update(['text' => $item['text']]);
}

session()->flash('success', 'Records updated successfully');

// return the view directly (not a redirect) so the delete confirmation
// step below can see the submitted 'items' delete checkboxes
$itemCollection = Note::where('languagepackid', $languagePack->id)
->orderBy('id')
->paginate(config('pagination.default'));

return view('languagepack.notes', [
'completedSteps' => ['lang_info', 'tiles', 'wordlist', 'keyboard', 'syllables', 'resources', 'game_settings', 'games', 'notes'],
'languagePack' => $languagePack,
'items' => $itemCollection,
'pagination' => $itemCollection->links(),
]);
}
}
5 changes: 5 additions & 0 deletions src/app/Models/LanguagePack.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ public function syllables(): HasMany
public function resources(): HasMany
{
return $this->hasMany(Resource::class, 'languagepackid');
}

public function notes(): HasMany
{
return $this->hasMany(Note::class, 'languagepackid');
}

public function gameSettings(): HasMany
Expand Down
13 changes: 13 additions & 0 deletions src/app/Models/Note.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Note extends Model
{
protected $fillable = [
'languagepackid',
'text',
];
}
22 changes: 19 additions & 3 deletions src/app/Services/ExportSheetService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Models\File;
use App\Models\Key;
use App\Models\Game;
use App\Models\Note;
use App\Models\Tile;
use App\Models\Word;
use App\Models\Resource;
Expand Down Expand Up @@ -83,11 +84,26 @@ private function notesSheet(string $spreadsheetId): void
{
$sheetName = 'notes';
$this->createSheetTab($spreadsheetId, $sheetName, 0);

$values = [
["#", "1"],
["#", "Note", "CreatedAt", "UpdatedAt"],
];

$sheetAndRange = $this->getSheetAndRange($sheetName, $values, count($values));

$items = Note::where('languagepackid', $this->languagePack->id)
->orderBy('id')
->get();
$sheetAndRange = $this->getSheetAndRange($sheetName, $values, count($items));

$i = 1;
foreach ($items as $item) {
$values[$i] = [
$i,
$item->text,
$item->created_at?->format('Y-m-d H:i:s'),
$item->updated_at?->format('Y-m-d H:i:s'),
];
$i++;
}

$this->clearAndAddValuesToSheet($spreadsheetId, $sheetAndRange, $values);
}
Expand Down
26 changes: 26 additions & 0 deletions src/app/Services/GenerateZipExportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use ZipArchive;
use App\Models\Key;
use App\Models\Game;
use App\Models\Note;
use App\Models\Tile;
use App\Models\Word;
use App\Models\Resource;
Expand Down Expand Up @@ -55,6 +56,10 @@ public function handle(): string
$tilesFile = $this->generateLanginfoFile($tilesFileName, $zip, $zipFileName);
$zip->addFile($tilesFile, "{$zipFileName}/res/raw/{$tilesFileName}");

$notesFileName = 'aa_notes.txt';
$notesFile = $this->generateNotesFile($notesFileName);
$zip->addFile($notesFile, "{$zipFileName}/res/raw/{$notesFileName}");

$tilesFileName = 'aa_gametiles.txt';
$tilesFile = $this->generateTilesFile($tilesFileName, $zip, $zipFileName);
$zip->addFile($tilesFile, "{$zipFileName}/res/raw/{$tilesFileName}");
Expand Down Expand Up @@ -307,6 +312,27 @@ public function generateKeyboardFile(string $fileName): string
return $file;
}

public function generateNotesFile(string $fileName): string
{
$notes = Note::where('languagepackid', $this->languagePack->id)
->orderBy('id')
->get();
$fileContent = "#" . self::SEPARATOR . "Note" . self::SEPARATOR . "CreatedAt" . self::SEPARATOR . "UpdatedAt\n";

$i = 1;
foreach ($notes as $note) {
$fileContent .= "{$i}" . self::SEPARATOR
. "{$note->text}" . self::SEPARATOR
. $note->created_at?->format('Y-m-d H:i:s') . self::SEPARATOR
. $note->updated_at?->format('Y-m-d H:i:s') . "\n";
$i++;
}

$file = "{$this->tempDir}/{$fileName}";
file_put_contents($file, $fileContent);

return $file;
}

public function generateSyllablesFile(string $syllablesFileName, ZipArchive $zip, string $zipFileName): string
{
Expand Down
42 changes: 42 additions & 0 deletions src/app/Services/ImportSheetService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Models\Game;
use App\Models\Key;
use App\Models\File;
use App\Models\Note;
use App\Models\Tile;
use App\Models\Word;
use App\Models\Syllable;
Expand Down Expand Up @@ -55,6 +56,7 @@ public function readAndSaveData(string $spreadSheetId, string $sheetType)
}

try {
$this->saveNotes('notes');
$this->saveLanginfo('langinfo');
$this->saveTiles('gametiles');
$this->saveWords('wordlist');
Expand Down Expand Up @@ -290,6 +292,46 @@ private function saveKeyboard(string $worksheetName)
}
}

private function saveNotes(string $worksheetName): void
{
$rows = $this->getWorksheetRows($worksheetName);

$firstRow = true;
$data = [];
$key = 0;
foreach ($rows as $row) {
if ($firstRow) {
$firstRow = false;
continue;
}

if (!empty($row[1])) {
$data[$key]['languagepackid'] = $this->languagePack->id;
$data[$key]['text'] = $row[1];
$data[$key]['created_at'] = $this->parseDateOrNow($row[2] ?? null);
$data[$key]['updated_at'] = $this->parseDateOrNow($row[3] ?? null);
$key++;
}
}

if (!empty($data)) {
Note::insert($data);
}
}

private function parseDateOrNow(?string $value): string
{
if (empty($value)) {
return now()->format('Y-m-d H:i:s');
}

try {
return \Carbon\Carbon::parse($value)->format('Y-m-d H:i:s');
} catch (Exception) {
return now()->format('Y-m-d H:i:s');
}
}

private function saveGames(string $worksheetName): void
{
try {
Expand Down
30 changes: 30 additions & 0 deletions src/database/migrations/2026_09_10_000000_create_notes_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('notes', function (Blueprint $table) {
$table->id();
$table->foreignId('languagepackid')->constrained('language_packs')
->onDelete('cascade');
$table->text('text');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('notes');
}
};
2 changes: 1 addition & 1 deletion src/resources/views/languagepack/games.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class="inline-flex items-center gap-2 text-sm {{ $requiredAssetsFilter === 'my_g

<div class="mt-6 w-9/12">
<a href="#" onClick='autoSavePage("/languagepack/game_settings/{{ $languagePack->id }}");' class="inline-block no-underline btn-sm btn-secondary pt-0.5 font-normal">{{ __('Back') }}</a>
<a href="#" onClick='autoSavePage("/languagepack/export/{{ $languagePack->id }}");' class="inline-block no-underline btn-sm btn-primary ml-1 pt-0.5 text-white font-normal">{{ __('Next') }}</a>
<a href="#" onClick='autoSavePage("/languagepack/notes/{{ $languagePack->id }}");' class="inline-block no-underline btn-sm btn-primary ml-1 pt-0.5 text-white font-normal">{{ __('Next') }}</a>
</div>

<div class="mt-4">
Expand Down
Loading