Commit b6c2ddd4 authored by Arnaud Bey's avatar Arnaud Bey
Browse files

fix display possible combos in conquer editor

parent ce23f826
......@@ -77,11 +77,10 @@ class GridManager
$language = $this->em->getRepository('LexiconBundle:Language')->find($languageId);
$grid = $this->newGrid($language, 4);
$this->addSquares($grid, $request->request->get('squares'));
if ($save) {
$grid = $this->saveInflections($grid);
$grid = $this->saveFoundables($grid);
}
return $grid;
......@@ -97,7 +96,7 @@ class GridManager
$this->em->refresh($grid);
$this->addSquares($grid, $request->request->get('squares'));
$grid = $this->saveInflections($grid);
$grid = $this->saveFoundables($grid);
$this->em->persist($grid);
$this->em->flush($grid);
......@@ -105,7 +104,7 @@ class GridManager
return $grid;
}
public function saveInflections(Grid $grid)
public function saveFoundables(Grid $grid)
{
$this->em->getConnection()->getConfiguration()->setSQLLogger(null);
$inflections = $this->findWords($grid);
......@@ -165,36 +164,35 @@ class GridManager
return $grid->getFoundableForms();
}
public function getCombos($inflections)
public function getCombos($words)
{
$combos = [];
foreach ($inflections as $inflection) {
$lemma = $inflection->getLemma();
$form = $inflection->getCleanedContent();
$lemmaId = $lemma->getId();
if (!isset($combos[$lemmaId])) {
$combos[$lemmaId] = [
'lemma' => [
'id' => $lemmaId,
'content' => $lemma->getContent(),
'POS' => $lemma->getCategory() ? $lemma->getCategory()->getValue() : '',
foreach ($words as $word) {
$root = $word->getRoot();
$form = $word->getCleanValue();
$rootId = $root->getId();
if (!isset($combos[$rootId])) {
$combos[$rootId] = [
'root' => [
'id' => $rootId,
'value' => $root->getValue(),
],
'inflections' => [],
'words' => [],
];
}
if (!in_array($form, $combos[$lemmaId]['inflections'])) {
$combos[$lemmaId]['inflections'][] = $form;
if (!in_array($form, $combos[$rootId]['words'])) {
$combos[$rootId]['words'][] = $form;
}
}
$combos = array_filter($combos, function ($v) {
return count($v['inflections']) > 1;
return count($v['words']) > 1;
});
usort($combos, function ($a, $b) {
return count($b['inflections']) - count($a['inflections']);
return count($b['words']) - count($a['words']);
});
return $combos;
......
......@@ -3,21 +3,17 @@
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingOne">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-parent="#accordion" href="#{{ combo.lemma.id }}" aria-expanded="true" aria-controls="{{ combo.lemma.id }}">
{{ combo.lemma.content }}
<span class="text-muted">
{{ combo.lemma.POS }}
</span>
- {{combo.inflections|length}}
<a role="button" data-toggle="collapse" data-parent="#accordion" href="#{{ combo.root.id }}" aria-expanded="true" aria-controls="{{ combo.root.id }}">
{{ combo.root.value }} - {{combo.words|length}}
</a>
</h4>
</div>
<div id="{{ combo.lemma.id }}" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">
<div id="{{ combo.root.id }}" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">
<div class="list-group" >
{% for inflection in combo.inflections %}
{% for word in combo.words %}
<li class="list-group-item">
{{ inflection }}
<span class="btn btn-default btn-xs pull-right" onclick="findwords.addInflection('{{ inflection }}')">
{{ word }}
<span class="btn btn-default btn-xs pull-right" onclick="findwords.addInflection('{{ word }}')">
<i class="fa fa-plus" aria-hidden="true"></i> {{ 'add' | trans }}
</span>
</li>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment