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); $person = $this->_getPerson($person_id);
$accompanyingPeriod = new AccompanyingPeriod(new \DateTime()); $accompanyingPeriod = new AccompanyingPeriod(new \DateTime());
$accompanyingPeriod->setDateClosing(new \DateTime()); $accompanyingPeriod->setClosingDate(new \DateTime());
$person->addAccompanyingPeriod( $person->addAccompanyingPeriod(
$accompanyingPeriod); $accompanyingPeriod);

View File

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

View File

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

View File

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

View File

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

View File

@ -48,11 +48,11 @@ chill_person_search:
chill_person_accompanying_period_list: chill_person_accompanying_period_list:
path: /{_locale}/person/{person_id}/accompanying-period path: /{_locale}/person/{person_id}/accompanying-period
defaults: { _controller: ChillPersonBundle:AccompanyingPeriod:list } defaults: { _controller: ChillPersonBundle:AccompanyingPeriod:list }
# options: options:
# menus: menus:
# person: person:
# order: 100 order: 100
# label: menu.person.history label: Accompanying period list
chill_person_accompanying_period_create: chill_person_accompanying_period_create:
path: /{_locale}/person/{person_id}/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: Chill\PersonBundle\Entity\AccompanyingPeriod:
properties: properties:
date_opening: openingDate:
- Date: - Date:
message: 'Opening date is not valid' message: 'Opening date is not valid'
- NotNull: - NotNull:
message: 'Opening date can not be null' message: 'Opening date can not be null'
date_closing: closingDate:
- Date: - Date:
message: 'Closing date is not valid' message: 'Closing date is not valid'
- NotNull: - 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) }} {{ form_start(form) }}
{{ 'Last opening since %last_opening%'|trans( {{ '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 %} {% if form.closingDate is defined %}
{{ form_row(form.dateClosing, {'label' : 'Closing date'} ) }} {{ form_row(form.closingDate, {'label' : 'Closing date'} ) }}
{% endif %} {% endif %}
{% if form.closingMotive is defined %} {% if form.closingMotive is defined %}
{{ form_row(form.closingMotive, {'label' : 'Closing motive'} ) }} {{ form_row(form.closingMotive, {'label' : 'Closing motive'} ) }}
{% endif %} {% endif %}
{{ form_row(form.memo, {'label' : 'Memo' } ) }} {{ form_row(form.remark, {'label' : 'Remark' } ) }}
{{ form_rest(form) }} {{ form_rest(form) }}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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