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