Skip to content

Commit

Permalink
switch to sibling account
Browse files Browse the repository at this point in the history
  • Loading branch information
leemyongpakvn committed Feb 7, 2024
1 parent 4725023 commit 3945c1c
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 16 deletions.
23 changes: 10 additions & 13 deletions controllers/admin/AdminBlockListingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,21 @@ public function displayAjaxDeleteBlock()
{
$result = false;
$idPSR = (int) Tools::getValue('idBlock');
$blockPSR = Db::getInstance()->getRow('SELECT * FROM ' . _DB_PREFIX_ . 'psreassurance WHERE `id_psreassurance` = ' . (int) $idPSR);
if (!empty($blockPSR)) {
$reassuranceRepository = $this->context->controller->getContainer()->get('block_reassurance_repository');
$blockPSR = $reassuranceRepository->find($idPSR);
if ($blockPSR !== null) {
$result = true;
// Remove Custom icon
if (!empty($blockPSR['custom_icon'])) {
$filePath = _PS_ROOT_DIR_ . $this->module->img_path_perso . '/' . basename($blockPSR['custom_icon']);
if (!empty($blockPSR->getCustomIcon())) {
$filePath = _PS_ROOT_DIR_ . $this->module->img_path_perso . '/' . basename($blockPSR->getCustomIcon());
if (file_exists($filePath)) {
$result = unlink($filePath);
}
}
// Remove Block Translations
if ($result) {
$result = Db::getInstance()->delete('psreassurance_lang', 'id_psreassurance = ' . (int) $idPSR);
}
// Remove Block

// Remove Block, translation is cascade removed
if ($result) {
$result = Db::getInstance()->delete('psreassurance', 'id_psreassurance = ' . (int) $idPSR);
$reassuranceRepository->delete($blockPSR);
}
}

Expand Down Expand Up @@ -161,9 +159,7 @@ public function displayAjaxSaveBlockContent()
$blockPsr = $reassuranceRepository->find($id_block);
} else {
$blockPsr = new Psreassurance();
// Last position
$blockPsr->setPosition((int) Db::getInstance()->getValue('SELECT MAX(position) AS max FROM ' . _DB_PREFIX_ . 'psreassurance'));
$blockPsr->setPosition($blockPsr->getPosition() ? $blockPsr->getPosition() + 1 : 1);
$blockPsr->setPosition($reassuranceRepository->getMaxPosition() + 1);
$blockPsr->setStatus(0);
}

Expand Down Expand Up @@ -219,6 +215,7 @@ public function displayAjaxUpdatePosition()
{
$blocks = Tools::getValue('blocks');
$result = false;
$reassuranceFormHandler = $this->context->controller->getContainer()->get('block_reassurance_form_data_handler');

if (!empty($blocks) && is_array($blocks)) {
$updateResult = true;
Expand Down
26 changes: 26 additions & 0 deletions src/Form/PsreassuranceFormDataHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,32 @@ public function create(array $data)
*/
public function update($id, array $data)
{
$psreassurance = $this->psreassuranceRepository->find($id);

if ($psreassurance === null) {
return 0;
} else {
foreach ($data as $key => $value) {
switch ($key) {
case 'date_upd':
$psreassurance->setDateUpd($value);
break;
case 'position':
$psreassurance->setPosition($value);
break;
case 'status':
$psreassurance->setStatus($value);
break;
}
}

$this->entityManager->persist($psreassurance);
$this->entityManager->flush();

//file_put_contents('tangiaba', $data['status'] . ' || ' . $psreassurance->getStatus());

return 1;
}
}

/**
Expand Down
14 changes: 14 additions & 0 deletions src/Repository/PsreassuranceRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,18 @@ public function getAllBlockByStatus($id_lang = 1)

return $result;
}

/**
* @return int
*/
public function getMaxPosition()
{
$qb = $this->connection->createQueryBuilder();
$qb
->select('MAX(position) AS max')
->from($this->databasePrefix . 'psreassurance')
;

return (int) $qb->execute()->fetch(\PDO::FETCH_COLUMN);
}
}
4 changes: 2 additions & 2 deletions views/dist/back.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Vue.js v2.7.15
* Vue.js v2.7.16
* (c) 2014-2023 Evan You
* Released under the MIT License.
*/
Expand All @@ -24,7 +24,7 @@
*/

/**!
* Sortable 1.15.1
* Sortable 1.15.2
* @author RubaXa <trash@rubaxa.org>
* @author owenm <owen23355@gmail.com>
* @license MIT
Expand Down
2 changes: 1 addition & 1 deletion views/dist/back.js.map

Large diffs are not rendered by default.

0 comments on commit 3945c1c

Please sign in to comment.