Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

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

WIP fixing objectives JS

parent b4e4bc67
...@@ -64,7 +64,6 @@ class Constraint extends Objective ...@@ -64,7 +64,6 @@ class Constraint extends Objective
'type' => $this->discr, 'type' => $this->discr,
'numberToFind' => $this->numberToFind, 'numberToFind' => $this->numberToFind,
'features' => $this->feature ? $this->feature->getId() : null, 'features' => $this->feature ? $this->feature->getId() : null,
); );
return $jsonArray; return $jsonArray;
......
...@@ -283,17 +283,15 @@ class Round implements \JsonSerializable ...@@ -283,17 +283,15 @@ class Round implements \JsonSerializable
]; ];
} }
foreach ($this->getConstraints() as $constraint) { foreach ($this->getConstraints() as $c) {
$jsonArray['constraints'][] = [ $constraint = [];
'id' => $constraint->getId(), $constraint["id"] = $c->getId();
'numberToFind' => $constraint->getNumberToFind(), $constraint["numberToFind"] = $c->getNumberToFind();
'category' => $constraint->getCategory() ? $constraint->getCategory()->getId() : null, foreach ($c->getFeatures() as $feature) {
'gender' => $constraint->getGender() ? $constraint->getGender()->getId() : null, $constraint[$feature->getLabel()] = $feature->getValue();
'number' => $constraint->getNumber() ? $constraint->getNumber()->getId() : null, }
'tense' => $constraint->getTense() ? $constraint->getTense()->getId() : null,
'mood' => $constraint->getMood() ? $constraint->getMood()->getId() : null, $jsonArray['constraints'][] = $constraint;
'person' => $constraint->getPerson() ? $constraint->getPerson()->getId() : null,
];
} }
} }
......
var objectiveConstraint = { var objectiveConstraint = {
properties: ["category", "number", "gender", "person", "mood", "tense"], properties: ["category", "number", "gender", "person", "mood", "tense"],
constraintRealized: [], constraintRealized: [],
add: function(inflection){ add: function(inflection) {
var infos = gridJSON.inflections[inflection.toLowerCase()].infos; var infos = gridJSON.inflections[inflection.toLowerCase()].features;
var incrementedObjs = []; var incrementedObjs = [];
for (var i = 0; i < infos.length; i++) { for (var i = 0; i < infos.length; i++) {
currentInflectionInfos = infos[i]; currentInflectionInfos = infos[i];
for (var j = 0; j < roundJSON.constraints.length; j++) { for (var j = 0; j < roundJSON.constraints.length; j++) {
var objective = roundJSON.constraints[j]; var objective = roundJSON.constraints[j];
if(this.isPertinent(objective, currentInflectionInfos)){ if (this.isPertinent(objective, currentInflectionInfos)) {
if ($.inArray(objective.id, incrementedObjs) == -1) { if ($.inArray(objective.id, incrementedObjs) == -1) {
objectives.updateProgress(objective.id); objectives.updateProgress(objective.id);
this.constraintRealized.push(objective.id); this.constraintRealized.push(objective.id);
incrementedObjs.push(objective.id); incrementedObjs.push(objective.id);
if(this.checkCompletion(objective)){ if (this.checkCompletion(objective)) {
objectives.considerAsDone(objective.id); objectives.considerAsDone(objective.id);
activity.sendObjectiveDone(objective.id); activity.sendObjectiveDone(objective.id);
}
}
}
} }
} }
},
countByObjective: function(objectiveId){
var count = 0;
for(var i = 0; i < this.constraintRealized.length; ++i){
if(this.constraintRealized[i] == objectiveId){
count++;
}
}
return count;
},
isPertinent: function(objective, infos){
for (var i = 0; i < this.properties.length; i++) {
var property = this.properties[i];
if (objective[property] != null && objective[property] != infos[property]) {
return false;
};
} }
}
}
},
countByObjective: function(objectiveId) {
var count = 0;
for (var i = 0; i < this.constraintRealized.length; ++i) {
if (this.constraintRealized[i] == objectiveId) {
count++;
}
}
return true; return count;
}, },
checkCompletion: function(objective){
if(this.countByObjective(objective.id) == objective.numberToFind){
return true;
}
isPertinent: function(objective, infos) {
for (var i = 0; i < this.properties.length; i++) {
var property = this.properties[i];
if (objective[property] != null && objective[property] != infos[property]) {
return false; return false;
};
} }
return true;
},
checkCompletion: function(objective) {
if (this.countByObjective(objective.id) == objective.numberToFind) {
return true;
}
return false;
}
} }
...@@ -5,7 +5,7 @@ var findword = { ...@@ -5,7 +5,7 @@ var findword = {
this.found(roundJSON.findWords[inflectionLower], inflection); this.found(roundJSON.findWords[inflectionLower], inflection);
return true; return true;
} else { } else {
var lemmaIds = gridJSON.inflections[inflectionLower].lemmaIds; var lemmaIds = gridJSON.inflections[inflectionLower].rootIds;
for (var i = 0; i < lemmaIds.length; i++) { for (var i = 0; i < lemmaIds.length; i++) {
for (var key in roundJSON.findWords) { for (var key in roundJSON.findWords) {
if (!roundJSON.findWords.hasOwnProperty(key)) continue; if (!roundJSON.findWords.hasOwnProperty(key)) continue;
......
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