mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-10-09 14:59:43 +00:00
upgrade and refactor personhistoryFile
This commit is contained in:
92
Entity/AccompanyingPeriod/ClosingMotive.php
Normal file
92
Entity/AccompanyingPeriod/ClosingMotive.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
|
||||
/**
|
||||
* ClosingMotive give an explanation why we closed the Accompanying period
|
||||
*/
|
||||
class ClosingMotive
|
||||
{
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
private $active;
|
||||
|
||||
|
||||
/**
|
||||
* Get id
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set name
|
||||
*
|
||||
* @param array $name
|
||||
*
|
||||
* @return ClosingMotive
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function isActive()
|
||||
{
|
||||
return $this->active;
|
||||
}
|
||||
|
||||
public function setActive($active)
|
||||
{
|
||||
$this->active = $active;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -110,11 +110,9 @@ class Person {
|
||||
*
|
||||
* @param \DateTime $date
|
||||
*/
|
||||
public function open(\DateTime $date, $memo = '') {
|
||||
$history = new PersonHistoryFile($date);
|
||||
$history->setMemo($memo);
|
||||
public function open(PersonHistoryFile $accompanyingPeriod) {
|
||||
$this->proxyHistoryOpenState = true;
|
||||
$this->addHistoryFile($history);
|
||||
$this->addHistoryFile($accompanyingPeriod);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,30 +124,12 @@ class Person {
|
||||
*
|
||||
* To check if the Person and his history are consistent, use validation.
|
||||
*
|
||||
* @param \DateTime $date
|
||||
* @param string $motive
|
||||
* @param string $memo
|
||||
* @param PersonHistoryFile
|
||||
* @throws \Exception if two lines of history are open.
|
||||
*/
|
||||
public function close(\DateTime $date, $motive, $memo = '') {
|
||||
$histories = $this->history;
|
||||
|
||||
$found = false;
|
||||
|
||||
foreach ($histories as $history) {
|
||||
if ($history->isOpen()) {
|
||||
|
||||
if ($found === true) {
|
||||
throw new \Exception('two open line in history were found. This should not happen.');
|
||||
}
|
||||
|
||||
$history->setDateClosing($date);
|
||||
$history->setMotive($motive);
|
||||
$history->setMemo($memo);
|
||||
$this->proxyHistoryOpenState = false;
|
||||
$found = true;
|
||||
}
|
||||
}
|
||||
public function close(PersonHistoryFile $accompanyingPeriod)
|
||||
{
|
||||
$this->proxyHistoryOpenState = false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -25,11 +25,6 @@ class PersonHistoryFile
|
||||
*/
|
||||
private $date_closing;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $motive = '';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
@@ -40,6 +35,12 @@ class PersonHistoryFile
|
||||
*/
|
||||
private $person;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var AccompanyingPeriod\ClosingMotive
|
||||
*/
|
||||
private $closingMotive = null;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param \DateTime $dateOpening
|
||||
@@ -121,29 +122,6 @@ class PersonHistoryFile
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set motive
|
||||
*
|
||||
* @param string $motive
|
||||
* @return PersonHistoryFile
|
||||
*/
|
||||
public function setMotive($motive)
|
||||
{
|
||||
$this->motive = $motive;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get motive
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMotive()
|
||||
{
|
||||
return $this->motive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set memo
|
||||
*
|
||||
@@ -197,6 +175,18 @@ class PersonHistoryFile
|
||||
return $this->person;
|
||||
}
|
||||
|
||||
public function getClosingMotive()
|
||||
{
|
||||
return $this->closingMotive;
|
||||
}
|
||||
|
||||
public function setClosingMotive(AccompanyingPeriod\ClosingMotive $closingMotive)
|
||||
{
|
||||
$this->closingMotive = $closingMotive;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// VALIDATION function
|
||||
|
||||
|
Reference in New Issue
Block a user