- Introduced Domain\Article\ArticleRepository for better data access. - Migrated article_edit functionality to admin\Controllers\ArticlesController. - Updated admin\factory\Articles::article_details() to use the new repository. - Marked legacy methods in admin\controls as @deprecated for clarity. - Updated changelog and versioning to reflect changes in version 0.242.
44 lines
1.2 KiB
PHP
44 lines
1.2 KiB
PHP
<?php
|
|
namespace Domain\Article;
|
|
|
|
/**
|
|
* Repository odpowiedzialny za dostep do danych artykulow
|
|
*/
|
|
class ArticleRepository
|
|
{
|
|
private $db;
|
|
|
|
public function __construct($db)
|
|
{
|
|
$this->db = $db;
|
|
}
|
|
|
|
/**
|
|
* Pobiera artykul po ID wraz z tlumaczeniami, obrazami, plikami i powiazanymi stronami
|
|
*/
|
|
public function find(int $articleId): ?array
|
|
{
|
|
$article = $this->db->get('pp_articles', '*', ['id' => $articleId]);
|
|
|
|
if (!$article) {
|
|
return null;
|
|
}
|
|
|
|
$results = $this->db->select('pp_articles_langs', '*', ['article_id' => $articleId]);
|
|
if (is_array($results)) {
|
|
foreach ($results as $row) {
|
|
$article['languages'][$row['lang_id']] = $row;
|
|
}
|
|
}
|
|
|
|
$article['images'] = $this->db->select('pp_articles_images', '*', [
|
|
'article_id' => $articleId,
|
|
'ORDER' => ['o' => 'ASC', 'id' => 'DESC']
|
|
]);
|
|
$article['files'] = $this->db->select('pp_articles_files', '*', ['article_id' => $articleId]);
|
|
$article['pages'] = $this->db->select('pp_articles_pages', 'page_id', ['article_id' => $articleId]);
|
|
|
|
return $article;
|
|
}
|
|
}
|