Skip to content

Commit

Permalink
migration for missing uploads, add status
Browse files Browse the repository at this point in the history
  • Loading branch information
mrothauer committed Dec 9, 2024
1 parent 03c6f20 commit 26f6335
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
43 changes: 43 additions & 0 deletions config/Migrations/20241209153457_Fundings7.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);

use Cake\Datasource\FactoryLocator;
use Migrations\AbstractMigration;
use App\Model\Entity\Funding;

class Fundings7 extends AbstractMigration
{
public function change(): void
{

$uploadTypes = [
'activity_proof',
'freistellungsbescheid',
'zuwendungsbestaetigung',
];

$fundingsTable = FactoryLocator::get('Table')->get('Fundings');
$fundings = $fundingsTable->find()->contain([
'FundinguploadsActivityProofs',
'FundinguploadsFreistellungsbescheids',
'FundinguploadsZuwendungsbestaetigungs',
]);

foreach($uploadTypes as $uploadType) {
$uploadEntity = 'fundinguploads_' . $uploadType . 's';
$uploadStatusField = $uploadType . '_status';
$sql = "ALTER TABLE `fundings` CHANGE `".$uploadStatusField."` `".$uploadStatusField."` INT NULL DEFAULT '" . Funding::STATUS_UPLOAD_MISSING . "';";
$this->execute($sql);

foreach($fundings as $funding) {
$uploadsCount = count($funding->$uploadEntity);
if ($uploadsCount == 0 && $funding->$uploadStatusField == Funding::STATUS_PENDING) {
$funding->$uploadStatusField = Funding::STATUS_UPLOAD_MISSING;
$fundingsTable->save($funding);
}
}

}

}
}
5 changes: 5 additions & 0 deletions src/Model/Entity/Funding.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ class Funding extends Entity
const STATUS_DESCRIPTION_MISSING = 60;
const STATUS_CHECKBOXES_MISSING = 70;
const STATUS_CHECKBOXES_OK = 80;
const STATUS_UPLOAD_MISSING = 90;

const MAX_FUNDING_SUM = 3000;

const STATUS_MAPPING_UPLOADS = [
self::STATUS_UPLOAD_MISSING => 'wurde noch nicht hochgeladen',
self::STATUS_PENDING => 'Bestätigung von Admin ausstehend',
self::STATUS_VERIFIED_BY_ADMIN => 'von Admin bestätigt',
self::STATUS_REJECTED_BY_ADMIN => 'von Admin beanstandet',
Expand Down Expand Up @@ -238,6 +240,9 @@ public function _getZuwendungsbestaetigungStatusCssClass() {
}

private function getAdminStatusCssClass($statusField) {
if ($this->$statusField == self::STATUS_UPLOAD_MISSING) {
return 'is-missing';
}
if ($this->$statusField == self::STATUS_PENDING) {
return 'is-pending';
}
Expand Down

0 comments on commit 26f6335

Please sign in to comment.