/** * @param Node $node * @return string */ protected function renderNode(Node $node) { $this->setRelations($node->getId(), $node->getAttachedClasses()); $result = $node->getId(); # Remember that we might not always have a text to work with. if (!is_null($node->getText())) { # The style variable already contains a nice template, making our life easier. $result .= sprintf($node->getStyle(), $node->getText()); } return $result; }
/** * Compute the tree with a backtrace stack. * * @access protected * @param array $array Backtrace stack. * @return void */ protected function computeTree(array $array = array()) { $node = null; $child = null; $currentNode = $this->_tree; foreach ($array as $i => $trace) { $node = new Node($trace); if (true === $currentNode->childExists($node->getId())) { $currentNode = $currentNode->getChild($node->getId()); } else { $child = new \Hoa\Tree($node); $currentNode->insert($child); $currentNode = $child; } } return; }
/** * remove indexed node * * @throws \Neo4j\Exception\HttpException * * @param \Neo4j\Node $node * @param string $key * @param string $value * * @return void */ public function remove(Node $node, $key, $value) { $this->_uri = $this->_db->getBaseUri() . 'index/node/' . $key . '/' . $value . '/' . $node->getId(); list($response, $http_code) = Request::delete($this->_uri); if ($http_code != 204) { throw new \Neo4j\Exception\HttpException($http_code); } }
/** * @param Node $node * @return ListNode */ protected function convertNode(Node $node) { if ($node instanceof ListNode) { return $node; } $listNode = new ListNode($node->getId(), $node->getX(), $node->getY(), 0); $listNode->setData($node->getData()); return $listNode; }
/** * @param Node $start * @param Node $end * @param callable $getSuccessors * @return Path */ public static function findPath(Node $start, Node $end, callable $getSuccessors) { self::$openList = new OpenList(); self::$closedList = new ClosedList(); self::$openList->add($start); $current = null; do { /** @var ListNode $current */ $current = self::$openList->removeMin(); if ($current->getId() === $end->getId()) { return new Path($current); } self::$closedList->add($current); self::expandNode($current, $end, $getSuccessors); } while (!self::$openList->isEmpty()); return null; }
/** * Create a new node and its children * * @param object Hierarchy $newHierarchy * @param object Node $oldNode * @param optional object Id $parentId * @return void * @access protected * @since 4/17/08 */ protected function addNode(Hierarchy $newHierarchy, Node $oldNode, Id $parentId = null) { // If it has already been created, get it and try to set its parent try { $newNode = $newHierarchy->getNode($oldNode->getId()); if (!is_null($parentId)) { try { $newNode->addParent($parentId); } catch (Exception $e) { // Do nothing if the child already exists if ($e->getMessage() != "A child with the given id already exists!") { throw $e; } } } } catch (UnknownIdException $e) { if (is_null($parentId)) { $newNode = $newHierarchy->createRootNode($oldNode->getId(), $oldNode->getType(), $oldNode->getDisplayName(), $oldNode->getDescription()); } else { $newNode = $newHierarchy->createNode($oldNode->getId(), $parentId, $oldNode->getType(), $oldNode->getDisplayName(), $oldNode->getDescription()); } $this->nodeStatus->updateStatistics(); } $oldChildren = $oldNode->getChildren(); while ($oldChildren->hasNext()) { $oldChild = $oldChildren->next(); $this->addNode($newHierarchy, $oldChild, $newNode->getId()); } }
/** * Convert an alfresco node to a File object * * @param Node $node */ private function nodeToFile($node) { if (!$this->getConnection()) { return null; } if ($node == null) { throw new Exception("Cannot convert null node to File"); } $fileObject = new File(); $fileObject->id = $node->getId(); $fileObject->path = $node->getPrimaryParent()->__toString(); $fileObject->filename = $node->cm_name; $fileObject->title = $node->cm_title; $fileObject->description = $node->cm_description; $fileObject->created = $node->cm_created; $fileObject->updated = $node->cm_modified; $props = $node->getProperties(); $fileObject->isprivate = ifset($props, '{simplecrm.model}isPrivate', "false") == "true" ? 1 : 0; return $fileObject; }
public function setEndNode(Node $object) { $this->_data['end'] = $object->getId(); return $this; }
/** * @param Node $node * @return $this * @throws \Exception */ public function removeNode($node) { // For reorder old node branch $dataReorderOld = [$this->_orderField => new \Zend_Db_Expr($this->_conn->quoteIdentifier($this->_orderField) . '-1')]; $conditionReorderOld = $this->_conn->quoteIdentifier($this->_parentField) . '=' . $node->getData($this->_parentField) . ' AND ' . $this->_conn->quoteIdentifier($this->_orderField) . '>' . $node->getData($this->_orderField); $this->_conn->beginTransaction(); try { $condition = $this->_conn->quoteInto("{$this->_idField}=?", $node->getId()); $this->_conn->delete($this->_table, $condition); // Update old node branch $this->_conn->update($this->_table, $dataReorderOld, $conditionReorderOld); $this->_conn->commit(); } catch (\Exception $e) { $this->_conn->rollBack(); throw new \Exception('Can\'t remove tree node'); } parent::removeNode($node); return $this; }
/** * @param Node $node * @return Node */ public function getOtherNode(Node $node) { return $this->_node1->getId() == $node->getId() ? $this->getStartNode() : $this->getEndNode(); }
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()); } } } }
/** * Load the given node with data from the server * * @param Node $node * @return boolean */ public function loadNode(Node $node) { $cached = $this->getEntityCache()->getCachedEntity($node->getId(), 'node'); if ($cached) { $node->setProperties($cached->getProperties()); return true; } return $this->runCommand(new Command\GetNode($this, $node)); }
/** * @test */ public function getTheId() { $node = new Node(array('id' => 16)); $this->assertEquals(16, $node->getId()); }
/** * @param Node $node * * @return $this */ public function addChild(Node $node) { $this->childs[$node->getId()] = $node; return $this; }
public function insert(Node $node, $priority) { $this->queue[$node->getId()] = $priority; $this->map[$node->getId()] = $node; asort($this->queue); }
public function getEdgesTo(Node $vertexTo) { $edges = array(); $vertexToId = $vertexTo->getId(); foreach ($this->vertexes as $vertexFromId => $vertexFrom) { if (isset($this->edges[$vertexFromId][$vertexToId])) { $edges[$vertexToId] = $this->edges[$vertexFromId][$vertexToId]; } } return $edges; }
/** * @param Node $node * @return bool */ public function hasNode(Node $node) { return isset($this->_nodes[$node->getId()]); }
/** * Creates a new root node * * @param Node * * @return NodeWrapper */ public function createRoot(Node $node) { if ($node instanceof NodeWrapper) { throw new \InvalidArgumentException('Can\'t create a root node from a NodeWrapper node'); } $node->setLeftValue(1); $node->setRightValue(2); if ($this->getConfiguration()->hasManyRoots()) { $rootValue = $node->getId(); if ($rootValue === null) { // Set a temporary value in case wrapped node requires root value to be set $node->setRootValue(0); $this->getEntityManager()->persist($node); $this->getEntityManager()->flush(); $rootValue = $node->getId(); } if ($rootValue === null) { // @codeCoverageIgnoreStart throw new \RuntimeException('Node must have an identifier available via getId()'); // @codeCoverageIgnoreEnd } $node->setRootValue($rootValue); } $this->getEntityManager()->persist($node); $this->getEntityManager()->flush(); return $this->wrapNode($node); }
public function add(Node $node, $lowestCosts = 0) { $this->nodes[$node->getId()] = ['node' => $this->convertNode($node), 'lowestCosts' => $lowestCosts, 'previousCosts' => 0, 'predecessor' => null]; }
public function addNode(Node $node) { $this->nodes[$node->getId()] = $node; }
public function insert(Node $node, $value = true) { $this->map[$node->getId()] = $value; }
/** * find path between to nodes * * @todo Add handling for relationships * @todo Add algorithm parameter * * @example curl -H Accept:application/json -H Content-Type:application/json -d '{ "to": "http://localhost:9999/node/3" }' -X POST http://localhost:9999/node/1/pathfinder * * @throws \Neo4j\Exception\HttpException * @throws \Neo4j\Exception\NotFoundException * * @param Node $toNode * @param int|null $maxDepth * @param Relationships|null $relationships * @param string|null $singlePath * * @return array */ public function findPaths(Node $toNode, $maxDepth = null, Relationships $relationships = null, $singlePath = null) { $this->_pathFinderData['to'] = $this->_db->getBaseUri() . 'node' . '/' . $toNode->getId(); if ($maxDepth) { $this->_pathFinderData['max depth'] = $maxDepth; } if ($singlePath) { $this->_pathFinderData['single path'] = $singlePath; } if ($relationships) { $this->_pathFinderData['relationships'] = $relationships->get(); } list($response, $http_code) = Request::post($this->getUri() . '/pathfinder', $this->_pathFinderData); if ($http_code == 404) { throw new \Neo4j\Exception\NotFoundException(); } if ($http_code != 200) { throw new \Neo4j\Exception\HttpException("http code: " . $http_code . ", response: " . print_r($response, true)); } $paths = array(); foreach ($response as $result) { $paths[] = Path::inflateFromResponse($this->_db, $result); } if (empty($paths)) { throw new \Neo4j\Exception\NotFoundException(); } return $paths; }
/** * Create implicit Authorizations given a sub-tree node and an array ids of that * node's new parents or ancestors. * * @param object Node $subtreeRootNode * @param array $newAncestorIds An array of Id objects * @return void * @access public * @since 4/21/08 */ public function createHierarchyImplictAZs(Node $subtreeRootNode, array $newAncestorIds) { // Wrap this operation in a transaction to prevent partial addition. if (isset($this->harmoni_db)) { $this->harmoni_db->beginTransaction(); } else { $dbHandler = Services::getService("DatabaseManager"); $dbHandler->beginTransaction($this->_dbIndex); } // Get a list of Explicit Authorizations in the subtree that will // cascade up to the new ancestors and add the corresponding // implicit AZs to the new ancestors. $upAZs = $this->getCascadingUpAZs(array($subtreeRootNode->getId())); $this->createImplicitAZs($upAZs, $newAncestorIds); // Get a list of the Explicit Authorizations in the new ancestors that will // cascade down to the subtree and add the corresponding implicit // AZs to the subtree. $downAZs = $this->getCascadingDownAZs($newAncestorIds); $nodes = $this->getQualifierDescendentIds($subtreeRootNode->getId()); $nodes[] = $subtreeRootNode->getId(); $this->createImplicitAZs($downAZs, $nodes); // Wrap this operation in a transaction to prevent partial addition. if (isset($this->harmoni_db)) { $this->harmoni_db->commit(); } else { $dbHandler = Services::getService("DatabaseManager"); $dbHandler->commitTransaction($this->_dbIndex); } }