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

WIP replace lemma by root

parent 2dec3c73
......@@ -130,27 +130,22 @@ class Grid implements \JsonSerializable
];
foreach ($this->getFoundableForms() as $foundable) {
$form = $foundable->getForm();
$jsonArray['inflections'][$form] = ['id' => $foundable->getId(), 'points' => $foundable->getPoints(), 'infos' => [], 'ids' => [], 'lemmaIds' => []];
$jsonArray['inflections'][$form] = [
'id' => $foundable->getId(),
'points' => $foundable->getPoints(),
'features' => [],
'ids' => [],
'rootIds' => []
];
foreach ($foundable->getWords() as $word) {
$root = $word->getRoot();
$jsonArray['inflections'][$form]['infos'][] = 1;
/*
[
'category' => !$root->getCategory() ? null : $root->getCategory()->getId(),
'number' => !$word->getNumber() ? null : $word->getNumber()->getId(),
'gender' => !$word->getGender() ? null : $word->getGender()->getId(),
'person' => !$word->getPerson() ? null : $word->getPerson()->getId(),
'mood' => !$word->getMood() ? null : $word->getMood()->getId(),
'tense' => !$word->getTense() ? null : $word->getTense()->getId(),
];
*/
foreach ($word->getFeatures() as $feature) {
$jsonArray['inflections'][$form]['features'][$feature->getId()] = $feature->getValue();
}
$jsonArray['inflections'][$form]['ids'][] = $word->getId();
$rootId = $root->getId();
if (!in_array($rootId, $jsonArray['inflections'][$form]['lemmaIds'])) {
$jsonArray['inflections'][$form]['lemmaIds'][] = $rootId;
if (!in_array($rootId, $jsonArray['inflections'][$form]['rootIds'])) {
$jsonArray['inflections'][$form]['rootIds'][] = $rootId;
}
}
}
......
......@@ -254,49 +254,46 @@ class Round implements \JsonSerializable
public function jsonSerialize()
{
$jsonArray = array(
$jsonArray = [
'id' => $this->id,
'findWords' => array(),
'combos' => array(),
'constraints' => array(),
'findWords' => [],
'combos' => [],
'constraints' => [],
'type' => $this->discr,
);
];
if ($this->discr == 'conquer') {
foreach ($this->getFindWords() as $findWord) {
$jsonArray['findWords'][$findWord->getInflection()] =
[
'id' => $findWord->getId(),
'hint' => $findWord->getHint(),
'lemmaIds' => [],
$jsonArray['findWords'][$findWord->getInflection()] = [
'id' => $findWord->getId(),
'hint' => $findWord->getHint(),
'lemmaIds' => [],
];
foreach ($findWord->getLemmas() as $lemma) {
$jsonArray['findWords'][$findWord->getInflection()]['lemmaIds'][] = $lemma->getId();
foreach ($findWord->getRoots() as $root) {
$jsonArray['findWords'][$findWord->getInflection()]['rootIds'][] = $root->getId();
}
}
foreach ($this->getCombos() as $combo) {
$jsonArray['combos'][] =
[
'id' => $combo->getId(),
'length' => $combo->getLenght(),
'number' => $combo->getNumber(),
];
$jsonArray['combos'][] = [
'id' => $combo->getId(),
'length' => $combo->getLenght(),
'number' => $combo->getNumber(),
];
}
foreach ($this->getConstraints() as $constraint) {
$jsonArray['constraints'][] =
[
'id' => $constraint->getId(),
'numberToFind' => $constraint->getNumberToFind(),
'category' => $constraint->getCategory() ? $constraint->getCategory()->getId() : null,
'gender' => $constraint->getGender() ? $constraint->getGender()->getId() : null,
'number' => $constraint->getNumber() ? $constraint->getNumber()->getId() : null,
'tense' => $constraint->getTense() ? $constraint->getTense()->getId() : null,
'mood' => $constraint->getMood() ? $constraint->getMood()->getId() : null,
'person' => $constraint->getPerson() ? $constraint->getPerson()->getId() : null,
];
$jsonArray['constraints'][] = [
'id' => $constraint->getId(),
'numberToFind' => $constraint->getNumberToFind(),
'category' => $constraint->getCategory() ? $constraint->getCategory()->getId() : null,
'gender' => $constraint->getGender() ? $constraint->getGender()->getId() : null,
'number' => $constraint->getNumber() ? $constraint->getNumber()->getId() : null,
'tense' => $constraint->getTense() ? $constraint->getTense()->getId() : null,
'mood' => $constraint->getMood() ? $constraint->getMood()->getId() : null,
'person' => $constraint->getPerson() ? $constraint->getPerson()->getId() : null,
];
}
}
......
......@@ -2,24 +2,24 @@ var combo = {
newIds: [],
previousIds: [],
currentComboLength: 0,
currentComboLemmas: [],
currentComboRoots: [],
comboSelector: $("#combo"),
handleNewIds: function(callback){
var increment = false;
var comboEnded = false;
if (this.currentComboLemmas.length === 0) {
if (this.currentComboRoots.length === 0) {
//ajout des nouveaux lemmes dans currentcombos
for (var i = this.newIds.length; i--;) {
this.currentComboLemmas.push(this.newIds[i]);
this.currentComboRoots.push(this.newIds[i]);
}
this.currentComboLength = 1;
increment = true;
} else {
// suppression dans current combos des lemmes qui ne font pas partie des nouveaux lemmes.
for (var i = this.currentComboLemmas.length; i--;) {
if ($.inArray(this.currentComboLemmas[i],this.newIds) == -1) {
this.currentComboLemmas.splice(i,1);
for (var i = this.currentComboRoots.length; i--;) {
if ($.inArray(this.currentComboRoots[i],this.newIds) == -1) {
this.currentComboRoots.splice(i,1);
} else if (!increment) {
increment = true;
this.currentComboLength++;
......@@ -47,8 +47,8 @@ var combo = {
// ajout des nouveaux lemmes dans currentcombos
for (var i = this.newIds.length; i--;) {
if ($.inArray(this.newIds[i], this.currentComboLemmas) == -1) {
this.currentComboLemmas.push(this.newIds[i]);
if ($.inArray(this.newIds[i], this.currentComboRoots) == -1) {
this.currentComboRoots.push(this.newIds[i]);
if (!increment) {
this.currentComboLength = 1;
}
......@@ -61,7 +61,7 @@ var combo = {
handleNewInflection: function(inflection){
this.previousIds = this.newIds;
this.newIds = gridJSON.inflections[inflection.toLowerCase()].lemmaIds;
this.newIds = gridJSON.inflections[inflection.toLowerCase()].rootIds;
this.handleNewIds(objectiveCombo.checkLastObjective);
return;
......@@ -87,7 +87,7 @@ var combo = {
this.newIds = [];
this.previousIds = [];
this.currentComboLength = 0;
this.currentComboLemmas = [];
this.currentComboRoots = [];
this.showCombo();
},
......
Markdown is supported
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