feat: Refactor article handling and introduce ArticleRepository
- 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.
This commit is contained in:
43
autoload/Domain/Article/ArticleRepository.php
Normal file
43
autoload/Domain/Article/ArticleRepository.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user