55 lines
1.7 KiB
PHP
55 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace KupShop\LabelsBundle\Admin\Actions;
|
|
|
|
use KupShop\AdminBundle\Admin\Actions\AbstractAction;
|
|
use KupShop\AdminBundle\Admin\Actions\ActionResult;
|
|
use KupShop\AdminBundle\Admin\Actions\IAction;
|
|
use KupShop\LabelsBundle\Util\ProductLabelUtil;
|
|
use Query\Operator;
|
|
use Symfony\Contracts\Service\Attribute\Required;
|
|
|
|
class UpdateLabelsRelationAction extends AbstractAction implements IAction
|
|
{
|
|
#[Required]
|
|
public ProductLabelUtil $productLabelUtil;
|
|
|
|
public function getTypes(): array
|
|
{
|
|
return ['Label'];
|
|
}
|
|
|
|
public function getIcon(): string
|
|
{
|
|
return 'glyphicon glyphicon-refresh';
|
|
}
|
|
|
|
public function getName(): string
|
|
{
|
|
return translate('update_labels_relations', 'Label');
|
|
}
|
|
|
|
public function execute(&$data, array $config, string $type): ActionResult
|
|
{
|
|
$label = sqlQueryBuilder()
|
|
->select('l.id, l.data, l.cron_assignment')
|
|
->from('labels', 'l')
|
|
->andWhere(Operator::equals(['id' => $this->getID()]))
|
|
->execute()
|
|
->fetchAssociative();
|
|
|
|
$data = json_decode($label['data'] ?? '{}', true);
|
|
if ($label['cron_assignment'] == 'Y' || $data['active_type'] == 'Y') {
|
|
$result = $this->productLabelUtil->updateProductLabelRelationsByAutoAssignment($this->getID(), $data);
|
|
|
|
return new ActionResult(true, "Dokončeno. Smazáno: {$result['deleted']}, Přiřazeno: {$result['inserted']}");
|
|
} else {
|
|
$result = $this->productLabelUtil->removeProductLabelRelationsByAutoAssignment($this->getID());
|
|
|
|
return new ActionResult(false, "Štítek nemá platné nastavení. Počet odebraných přiřazení: {$result}");
|
|
}
|
|
}
|
|
}
|