ver. 0.273 - ShopProducer refactor + cleanup 6 factory facades

- Domain\Producer\ProducerRepository (CRUD + frontend)
- admin\Controllers\ShopProducerController (DI)
- Nowe widoki: producers-list, producer-edit (table-list/form-edit)
- shop\Producer -> fasada do ProducerRepository
- Przepiecie ShopProduct factory na TransportRepository
- Usuniete 6 pustych factory facades: Languages, Newsletter, Scontainers, ShopProducer, ShopTransport, Layouts
- Usuniete legacy: controls\ShopProducer, stare szablony
- Testy: 338 tests, 1063 assertions OK
This commit is contained in:
2026-02-15 10:46:55 +01:00
parent fe51a1f4c4
commit 3bac7616e7
26 changed files with 1134 additions and 632 deletions

View File

@@ -0,0 +1,332 @@
<?php
namespace Domain\Producer;
class ProducerRepository
{
private const MAX_PER_PAGE = 100;
private $db;
public function __construct($db)
{
$this->db = $db;
}
/**
* Lista producentów dla panelu admin (paginowana, filtrowalna, sortowalna).
*
* @return array{items: array<int, array<string, mixed>>, total: int}
*/
public function listForAdmin(
array $filters,
string $sortColumn = 'name',
string $sortDir = 'ASC',
int $page = 1,
int $perPage = 15
): array {
$allowedSortColumns = [
'id' => 'p.id',
'name' => 'p.name',
'status' => 'p.status',
];
$sortSql = $allowedSortColumns[$sortColumn] ?? 'p.name';
$sortDir = strtoupper(trim($sortDir)) === 'DESC' ? 'DESC' : 'ASC';
$page = max(1, $page);
$perPage = min(self::MAX_PER_PAGE, max(1, $perPage));
$offset = ($page - 1) * $perPage;
$where = ['1 = 1'];
$params = [];
$name = trim((string)($filters['name'] ?? ''));
if ($name !== '') {
if (strlen($name) > 255) {
$name = substr($name, 0, 255);
}
$where[] = 'p.name LIKE :name';
$params[':name'] = '%' . $name . '%';
}
$status = trim((string)($filters['status'] ?? ''));
if ($status === '0' || $status === '1') {
$where[] = 'p.status = :status';
$params[':status'] = (int)$status;
}
$whereSql = implode(' AND ', $where);
$sqlCount = "
SELECT COUNT(0)
FROM pp_shop_producer AS p
WHERE {$whereSql}
";
$stmtCount = $this->db->query($sqlCount, $params);
$countRows = $stmtCount ? $stmtCount->fetchAll() : [];
$total = isset($countRows[0][0]) ? (int)$countRows[0][0] : 0;
$sql = "
SELECT
p.id,
p.name,
p.status,
p.img
FROM pp_shop_producer AS p
WHERE {$whereSql}
ORDER BY {$sortSql} {$sortDir}, p.id DESC
LIMIT {$perPage} OFFSET {$offset}
";
$stmt = $this->db->query($sql, $params);
$items = $stmt ? $stmt->fetchAll() : [];
if (!is_array($items)) {
$items = [];
}
foreach ($items as &$item) {
$item['id'] = (int)($item['id'] ?? 0);
$item['status'] = $this->toSwitchValue($item['status'] ?? 0);
}
unset($item);
return [
'items' => $items,
'total' => $total,
];
}
/**
* Pobiera producenta z tłumaczeniami.
*/
public function find(int $id): array
{
if ($id <= 0) {
return $this->defaultProducer();
}
$producer = $this->db->get('pp_shop_producer', '*', ['id' => $id]);
if (!is_array($producer)) {
return $this->defaultProducer();
}
$producer['id'] = (int)($producer['id'] ?? 0);
$producer['status'] = $this->toSwitchValue($producer['status'] ?? 0);
// Tłumaczenia
$rows = $this->db->select('pp_shop_producer_lang', '*', ['producer_id' => $id]);
$languages = [];
if (is_array($rows)) {
foreach ($rows as $row) {
$langId = $row['lang_id'] ?? '';
$languages[$langId] = [
'description' => $row['description'] ?? null,
'data' => $row['data'] ?? null,
'meta_title' => $row['meta_title'] ?? null,
];
}
}
$producer['languages'] = $languages;
return $producer;
}
/**
* Zapisuje producenta (insert / update) wraz z tłumaczeniami.
*
* @return int|null ID producenta lub null przy błędzie
*/
public function save(
int $id,
string $name,
int $status,
?string $img,
array $description,
array $data,
array $metaTitle,
array $langs
): ?int {
$row = [
'name' => trim($name),
'status' => $status === 1 ? 1 : 0,
'img' => $img,
];
if ($id <= 0) {
$this->db->insert('pp_shop_producer', $row);
$id = (int)$this->db->id();
if ($id <= 0) {
return null;
}
} else {
$this->db->update('pp_shop_producer', $row, ['id' => $id]);
}
// Tłumaczenia
foreach ($langs as $lg) {
$langId = $lg['id'] ?? '';
$translationData = [
'description' => $description[$langId] ?? null,
'data' => $data[$langId] ?? null,
'meta_title' => $metaTitle[$langId] ?? null,
];
$translationId = $this->db->get(
'pp_shop_producer_lang',
'id',
['AND' => ['producer_id' => $id, 'lang_id' => $langId]]
);
if ($translationId) {
$this->db->update('pp_shop_producer_lang', $translationData, ['id' => $translationId]);
} else {
$this->db->insert('pp_shop_producer_lang', array_merge($translationData, [
'producer_id' => $id,
'lang_id' => $langId,
]));
}
}
return $id;
}
/**
* Usuwa producenta (kaskadowo z pp_shop_producer_lang przez FK).
*/
public function delete(int $id): bool
{
if ($id <= 0) {
return false;
}
$result = (bool)$this->db->delete('pp_shop_producer', ['id' => $id]);
return $result;
}
/**
* Wszystkie producenty (do select w edycji produktu).
*
* @return array<int, array{id: int, name: string}>
*/
public function allProducers(): array
{
$rows = $this->db->select('pp_shop_producer', ['id', 'name'], ['ORDER' => ['name' => 'ASC']]);
if (!is_array($rows)) {
return [];
}
$producers = [];
foreach ($rows as $row) {
$producers[] = [
'id' => (int)($row['id'] ?? 0),
'name' => (string)($row['name'] ?? ''),
];
}
return $producers;
}
/**
* Pobiera producenta z tłumaczeniami dla danego języka (frontend).
*/
public function findForFrontend(int $id, string $langId): ?array
{
if ($id <= 0) {
return null;
}
$producer = $this->db->get('pp_shop_producer', '*', ['id' => $id]);
if (!is_array($producer)) {
return null;
}
$producer['id'] = (int)($producer['id'] ?? 0);
$langRow = $this->db->get('pp_shop_producer_lang', '*', [
'AND' => ['producer_id' => $id, 'lang_id' => $langId],
]);
$producer['languages'] = [];
if (is_array($langRow)) {
$producer['languages'][$langId] = [
'description' => $langRow['description'] ?? null,
'data' => $langRow['data'] ?? null,
'meta_title' => $langRow['meta_title'] ?? null,
];
}
return $producer;
}
/**
* Produkty producenta (paginowane) — frontend.
*
* @return array{products: array, ls: int}
*/
public function producerProducts(int $producerId, int $perPage = 12, int $page = 1): array
{
$count = $this->db->count('pp_shop_products', [
'AND' => ['producer_id' => $producerId, 'status' => 1],
]);
$totalPages = max(1, (int)ceil($count / $perPage));
$page = max(1, min($page, $totalPages));
$offset = $perPage * ($page - 1);
$products = $this->db->select('pp_shop_products', 'id', [
'AND' => ['producer_id' => $producerId, 'status' => 1],
'LIMIT' => [$offset, $perPage],
]);
return [
'products' => is_array($products) ? $products : [],
'ls' => $totalPages,
];
}
/**
* Aktywni producenci (frontend lista).
*
* @return array<int>
*/
public function allActiveIds(): array
{
$rows = $this->db->select('pp_shop_producer', 'id', [
'status' => 1,
'ORDER' => ['name' => 'ASC'],
]);
return is_array($rows) ? array_map('intval', $rows) : [];
}
private function defaultProducer(): array
{
return [
'id' => 0,
'name' => '',
'status' => 1,
'img' => null,
'languages' => [],
];
}
private function toSwitchValue($value): int
{
if (is_bool($value)) {
return $value ? 1 : 0;
}
if (is_numeric($value)) {
return ((int)$value) === 1 ? 1 : 0;
}
if (is_string($value)) {
$normalized = strtolower(trim($value));
return in_array($normalized, ['1', 'on', 'true', 'yes'], true) ? 1 : 0;
}
return 0;
}
}

View File

@@ -0,0 +1,379 @@
<?php
namespace admin\Controllers;
use Domain\Producer\ProducerRepository;
use Domain\Languages\LanguagesRepository;
use admin\ViewModels\Common\PaginatedTableViewModel;
use admin\ViewModels\Forms\FormAction;
use admin\ViewModels\Forms\FormEditViewModel;
use admin\ViewModels\Forms\FormField;
use admin\ViewModels\Forms\FormTab;
use admin\Support\Forms\FormRequestHandler;
class ShopProducerController
{
private ProducerRepository $repository;
private LanguagesRepository $languagesRepository;
private FormRequestHandler $formHandler;
public function __construct(ProducerRepository $repository, LanguagesRepository $languagesRepository)
{
$this->repository = $repository;
$this->languagesRepository = $languagesRepository;
$this->formHandler = new FormRequestHandler();
}
public function list(): string
{
$sortableColumns = ['id', 'name', 'status'];
$filterDefinitions = [
[
'key' => 'name',
'label' => 'Nazwa',
'type' => 'text',
],
[
'key' => 'status',
'label' => 'Aktywny',
'type' => 'select',
'options' => [
'' => '- aktywny -',
'1' => 'tak',
'0' => 'nie',
],
],
];
$listRequest = \admin\Support\TableListRequestFactory::fromRequest(
$filterDefinitions,
$sortableColumns,
'name'
);
$sortDir = $listRequest['sortDir'];
if (trim((string)\S::get('sort')) === '') {
$sortDir = 'ASC';
}
$result = $this->repository->listForAdmin(
$listRequest['filters'],
$listRequest['sortColumn'],
$sortDir,
$listRequest['page'],
$listRequest['perPage']
);
$rows = [];
$lp = ($listRequest['page'] - 1) * $listRequest['perPage'] + 1;
foreach ($result['items'] as $item) {
$id = (int)($item['id'] ?? 0);
$name = trim((string)($item['name'] ?? ''));
$status = (int)($item['status'] ?? 0);
$img = trim((string)($item['img'] ?? ''));
$imgHtml = '';
if ($img !== '') {
$imgHtml = '<img src="' . htmlspecialchars($img, ENT_QUOTES, 'UTF-8') . '" style="max-height:30px;" />';
}
$rows[] = [
'lp' => $lp++ . '.',
'name' => '<a href="/admin/shop_producer/edit/id=' . $id . '">' . htmlspecialchars($name, ENT_QUOTES, 'UTF-8') . '</a>',
'img' => $imgHtml,
'status' => $status === 1 ? 'tak' : '<span style="color: #FF0000;">nie</span>',
'_actions' => [
[
'label' => 'Edytuj',
'url' => '/admin/shop_producer/edit/id=' . $id,
'class' => 'btn btn-xs btn-primary',
],
[
'label' => 'Usun',
'url' => '/admin/shop_producer/delete/id=' . $id,
'class' => 'btn btn-xs btn-danger',
'confirm' => 'Na pewno chcesz usunac wybranego producenta?',
'confirm_ok' => 'Usun',
'confirm_cancel' => 'Anuluj',
],
],
];
}
$total = (int)$result['total'];
$totalPages = max(1, (int)ceil($total / $listRequest['perPage']));
$viewModel = new PaginatedTableViewModel(
[
['key' => 'lp', 'label' => 'Lp.', 'class' => 'text-center', 'sortable' => false],
['key' => 'name', 'sort_key' => 'name', 'label' => 'Nazwa', 'sortable' => true, 'raw' => true],
['key' => 'img', 'label' => 'Logo', 'sortable' => false, 'raw' => true],
['key' => 'status', 'sort_key' => 'status', 'label' => 'Aktywny', 'class' => 'text-center', 'sortable' => true, 'raw' => true],
],
$rows,
$listRequest['viewFilters'],
[
'column' => $listRequest['sortColumn'],
'dir' => $sortDir,
],
[
'page' => $listRequest['page'],
'per_page' => $listRequest['perPage'],
'total' => $total,
'total_pages' => $totalPages,
],
array_merge($listRequest['queryFilters'], [
'sort' => $listRequest['sortColumn'],
'dir' => $sortDir,
'per_page' => $listRequest['perPage'],
]),
$listRequest['perPageOptions'],
$sortableColumns,
'/admin/shop_producer/list/',
'Brak danych w tabeli.',
'/admin/shop_producer/edit/',
'Dodaj producenta'
);
return \Tpl::view('shop-producer/producers-list', [
'viewModel' => $viewModel,
]);
}
public function view_list(): string
{
return $this->list();
}
public function edit(): string
{
$producer = $this->repository->find((int)\S::get('id'));
$languages = $this->languagesRepository->languagesList();
$validationErrors = $_SESSION['form_errors'][$this->formId()] ?? null;
if ($validationErrors) {
unset($_SESSION['form_errors'][$this->formId()]);
}
return \Tpl::view('shop-producer/producer-edit', [
'form' => $this->buildFormViewModel($producer, $languages, $validationErrors),
]);
}
public function producer_edit(): string
{
return $this->edit();
}
public function save(): void
{
// Legacy JSON (gridEdit)
$legacyValues = \S::get('values');
if ($legacyValues) {
$values = json_decode((string)$legacyValues, true);
$response = [
'status' => 'error',
'msg' => 'Podczas zapisywania producenta wystapil blad. Prosze sprobowac ponownie.',
];
if (is_array($values)) {
$langs = $this->languagesRepository->languagesList(true);
$id = $this->repository->save(
(int)($values['id'] ?? 0),
(string)($values['name'] ?? ''),
$this->toSwitchValue($values['status'] ?? 0),
$values['img'] ?? null,
$values['description'] ?? [],
$values['data'] ?? [],
$values['meta_title'] ?? [],
$langs
);
if (!empty($id)) {
\S::htacces();
\S::delete_dir('../temp/');
$response = [
'status' => 'ok',
'msg' => 'Producent zostal zapisany.',
'id' => (int)$id,
];
}
}
echo json_encode($response);
exit;
}
// Nowy flow (form-edit)
$producer = $this->repository->find((int)\S::get('id'));
$languages = $this->languagesRepository->languagesList();
$form = $this->buildFormViewModel($producer, $languages);
$result = $this->formHandler->handleSubmit($form, $_POST);
if (!$result['success']) {
$_SESSION['form_errors'][$this->formId()] = $result['errors'];
echo json_encode(['success' => false, 'errors' => $result['errors']]);
exit;
}
$data = $result['data'];
$langs = $this->languagesRepository->languagesList(true);
$translations = $data['translations'] ?? [];
$description = [];
$metaData = [];
$metaTitle = [];
foreach ($translations as $langId => $fields) {
$description[$langId] = $fields['description'] ?? null;
$metaData[$langId] = $fields['data'] ?? null;
$metaTitle[$langId] = $fields['meta_title'] ?? null;
}
$savedId = $this->repository->save(
(int)($data['id'] ?? 0),
(string)($data['name'] ?? ''),
$this->toSwitchValue($data['status'] ?? 0),
$data['img'] ?? null,
$description,
$metaData,
$metaTitle,
$langs
);
if ($savedId) {
\S::htacces();
\S::delete_dir('../temp/');
echo json_encode([
'success' => true,
'id' => $savedId,
'message' => 'Producent zostal zapisany.',
]);
exit;
}
echo json_encode([
'success' => false,
'errors' => ['general' => 'Podczas zapisywania producenta wystapil blad.'],
]);
exit;
}
public function producer_save(): void
{
$this->save();
}
public function delete(): void
{
if ($this->repository->delete((int)\S::get('id'))) {
\S::htacces();
\S::delete_dir('../temp/');
\S::alert('Producent zostal usuniety.');
}
header('Location: /admin/shop_producer/list/');
exit;
}
public function producer_delete(): void
{
$this->delete();
}
private function buildFormViewModel(array $producer, array $languages, ?array $errors = null): FormEditViewModel
{
$id = (int)($producer['id'] ?? 0);
$isNew = $id <= 0;
$data = [
'id' => $id,
'name' => (string)($producer['name'] ?? ''),
'status' => (int)($producer['status'] ?? 1),
'img' => $producer['img'] ?? null,
'languages' => is_array($producer['languages'] ?? null) ? $producer['languages'] : [],
];
$fields = [
FormField::hidden('id', $id),
FormField::text('name', [
'label' => 'Nazwa',
'required' => true,
'tab' => 'general',
]),
FormField::switch('status', [
'label' => 'Aktywny',
'tab' => 'general',
'value' => true,
]),
FormField::image('img', [
'label' => 'Logo',
'tab' => 'general',
]),
FormField::langSection('translations', 'description', [
FormField::editor('description', [
'label' => 'Opis',
'height' => 250,
]),
FormField::editor('data', [
'label' => 'Dane producenta',
'height' => 250,
]),
]),
FormField::langSection('translations', 'seo', [
FormField::text('meta_title', [
'label' => 'Meta title',
]),
]),
];
$tabs = [
new FormTab('general', 'Ogolne', 'fa-file'),
new FormTab('description', 'Opis', 'fa-file'),
new FormTab('seo', 'SEO', 'fa-globe'),
];
$actionUrl = '/admin/shop_producer/save/' . ($isNew ? '' : ('id=' . $id));
$actions = [
FormAction::save($actionUrl, '/admin/shop_producer/list/'),
FormAction::cancel('/admin/shop_producer/list/'),
];
return new FormEditViewModel(
$this->formId(),
'Edycja producenta',
$data,
$fields,
$tabs,
$actions,
'POST',
$actionUrl,
'/admin/shop_producer/list/',
true,
[],
$languages,
$errors
);
}
private function formId(): string
{
return 'shop-producer-edit';
}
private function toSwitchValue($value): int
{
if (is_bool($value)) {
return $value ? 1 : 0;
}
if (is_numeric($value)) {
return ((int)$value) === 1 ? 1 : 0;
}
if (is_string($value)) {
$normalized = strtolower(trim($value));
return in_array($normalized, ['1', 'on', 'true', 'yes'], true) ? 1 : 0;
}
return 0;
}
}

View File

@@ -369,6 +369,14 @@ class Site
new \Domain\ProductSet\ProductSetRepository( $mdb )
);
},
'ShopProducer' => function() {
global $mdb;
return new \admin\Controllers\ShopProducerController(
new \Domain\Producer\ProducerRepository( $mdb ),
new \Domain\Languages\LanguagesRepository( $mdb )
);
},
];
return self::$newControllers;

View File

@@ -1,37 +0,0 @@
<?
namespace admin\controls;
class ShopProducer
{
static public function delete()
{
if ( \admin\factory\ShopProducer::delete( \S::get( 'id' ) ) )
\S::alert( 'Producent został usunięty' );
header( 'Location: /admin/shop_producer/list/' );
exit;
}
static public function save()
{
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania producenta wystąpił błąd. Proszę spróbować ponownie.' ];
$values = json_decode( \S::get( 'values' ), true );
if ( $producer_id = \admin\factory\ShopProducer::save( $values['id'], $values['name'], $values['status'] == 'on' ? 1 : 0, $values['img'], $values['description'], $values['data'], $values['meta_title'] ) )
$response = [ 'status' => 'ok', 'msg' => 'Producent został zapisany.', 'id' => $producer_id ];
echo json_encode( $response );
exit;
}
static public function edit()
{
return \Tpl::view( 'shop-producer/edit', [
'producer' => \S::get( 'id' ) ? new \shop\Producer( \S::get( 'id' ) ) : null,
'languages' => ( new \Domain\Languages\LanguagesRepository( $GLOBALS['mdb'] ) )->languagesList()
] );
}
static public function list()
{
return \Tpl::view( 'shop-producer/list' );
}
}

View File

@@ -248,7 +248,7 @@ class ShopProduct
'products' => \admin\factory\ShopProduct::products_list(),
'dlang' => \front\factory\Languages::default_language(),
'sets' => \shop\ProductSet::sets_list(),
'producers' => \admin\factory\ShopProducer::all(),
'producers' => ( new \Domain\Producer\ProducerRepository( $mdb ) )->allProducers(),
'units' => ( new \Domain\Dictionaries\DictionariesRepository( $mdb ) ) -> allUnits(),
'user' => $user
] );
@@ -262,12 +262,6 @@ class ShopProduct
return is_array( $rows ) ? $rows : [];
}
if ( class_exists( '\admin\factory\Layouts' ) )
{
$rows = \admin\factory\Layouts::layouts_list();
return is_array( $rows ) ? $rows : [];
}
return [];
}

View File

@@ -1,51 +0,0 @@
<?php
namespace admin\factory;
class Languages
{
private static function repository(): \Domain\Languages\LanguagesRepository
{
global $mdb;
return new \Domain\Languages\LanguagesRepository($mdb);
}
public static function translation_delete($translation_id)
{
return self::repository()->deleteTranslation((int)$translation_id);
}
public static function translation_save($translation_id, $text, $languages)
{
return self::repository()->saveTranslation((int)$translation_id, (string)$text, is_array($languages) ? $languages : []);
}
public static function translation_details($translation_id)
{
return self::repository()->translationDetails((int)$translation_id);
}
public static function language_delete($language_id)
{
return self::repository()->deleteLanguage((string)$language_id);
}
public static function max_order()
{
return self::repository()->maxOrder();
}
public static function language_save($language_id, $name, $status, $start, $o)
{
return self::repository()->saveLanguage((string)$language_id, (string)$name, $status, $start, (int)$o);
}
public static function language_details($language_id)
{
return self::repository()->languageDetails((string)$language_id);
}
public static function languages_list($only_active = false)
{
return self::repository()->languagesList((bool)$only_active);
}
}

View File

@@ -1,65 +0,0 @@
<?php
namespace admin\factory;
use Domain\Layouts\LayoutsRepository;
use Domain\Pages\PagesRepository;
class Layouts
{
public static function layout_delete($layout_id)
{
return self::repository()->delete((int)$layout_id);
}
public static function layout_details($layout_id)
{
return self::repository()->find((int)$layout_id);
}
public static function layout_save(
$layout_id,
$name,
$status,
$pages,
$html,
$css,
$js,
$m_html,
$m_css,
$m_js,
$categories,
$categories_default
) {
return self::repository()->save([
'id' => $layout_id,
'name' => $name,
'status' => $status,
'pages' => $pages,
'html' => $html,
'css' => $css,
'js' => $js,
'm_html' => $m_html,
'm_css' => $m_css,
'm_js' => $m_js,
'categories' => $categories,
'categories_default' => $categories_default,
]);
}
public static function menus_list()
{
global $mdb;
return (new PagesRepository($mdb))->menusWithPages();
}
public static function layouts_list()
{
return self::repository()->listAll();
}
private static function repository(): LayoutsRepository
{
global $mdb;
return new LayoutsRepository($mdb);
}
}

View File

@@ -1,48 +0,0 @@
<?php
namespace admin\factory;
use Domain\Newsletter\NewsletterRepository;
use Domain\Settings\SettingsRepository;
class Newsletter
{
public static function is_admin_template( $template_id )
{
return self::repository() -> isAdminTemplate( (int)$template_id );
}
public static function newsletter_template_delete( $template_id )
{
return self::repository() -> deleteTemplate( (int)$template_id );
}
public static function send( $dates, $template )
{
return self::repository() -> queueSend( (string)$dates, (int)$template );
}
public static function email_template_detalis( $id_template )
{
return self::repository() -> templateDetails( (int)$id_template );
}
public static function template_save( $id, $name, $text )
{
return self::repository() -> saveTemplate( (int)$id, (string)$name, (string)$text );
}
public static function templates_list()
{
return self::repository() -> listTemplatesSimple( false );
}
private static function repository(): NewsletterRepository
{
global $mdb;
return new NewsletterRepository(
$mdb,
new SettingsRepository($mdb)
);
}
}

View File

@@ -1,32 +0,0 @@
<?php
namespace admin\factory;
class Scontainers
{
private static function repository(): \Domain\Scontainers\ScontainersRepository
{
global $mdb;
return new \Domain\Scontainers\ScontainersRepository($mdb);
}
public static function container_delete($container_id)
{
return self::repository()->delete((int)$container_id);
}
public static function container_save($container_id, $title, $text, $status, $show_title)
{
return self::repository()->save([
'id' => (int)$container_id,
'title' => is_array($title) ? $title : [],
'text' => is_array($text) ? $text : [],
'status' => $status,
'show_title' => $show_title,
]);
}
public static function container_details($container_id)
{
return self::repository()->find((int)$container_id);
}
}

View File

@@ -1,89 +0,0 @@
<?
namespace admin\factory;
class ShopProducer
{
static public function all()
{
global $mdb;
return $mdb -> select( 'pp_shop_producer', '*', [ 'ORDER' => [ 'name' => 'ASC' ] ] );
}
static public function delete( int $producer_id )
{
global $mdb;
return $mdb -> delete( 'pp_shop_producer', [ 'id' => $producer_id ] );
}
static public function save( $producer_id, $name, int $status, $img, $description, $data, $meta_title )
{
global $mdb;
if ( !$producer_id )
{
$mdb -> insert( 'pp_shop_producer', [
'name' => $name,
'status' => $status,
'img' => $img
] );
$id = $mdb -> id();
$langs = ( new \Domain\Languages\LanguagesRepository( $mdb ) )->languagesList( true );
foreach ( $langs as $lg )
{
$mdb -> insert( 'pp_shop_producer_lang', [
'producer_id' => $id,
'lang_id' => $lg['id'],
'description' => $description[ $lg['id'] ] ?? null,
'data' => $data[ $lg['id'] ] ?? null,
'meta_title' => $meta_title[ $lg['id'] ] ?? null
] );
}
\S::htacces();
\S::delete_dir( '../temp/' );
return $id;
}
else
{
$mdb -> update( 'pp_shop_producer', [
'name' => $name,
'status' => $status,
'img' => $img
], [
'id' => (int) $producer_id
] );
$langs = ( new \Domain\Languages\LanguagesRepository( $mdb ) )->languagesList( true );
foreach ( $langs as $lg )
{
if ( $translation_id = $mdb -> get( 'pp_shop_producer_lang', 'id', [ 'AND' => [ 'producer_id' => $producer_id, 'lang_id' => $lg['id'] ] ] ) )
{
$mdb -> update( 'pp_shop_producer_lang', [
'description' => $description[ $lg['id'] ] ?? null,
'meta_title' => $meta_title[ $lg['id'] ] ?? null,
'data' => $data[ $lg['id'] ] ?? null
], [
'id' => $translation_id
] );
}
else
{
$mdb -> insert( 'pp_shop_producer_lang', [
'producer_id' => $producer_id,
'lang_id' => $lg['id'],
'description' => $description[ $lg['id'] ] ?? null,
'data' => $data[ $lg['id'] ] ?? null,
'meta_title' => $meta_title[ $lg['id'] ] ?? null
] );
}
}
\S::htacces();
\S::delete_dir( '../temp/' );
return $producer_id;
}
return false;
}
}

View File

@@ -397,7 +397,7 @@ class ShopProduct
$p_gshipping = $itemNode -> appendChild( $doc -> createElement( 'g:shipping' ) );
$p_gcountry = $p_gshipping -> appendChild( $doc -> createElement( 'g:country', 'PL' ) );
$p_gservice = $p_gshipping -> appendChild( $doc -> createElement( 'g:service', '1 dzień roboczy' ) );
$p_gprice = $p_gshipping -> appendChild( $doc -> createElement( 'g:price', \admin\factory\ShopTransport::lowest_transport_price( (int) $product -> wp ) . ' PLN' ) );
$p_gprice = $p_gshipping -> appendChild( $doc -> createElement( 'g:price', ( new \Domain\Transport\TransportRepository( $mdb ) )->lowestTransportPrice( (int) $product -> wp ) . ' PLN' ) );
}
}
}
@@ -484,7 +484,7 @@ class ShopProduct
$p_gshipping = $itemNode -> appendChild( $doc -> createElement( 'g:shipping' ) );
$p_gcountry = $p_gshipping -> appendChild( $doc -> createElement( 'g:country', 'PL' ) );
$p_gservice = $p_gshipping -> appendChild( $doc -> createElement( 'g:service', '1 dzień roboczy' ) );
$p_gprice = $p_gshipping -> appendChild( $doc -> createElement( 'g:price', \admin\factory\ShopTransport::lowest_transport_price( (int) $product -> wp ) . ' PLN' ) );
$p_gprice = $p_gshipping -> appendChild( $doc -> createElement( 'g:price', ( new \Domain\Transport\TransportRepository( $mdb ) )->lowestTransportPrice( (int) $product -> wp ) . ' PLN' ) );
}
}
file_put_contents('../google-feed.xml', $doc -> saveXML());

View File

@@ -1,10 +0,0 @@
<?php
namespace admin\factory;
class ShopTransport
{
public static function lowest_transport_price( $wp ) {
global $mdb;
$repo = new \Domain\Transport\TransportRepository($mdb);
return $repo->lowestTransportPrice($wp);
}
}

View File

@@ -1,4 +1,4 @@
<?
<?php
namespace shop;
class Producer implements \ArrayAccess
{
@@ -6,43 +6,19 @@ class Producer implements \ArrayAccess
{
global $mdb;
$result = $mdb -> get( 'pp_shop_producer', '*', [ 'id' => $producer_id ] );
foreach ( $result as $key => $val )
$this -> $key = $val;
$repo = new \Domain\Producer\ProducerRepository( $mdb );
$data = $repo->find( $producer_id );
$rows = $mdb -> select( 'pp_shop_producer_lang', '*', [ 'producer_id' => $producer_id ] );
foreach ( $rows as $row )
{
$languages[ $row['lang_id'] ]['description'] = $row['description'];
$languages[ $row['lang_id'] ]['data'] = $row['data'];
$languages[ $row['lang_id'] ]['meta_title'] = $row['meta_title'];
}
$this -> languages = $languages;
foreach ( $data as $key => $val )
$this->$key = $val;
}
static public function producer_products( $producer_id, $lang_id, $bs )
{
global $mdb;
$count = $mdb -> count( 'pp_shop_products', [ 'AND' => [ 'producer_id' => $producer_id, 'status' => 1 ] ] );
$ls = ceil( $count / 12 );
if ( $bs < 1 )
$bs = 1;
else if ( $bs > $ls )
$bs = $ls;
$from = 12 * ( $bs - 1 );
if ( $from < 0 )
$from = 0;
$results['products'] = $mdb -> select( 'pp_shop_products', 'id', [ 'AND' => [ 'producer_id' => $producer_id, 'status' => 1 ], 'LIMIT' => [ $from, 12 ] ] );
$results['ls'] = $ls;
return $results;
$repo = new \Domain\Producer\ProducerRepository( $mdb );
return $repo->producerProducts( (int) $producer_id, 12, (int) $bs );
}
public function __get( $variable )