mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
An activity may have multiple reasons
The relationship between Activity and Reasons is now many-to-many. Some improvement in show activity layout. refs #4 #7
This commit is contained in:
parent
65e7a130c5
commit
c60d6acf97
@ -84,9 +84,15 @@ class LoadActivity extends AbstractFixture implements OrderedFixtureInterface, C
|
|||||||
*
|
*
|
||||||
* @return \Chill\ActivityBundle\Entity\ActivityReason
|
* @return \Chill\ActivityBundle\Entity\ActivityReason
|
||||||
*/
|
*/
|
||||||
private function getRandomActivityReason()
|
private function getRandomActivityReason(array $excludingIds)
|
||||||
{
|
{
|
||||||
$reasonRef = LoadActivityReason::$references[array_rand(LoadActivityReason::$references)];
|
$reasonRef = LoadActivityReason::$references[array_rand(LoadActivityReason::$references)];
|
||||||
|
|
||||||
|
if (in_array($this->getReference($reasonRef)->getId(), $excludingIds)) {
|
||||||
|
// we have a reason which should be excluded. Find another...
|
||||||
|
return $this->getRandomActivityReason($excludingIds);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->getReference($reasonRef);
|
return $this->getReference($reasonRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,10 +115,17 @@ class LoadActivity extends AbstractFixture implements OrderedFixtureInterface, C
|
|||||||
->setDate($this->faker->dateTimeThisYear())
|
->setDate($this->faker->dateTimeThisYear())
|
||||||
->setDurationTime($this->faker->dateTime(36000))
|
->setDurationTime($this->faker->dateTime(36000))
|
||||||
->setType($this->getRandomActivityType())
|
->setType($this->getRandomActivityType())
|
||||||
->setReason($this->getRandomActivityReason())
|
|
||||||
->setScope($this->getRandomScope())
|
->setScope($this->getRandomScope())
|
||||||
->setAttendee($this->faker->boolean())
|
->setAttendee($this->faker->boolean())
|
||||||
->setRemark('A remark');
|
->setRemark('A remark');
|
||||||
|
|
||||||
|
$usedId = array();
|
||||||
|
for ($i = 0; $i < rand(0, 4); $i++) {
|
||||||
|
$reason = $this->getRandomActivityReason($usedId);
|
||||||
|
$usedId[] = $reason->getId();
|
||||||
|
$activity->addReason($reason);
|
||||||
|
}
|
||||||
|
|
||||||
return $activity;
|
return $activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ use Chill\ActivityBundle\Entity\ActivityType;
|
|||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
use Chill\MainBundle\Entity\HasCenterInterface;
|
use Chill\MainBundle\Entity\HasCenterInterface;
|
||||||
use Chill\MainBundle\Entity\HasScopeInterface;
|
use Chill\MainBundle\Entity\HasScopeInterface;
|
||||||
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Activity
|
* Activity
|
||||||
@ -64,9 +65,9 @@ class Activity implements HasCenterInterface, HasScopeInterface
|
|||||||
private $attendee;
|
private $attendee;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ActivityReason
|
* @var \Doctrine\Common\Collections\Collection
|
||||||
*/
|
*/
|
||||||
private $reason;
|
private $reasons;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ActivityType
|
* @var ActivityType
|
||||||
@ -82,6 +83,11 @@ class Activity implements HasCenterInterface, HasScopeInterface
|
|||||||
* @var Person
|
* @var Person
|
||||||
*/
|
*/
|
||||||
private $person;
|
private $person;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->reasons = new ArrayCollection();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -215,27 +221,32 @@ class Activity implements HasCenterInterface, HasScopeInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set reason
|
* Add a reason
|
||||||
*
|
*
|
||||||
* @param ActivityReason $reason
|
* @param ActivityReason $reason
|
||||||
*
|
*
|
||||||
* @return Activity
|
* @return Activity
|
||||||
*/
|
*/
|
||||||
public function setReason(ActivityReason $reason)
|
public function addReason(ActivityReason $reason)
|
||||||
{
|
{
|
||||||
$this->reason = $reason;
|
$this->reasons[] = $reason;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function removeReason(ActivityReason $reason)
|
||||||
|
{
|
||||||
|
$this->reasons->removeElement($reason);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get reason
|
* Get reasons
|
||||||
*
|
*
|
||||||
* @return ActivityReason
|
* @return \Doctrine\Common\Collections\Collection
|
||||||
*/
|
*/
|
||||||
public function getReason()
|
public function getReasons()
|
||||||
{
|
{
|
||||||
return $this->reason;
|
return $this->reasons;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -85,7 +85,10 @@ class ActivityType extends AbstractType
|
|||||||
))
|
))
|
||||||
->add('user')
|
->add('user')
|
||||||
->add('scope')
|
->add('scope')
|
||||||
->add('reason', 'translatable_activity_reason')
|
->add('reasons', 'translatable_activity_reason', array(
|
||||||
|
'multiple' => true,
|
||||||
|
'required' => false
|
||||||
|
))
|
||||||
->add('type', 'translatable_activity_type')
|
->add('type', 'translatable_activity_type')
|
||||||
//->add('person')
|
//->add('person')
|
||||||
;
|
;
|
||||||
|
@ -16,13 +16,14 @@ Chill\ActivityBundle\Entity\Activity:
|
|||||||
type: text
|
type: text
|
||||||
attendee:
|
attendee:
|
||||||
type: boolean
|
type: boolean
|
||||||
|
manyToMany:
|
||||||
|
reasons:
|
||||||
|
targetEntity: Chill\ActivityBundle\Entity\ActivityReason
|
||||||
manyToOne:
|
manyToOne:
|
||||||
user:
|
user:
|
||||||
targetEntity: Chill\MainBundle\Entity\User
|
targetEntity: Chill\MainBundle\Entity\User
|
||||||
scope:
|
scope:
|
||||||
targetEntity: Chill\MainBundle\Entity\Scope
|
targetEntity: Chill\MainBundle\Entity\Scope
|
||||||
reason:
|
|
||||||
targetEntity: Chill\ActivityBundle\Entity\ActivityReason
|
|
||||||
type:
|
type:
|
||||||
targetEntity: Chill\ActivityBundle\Entity\ActivityType
|
targetEntity: Chill\ActivityBundle\Entity\ActivityType
|
||||||
person:
|
person:
|
||||||
|
79
Resources/migrations/Version20160222103457.php
Normal file
79
Resources/migrations/Version20160222103457.php
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Application\Migrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Migrations\AbstractMigration;
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Migrate schema to allow multiple or empty reasons on an activity.
|
||||||
|
*
|
||||||
|
* The relation between the activity and reason **was** oneToMany. After this
|
||||||
|
* migration, the relation will be manyToMany.
|
||||||
|
*/
|
||||||
|
class Version20160222103457 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\'.');
|
||||||
|
|
||||||
|
// create the new table activity reason
|
||||||
|
$this->addSql('CREATE TABLE activity_activityreason ('
|
||||||
|
. 'activity_id INT NOT NULL, '
|
||||||
|
. 'activityreason_id INT NOT NULL, '
|
||||||
|
. 'PRIMARY KEY(activity_id, activityreason_id))'
|
||||||
|
);
|
||||||
|
$this->addSql('CREATE INDEX IDX_338A864381C06096 ON activity_activityreason (activity_id)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_338A8643D771E0FC ON activity_activityreason (activityreason_id)');
|
||||||
|
$this->addSql('ALTER TABLE activity_activityreason '
|
||||||
|
. 'ADD CONSTRAINT FK_338A864381C06096 FOREIGN KEY (activity_id) '
|
||||||
|
. 'REFERENCES Activity (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE activity_activityreason '
|
||||||
|
. 'ADD CONSTRAINT FK_338A8643D771E0FC FOREIGN KEY (activityreason_id) '
|
||||||
|
. 'REFERENCES ActivityReason (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
|
||||||
|
// migrate old data to new table
|
||||||
|
$this->addSql('INSERT INTO activity_activityreason (activity_id, activityreason_id) '
|
||||||
|
. 'SELECT id, reason_id FROM activity WHERE reason_id IS NOT NULL');
|
||||||
|
|
||||||
|
|
||||||
|
// remove old column
|
||||||
|
$this->addSql('ALTER TABLE activity DROP CONSTRAINT fk_55026b0c59bb1592');
|
||||||
|
$this->addSql('DROP INDEX idx_55026b0c59bb1592');
|
||||||
|
$this->addSql('ALTER TABLE activity DROP reason_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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 Activity ADD reason_id INT DEFAULT NULL');
|
||||||
|
$this->addSql('ALTER TABLE Activity ADD CONSTRAINT '
|
||||||
|
. 'fk_55026b0c59bb1592 FOREIGN KEY (reason_id) '
|
||||||
|
. 'REFERENCES activityreason (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('CREATE INDEX idx_55026b0c59bb1592 ON Activity (reason_id)');
|
||||||
|
|
||||||
|
// try to keep at least on activity reason...
|
||||||
|
$this->addSql('UPDATE activity
|
||||||
|
SET reason_id=rid
|
||||||
|
FROM (
|
||||||
|
SELECT activity_id AS aid, MIN(activityreason_id) AS rid
|
||||||
|
FROM activity_activityreason
|
||||||
|
GROUP BY activity_id ) AS sb
|
||||||
|
WHERE sb.aid = activity.id'
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
$this->addSql('DROP TABLE activity_activityreason');
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -4,7 +4,7 @@ Edit the activity: Modifier l'activité
|
|||||||
Activity: Activité
|
Activity: Activité
|
||||||
Duration time: Durée
|
Duration time: Durée
|
||||||
Duration Time: Durée
|
Duration Time: Durée
|
||||||
Reason: Sujet
|
Reasons: Sujets
|
||||||
Attendee: Présence de la personne
|
Attendee: Présence de la personne
|
||||||
Remark: Notes
|
Remark: Notes
|
||||||
Add a new activity: Ajouter une nouvelle activité
|
Add a new activity: Ajouter une nouvelle activité
|
||||||
@ -15,6 +15,8 @@ Delete: Supprimer
|
|||||||
Update: Mettre à jour
|
Update: Mettre à jour
|
||||||
Update activity: Édition de l'activité
|
Update activity: Édition de l'activité
|
||||||
Scope: Cercle
|
Scope: Cercle
|
||||||
|
Activity data: Données de l'activité
|
||||||
|
No reason associated: Aucun sujet
|
||||||
|
|
||||||
#forms
|
#forms
|
||||||
Activity creation: Nouvelle activité
|
Activity creation: Nouvelle activité
|
||||||
|
@ -18,12 +18,23 @@
|
|||||||
|
|
||||||
{% set activeRouteKey = 'chill_activity_activity_list' %}
|
{% set activeRouteKey = 'chill_activity_activity_list' %}
|
||||||
|
|
||||||
{% block title %}{{ 'Activity edit' |trans }}{% endblock title %}
|
{% block title 'Update activity'|trans %}
|
||||||
|
|
||||||
{% block personcontent %}
|
{% block personcontent %}
|
||||||
<h1>{{ "Update activity"|trans }}</h1>
|
<h1>{{ "Update activity"|trans }}</h1>
|
||||||
|
|
||||||
{{ form_start(edit_form) }}
|
{{ form_start(edit_form) }}
|
||||||
|
|
||||||
|
{{ form_row(edit_form.user) }}
|
||||||
|
{{ form_row(edit_form.scope) }}
|
||||||
|
|
||||||
|
<h2>{{ 'Activity data'|trans }}</h2>
|
||||||
|
{{ form_row(edit_form.date) }}
|
||||||
|
{{ form_row(edit_form.durationTime) }}
|
||||||
|
{{ form_row(edit_form.remark) }}
|
||||||
|
{{ form_row(edit_form.attendee) }}
|
||||||
|
{{ form_row(edit_form.reasons) }}
|
||||||
|
{{ form_row(edit_form.type) }}
|
||||||
|
|
||||||
{{ form_widget(edit_form) }}
|
{{ form_widget(edit_form) }}
|
||||||
<div class="grid-12 centered sticky-form-buttons">
|
<div class="grid-12 centered sticky-form-buttons">
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
#}
|
#}
|
||||||
{% extends "ChillPersonBundle::layout.html.twig" %}
|
{% extends "ChillPersonBundle::layout.html.twig" %}
|
||||||
|
|
||||||
|
{% import 'ChillActivityBundle:ActivityReason:macro.html.twig' as m %}
|
||||||
|
|
||||||
{% set activeRouteKey = 'chill_activity_activity_list' %}
|
{% set activeRouteKey = 'chill_activity_activity_list' %}
|
||||||
|
|
||||||
{% block title %}{{ 'Activity list' |trans }}{% endblock title %}
|
{% block title %}{{ 'Activity list' |trans }}{% endblock title %}
|
||||||
@ -26,10 +28,9 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th class="chill-red">{{'Date' | trans }}</th>
|
<th class="chill-red">{{'Date' | trans }}</th>
|
||||||
<th class="chill-green">{{'Duration Time' | trans }}</th>
|
<th class="chill-green">{{'Duration Time' | trans }}</th>
|
||||||
<th class="chill-orange">{{'Reason' | trans}}</th>
|
<th class="chill-orange">{{'Reasons' | trans}}</th>
|
||||||
<th>{{'Type' | trans}}</th>
|
<th>{{'Type' | trans}}</th>
|
||||||
<th></th>
|
<th> </th>
|
||||||
<th></th>
|
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@ -37,13 +38,22 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>{% if activity.date %}{{ activity.date|localizeddate('long', 'none') }}{% endif %}</td>
|
<td>{% if activity.date %}{{ activity.date|localizeddate('long', 'none') }}{% endif %}</td>
|
||||||
<td>{{ activity.durationTime|date('H:i') }}</td>
|
<td>{{ activity.durationTime|date('H:i') }}</td>
|
||||||
<td>{{ activity.reason.name | localize_translatable_string }}</td>
|
<td>
|
||||||
|
{%- if activity.reasons is empty -%}
|
||||||
|
{{ 'No reason associated'|trans }}
|
||||||
|
{%- else -%}
|
||||||
|
{% for r in activity.reasons %}{{ m.reason(r) }} {% endfor %}
|
||||||
|
{%- endif -%}
|
||||||
|
</td>
|
||||||
<td>{{ activity.type.name | localize_translatable_string }}</td>
|
<td>{{ activity.type.name | localize_translatable_string }}</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="{{ path('chill_activity_activity_show', { 'id': activity.id, 'person_id': person.id }) }}" class="sc-button black">{{ 'Show' | trans }}</a>
|
<ul class="record_actions">
|
||||||
</td>
|
<li>
|
||||||
<td>
|
<a href="{{ path('chill_activity_activity_show', { 'id': activity.id, 'person_id': person.id }) }}" class="sc-button">{{ 'show'|trans|capitalize }}</a>
|
||||||
<a href="{{ path('chill_activity_activity_edit', { 'id': activity.id, 'person_id': person.id }) }}" class="sc-button bt-update">{{ 'Edit' | trans }}</a>
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{{ path('chill_activity_activity_edit', { 'id': activity.id, 'person_id': person.id }) }}" class="sc-button bt-update">{{ 'Edit' | trans }}</a>
|
||||||
|
</li>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -2,28 +2,43 @@
|
|||||||
|
|
||||||
{% set activeRouteKey = 'chill_activity_activity_list' %}
|
{% set activeRouteKey = 'chill_activity_activity_list' %}
|
||||||
|
|
||||||
|
{% block title 'Activity'|trans %}
|
||||||
|
|
||||||
|
{% import 'ChillActivityBundle:ActivityReason:macro.html.twig' as m %}
|
||||||
|
|
||||||
{% block personcontent -%}
|
{% block personcontent -%}
|
||||||
<h2 class="chill-red">{{ "Activity"|trans }}</h1>
|
<h1 >{{ "Activity"|trans }}</h1>
|
||||||
|
|
||||||
<dl>
|
<dl class="chill_view_data">
|
||||||
<dt class="inline">{{ 'Person'|trans }}</dt>
|
<dt class="inline">{{ 'User'|trans }}</dt>
|
||||||
<dd>{{ entity.person }}</dd>
|
<dd>{{ entity.user }}</dd>
|
||||||
<dt class="inline">{{ 'Scope'|trans }}</dt>
|
<dt class="inline">{{ 'Scope'|trans }}</dt>
|
||||||
<dd><span class="scope">{{ entity.scope.name|localize_translatable_string }}</span></dd>
|
<dd><span class="scope">{{ entity.scope.name|localize_translatable_string }}</span></dd>
|
||||||
|
|
||||||
|
<h2 class="chill-red">{{ 'Activity data'|trans }}</h2>
|
||||||
|
<dt class="inline">{{ 'Person'|trans }}</dt>
|
||||||
|
<dd>{{ entity.person }}</dd>
|
||||||
|
|
||||||
<dt class="inline">{{ 'Date'|trans }}</dt>
|
<dt class="inline">{{ 'Date'|trans }}</dt>
|
||||||
<dd>{{ entity.date|localizeddate('long', 'none') }}</dd>
|
<dd>{{ entity.date|localizeddate('long', 'none') }}</dd>
|
||||||
<dt class="inline">{{ 'Duration Time'|trans }}</dt>
|
<dt class="inline">{{ 'Duration Time'|trans }}</dt>
|
||||||
<dd>{{ entity.durationTime|date('H:i') }}</dd>
|
<dd>{{ entity.durationTime|date('H:i') }}</dd>
|
||||||
<dt class="inline">{{ 'User'|trans }}</dt>
|
<dt class="inline">{{ 'Remark'|trans }}</dt>
|
||||||
<dd>{{ entity.user }}</dd>
|
<dd>{% if entity.remark is empty %}{{ 'No remarks'|trans }}{% else %}<blockquote class="chill-user-quote">{{ entity.remark|nl2br }}</blockquote>{% endif %}</dd>
|
||||||
<dt class="inline">{{ 'Reason'|trans }}</dt>
|
|
||||||
<dd>{{ entity.reason.name | localize_translatable_string }}</dd>
|
|
||||||
<dt class="inline">{{ 'Type'|trans }}</dt>
|
|
||||||
<dd>{{ entity.type.name | localize_translatable_string }}</dd>
|
|
||||||
<dt class="inline">{{ 'Attendee'|trans }}</dt>
|
<dt class="inline">{{ 'Attendee'|trans }}</dt>
|
||||||
<dd>{% if entity.attendee is not null %}{% if entity.attendee %}{{ 'present'|trans|capitalize }} {% else %} {{ 'not present'|trans|capitalize }}{% endif %}{% else %}{{ 'None'|trans|capitalize }}{% endif %}</dd>
|
<dd>{% if entity.attendee is not null %}{% if entity.attendee %}{{ 'present'|trans|capitalize }} {% else %} {{ 'not present'|trans|capitalize }}{% endif %}{% else %}{{ 'None'|trans|capitalize }}{% endif %}</dd>
|
||||||
<dt class="inline">{{ 'Remark'|trans }}</dt>
|
|
||||||
<dd>{% if entity.remark is empty %}{{ 'No remarks'|trans }}{% else %}<pre>{{ entity.remark }}</pre>{% endif %}</dd>
|
<dt class="inline">{{ 'Reasons'|trans }}</dt>
|
||||||
|
{%- if entity.reasons is empty -%}
|
||||||
|
<dd><span class="chill-no-data-statement">{{ 'No reason associated'|trans }}</span></dd>
|
||||||
|
{%- else -%}
|
||||||
|
<dd>{% for r in entity.reasons %}{{ m.reason(r) }} {% endfor %}</dd>
|
||||||
|
{%- endif -%}
|
||||||
|
|
||||||
|
<dt class="inline">{{ 'Type'|trans }}</dt>
|
||||||
|
<dd>{{ entity.type.name | localize_translatable_string }}</dd>
|
||||||
|
|
||||||
<dt class="inline">{{ ''|trans }}</dt>
|
<dt class="inline">{{ ''|trans }}</dt>
|
||||||
<dd></dd>
|
<dd></dd>
|
||||||
<dt class="inline">{{ ''|trans }}</dt>
|
<dt class="inline">{{ ''|trans }}</dt>
|
||||||
|
3
Resources/views/ActivityReason/macro.html.twig
Normal file
3
Resources/views/ActivityReason/macro.html.twig
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{%- macro reason(r) -%}
|
||||||
|
<span class="entity entity-activity activity-reason"><i class="fa fa-question-circle"></i> {{ r.name | localize_translatable_string }}</span>
|
||||||
|
{%- endmacro -%}
|
@ -106,6 +106,9 @@ class ActivityControllerTest extends WebTestCase
|
|||||||
"Unexpected HTTP status code for GET /activity/");
|
"Unexpected HTTP status code for GET /activity/");
|
||||||
$crawler = $client->click($crawler->selectLink('Ajouter une nouvelle activité')
|
$crawler = $client->click($crawler->selectLink('Ajouter une nouvelle activité')
|
||||||
->link());
|
->link());
|
||||||
|
|
||||||
|
$reason1 = $this->getRandomActivityReason();
|
||||||
|
$reason2 = $this->getRandomActivityReason(array($reason1->getId()));
|
||||||
|
|
||||||
// Fill in the form and submit it
|
// Fill in the form and submit it
|
||||||
$form = $crawler->selectButton('Ajouter une nouvelle activité')->form(array(
|
$form = $crawler->selectButton('Ajouter une nouvelle activité')->form(array(
|
||||||
@ -117,10 +120,10 @@ class ActivityControllerTest extends WebTestCase
|
|||||||
),
|
),
|
||||||
'remark' => 'blabla',
|
'remark' => 'blabla',
|
||||||
'scope' => $this->getRandomScope('center a_social', 'Center A')->getId(),
|
'scope' => $this->getRandomScope('center a_social', 'Center A')->getId(),
|
||||||
'reason' => $this->getRandomActivityReason()->getId(),
|
|
||||||
'type' => $this->getRandomActivityType()->getId()
|
'type' => $this->getRandomActivityType()->getId()
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
|
$form['chill_activitybundle_activity[reasons]']->select(array ($reason1->getId(), $reason2->getId()));
|
||||||
|
|
||||||
$client->submit($form);
|
$client->submit($form);
|
||||||
|
|
||||||
@ -240,16 +243,23 @@ class ActivityControllerTest extends WebTestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
* @param int[] $excludeIds An array of id to exclude
|
||||||
* @return \Chill\ActivityBundle\Entity\ActivityReason
|
* @return \Chill\ActivityBundle\Entity\ActivityReason
|
||||||
*/
|
*/
|
||||||
private function getRandomActivityReason()
|
private function getRandomActivityReason(array $excludeIds = array())
|
||||||
{
|
{
|
||||||
$reasons = static::$kernel->getContainer()
|
$reasons = static::$kernel->getContainer()
|
||||||
->get('doctrine.orm.entity_manager')
|
->get('doctrine.orm.entity_manager')
|
||||||
->getRepository('ChillActivityBundle:ActivityReason')
|
->getRepository('ChillActivityBundle:ActivityReason')
|
||||||
->findAll();
|
->findAll();
|
||||||
|
|
||||||
return $reasons[array_rand($reasons)];
|
$reason = $reasons[array_rand($reasons)];
|
||||||
|
|
||||||
|
if (in_array($reason->getId(), $excludeIds)) {
|
||||||
|
return $this->getRandomActivityReason($excludeIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user