fixed filter order
This commit is contained in:
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Phinx\Migration\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ex public/userarea/sql/lims_value_binding.sql (feature/xls-mapping)
|
||||||
|
*/
|
||||||
|
final class CreateLimsValueBinding extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
if ($this->hasTable('lims_value_binding')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->execute("
|
||||||
|
CREATE TABLE `lims_value_binding` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`template_id` int(11) NOT NULL,
|
||||||
|
`mapping_id` int(11) NOT NULL,
|
||||||
|
`field_id` int(11) NOT NULL,
|
||||||
|
`source_value` varchar(500) NOT NULL,
|
||||||
|
`source_key` varchar(500) NOT NULL,
|
||||||
|
`lims_value_id` int(11) NOT NULL,
|
||||||
|
`lims_value` varchar(500) DEFAULT NULL,
|
||||||
|
`created_by` int(11) DEFAULT NULL,
|
||||||
|
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
UNIQUE KEY `uq_mapping_source` (`mapping_id`, `source_key`),
|
||||||
|
KEY `idx_template` (`template_id`),
|
||||||
|
KEY `idx_field_source` (`field_id`, `source_key`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci
|
||||||
|
");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
$this->execute("DROP TABLE IF EXISTS `lims_value_binding`");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Phinx\Migration\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ex public/userarea/sql/fixed_field_binding.sql (feature/xls-mapping)
|
||||||
|
* Idempotente: salta colonne/indici gia' presenti.
|
||||||
|
*/
|
||||||
|
final class XlsFixedFieldBinding extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
// --- template_fixed_mapping ---
|
||||||
|
$tfm = $this->table('template_fixed_mapping');
|
||||||
|
|
||||||
|
if (!$tfm->hasColumn('json_node')) {
|
||||||
|
$this->execute("ALTER TABLE `template_fixed_mapping`
|
||||||
|
ADD COLUMN `json_node` varchar(500) DEFAULT NULL");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$tfm->hasColumn('default_source')) {
|
||||||
|
$this->execute("ALTER TABLE `template_fixed_mapping`
|
||||||
|
ADD COLUMN `default_source` enum('manual','xls','json') NOT NULL DEFAULT 'manual'");
|
||||||
|
} else {
|
||||||
|
$this->execute("ALTER TABLE `template_fixed_mapping`
|
||||||
|
MODIFY COLUMN `default_source` enum('manual','xls','json') NOT NULL DEFAULT 'manual'");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$tfm->hasColumn('excel_column')) {
|
||||||
|
$this->execute("ALTER TABLE `template_fixed_mapping`
|
||||||
|
ADD COLUMN `excel_column` varchar(255) DEFAULT NULL AFTER `json_node`");
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- lims_value_binding ---
|
||||||
|
$lvb = $this->table('lims_value_binding');
|
||||||
|
|
||||||
|
if (!$lvb->hasColumn('binding_kind')) {
|
||||||
|
$this->execute("ALTER TABLE `lims_value_binding`
|
||||||
|
ADD COLUMN `binding_kind` enum('custom','fixed') NOT NULL DEFAULT 'custom' AFTER `template_id`");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->execute("ALTER TABLE `lims_value_binding`
|
||||||
|
MODIFY COLUMN `field_id` int(11) NOT NULL DEFAULT 0");
|
||||||
|
|
||||||
|
if ($lvb->hasIndexByName('uq_mapping_source')) {
|
||||||
|
$this->execute("ALTER TABLE `lims_value_binding` DROP INDEX `uq_mapping_source`");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$lvb->hasIndexByName('uq_kind_mapping_source')) {
|
||||||
|
$this->execute("ALTER TABLE `lims_value_binding`
|
||||||
|
ADD UNIQUE KEY `uq_kind_mapping_source` (`binding_kind`, `mapping_id`, `source_key`)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
$lvb = $this->table('lims_value_binding');
|
||||||
|
|
||||||
|
if ($lvb->hasIndexByName('uq_kind_mapping_source')) {
|
||||||
|
$this->execute("ALTER TABLE `lims_value_binding` DROP INDEX `uq_kind_mapping_source`");
|
||||||
|
}
|
||||||
|
if (!$lvb->hasIndexByName('uq_mapping_source')) {
|
||||||
|
$this->execute("ALTER TABLE `lims_value_binding`
|
||||||
|
ADD UNIQUE KEY `uq_mapping_source` (`mapping_id`, `source_key`)");
|
||||||
|
}
|
||||||
|
if ($lvb->hasColumn('binding_kind')) {
|
||||||
|
$this->execute("ALTER TABLE `lims_value_binding` DROP COLUMN `binding_kind`");
|
||||||
|
}
|
||||||
|
$this->execute("ALTER TABLE `lims_value_binding`
|
||||||
|
MODIFY COLUMN `field_id` int(11) NOT NULL");
|
||||||
|
|
||||||
|
$tfm = $this->table('template_fixed_mapping');
|
||||||
|
foreach (['excel_column', 'default_source', 'json_node'] as $col) {
|
||||||
|
if ($tfm->hasColumn($col)) {
|
||||||
|
$this->execute("ALTER TABLE `template_fixed_mapping` DROP COLUMN `$col`");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -39,8 +39,14 @@ if (!empty($explicitIds)) {
|
|||||||
// Scoping di sicurezza: solo record del template/utente/import corretti.
|
// Scoping di sicurezza: solo record del template/utente/import corretti.
|
||||||
$conds = ['d.templateid = ?', 'd.status = ?'];
|
$conds = ['d.templateid = ?', 'd.status = ?'];
|
||||||
$params = [$templateId, $status];
|
$params = [$templateId, $status];
|
||||||
if (!$showAll) { $conds[] = 'd.user_id = ?'; $params[] = $userId; }
|
if (!$showAll) {
|
||||||
if ($importref !== '') { $conds[] = 'd.importreferencecode = ?'; $params[] = $importref; }
|
$conds[] = 'd.user_id = ?';
|
||||||
|
$params[] = $userId;
|
||||||
|
}
|
||||||
|
if ($importref !== '') {
|
||||||
|
$conds[] = 'd.importreferencecode = ?';
|
||||||
|
$params[] = $importref;
|
||||||
|
}
|
||||||
$ph = implode(',', array_fill(0, count($explicitIds), '?'));
|
$ph = implode(',', array_fill(0, count($explicitIds), '?'));
|
||||||
$conds[] = "d.iddatadb IN ($ph)";
|
$conds[] = "d.iddatadb IN ($ph)";
|
||||||
foreach ($explicitIds as $id) $params[] = $id;
|
foreach ($explicitIds as $id) $params[] = $id;
|
||||||
@@ -57,7 +63,7 @@ if (!empty($explicitIds)) {
|
|||||||
$idStmt = $pdo->prepare("
|
$idStmt = $pdo->prepare("
|
||||||
SELECT d.iddatadb FROM datadb d
|
SELECT d.iddatadb FROM datadb d
|
||||||
WHERE {$whereSql}
|
WHERE {$whereSql}
|
||||||
ORDER BY d.excelrow ASC, d.iddatadb ASC
|
ORDER BY CAST(d.excelrow AS UNSIGNED) ASC, d.excelrow ASC, d.iddatadb ASC
|
||||||
LIMIT {$perPage} OFFSET {$offset}
|
LIMIT {$perPage} OFFSET {$offset}
|
||||||
");
|
");
|
||||||
$idStmt->execute($params);
|
$idStmt->execute($params);
|
||||||
|
|||||||
Reference in New Issue
Block a user