mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Activity Reasons, Activity Reasons Category, Activity Types in Translatable strings
This commit is contained in:
parent
e9fdfb341d
commit
5bd8b22569
@ -33,9 +33,9 @@ class ActivityReason
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @var array
|
||||
*/
|
||||
private $label;
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @var ActivityReasonCategory
|
||||
@ -59,29 +59,42 @@ class ActivityReason
|
||||
}
|
||||
|
||||
/**
|
||||
* Set label
|
||||
* Set name
|
||||
*
|
||||
* @param string $label
|
||||
* @param array $name
|
||||
*
|
||||
* @return ActivityReason
|
||||
*/
|
||||
public function setLabel($label)
|
||||
public function setName($name)
|
||||
{
|
||||
$this->label = $label;
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get label
|
||||
* Get name
|
||||
*
|
||||
* @return string
|
||||
* @return array | string
|
||||
*/
|
||||
public function getLabel()
|
||||
public function getName($locale = null)
|
||||
{
|
||||
return $this->label;
|
||||
if ($locale) {
|
||||
if (isset($this->name[$locale])) {
|
||||
return $this->name[$locale];
|
||||
} else {
|
||||
foreach ($this->name as $name) {
|
||||
if (!empty($name)) {
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
}
|
||||
return '';
|
||||
} else {
|
||||
return $this->name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set category
|
||||
*
|
||||
|
@ -33,12 +33,18 @@ class ActivityReasonCategory
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $label;
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
private $active;
|
||||
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return 'blop';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -52,27 +58,40 @@ class ActivityReasonCategory
|
||||
}
|
||||
|
||||
/**
|
||||
* Set label
|
||||
* Set name
|
||||
*
|
||||
* @param string $label
|
||||
* @param array $name
|
||||
*
|
||||
* @return ActivityReasonCategory
|
||||
*/
|
||||
public function setLabel($label)
|
||||
public function setName($name)
|
||||
{
|
||||
$this->label = $label;
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get label
|
||||
* Get name
|
||||
*
|
||||
* @return string
|
||||
* @return array
|
||||
*/
|
||||
public function getLabel()
|
||||
public function getName($locale = null)
|
||||
{
|
||||
return $this->label;
|
||||
if ($locale) {
|
||||
if (isset($this->name[$locale])) {
|
||||
return $this->name[$locale];
|
||||
} else {
|
||||
foreach ($this->name as $name) {
|
||||
if (!empty($name)) {
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
}
|
||||
return '';
|
||||
} else {
|
||||
return $this->name;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -31,7 +31,7 @@ class ActivityType
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @var array
|
||||
*/
|
||||
private $name;
|
||||
|
||||
@ -49,7 +49,7 @@ class ActivityType
|
||||
/**
|
||||
* Set name
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $name
|
||||
*
|
||||
* @return ActivityType
|
||||
*/
|
||||
@ -63,11 +63,24 @@ class ActivityType
|
||||
/**
|
||||
* Get name
|
||||
*
|
||||
* @return string
|
||||
* @return array | string
|
||||
*/
|
||||
public function getName()
|
||||
public function getName($locale = null)
|
||||
{
|
||||
return $this->name;
|
||||
if ($locale) {
|
||||
if (isset($this->name[$locale])) {
|
||||
return $this->name[$locale];
|
||||
} else {
|
||||
foreach ($this->name as $name) {
|
||||
if (!empty($name)) {
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
}
|
||||
return '';
|
||||
} else {
|
||||
return $this->name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ class ActivityReasonCategoryType extends AbstractType
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('label')
|
||||
->add('name', 'translatable_string')
|
||||
->add('active')
|
||||
;
|
||||
}
|
||||
|
@ -15,9 +15,9 @@ class ActivityReasonType extends AbstractType
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('label')
|
||||
->add('name', 'translatable_string')
|
||||
->add('active')
|
||||
->add('category')
|
||||
->add('category', 'translatable_activity_reason_category')
|
||||
;
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ class ActivityTypeType extends AbstractType
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('name')
|
||||
->add('name', 'translatable_string')
|
||||
;
|
||||
}
|
||||
|
||||
|
68
Form/Type/TranslatableActivityReasonCategory.php
Normal file
68
Form/Type/TranslatableActivityReasonCategory.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?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 Chill\ActivityBundle\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
|
||||
/**
|
||||
* Description of TranslatableActivityReasonCategory
|
||||
*
|
||||
* @author Champs-Libres Coop
|
||||
*/
|
||||
|
||||
|
||||
class TranslatableActivityReasonCategory extends AbstractType
|
||||
{
|
||||
/**
|
||||
* @var RequestStack
|
||||
*/
|
||||
private $requestStack;
|
||||
|
||||
public function __construct(RequestStack $requestStack)
|
||||
{
|
||||
$this->requestStack = $requestStack;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'translatable_activity_reason_category';
|
||||
}
|
||||
|
||||
public function getParent()
|
||||
{
|
||||
return 'entity';
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$locale = $this->requestStack->getCurrentRequest()->getLocale();
|
||||
$resolver->setDefaults(
|
||||
array(
|
||||
'class' => 'ChillActivityBundle:ActivityReasonCategory',
|
||||
'property' => 'name['.$locale.']'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@ -8,9 +8,8 @@ Chill\ActivityBundle\Entity\ActivityReason:
|
||||
generator:
|
||||
strategy: AUTO
|
||||
fields:
|
||||
label:
|
||||
type: string
|
||||
length: 255
|
||||
name:
|
||||
type: json_array
|
||||
active:
|
||||
type: boolean
|
||||
manyToOne:
|
||||
|
@ -8,9 +8,8 @@ Chill\ActivityBundle\Entity\ActivityReasonCategory:
|
||||
generator:
|
||||
strategy: AUTO
|
||||
fields:
|
||||
label:
|
||||
type: string
|
||||
length: 255
|
||||
name:
|
||||
type: json_array
|
||||
active:
|
||||
type: boolean
|
||||
lifecycleCallbacks: { }
|
||||
|
@ -9,6 +9,5 @@ Chill\ActivityBundle\Entity\ActivityType:
|
||||
strategy: AUTO
|
||||
fields:
|
||||
name:
|
||||
type: string
|
||||
length: 255
|
||||
type: json_array
|
||||
lifecycleCallbacks: { }
|
||||
|
@ -1,4 +1,4 @@
|
||||
activitytype:
|
||||
chill_activity_activitytype:
|
||||
path: /{_locale}/admin/activitytype/
|
||||
defaults: { _controller: "ChillActivityBundle:ActivityType:index" }
|
||||
options:
|
||||
|
@ -1,4 +1,7 @@
|
||||
services:
|
||||
# chill_activity.example:
|
||||
# class: Chill\ActivityBundle\Example
|
||||
# arguments: [@service_id, "plain_value", %parameter%]
|
||||
chill.activity.form.type.translatableactivityreasoncategory:
|
||||
class: Chill\ActivityBundle\Form\Type\TranslatableActivityReasonCategory
|
||||
arguments:
|
||||
- "@request_stack"
|
||||
tags:
|
||||
- { name: form.type, alias: translatable_activity_reason_category }
|
64
Resources/migrations/Version20150702093317.php
Normal file
64
Resources/migrations/Version20150702093317.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
class Version20150702093317 extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* @param Schema $schema
|
||||
*/
|
||||
public function up(Schema $schema)
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
|
||||
|
||||
$this->addSql('ALTER TABLE ActivityReasonCategory DROP COLUMN label;');
|
||||
$this->addSql('ALTER TABLE ActivityReasonCategory ADD COLUMN name JSON;');
|
||||
$this->addSql('ALTER TABLE ActivityReason DROP COLUMN label;');
|
||||
$this->addSql('ALTER TABLE ActivityReason ADD COLUMN name JSON;');
|
||||
$this->addSql('ALTER TABLE ActivityType DROP COLUMN name;');
|
||||
$this->addSql('ALTER TABLE ActivityType ADD COLUMN name JSON;');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Schema $schema
|
||||
*/
|
||||
public function down(Schema $schema)
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
|
||||
|
||||
$this->addSql('ALTER TABLE ActivityReasonCategory DROP COLUMN name;');
|
||||
$this->addSql('ALTER TABLE ActivityReasonCategory ADD COLUMN label VARCHAR(255) NOT NULL;');
|
||||
$this->addSql('ALTER TABLE ActivityReason DROP COLUMN name;');
|
||||
$this->addSql('ALTER TABLE ActivityReason ADD COLUMN label VARCHAR(255) NOT NULL;');
|
||||
$this->addSql('ALTER TABLE ActivityType DROP COLUMN name;');
|
||||
$this->addSql('ALTER TABLE ActivityType ADD COLUMN name VARCHAR(255) NOT NULL;');
|
||||
}
|
||||
}
|
@ -23,7 +23,7 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Id</th>
|
||||
<th>Label</th>
|
||||
<th>Name</th>
|
||||
<th>Active</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
@ -32,7 +32,7 @@
|
||||
{% for entity in entities %}
|
||||
<tr>
|
||||
<td><a href="{{ path('chill_activity_activityreason_show', { 'id': entity.id }) }}">{{ entity.id }}</a></td>
|
||||
<td>{{ entity.label }}</td>
|
||||
<td>{{ entity.name|localize_translatable_string }}</td>
|
||||
<td>{{ entity.active }}</td>
|
||||
<td>
|
||||
<ul>
|
||||
|
@ -26,8 +26,8 @@
|
||||
<td>{{ entity.id }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Label</th>
|
||||
<td>{{ entity.label }}</td>
|
||||
<th>Name</th>
|
||||
<td>{{ entity.name|localize_translatable_string }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Active</th>
|
||||
|
@ -23,7 +23,7 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Id</th>
|
||||
<th>Label</th>
|
||||
<th>Name</th>
|
||||
<th>Active</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
@ -32,7 +32,7 @@
|
||||
{% for entity in entities %}
|
||||
<tr>
|
||||
<td><a href="{{ path('chill_activity_activityreasoncategory_show', { 'id': entity.id }) }}">{{ entity.id }}</a></td>
|
||||
<td>{{ entity.label }}</td>
|
||||
<td>{{ entity.name|localize_translatable_string }}</td>
|
||||
<td>{{ entity.active }}</td>
|
||||
<td>
|
||||
<ul>
|
||||
|
@ -26,8 +26,8 @@
|
||||
<td>{{ entity.id }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Label</th>
|
||||
<td>{{ entity.label }}</td>
|
||||
<th>Name</th>
|
||||
<td>{{ entity.name|localize_translatable_string }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Active</th>
|
||||
|
@ -31,7 +31,7 @@
|
||||
{% for entity in entities %}
|
||||
<tr>
|
||||
<td><a href="{{ path('chill_activity_activitytype_show', { 'id': entity.id }) }}">{{ entity.id }}</a></td>
|
||||
<td>{{ entity.name }}</td>
|
||||
<td>{{ entity.name|localize_translatable_string }}</td>
|
||||
<td>
|
||||
<ul>
|
||||
<li>
|
||||
|
@ -27,7 +27,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<td>{{ entity.name }}</td>
|
||||
<td>{{ entity.name|localize_translatable_string }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
Loading…
x
Reference in New Issue
Block a user