Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Mathieu Loiseau
MagicWord
Commits
b10ed9e0
Commit
b10ed9e0
authored
May 13, 2019
by
Arnaud Bey
Browse files
WIP features
parent
41a718c1
Changes
10
Hide whitespace changes
Inline
Side-by-side
application/src/MagicWordBundle/Controller/RoundType/ConquerController.php
View file @
b10ed9e0
...
...
@@ -20,7 +20,6 @@ class ConquerController extends Controller
public
function
displayConquerAction
(
Conquer
$conquer
)
{
$form
=
$this
->
createForm
(
RoundType
::
class
,
$conquer
)
->
createView
();
return
$this
->
render
(
'MagicWordBundle:Round/Conquer:edit.html.twig'
,
[
...
...
application/src/MagicWordBundle/Entity/ObjectiveType/Constraint.php
View file @
b10ed9e0
...
...
@@ -28,9 +28,9 @@ class Constraint extends Objective
private
$numberToFind
;
/**
* @ORM\ManyTo
One
(targetEntity="LexiconBundle\Entity\Feature")
* @ORM\ManyTo
many
(targetEntity="LexiconBundle\Entity\Feature")
*/
private
$feature
;
private
$feature
s
;
/**
* Set numberToFind.
...
...
@@ -63,10 +63,53 @@ class Constraint extends Objective
$jsonArray
=
array
(
'type'
=>
$this
->
discr
,
'numberToFind'
=>
$this
->
numberToFind
,
'feature'
=>
$this
->
feature
?
$this
->
feature
->
getId
()
:
null
,
'feature
s
'
=>
$this
->
feature
?
$this
->
feature
->
getId
()
:
null
,
);
return
$jsonArray
;
}
/**
* Constructor
*/
public
function
__construct
()
{
$this
->
features
=
new
\
Doctrine\Common\Collections\ArrayCollection
();
}
/**
* Add feature.
*
* @param \LexiconBundle\Entity\Feature $feature
*
* @return Constraint
*/
public
function
addFeature
(
\
LexiconBundle\Entity\Feature
$feature
)
{
$this
->
features
[]
=
$feature
;
return
$this
;
}
/**
* Remove feature.
*
* @param \LexiconBundle\Entity\Feature $feature
*
* @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
*/
public
function
removeFeature
(
\
LexiconBundle\Entity\Feature
$feature
)
{
return
$this
->
features
->
removeElement
(
$feature
);
}
/**
* Get features.
*
* @return \Doctrine\Common\Collections\Collection
*/
public
function
getFeatures
()
{
return
$this
->
features
;
}
}
application/src/MagicWordBundle/Form/Type/ObjectiveType/ConstraintType.php
View file @
b10ed9e0
...
...
@@ -2,17 +2,23 @@
namespace
MagicWordBundle\Form\Type\ObjectiveType
;
use
MagicWordBundle\Form\Type\ObjectiveType\FeatureType
;
use
Symfony\Bridge\Doctrine\Form\Type\EntityType
;
use
Symfony\Component\Form\AbstractType
;
use
Symfony\Component\Form\Extension\Core\Type\CollectionType
;
use
Symfony\Component\Form\Extension\Core\Type\IntegerType
;
use
Symfony\Component\Form\FormBuilderInterface
;
use
Symfony\Component\OptionsResolver\OptionsResolver
;
use
Symfony\Component\Form\Extension\Core\Type\IntegerType
;
use
Symfony\Bridge\Doctrine\Form\Typ
e\Entity
Typ
e
;
use
Doctrine\ORM\EntityRepository
;
use
LexiconBundl
e\Entity
\Featur
e
;
class
ConstraintType
extends
AbstractType
{
public
function
buildForm
(
FormBuilderInterface
$builder
,
array
$options
)
{
$builder
->
add
(
'numberToFind'
,
IntegerType
::
class
,
array
(
$languageId
=
$options
[
"languageId"
];
$builder
->
add
(
'numberToFind'
,
IntegerType
::
class
,
[
'label'
=>
'constraint_number'
,
'translation_domain'
=>
'messages'
,
'attr'
=>
[
...
...
@@ -22,19 +28,27 @@ class ConstraintType extends AbstractType
'min'
=>
1
,
'step'
=>
1
],
));
$builder
->
add
(
'feature'
,
EntityType
::
class
,
array
(
'class'
=>
'LexiconBundle:Feature'
,
'placeholder'
=>
'- feature -'
,
'required'
=>
false
,
'empty_data'
=>
null
,
'choice_label'
=>
'value'
,
'attr'
=>
array
(
'class'
=>
'form-control'
),
'label'
=>
'feature'
,
'translation_domain'
=>
'messages'
,
'choice_translation_domain'
=>
'messages'
,
));
]);
$builder
->
add
(
'features'
,
EntityType
::
class
,
[
'choice_label'
=>
'value'
,
'class'
=>
Feature
::
class
,
'query_builder'
=>
function
(
EntityRepository
$repo
)
use
(
$languageId
)
{
$qb
=
$repo
->
createQueryBuilder
(
'f'
);
$qb
->
andWhere
(
'f.language = '
.
$languageId
);
$qb
->
orderBy
(
'f.value'
,
'ASC'
);
return
$qb
;
},
'group_by'
=>
'label'
,
'multiple'
=>
true
,
'placeholder'
=>
'- feature -'
,
'required'
=>
true
,
'empty_data'
=>
null
,
'attr'
=>
[
'class'
=>
'form-control'
]
]);
}
public
function
getName
()
...
...
@@ -44,8 +58,9 @@ class ConstraintType extends AbstractType
public
function
configureOptions
(
OptionsResolver
$resolver
)
{
$resolver
->
setDefaults
(
array
(
'data_class'
=>
'MagicWordBundle\Entity\ObjectiveType\Constraint'
,
));
$resolver
->
setDefaults
([
'languageId'
=>
null
,
'data_class'
=>
'MagicWordBundle\Entity\ObjectiveType\Constraint'
]);
}
}
application/src/MagicWordBundle/Form/Type/ObjectiveType/FeatureType.php
0 → 100644
View file @
b10ed9e0
<?php
namespace
MagicWordBundle\Form\Type\ObjectiveType
;
use
Symfony\Component\Form\AbstractType
;
use
Symfony\Component\Form\FormBuilderInterface
;
use
Symfony\Component\OptionsResolver\OptionsResolver
;
use
Symfony\Component\Form\Extension\Core\Type\IntegerType
;
use
Symfony\Bridge\Doctrine\Form\Type\EntityType
;
use
Doctrine\ORM\EntityRepository
;
class
FeatureType
extends
AbstractType
{
public
function
buildForm
(
FormBuilderInterface
$builder
,
array
$options
)
{
$languageId
=
$options
[
"languageId"
];
$builder
->
add
(
'feature'
,
EntityType
::
class
,
[
'class'
=>
'LexiconBundle:Feature'
,
'query_builder'
=>
function
(
$repo
)
use
(
$languageId
)
{
$qb
=
$repo
->
createQueryBuilder
(
'f'
);
$qb
->
andWhere
(
'f.language = '
.
$languageId
);
$qb
->
orderBy
(
'f.value'
,
'ASC'
);
return
$qb
;
},
'group_by'
=>
'label'
,
'placeholder'
=>
'- feature -'
,
'required'
=>
true
,
'empty_data'
=>
null
,
'choice_label'
=>
'value'
,
'attr'
=>
array
(
'class'
=>
'form-control'
),
]);
}
public
function
configureOptions
(
OptionsResolver
$resolver
)
{
$resolver
->
setDefaults
([
'data_class'
=>
'LexiconBundle\Entity\Feature'
,
'languageId'
=>
null
]);
}
}
application/src/MagicWordBundle/Form/Type/RoundType.php
View file @
b10ed9e0
...
...
@@ -2,17 +2,20 @@
namespace
MagicWordBundle\Form\Type
;
use
Symfony\Component\Form\AbstractType
;
use
Symfony\Component\Form\FormBuilderInterface
;
use
Symfony\Component\Form\Extension\Core\Type\CollectionType
;
use
MagicWordBundle\Form\Type\ObjectiveType\FindWordType
;
use
MagicWordBundle\Form\Type\ObjectiveType\ComboType
;
use
MagicWordBundle\Form\Type\ObjectiveType\ConstraintType
;
use
MagicWordBundle\Form\Type\ObjectiveType\FindWordType
;
use
Symfony\Component\Form\AbstractType
;
use
Symfony\Component\Form\Extension\Core\Type\CollectionType
;
use
Symfony\Component\Form\FormBuilderInterface
;
use
Symfony\Component\OptionsResolver\OptionsResolver
;
class
RoundType
extends
AbstractType
{
public
function
buildForm
(
FormBuilderInterface
$builder
,
array
$options
)
{
$languageId
=
$options
[
"languageId"
];
$builder
->
add
(
'findWords'
,
CollectionType
::
class
,
array
(
'entry_type'
=>
FindWordType
::
class
,
'prototype'
=>
true
,
...
...
@@ -22,14 +25,18 @@ class RoundType extends AbstractType
'by_reference'
=>
false
,
));
$builder
->
add
(
'constraints'
,
CollectionType
::
class
,
array
(
$builder
->
add
(
'constraints'
,
CollectionType
::
class
,
[
'entry_type'
=>
ConstraintType
::
class
,
'prototype'
=>
true
,
'allow_add'
=>
true
,
'allow_delete'
=>
true
,
'mapped'
=>
true
,
'by_reference'
=>
false
,
));
'prototype_name'
=>
'__constraint_prot__'
,
'entry_options'
=>
[
'languageId'
=>
$languageId
],
]);
$builder
->
add
(
'combos'
,
CollectionType
::
class
,
array
(
'entry_type'
=>
ComboType
::
class
,
...
...
@@ -45,4 +52,11 @@ class RoundType extends AbstractType
{
return
'conquer'
;
}
public
function
configureOptions
(
OptionsResolver
$resolver
)
{
$resolver
->
setDefaults
([
'languageId'
=>
null
]);
}
}
application/src/MagicWordBundle/Manager/ObjectiveManager.php
View file @
b10ed9e0
...
...
@@ -39,7 +39,8 @@ class ObjectiveManager
public
function
saveObjectives
(
Conquer
$conquer
,
Request
$request
)
{
$form
=
$this
->
formFactory
->
createBuilder
(
RoundType
::
class
,
$conquer
)
->
getForm
();
$languageId
=
$conquer
->
getLanguage
()
->
getId
();
$form
=
$this
->
formFactory
->
createBuilder
(
RoundType
::
class
,
$conquer
,
[
'languageId'
=>
$languageId
])
->
getForm
();
// retrieve former objectives
$formerObjectives
=
new
ArrayCollection
();
...
...
@@ -202,10 +203,11 @@ class ObjectiveManager
break
;
case
'constraint'
:
$foundables
=
$foundableRepo
->
getByGridAndCriteria
(
$grid
,
$objective
);
echo
count
(
$foundables
);
die
();
if
(
count
(
$foundables
)
<
$objective
->
getNumberToFind
())
{
$errors
[]
=
'problème constraint non réalisable round '
.
$roundName
;
}
// no break
default
:
break
;
}
...
...
application/src/MagicWordBundle/Manager/RoundManager.php
View file @
b10ed9e0
...
...
@@ -164,8 +164,9 @@ class RoundManager
public
function
getForm
(
Round
$round
)
{
$languageId
=
$round
->
getLanguage
()
->
getId
();
return
$form
=
(
$round
->
getDiscr
()
==
'conquer'
)
?
$this
->
formFactory
->
createBuilder
(
RoundType
::
class
,
$round
)
->
getForm
()
->
createView
()
?
$this
->
formFactory
->
createBuilder
(
RoundType
::
class
,
$round
,
[
'languageId'
=>
$languageId
]
)
->
getForm
()
->
createView
()
:
null
;
}
...
...
application/src/MagicWordBundle/Repository/FoundableRepository.php
View file @
b10ed9e0
...
...
@@ -15,34 +15,30 @@ class FoundableRepository extends \Doctrine\ORM\EntityRepository
public
function
getByGridAndCriteria
(
$grid
,
$objective
)
{
$em
=
$this
->
_em
;
$dql
=
'SELECT f FROM MagicWordBundle\Entity\FoundableForm f JOIN f.words i JOIN i.root l WHERE f.grid = :grid'
;
$dql
.
=
$objective
->
getCategory
()
?
' AND l.category = '
.
$objective
->
getCategory
()
->
getId
()
:
''
;
$dql
.
=
$objective
->
getNumber
()
?
' AND i.number = '
.
$objective
->
getNumber
()
->
getId
()
:
''
;
$dql
.
=
$objective
->
getGender
()
?
' AND i.gender = '
.
$objective
->
getGender
()
->
getId
()
:
''
;
$dql
.
=
$objective
->
getPerson
()
?
' AND i.person = '
.
$objective
->
getPerson
()
->
getId
()
:
''
;
$dql
.
=
$objective
->
getTense
()
?
' AND i.tense = '
.
$objective
->
getTense
()
->
getId
()
:
''
;
$dql
=
'SELECT f FROM MagicWordBundle\Entity\FoundableForm f JOIN f.words w WHERE f.grid = :grid'
;
$dql
.
=
' AND :features MEMBER OF w.features'
;
/*
$i = 0;
foreach ($objective->getFeatures() as $f) {
$dql .= ' AND :feature-'.$i.' MEMBER OF w.features';
$i++;
}*/
$features
=
[];
foreach
(
$objective
->
getFeatures
()
as
$f
)
{
$features
[]
=
$f
->
getId
();
}
$query
=
$em
->
createQuery
(
$dql
);
$dql
.
=
$objective
->
getMood
()
?
' AND i.mood = '
.
$objective
->
getMood
()
->
getId
()
:
''
;
/*
$i = 0;
foreach ($objective->getFeatures() as $f) {
$query->setParameter('feature-'.$i, $f);
$i++;
}
*/
$query
=
$em
->
createQuery
(
$dql
);
$query
->
setParameter
(
'grid'
,
$grid
);
$query
->
setParameter
(
'features'
,
$features
);
return
$query
->
getResult
();
}
...
...
application/src/MagicWordBundle/Resources/public/js/edit/constraint.js
View file @
b10ed9e0
var
constraints
=
{
add
:
function
(){
var
prototype
=
$
(
"
#prototypes
"
).
data
(
"
prototype-constraint
"
);
var
constraints
=
$
(
'
#constraints
'
);
var
constraint
=
constraints
.
data
(
'
prototype
'
)
;
var
constraint
=
prototype
;
constraint
=
constraint
.
replace
(
/__name__/g
,
$
(
"
.constraint-objective
"
).
length
);
constraints
.
append
(
constraint
);
},
...
...
@@ -27,3 +28,18 @@ $( "#constraints-tab" ).on( "change", "select", function(){
$
(
"
#constraints-tab
"
).
ready
(
function
()
{
constraints
.
checkAll
();
});
var
features
=
{
add
:
function
(
btn
){
var
constraint
=
btn
.
closest
(
'
li
'
);
var
prototype
=
$
(
"
#prototypes
"
).
data
(
"
prototype-feature
"
);
var
features
=
$
(
constraint
).
find
(
'
.features
'
);
var
feature
=
prototype
;
feature
=
feature
.
replace
(
/__name__/g
,
features
.
find
(
"
.feature-objective
"
).
length
);
features
.
append
(
feature
);
},
remove
:
function
(
btn
){
btn
.
closest
(
'
li
'
).
remove
();
},
};
application/src/MagicWordBundle/Resources/views/Round/Conquer/Objective/constraint.html.twig
View file @
b10ed9e0
{%
import
_self
as
my_macros
%}
<div
class=
"panel panel-default"
>
<div
id=
"prototypes"
data-prototype-constraint=
"
{{
my_macros.constraints_prototype
(
form.constraints.vars.prototype
)
|
e
}}
"
>
</div>
<div
class=
"panel-heading"
>
<span
class=
"pull-right"
>
...
...
@@ -17,7 +21,7 @@
</span>
</div>
<ul
class=
"list-group"
id=
"constraints"
data-prototype=
"
{{
my_macros.constraints_prototype
(
form.constraints.vars.prototype
)
|
e
}}
"
>
<ul
class=
"list-group"
id=
"constraints"
>
{%
for
constraint
in
form.constraints
%}
{{
my_macros.constraints_prototype
(
constraint
)
}}
{%
endfor
%}
...
...
@@ -25,13 +29,15 @@
</div>
{%
macro
constraints_prototype
(
constraint
)
%}
<li
class=
"list-group-item constraint-objective"
>
<p>
{{
form_label
(
constraint.numberToFind
)
}}
:
{{
form_widget
(
constraint.numberToFind
)
}}
</p>
<span
class=
"constraint"
>
{{
form_widget
(
constraint.feature
)
}}
</span>
<span
class=
"pull-right"
>
<span
onclick=
"objectives.remove(this);"
class=
"btn btn-danger"
>
<i
class=
"fa fa-times"
aria-hidden=
"true"
></i>
</span>
</span>
</li>
<li
class=
"list-group-item constraint-objective"
>
<p>
{{
form_label
(
constraint.numberToFind
)
}}
:
{{
form_widget
(
constraint.numberToFind
)
}}
<span>
{{
form_widget
(
constraint.features
)
}}
</span>
</p>
<span
class=
"pull-right"
>
<span
onclick=
"objectives.remove(this);"
class=
"btn btn-danger"
>
<i
class=
"fa fa-times"
aria-hidden=
"true"
></i>
</span>
</span>
</li>
{%
endmacro
%}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment