Skip to content

Commit

Permalink
Update Checker to search for issues with "Inactief Lid" of organs
Browse files Browse the repository at this point in the history
The `Checker` can now determine that a member cannot be "Lid" AND
"Inactief Lid" of the same organ, it guesses whether or not the
member should actually be "Lid" or "Inactief Lid", however, there
is no guarantee this is correct.

Additionally, it can detect "Inactief Lid" members who still have
a special role in the organ.

Co-Authored-By: rinkp <[email protected]>
  • Loading branch information
tomudding and rinkp committed Aug 9, 2022
1 parent 2da6284 commit 52ad859
Show file tree
Hide file tree
Showing 12 changed files with 384 additions and 172 deletions.
28 changes: 8 additions & 20 deletions module/Checker/src/Mapper/Installation.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,16 @@
namespace Checker\Mapper;

use Database\Model\Meeting as MeetingModel;
use Database\Model\SubDecision\Discharge as DischargeModel;
use Database\Model\SubDecision\Installation as InstallationModel;
use Doctrine\ORM\EntityManager;

class Installation
{
use Filter;

/**
* Doctrine entity manager.
*
* @var EntityManager
*/
protected $em;
protected EntityManager $em;

/**
* Constructor
*
* @param EntityManager $em
*/
public function __construct(EntityManager $em)
{
$this->em = $em;
Expand All @@ -29,11 +21,9 @@ public function __construct(EntityManager $em)
/**
* Returns an array of all installations that are discharged again before or during $meeting
*
* @param MeetingModel $meeting Meeting for which to check
*
* @return array \Database\Model\SubDecision\Installation
* @return array<array-key, DischargeModel>
*/
public function getAllInstallationsDischarged(MeetingModel $meeting)
public function getAllInstallationsDischarged(MeetingModel $meeting): array
{
$qb = $this->em->createQueryBuilder();

Expand All @@ -48,13 +38,11 @@ public function getAllInstallationsDischarged(MeetingModel $meeting)
}

/**
* Returns an array of all installations that have bbeen done before or during $meeting
*
* @param MeetingModel $meeting Meeting for which to check
* Returns an array of all installations that have been done before or during `$meeting`.
*
* @return array \Database\Model\SubDecision\Installation
* @return array<array-key, InstallationModel>
*/
public function getAllInstallationsInstalled(MeetingModel $meeting)
public function getAllInstallationsInstalled(MeetingModel $meeting): array
{
$qb = $this->em->createQueryBuilder();
$qb->select('i')
Expand Down
47 changes: 17 additions & 30 deletions module/Checker/src/Model/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,23 @@
/**
* Class Error
*
* Denotes an error that was occured while checking a database
* Denotes an error that was occurred while checking a database
* i.e. the database is left in a wrong state
*
* @package Checker\Model
*/
abstract class Error
{
/**
* @var MeetingModel Meeting for which the error is detected
*/
protected $meeting;

/**
* @return MeetingModel
*/
public function getMeeting()
{
return $this->meeting;
}

/**
* @var SubDecisionModel Decision that caused the error
* Note that this does not necessarily have to made made during $meeting
* Meeting for which the error is detected.
*/
protected $subDecision;
protected MeetingModel $meeting;

/**
* @return SubDecisionModel
* Note that this does not necessarily have to be made during `$meeting`.
*/
public function getSubDecision()
{
return $this->subDecision;
}
protected SubDecisionModel $subDecision;

/**
* Create a new desciption
*
* @param MeetingModel $meeting Meeting for which the error is detected
* @param SubDecisionModel $subDecision DEcision that caused the error
* Create a new description.
*/
public function __construct(
MeetingModel $meeting,
Expand All @@ -56,9 +34,18 @@ public function __construct(
$this->subDecision = $subDecision;
}

public function getMeeting(): MeetingModel
{
return $this->meeting;
}

public function getSubDecision(): SubDecisionModel
{
return $this->subDecision;
}

/**
* Return a textual representation of the Error
* Return a textual representation of the error.
*/
abstract public function asText();
abstract public function asText(): string;
}
27 changes: 14 additions & 13 deletions module/Checker/src/Model/Error/BudgetOrganDoesNotExist.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,26 @@
namespace Checker\Model\Error;

use Checker\Model\Error;
use Database\Model\SubDecision\Budget as BudgetModel;
use Database\Model\SubDecision\Foundation as FoundationModel;
use Database\Model\SubDecision\{
Budget as BudgetModel,
Foundation as FoundationModel,
};

/**
* Class BudgetOrganDoesNotExist
*
* This class denotes an error where a budget is created for an organ that does not exist
*
* @package Checker\Model\Error
* Error for when a budget is created for an organ that does not exist.
*/
class BudgetOrganDoesNotExist extends Error
{
public function __construct(BudgetModel $budget)
{
parent::__construct($budget->getDecision()->getMeeting(), $budget);
parent::__construct(
$budget->getDecision()->getMeeting(),
$budget,
);
}

/**
* Return the foundation where this budget belongs to
*
* @return FoundationModel
* Return the foundation where this budget belongs to.
*/
public function getFoundation(): FoundationModel
{
Expand All @@ -32,7 +31,9 @@ public function getFoundation(): FoundationModel

public function asText(): string
{
return 'Budget from ' . $this->getFoundation()->getName() . ' has been created. However '
. $this->getFoundation()->getName() . ' does not exist';
return sprintf(
'A budget for %s has been created, however, the organ does not exist.',
$this->getFoundation()->getName(),
);
}
}
56 changes: 56 additions & 0 deletions module/Checker/src/Model/Error/MemberActiveAndInactiveInOrgan.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Checker\Model\Error;

use Checker\Model\Error;
use Database\Model\{
Meeting as MeetingModel,
Member as MemberModel,
};
use Database\Model\SubDecision\{
Foundation as FoundationModel,
Installation as InstallationModel,
};

/**
* Error for when a member is "Inactief Lid" and "Lid" in an organ WITHOUT any special roles. We assume that the member
* should NOT be "Lid".
*/
class MemberActiveAndInactiveInOrgan extends Error
{
public function __construct(
MeetingModel $meeting,
InstallationModel $installation,
) {
parent::__construct(
$meeting,
$installation,
);
}

/**
* Get the member who is installed as "Inactief Lid" and "Lid" but without any special roles.
*/
public function getMember(): MemberModel
{
return $this->getSubDecision()->getMember();
}

/**
* Get the organ the member is installed in.
*/
public function getFoundation(): FoundationModel
{
return $this->getSubDecision()->getFoundation();
}

public function asText(): string
{
return sprintf(
'Member %s (%d) is marked as "Inactief Lid" of %s but is still a "Lid".',
$this->getMember()->getFullName(),
$this->getMember()->getLidNr(),
$this->getFoundation()->getName(),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Checker\Model\Error;

use Checker\Model\Error;
use Database\Model\{
Meeting as MeetingModel,
Member as MemberModel,
};
use Database\Model\SubDecision\{
Foundation as FoundationModel,
Installation as InstallationModel,
};

/**
* Error for when a member is "Inactief Lid" and "Lid" in an organ WITH special roles. We assume that the member should
* be "Lid" and NOT "Inactief Lid".
*/
class MemberActiveWithRoleAndInactiveInOrgan extends Error
{
public function __construct(
MeetingModel $meeting,
InstallationModel $installation,
) {
parent::__construct(
$meeting,
$installation,
);
}

/**
* Get the member who is installed as "Inactief Lid" and "Lid" with special roles.
*/
public function getMember(): MemberModel
{
return $this->getSubDecision()->getMember();
}

/**
* Get the organ the member is installed in.
*/
public function getFoundation(): FoundationModel
{
return $this->getSubDecision()->getFoundation();
}

public function asText(): string
{
return sprintf(
'Member %s (%d) is installed as "Lid" in %s with special roles but is also installed as "Inactief Lid".',
$this->getMember()->getFullName(),
$this->getMember()->getLidNr(),
$this->getFoundation()->getName(),
);
}
}
42 changes: 26 additions & 16 deletions module/Checker/src/Model/Error/MemberExpiredButStillInOrgan.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,53 @@
namespace Checker\Model\Error;

use Checker\Model\Error;
use Database\Model\Meeting as MeetingModel;
use Database\Model\Member as MemberModel;
use Database\Model\SubDecision\Foundation as FoundationModel;
use Database\Model\SubDecision\Installation as InstallationModel;
use Database\Model\{
Meeting as MeetingModel,
Member as MemberModel,
};
use Database\Model\SubDecision\{
Foundation as FoundationModel,
Installation as InstallationModel,
};

/**
* Error for when a member is installed in an organ while their GEWIS membership has expired.
*/
class MemberExpiredButStillInOrgan extends Error
{
/**
* @param MeetingModel $meeting
* @param InstallationModel $installation
*/
public function __construct(
MeetingModel $meeting,
InstallationModel $installation,
) {
parent::__construct($meeting, $installation);
parent::__construct(
$meeting,
$installation,
);
}

/**
* @return MemberModel Member that is not member of GEWIS anymore
* Get the member who is no longer a member of GEWIS (i.e., their expiry has lapsed).
*/
public function getMember()
public function getMember(): MemberModel
{
return $this->getSubDecision()->getMember();
}

/**
* @return FoundationModel Organ that the member is still a member of
* Get the organ that the member is still installed in.
*/
public function getOrgan()
public function getOrgan(): FoundationModel
{
return $this->getSubDecision()->getFoundation();
}

public function asText()
public function asText(): string
{
return 'Member ' . $this->getMember()->getFullName() . ' is member of ' . $this->getOrgan()->getName()
. ' however ' . $this->getMember()->getFullName() . ' is not a member of GEWIS anymore';
return sprintf(
'Member %s (%d) is installed in %s, however, their GEWIS membership has expired.',
$this->getMember()->getFullName(),
$this->getMember()->getLidnr(),
$this->getOrgan()->getName(),
);
}
}
Loading

0 comments on commit 52ad859

Please sign in to comment.