Skip to content

Commit

Permalink
error not found moves to defect_found_reason
Browse files Browse the repository at this point in the history
  • Loading branch information
mrothauer committed Nov 14, 2023
1 parent 4214aa0 commit 9c19ba7
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 28 deletions.
20 changes: 20 additions & 0 deletions config/Migrations/20231114122353_InfoSheetAdaption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
declare(strict_types=1);

use Migrations\AbstractMigration;

class InfoSheetAdaption extends AbstractMigration
{

public function change(): void
{
$this->execute("INSERT INTO `form_field_options` (`id`, `form_field_id`, `value`, `name`, `rank`, `status`) VALUES (NULL, '3', '5', 'Fehler nicht gefunden', '50', '1');");
$this->execute("UPDATE `info_sheets` SET defect_found_reason = 5 WHERE defect_found = 0;");
$this->execute("ALTER TABLE `info_sheets` DROP `defect_found`;");
$this->execute("DELETE FROM `form_field_options` WHERE `form_field_options`.`id` = 6;");
$this->execute("DELETE FROM `form_field_options` WHERE `form_field_options`.`id` = 7;");
$this->execute("DELETE FROM `form_field_options_extra_infos` WHERE `form_field_options_extra_infos`.`id` = 17;");
$this->execute("INSERT INTO `form_field_options_extra_infos` (`id`, `form_field_options_id`, `repair_status`, `repair_barrier_if_end_of_life`) VALUES (NULL, '29', 'end of life', 'error not found');");
}

}
4 changes: 1 addition & 3 deletions config/sql/info-sheets-download.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ SELECT
DATE_FORMAT(i.created, '%Y') - i.device_age as "Baujahr",
DATE_FORMAT(e.datumstart, '%d.%m.%Y') as "Datum Reparaturveranstaltung",
defect_description as Fehlerbeschreibung,
defect_found_ffo2.name as "Fehler gefunden?",
defect_found_ffo3.name as Reparaturerfolg,
defect_found_ffo4.name as "Reparatur: vertagt",
defect_found_ffo5.name as "Reparatur: nicht erfolgt",
Expand All @@ -20,12 +19,11 @@ LEFT JOIN categories c ON c.id = i.category_id
LEFT JOIN categories pc ON pc.id = c.parent_id
JOIN events e ON e.uid = i.event_uid
JOIN workshops w ON e.workshop_uid = w.uid
LEFT JOIN form_field_options defect_found_ffo2 ON defect_found_ffo2.form_field_id = 2 AND defect_found_ffo2.value = i.defect_found
LEFT JOIN form_field_options defect_found_ffo3 ON defect_found_ffo3.form_field_id = 3 AND defect_found_ffo3.value = i.defect_found_reason
LEFT JOIN form_field_options defect_found_ffo4 ON defect_found_ffo4.form_field_id = 4 AND defect_found_ffo4.value = i.repair_postponed_reason
LEFT JOIN form_field_options defect_found_ffo5 ON defect_found_ffo5.form_field_id = 5 AND defect_found_ffo5.value = i.no_repair_reason
LEFT JOIN form_field_options defect_found_ffo6 ON defect_found_ffo6.form_field_id = 6 AND defect_found_ffo6.value = i.device_must_not_be_used_anymore
WHERE 1
AND i.status = 1
AND w.uid = :workshopUid
ORDER by e.datumstart DESC
ORDER by e.datumstart DESC, i.uid DESC
5 changes: 0 additions & 5 deletions config/sql/info-sheets-full-download.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ SELECT
DATE_FORMAT(i.created, '%Y') - i.device_age as "year_of_manufacture",
TRIM(
CONCAT(
COALESCE(ffoeiA.repair_status, ''), ' ',
COALESCE(ffoeiB.repair_status, ''), ' ',
COALESCE(ffoeiC.repair_status, ''), ' ',
COALESCE(ffoeiD.repair_status, ''), ' ',
Expand All @@ -21,14 +20,12 @@ SELECT
) as "repair_status",
TRIM(
CONCAT(
COALESCE(ffoeiA.repair_barrier_if_end_of_life, ''), ' ',
COALESCE(ffoeiB.repair_barrier_if_end_of_life, ''), ' ',
COALESCE(ffoeiC.repair_barrier_if_end_of_life, ''), ' ',
COALESCE(ffoeiD.repair_barrier_if_end_of_life, ''), ' ',
COALESCE(ffoeiE.repair_barrier_if_end_of_life, '')
)
) as "repair_barrier_if_end_of_life",
defect_found_ffo2.name as "defect_found_name",
defect_found_ffo3.name as "defect_found_reason",
defect_found_ffo4.name as "repair_postponed_reason",
defect_found_ffo5.name as "no_repair_reason",
Expand All @@ -48,12 +45,10 @@ LEFT JOIN ords_categories oc ON c.ords_category_id = oc.id
JOIN events e ON e.uid = i.event_uid
JOIN workshops w ON e.workshop_uid = w.uid
LEFT JOIN countries country ON w.country_code = country.code
LEFT JOIN form_field_options defect_found_ffo2 ON defect_found_ffo2.form_field_id = 2 AND defect_found_ffo2.value = i.defect_found
LEFT JOIN form_field_options defect_found_ffo3 ON defect_found_ffo3.form_field_id = 3 AND defect_found_ffo3.value = i.defect_found_reason
LEFT JOIN form_field_options defect_found_ffo4 ON defect_found_ffo4.form_field_id = 4 AND defect_found_ffo4.value = i.repair_postponed_reason
LEFT JOIN form_field_options defect_found_ffo5 ON defect_found_ffo5.form_field_id = 5 AND defect_found_ffo5.value = i.no_repair_reason
LEFT JOIN form_field_options defect_found_ffo6 ON defect_found_ffo6.form_field_id = 6 AND defect_found_ffo6.value = i.device_must_not_be_used_anymore
LEFT JOIN form_field_options_extra_infos ffoeiA ON ffoeiA.form_field_options_id = defect_found_ffo2.id
LEFT JOIN form_field_options_extra_infos ffoeiB ON ffoeiB.form_field_options_id = defect_found_ffo3.id
LEFT JOIN form_field_options_extra_infos ffoeiC ON ffoeiC.form_field_options_id = defect_found_ffo4.id
LEFT JOIN form_field_options_extra_infos ffoeiD ON ffoeiD.form_field_options_id = defect_found_ffo5.id
Expand Down
4 changes: 4 additions & 0 deletions src/Controller/EventsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ public function myEvents()
}
]);

$workshops->where([
'Workshops.uid' => 54724,
]);

$this->Workshop->getAssociation('Events')->setConditions(['Events.status > ' . APP_DELETED])
->setSort([
'Events.datumstart' => 'DESC',
Expand Down
3 changes: 0 additions & 3 deletions src/Controller/InfoSheetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,6 @@ private function _edit($infoSheet, $isEditMode)
$powerSupplyFormField = $this->FormField->getForForm(1);
$this->set('powerSupplyFormField', $powerSupplyFormField);

$defectFoundFormField = $this->FormField->getForForm(2);
$this->set('defectFoundFormField', $defectFoundFormField);

$defectFoundReasonFormField = $this->FormField->getForForm(3);
$this->set('defectFoundReasonFormField', $defectFoundReasonFormField);

Expand Down
20 changes: 11 additions & 9 deletions src/Model/Table/InfoSheetsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ public function initialize(array $config): void
]);
}

public function validationDefault(Validator $validator): \Cake\Validation\Validator
public function validationAdmin(Validator $validator): Validator
{
return $this->validationDefault($validator);
}

public function validationDefault(Validator $validator): Validator
{
$validator->notEmptyString('category_id', 'Bitte wähle eine Kategorie aus.');
$validator = $this->getNumberRangeValidator($validator, 'device_age', 0, 400);
Expand All @@ -56,7 +61,9 @@ public function validationDefault(Validator $validator): \Cake\Validation\Valida
return $this->isBrandCreateModeEnabled($context);
});

$validator->notEmptyString('defect_description', 'Bitte gib die Fehlerbeschreibung an (maximal 1.000 Zeichen).');
$validator->notEmptyString('defect_description', 'Bitte gib die Fehlerbeschreibung an (maximal 1.000 Zeichen).', function($context) {
return $this->isDefectFound($context);
});
$validator->maxLength('defect_description', 1000, 'Maximal 1.000 Zeichen bitte.');
$validator->notEmptyString('defect_found', 'Wurde der Fehler gefunden?');

Expand Down Expand Up @@ -238,14 +245,12 @@ private function setNotRepairedConditions($query)
$query->where(function ($exp, $query) {
return $exp->or([
$query->newExpr()->and([
'InfoSheets.defect_found' => 0,
'InfoSheets.defect_found_reason' => 5,
]),
$query->newExpr()->and([
'InfoSheets.defect_found' => 1,
'InfoSheets.defect_found_reason' => 4,
]),
$query->newExpr()->and([
'InfoSheets.defect_found' => 1,
'InfoSheets.defect_found_reason' => 3,
'InfoSheets.no_repair_reason IN' => [2,3,4,6,10,11,12,13,14],
]),
Expand All @@ -259,12 +264,10 @@ private function setRepairableConditions($query)
$query->where(function ($exp, $query) {
return $exp->or([
$query->newExpr()->and([
'InfoSheets.defect_found' => 1,
'InfoSheets.defect_found_reason' => 2,
'InfoSheets.repair_postponed_reason IN' => [1,2,3],
]),
$query->newExpr()->and([
'InfoSheets.defect_found' => 1,
'InfoSheets.defect_found_reason' => 3,
'InfoSheets.no_repair_reason IN' => [1,5,9],
]),
Expand All @@ -276,7 +279,6 @@ private function setRepairableConditions($query)
private function setRepairedConditions($query)
{
$query->where([
'InfoSheets.defect_found' => 1,
'InfoSheets.defect_found_reason' => 1,
]);
return $query;
Expand All @@ -294,7 +296,7 @@ private function isBrandCreateModeEnabled($context)

private function isDefectFound($context)
{
return !empty($context['data']) && $context['data']['defect_found'] == 1;
return !empty($context['data']) && in_array($context['data']['defect_found_reason'], [1,2,3,4]);
}

private function isRepairPostponed($context)
Expand Down
2 changes: 1 addition & 1 deletion src/View/Helper/MyHtmlHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function getGenders()
];
}

function generateGenericRadioButton($form, $formField, $labelClass = '')
function generateGenericRadioButton($form, $formField)
{
$result = '<div class="form-fields-checkbox-wrapper dependent-form-field '.$formField->identifier.'">'.
'<label>'.$formField->name.'</label>'.
Expand Down
1 change: 0 additions & 1 deletion templates/InfoSheets/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@
<?php
echo $this->Form->fieldset(
$this->Form->control('InfoSheets.defect_description', ['type' => 'textarea', 'label' => 'Fehlerbeschreibung:', 'placeholder' => 'Helft mit einer genauen Fehlerbeschreibung, wiederkehrende Defekte herauszufinden und so Schwachstellen in der Konstruktion von Geräten zu identifizieren! Maximal 1.000 Zeichen.', 'maxlength' => 1000]).
$this->Html->generateGenericRadioButton($this->Form, $defectFoundFormField).
$this->Html->generateGenericRadioButton($this->Form, $defectFoundReasonFormField).
$this->Html->generateGenericRadioButton($this->Form, $repairPostponedReasonFormField).
$this->Html->generateGenericRadioButton($this->Form, $noRepairReasonFormField).
Expand Down
3 changes: 0 additions & 3 deletions tests/TestCase/Controller/InfoSheetsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class InfoSheetsControllerTest extends AppTestCase
]
],
'defect_description' => '',
'defect_found' => '',
'defect_found_reason' => 2,
'repair_postponed_reason' => 3,
'no_repair_reason' => '',
Expand All @@ -54,7 +53,6 @@ public function testAddInfoSheetValidations()
);
$this->assertResponseContains('Bitte gib die Fehlerbeschreibung an (maximal 1.000 Zeichen).');
$this->assertResponseContains('Bitte wähle eine Kategorie aus.');
$this->assertResponseContains('Wurde der Fehler gefunden?');
}

public function testAddInfoSheetOk()
Expand All @@ -63,7 +61,6 @@ public function testAddInfoSheetOk()
$this->newInfoSheetData['defect_description'] = 'Defect description';
$this->newInfoSheetData['device_name'] = 'Device name';
$this->newInfoSheetData['category_id'] = 87;
$this->newInfoSheetData['defect_found'] = 1;
$this->newInfoSheetData['device_age'] = 1;
$this->post(
Configure::read('AppConfig.htmlHelper')->urlInfoSheetNew(6),
Expand Down
4 changes: 2 additions & 2 deletions tests/comparisons/info-sheets-download.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Laufzettel-UID,Oberkategorie,Unterkategorie,Marke,Gerät/Gegenstand,Baujahr,"Datum Reparaturveranstaltung",Fehlerbeschreibung,"Fehler gefunden?",Reparaturerfolg,"Reparatur: vertagt","Reparatur: nicht erfolgt","Reparatur: Abbruch","Keine Reparatur, weil",Url
7,,,,,,01.01.2040,,,,,,,,"https://www.reparatur-initiativen.de/test-workshop?event=6,2040-01-01"
Laufzettel-UID,Oberkategorie,Unterkategorie,Marke,Gerät/Gegenstand,Baujahr,"Datum Reparaturveranstaltung",Fehlerbeschreibung,Reparaturerfolg,"Reparatur: vertagt","Reparatur: nicht erfolgt","Reparatur: Abbruch","Keine Reparatur, weil",Url
7,,,,,,01.01.2040,,,,,,,"https://www.reparatur-initiativen.de/test-workshop?event=6,2040-01-01"
1 change: 0 additions & 1 deletion webroot/css/frontend.css
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,6 @@ div.admin div.edit.column-1 textarea {
width: 863px;
}
#infoSheetEditForm .power_supply,
#infoSheetEditForm .defect_found_reason,
#infoSheetEditForm .repair_postponed_reason,
#infoSheetEditForm .no_repair_reason,
#infoSheetEditForm .device_must_not_be_used_anymore,
Expand Down

0 comments on commit 9c19ba7

Please sign in to comment.