public function __construct($studentId, $courseId, $em, $student) { $this->nodes = array(); $this->edges = array(); $lessons = array(); $csSkill = array(); $cognitiveState = $em->getRepository('sociaLecompsSuperBundle:Student')->getCognitiveState($studentId); for ($i = 0; $i < count($cognitiveState); $i++) { $csSkill[$i] = $cognitiveState[$i]->getSkill()->getId(); } $course = $em->getRepository('sociaLecompsSuperBundle:Course')->find($courseId); if ($course != null) { $lessons = $em->getRepository('sociaLecompsSuperBundle:Lesson')->getLessons($course); } foreach ($lessons as $lesson) { $rk = $lesson->getRequiredSkills(); if (count($rk) == 0) { $basic = $em->getRepository('sociaLecompsSuperBundle:Skill')->findBy(array('name' => 'basic knowledge')); $node = new Node($basic[0], $lesson); $this->nodes[$node->getId()] = $node; $node->setInCS(); $node->setDistance(0); $currentNode = $this->nodes[$node->getId()]; $currentNode->addOut($lesson->getId()); } else { foreach ($rk as $skill) { /* * verifico se il nodo è già esistente nel grafo * se lo è devo solo aggiornare gli archi * se non lo è creo il nodo e poi aggiungo l'arco */ if (array_key_exists($skill->getId(), $this->nodes)) { $currentNode = $this->nodes[$skill->getId()]; $currentNode->addOut($lesson->getId()); } else { $node = new Node($skill, $lesson); $this->nodes[$node->getId()] = $node; if (in_array($node->getId(), $csSkill)) { $cs = $em->getRepository('sociaLecompsSuperBundle:CognitiveState')->findBy(array('skill' => $node->getId(), 'student' => $studentId)); $node->setInCS(); $node->setDistance(0); $node->setCertanty($cs[0]->getCertainty()); } $currentNode = $this->nodes[$skill->getId()]; $currentNode->addOut($lesson->getId()); } } } $ak = $lesson->getAcquiredSkills(); foreach ($ak as $skill) { if (array_key_exists($skill->getId(), $this->nodes)) { $currentNode = $this->nodes[$skill->getId()]; $currentNode->addIn($lesson->getId()); } else { $node = new Node($skill, $lesson); $this->nodes[$node->getId()] = $node; if (in_array($node->getId(), $csSkill)) { $cs = $em->getRepository('sociaLecompsSuperBundle:CognitiveState')->findBy(array('skill' => $node->getId(), 'student' => $studentId)); $node->setInCS(); $node->setDistance(0); $node->setCertanty($cs[0]->getCertainty()); } $currentNode = $this->nodes[$skill->getId()]; $currentNode->addIn($lesson->getId()); } } $edge = new Edge($lesson); //crea l'arco che rappresenta la lc $this->edges[$edge->getId()] = $edge; //inserisce l'arco nell'array degli archi del grafo } //Inizializza le distanze stimate di ogni nodo con il peso minimo degli archi entranti foreach ($this->nodes as $node) { foreach ($node->getIn() as $e) { $edge = $this->edges[$e]; if ($edge->getWeight() < $node->getDistance()) { $node->setDistance($edge->getWeight()); } } } }