Move article save/delete logic from monolithic factory to ArticleRepository with DI-based controller actions, following the established refactoring pattern. - ArticleRepository: add save() with 9 private helpers, archive() method - ArticlesController: add save() and delete() actions with DI - Factory methods delegate to repository (backward compatibility) - Router: add article_save/article_delete action mappings - Old controls methods marked @deprecated - 59 tests, 123 assertions passing Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
78 lines
1.9 KiB
PHP
78 lines
1.9 KiB
PHP
<?php
|
|
namespace admin\Controllers;
|
|
|
|
use Domain\Article\ArticleRepository;
|
|
|
|
class ArticlesController
|
|
{
|
|
private ArticleRepository $repository;
|
|
|
|
public function __construct(ArticleRepository $repository)
|
|
{
|
|
$this->repository = $repository;
|
|
}
|
|
|
|
/**
|
|
* Lista artykulow
|
|
*/
|
|
public function list(): string
|
|
{
|
|
return \admin\view\Articles::articles_list();
|
|
}
|
|
|
|
/**
|
|
* Zapis artykulu (AJAX)
|
|
*/
|
|
public function save(): void
|
|
{
|
|
global $user;
|
|
|
|
$values = json_decode(\S::get('values'), true);
|
|
$response = ['status' => 'error', 'msg' => 'Podczas zapisywania artykułu wystąpił błąd. Proszę spróbować ponownie.'];
|
|
|
|
if ($id = $this->repository->save((int)($values['id'] ?? 0), $values, (int)$user['id'])) {
|
|
$response = ['status' => 'ok', 'msg' => 'Artykuł został zapisany.', 'id' => $id];
|
|
}
|
|
|
|
echo json_encode($response);
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Archiwizacja artykulu (ustawia status = -1)
|
|
*/
|
|
public function delete(): void
|
|
{
|
|
if ($this->repository->archive((int)\S::get('id'))) {
|
|
\S::alert('Artykuł został przeniesiony do archiwum.');
|
|
}
|
|
|
|
header('Location: /admin/articles/view_list/');
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Edycja artykulu
|
|
*/
|
|
public function edit(): string
|
|
{
|
|
global $user;
|
|
|
|
if (!$user) {
|
|
header('Location: /admin/');
|
|
exit;
|
|
}
|
|
|
|
$this->repository->deleteNonassignedImages();
|
|
$this->repository->deleteNonassignedFiles();
|
|
|
|
return \Tpl::view('articles/article-edit', [
|
|
'article' => $this->repository->find((int)\S::get('id')),
|
|
'menus' => \admin\factory\Pages::menus_list(),
|
|
'languages' => \admin\factory\Languages::languages_list(),
|
|
'layouts' => \admin\factory\Layouts::layouts_list(),
|
|
'user' => $user
|
|
]);
|
|
}
|
|
}
|