first commit

This commit is contained in:
brusnitsyn
2025-10-31 16:48:05 +09:00
commit 8b650558e2
143 changed files with 24664 additions and 0 deletions

View File

@@ -0,0 +1,68 @@
<?php
namespace App\Models;
use App\Services\DocxTemplateProcessor;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;
class DocumentTemplate extends Model
{
protected $fillable = [
'name',
'description',
'content',
'variables',
'source_path'
];
protected $casts = [
'variables' => 'array'
];
/**
* Подстановка значений в DOCX шаблон
*/
public function generateDocument($data)
{
$tempDir = storage_path('app/temp/' . uniqid());
mkdir($tempDir, 0755, true);
// Копируем исходный шаблон
$templatePath = $tempDir . '/template.docx';
copy($this->source_path, $templatePath);
$docx = new DocxTemplateProcessor();
// Подставляем значения
$changedDocxPath = $docx->processWithPhpWord($templatePath, $data);
// Возвращаем путь к сгенерированному файлу
return $changedDocxPath;
}
/**
* Конвертация в PDF для предпросмотра
*/
public function convertToPdf($docxPath)
{
$pdfPath = str_replace('.docx', '.pdf', $docxPath);
// Надо добавить....
$home = config('libreoffice.home');
$user = config('libreoffice.user');
putenv("HOME=$home");
putenv("USER=$user");
$command = "libreoffice --headless --convert-to pdf --outdir " .
escapeshellarg(dirname($pdfPath)) . " " .
escapeshellarg($docxPath);
$result = shell_exec($command . " 2>&1");
if (!file_exists($pdfPath)) {
throw new \Exception("PDF conversion failed: " . $result);
}
return $pdfPath;
}
}

View File

@@ -0,0 +1,10 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class DocumentTemplateVariable extends Model
{
//
}

48
app/Models/User.php Normal file
View File

@@ -0,0 +1,48 @@
<?php
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{
/** @use HasFactory<\Database\Factories\UserFactory> */
use HasFactory, Notifiable;
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $fillable = [
'name',
'email',
'password',
];
/**
* The attributes that should be hidden for serialization.
*
* @var list<string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
}
}