Raw integration of accompanying person (with respect of 'cahier de cahrge)

This commit is contained in:
Marc Ducobu 2015-08-24 14:41:24 +02:00
parent 9decbf119a
commit f967285e34
15 changed files with 148 additions and 101 deletions

View File

@ -42,7 +42,7 @@ class AccompanyingPeriodController extends Controller
$person = $this->_getPerson($person_id);
$accompanyingPeriod = new AccompanyingPeriod(new \DateTime());
$accompanyingPeriod->setDateClosing(new \DateTime());
$accompanyingPeriod->setClosingDate(new \DateTime());
$person->addAccompanyingPeriod(
$accompanyingPeriod);

View File

@ -30,47 +30,33 @@ use Symfony\Component\Validator\ExecutionContextInterface;
*/
class AccompanyingPeriod
{
/**
* @var integer
*/
/** @var integer */
private $id;
/**
* @var \DateTime
*/
private $date_opening;
/** @var \DateTime */
private $openingDate;
/**
* @var \DateTime
*/
private $date_closing;
/** @var \DateTime */
private $closingDate;
/**
* @var string
*/
private $memo = '';
/** @var string */
private $remark = '';
/**
* @var \Chill\PersonBundle\Entity\Person
*/
/** @var \Chill\PersonBundle\Entity\Person */
private $person;
/**
*
* @var AccompanyingPeriod\ClosingMotive
*/
/** @var AccompanyingPeriod\ClosingMotive */
private $closingMotive = null;
/**
*
* @param \DateTime $dateOpening
* @uses AccompanyingPeriod::setDateClosing()
* @uses AccompanyingPeriod::setClosingDate()
*/
public function __construct(\DateTime $dateOpening) {
$this->setDateOpening($dateOpening);
$this->setOpeningDate($dateOpening);
}
/**
* Get id
*
@ -82,30 +68,30 @@ class AccompanyingPeriod
}
/**
* Set date_opening
* Set openingDate
*
* @param \DateTime $dateOpening
* @return AccompanyingPeriod
*/
public function setDateOpening($dateOpening)
public function setOpeningDate($openingDate)
{
$this->date_opening = $dateOpening;
$this->openingDate = $openingDate;
return $this;
}
/**
* Get date_opening
* Get openingDate
*
* @return \DateTime
*/
public function getDateOpening()
public function getOpeningDate()
{
return $this->date_opening;
return $this->openingDate;
}
/**
* Set date_closing
* Set closingDate
*
* For closing a Person file, you should use Person::setClosed instead.
*
@ -113,21 +99,21 @@ class AccompanyingPeriod
* @return AccompanyingPeriod
*
*/
public function setDateClosing($dateClosing)
public function setClosingDate($closingDate)
{
$this->date_closing = $dateClosing;
$this->closingDate = $closingDate;
return $this;
}
/**
* Get date_closing
* Get closingDate
*
* @return \DateTime
*/
public function getDateClosing()
public function getClosingDate()
{
return $this->date_closing;
return $this->closingDate;
}
/**
@ -135,7 +121,7 @@ class AccompanyingPeriod
* @return boolean
*/
public function isOpen() {
if ($this->getDateClosing() === null) {
if ($this->getClosingDate() === null) {
return true;
} else {
return false;
@ -143,30 +129,30 @@ class AccompanyingPeriod
}
/**
* Set memo
* Set remark
*
* @param string $memo
* @param string $remark
* @return AccompanyingPeriod
*/
public function setMemo($memo)
public function setRemark($remark)
{
if ($memo === null) {
$memo = '';
if ($remark === null) {
$remark = '';
}
$this->memo = $memo;
$this->remark = $remark;
return $this;
}
/**
* Get memo
* Get remark
*
* @return string
*/
public function getMemo()
public function getRemark()
{
return $this->memo;
return $this->remark;
}
/**
@ -225,7 +211,7 @@ class AccompanyingPeriod
* @return boolean
*/
public function isClosingAfterOpening() {
$diff = $this->getDateOpening()->diff($this->getDateClosing());
$diff = $this->getOpeningDate()->diff($this->getClosingDate());
if ($diff->invert === 0) {
return true;

View File

@ -192,12 +192,12 @@ class Person implements HasCenterInterface {
//order by date :
usort($periods, function($a, $b) {
$dateA = $a->getDateOpening();
$dateB = $b->getDateOpening();
$dateA = $a->getOpeningDate();
$dateB = $b->getOpeningDate();
if ($dateA == $dateB) {
$dateEA = $a->getDateClosing();
$dateEB = $b->getDateClosing();
$dateEA = $a->getClosingDate();
$dateEB = $b->getClosingDate();
if ($dateEA == $dateEB) {
return 0;
@ -647,17 +647,17 @@ class Person implements HasCenterInterface {
if($periodI->isOpen()) {
return array(
'result' => self::ERROR_ADDIND_PERIOD_AFTER_AN_OPEN_PERIOD,
'dateOpening' => $periodAfterI->getDateOpening(),
'dateClosing' => $periodAfterI->getDateClosing(),
'date' => $periodI->getDateOpening()
'dateOpening' => $periodAfterI->getOpeningDate(),
'dateClosing' => $periodAfterI->getClosingDate(),
'date' => $periodI->getOpeningDate()
);
} elseif ($periodI->getDateClosing() >= $periodAfterI->getDateOpening()) {
} elseif ($periodI->getClosingDate() >= $periodAfterI->getOpeningDate()) {
return array(
'result' => self::ERROR_PERIODS_ARE_COLLAPSING,
'dateOpening' => $periodI->getDateOpening(),
'dateOpening' => $periodI->getOpeningDate(),
'dateClosing' => $periodI->getDateClosing(),
'date' => $periodAfterI->getDateOpening()
'dateClosing' => $periodI->getClosingDate(),
'date' => $periodAfterI->getOpeningDate()
);
}
$i++;

View File

@ -19,7 +19,7 @@ class AccompanyingPeriodType extends AbstractType
//if the period_action is close, date opening should not be seen
if ($options['period_action'] !== 'close') {
$builder
->add('date_opening', 'date', array(
->add('openingDate', 'date', array(
"required" => true,
'widget' => 'single_text',
'format' => 'dd-MM-yyyy'
@ -40,13 +40,13 @@ class AccompanyingPeriodType extends AbstractType
OR
($options['period_action'] === 'update' AND !$accompanyingPeriod->isOpen())
) {
$form->add('date_closing', 'date', array('required' => true,
$form->add('closingDate', 'date', array('required' => true,
'widget' => 'single_text', 'format' => 'dd-MM-yyyy'));
$form->add('closingMotive', 'closing_motive');
}
});
$builder->add('memo', 'textarea', array(
$builder->add('remark', 'textarea', array(
'required' => false
))
;

View File

@ -7,13 +7,13 @@ Chill\PersonBundle\Entity\AccompanyingPeriod:
id: true
generator: { strategy: AUTO }
fields:
date_opening:
openingDate:
type: date
date_closing:
closingDate:
type: date
default: null
nullable: true
memo:
remark:
type: text
manyToOne:
person:

View File

@ -48,11 +48,11 @@ chill_person_search:
chill_person_accompanying_period_list:
path: /{_locale}/person/{person_id}/accompanying-period
defaults: { _controller: ChillPersonBundle:AccompanyingPeriod:list }
# options:
# menus:
# person:
# order: 100
# label: menu.person.history
options:
menus:
person:
order: 100
label: Accompanying period list
chill_person_accompanying_period_create:
path: /{_locale}/person/{person_id}/accompanying-period/create

View File

@ -35,12 +35,12 @@ Chill\PersonBundle\Entity\Person:
Chill\PersonBundle\Entity\AccompanyingPeriod:
properties:
date_opening:
openingDate:
- Date:
message: 'Opening date is not valid'
- NotNull:
message: 'Opening date can not be null'
date_closing:
closingDate:
- Date:
message: 'Closing date is not valid'
- NotNull:

View File

@ -0,0 +1,61 @@
<?php
/*
* Chill is a software for social workers
*
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
* <http://www.champs-libres.coop>, <info@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 Application\Migrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Migration for adapting the Person Bundle to the 'cahier de charge' :
* - update of accompanyingPerid
*/
class Version20150820113409 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
$this->abortIf(
$this->connection->getDatabasePlatform()->getName() != 'postgresql',
'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE accompanying_period RENAME COLUMN date_opening TO openingdate;');
$this->addSql('ALTER TABLE accompanying_period RENAME COLUMN date_closing TO closingdate;');
$this->addSql('ALTER TABLE accompanying_period RENAME COLUMN memo TO remark;');
}
/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
$this->abortIf(
$this->connection->getDatabasePlatform()->getName() != 'postgresql',
'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE accompanying_period RENAME COLUMN openingdate TO date_opening;');
$this->addSql('ALTER TABLE accompanying_period RENAME COLUMN closingdate TO date_closing;');
$this->addSql('ALTER TABLE accompanying_perod RENAME COLUMN remark TO memo;');
}
}

View File

@ -10,17 +10,17 @@
{{ form_start(form) }}
{{ 'Last opening since %last_opening%'|trans(
{ '%last_opening%' : accompanying_period.dateOpening|localizeddate('long', 'none', app.request.locale) }) }}
{ '%last_opening%' : accompanying_period.openingDate|localizeddate('long', 'none', app.request.locale) }) }}
{% if form.dateClosing is defined %}
{{ form_row(form.dateClosing, {'label' : 'Closing date'} ) }}
{% if form.closingDate is defined %}
{{ form_row(form.closingDate, {'label' : 'Closing date'} ) }}
{% endif %}
{% if form.closingMotive is defined %}
{{ form_row(form.closingMotive, {'label' : 'Closing motive'} ) }}
{% endif %}
{{ form_row(form.memo, {'label' : 'Memo' } ) }}
{{ form_row(form.remark, {'label' : 'Remark' } ) }}
{{ form_rest(form) }}

View File

@ -18,13 +18,13 @@
{% set i = 0 %}
{% for accompanying_period in accompanying_periods %}
<tr class="{% if i is not even %}striped{% endif %}">
<td>{{ accompanying_period.dateOpening|localizeddate('long', 'none', app.request.locale) }}</td>
<td>{{ accompanying_period.openingDate|localizeddate('long', 'none', app.request.locale) }}</td>
<td>{% spaceless %}
{% if accompanying_period.isOpen %}
{{ 'Still open'|trans }}
{% else %}
{{ accompanying_period.dateClosing|localizeddate('long', 'none', app.request.locale) }}
{{ accompanying_period.closingDate|localizeddate('long', 'none', app.request.locale) }}
{% endif %}
{% endspaceless %}</td>
@ -34,10 +34,10 @@
</div>
</td>
</tr>
{% if accompanying_period.memo is not empty %}
{% if accompanying_period.remark is not empty %}
<tr class="{% if i is not even %}striped{% endif %}">
<td colspan="3">
<pre>{{ accompanying_period.memo }}</pre>
<pre>{{ accompanying_period.remark }}</pre>
</td>
</tr>
{% endif %}

View File

@ -55,8 +55,8 @@ class AccompanyingPeriodControllerTest extends WebTestCase
*/
protected static $em;
const OPENING_INPUT = 'chill_personbundle_accompanyingperiod[date_opening]';
const CLOSING_INPUT = 'chill_personbundle_accompanyingperiod[date_closing]';
const OPENING_INPUT = 'chill_personbundle_accompanyingperiod[openingDate]';
const CLOSING_INPUT = 'chill_personbundle_accompanyingperiod[closingDate]';
const CLOSING_MOTIVE_INPUT = 'chill_personbundle_accompanyingperiod[closingMotive]';
/**
@ -114,7 +114,7 @@ class AccompanyingPeriodControllerTest extends WebTestCase
. 'motive into your periods fixtures');
}
$period->setDateClosing(new \DateTime($periodDef['closingDate']))
$period->setClosingDate(new \DateTime($periodDef['closingDate']))
->setClosingMotive($periodDef['closingMotive']);
}

View File

@ -32,7 +32,7 @@ class AccompanyingPeriodTest extends \PHPUnit_Framework_TestCase
$datetime2 = new \DateTime('tomorrow');
$period = new AccompanyingPeriod($datetime1);
$period->setDateClosing($datetime2);
$period->setClosingDate($datetime2);
$r = $period->isClosingAfterOpening();
@ -44,7 +44,7 @@ class AccompanyingPeriodTest extends \PHPUnit_Framework_TestCase
$datetime2 = new \DateTime('now');
$period = new AccompanyingPeriod($datetime1);
$period->setDateClosing($datetime2);
$period->setClosingDate($datetime2);
$this->assertFalse($period->isClosingAfterOpening());
}
@ -53,7 +53,7 @@ class AccompanyingPeriodTest extends \PHPUnit_Framework_TestCase
$datetime = new \DateTime('now');
$period = new AccompanyingPeriod($datetime);
$period->setDateClosing($datetime);
$period->setClosingDate($datetime);
$this->assertTrue($period->isClosingAfterOpening());
}
@ -66,7 +66,7 @@ class AccompanyingPeriodTest extends \PHPUnit_Framework_TestCase
public function testIsClosed() {
$period = new AccompanyingPeriod(new \DateTime());
$period->setDateClosing(new \DateTime('tomorrow'));
$period->setClosingDate(new \DateTime('tomorrow'));
$this->assertFalse($period->isOpen());
}

View File

@ -44,10 +44,10 @@ class PersonTest extends \PHPUnit_Framework_TestCase
$this->assertInstanceOf('Chill\PersonBundle\Entity\AccompanyingPeriod', $period);
$this->assertTrue($period->isOpen());
$this->assertEquals($d, $period->getDateOpening());
$this->assertEquals($d, $period->getOpeningDate());
//close and test
$period->setDateClosing(new \DateTime('tomorrow'));
$period->setClosingDate(new \DateTime('tomorrow'));
$shouldBeNull = $p->getCurrentAccompanyingPeriod();
$this->assertNull($shouldBeNull);
@ -63,19 +63,19 @@ class PersonTest extends \PHPUnit_Framework_TestCase
$p = new Person($d);
$e = new \DateTime("2013/3/1");
$period = $p->getCurrentAccompanyingPeriod()->setDateClosing($e);
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($e);
$p->close($period);
$f = new \DateTime("2013/1/1");
$p->open(new AccompanyingPeriod($f));
$g = new \DateTime("2013/4/1");
$period = $p->getCurrentAccompanyingPeriod()->setDateClosing($g);
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($g);
$p->close($period);
$r = $p->getAccompanyingPeriodsOrdered();
$date = $r[0]->getDateOpening()->format('Y-m-d');
$date = $r[0]->getOpeningDate()->format('Y-m-d');
$this->assertEquals($date, '2013-01-01');
}
@ -89,19 +89,19 @@ class PersonTest extends \PHPUnit_Framework_TestCase
$p = new Person($d);
$g = new \DateTime("2013/4/1");
$period = $p->getCurrentAccompanyingPeriod()->setDateClosing($g);
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($g);
$p->close($period);
$f = new \DateTime("2013/2/1");
$p->open(new AccompanyingPeriod($f));
$e = new \DateTime("2013/3/1");
$period = $p->getCurrentAccompanyingPeriod()->setDateClosing($e);
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($e);
$p->close($period);
$r = $p->getAccompanyingPeriodsOrdered();
$date = $r[0]->getDateClosing()->format('Y-m-d');
$date = $r[0]->getClosingDate()->format('Y-m-d');
$this->assertEquals($date, '2013-03-01');
}
@ -116,14 +116,14 @@ class PersonTest extends \PHPUnit_Framework_TestCase
$p = new Person($d);
$e = new \DateTime("2013/3/1");
$period = $p->getCurrentAccompanyingPeriod()->setDateClosing($e);
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($e);
$p->close($period);
$f = new \DateTime("2013/1/1");
$p->open(new AccompanyingPeriod($f));
$g = new \DateTime("2013/4/1");
$period = $p->getCurrentAccompanyingPeriod()->setDateClosing($g);
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($g);
$p->close($period);
$r = $p->checkAccompanyingPeriodsAreNotCollapsing();
@ -141,7 +141,7 @@ class PersonTest extends \PHPUnit_Framework_TestCase
$p = new Person($d);
$e = new \DateTime("2013/3/1");
$period = $p->getCurrentAccompanyingPeriod()->setDateClosing($e);
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($e);
$p->close($period);
$f = new \DateTime("2013/1/1");

View File

@ -83,7 +83,7 @@ abstract class AbstractTimelineAccompanyingPeriod implements TimelineProviderInt
return array(
'id' => $metadata->getColumnName('id'),
'date' => $metadata->getColumnName('date_opening'),
'date' => $metadata->getColumnName('openingDate'),
'FROM' => $metadata->getTableName(),
);
}

View File

@ -56,7 +56,7 @@ class TimelineAccompanyingPeriodClosing extends AbstractTimelineAccompanyingPeri
->getAssociationMapping('person')['joinColumns'][0]['name'],
$args['person']->getId(),
$metadata
->getColumnName('date_closing')
->getColumnName('closingDate')
);
return $data;