refactor articles_archive to DI controller and table-list
This commit is contained in:
@@ -331,6 +331,32 @@ class ArticleRepository
|
||||
return (bool)$result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Przywraca artykul z archiwum (status = 0).
|
||||
*/
|
||||
public function restore(int $articleId): bool
|
||||
{
|
||||
$result = $this->db->update('pp_articles', ['status' => 0], ['id' => $articleId]);
|
||||
return (bool)$result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trwale usuwa artykul wraz z relacjami i plikami z dysku.
|
||||
*/
|
||||
public function deletePermanently(int $articleId): bool
|
||||
{
|
||||
$this->db->delete('pp_articles_pages', ['article_id' => $articleId]);
|
||||
$this->db->delete('pp_articles_langs', ['article_id' => $articleId]);
|
||||
$this->db->delete('pp_articles_images', ['article_id' => $articleId]);
|
||||
$this->db->delete('pp_articles_files', ['article_id' => $articleId]);
|
||||
$this->db->delete('pp_articles', ['id' => $articleId]);
|
||||
|
||||
\S::delete_dir('../upload/article_images/article_' . $articleId . '/');
|
||||
\S::delete_dir('../upload/article_files/article_' . $articleId . '/');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca liste artykulow do panelu admin z filtrowaniem, sortowaniem i paginacja.
|
||||
*
|
||||
@@ -431,6 +457,93 @@ class ArticleRepository
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca liste artykulow z archiwum do panelu admin z filtrowaniem, sortowaniem i paginacja.
|
||||
*
|
||||
* @return array{items: array<int, array<string, mixed>>, total: int}
|
||||
*/
|
||||
public function listArchivedForAdmin(
|
||||
array $filters,
|
||||
string $sortColumn = 'date_add',
|
||||
string $sortDir = 'DESC',
|
||||
int $page = 1,
|
||||
int $perPage = 15
|
||||
): array {
|
||||
$sortColumn = trim($sortColumn);
|
||||
$sortDir = strtoupper(trim($sortDir));
|
||||
|
||||
$allowedSortColumns = [
|
||||
'title' => 'title',
|
||||
'date_add' => 'pa.date_add',
|
||||
'date_modify' => 'pa.date_modify',
|
||||
];
|
||||
|
||||
$sortSql = $allowedSortColumns[$sortColumn] ?? 'pa.date_add';
|
||||
$sortDir = $sortDir === 'ASC' ? 'ASC' : 'DESC';
|
||||
$page = max(1, $page);
|
||||
$perPage = min(self::MAX_PER_PAGE, max(1, $perPage));
|
||||
$offset = ($page - 1) * $perPage;
|
||||
|
||||
$where = ['pa.status = -1'];
|
||||
$params = [];
|
||||
|
||||
$title = trim((string)($filters['title'] ?? ''));
|
||||
if (strlen($title) > 255) {
|
||||
$title = substr($title, 0, 255);
|
||||
}
|
||||
if ($title !== '') {
|
||||
$where[] = "(
|
||||
SELECT title
|
||||
FROM pp_articles_langs AS pal, pp_langs AS pl
|
||||
WHERE lang_id = pl.id AND article_id = pa.id AND title != ''
|
||||
ORDER BY o ASC
|
||||
LIMIT 1
|
||||
) LIKE :title";
|
||||
$params[':title'] = '%' . $title . '%';
|
||||
}
|
||||
|
||||
$this->appendDateRangeFilter($where, $params, 'pa.date_add', 'date_add_from', 'date_add_to', $filters);
|
||||
$this->appendDateRangeFilter($where, $params, 'pa.date_modify', 'date_modify_from', 'date_modify_to', $filters);
|
||||
|
||||
$whereSql = implode(' AND ', $where);
|
||||
|
||||
$sqlCount = "
|
||||
SELECT COUNT(0)
|
||||
FROM pp_articles AS pa
|
||||
WHERE {$whereSql}
|
||||
";
|
||||
|
||||
$stmtCount = $this->db->query($sqlCount, $params);
|
||||
$countRows = $stmtCount ? $stmtCount->fetchAll() : [];
|
||||
$total = isset($countRows[0][0]) ? (int)$countRows[0][0] : 0;
|
||||
|
||||
$sql = "
|
||||
SELECT
|
||||
pa.id,
|
||||
pa.date_add,
|
||||
pa.date_modify,
|
||||
(
|
||||
SELECT title
|
||||
FROM pp_articles_langs AS pal, pp_langs AS pl
|
||||
WHERE lang_id = pl.id AND article_id = pa.id AND title != ''
|
||||
ORDER BY o ASC
|
||||
LIMIT 1
|
||||
) AS title
|
||||
FROM pp_articles AS pa
|
||||
WHERE {$whereSql}
|
||||
ORDER BY {$sortSql} {$sortDir}, pa.id {$sortDir}
|
||||
LIMIT {$perPage} OFFSET {$offset}
|
||||
";
|
||||
|
||||
$stmt = $this->db->query($sql, $params);
|
||||
$items = $stmt ? $stmt->fetchAll() : [];
|
||||
|
||||
return [
|
||||
'items' => is_array($items) ? $items : [],
|
||||
'total' => $total,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Zapisuje kolejnosc zdjec galerii artykulu.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user