S -> P P -> T R I I -> P I -> e R -> '[]' N O R -> N O O -> '{' P '}' O -> e N -> 'token=name' T -> 'token=type'
Beispiel #1
0
 public function testSet1()
 {
     $this->object->x = 37.5;
     $this->object->y = 45.33;
     $this->object->z = 0.26;
     $this->assertEquals('37.5 45.33 0.26', $this->object->set());
 }
 public function push($value)
 {
     $newHead = new Node($value);
     $newHead->setNext($this->linkedList);
     $this->linkedList = $newHead;
     $this->size++;
 }
Beispiel #3
0
 /**
  * Process the result of the given node. Returns false if no other nodes
  * should be run, or a string with the next node name.
  *
  * @param Node $node Node that was run
  *
  * @return string
  */
 protected function processNodeResult(Node $node)
 {
     $result = null;
     $name = $node->getName();
     if (isset($this->nodeResults[$name])) {
         foreach ($this->nodeResults[$name] as $resultInfo) {
             if ($resultInfo->appliesTo($node)) {
                 if ($resultInfo->isActionHangup()) {
                     // hanging up after $name
                     $this->client->hangup();
                 } elseif ($resultInfo->isActionJumpTo()) {
                     $data = $resultInfo->getActionData();
                     if (isset($data['nodeEval'])) {
                         $callback = $data['nodeEval'];
                         $nodeName = $callback($node);
                     } else {
                         $nodeName = $data['nodeName'];
                     }
                     // jumping from $name to $nodeName
                     $result = $nodeName;
                 } elseif ($resultInfo->isActionExecute()) {
                     // executing callback after $name
                     $data = $resultInfo->getActionData();
                     $callback = $data['callback'];
                     $callback($node);
                 }
             }
         }
     }
     return $result;
 }
 public function testGetIntersectingNode()
 {
     $a1 = new Node("one");
     $a2 = new Node("two");
     $a3 = new Node("three");
     $a4 = new Node("four");
     $a5 = new Node("five");
     $a1->setNext($a2);
     $a2->setNext($a3);
     $a3->setNext($a4);
     $a4->setNext($a5);
     $b1 = new Node("un");
     $b2 = new Node("deux");
     $b3 = new Node("trois");
     $b1->setNext($b2);
     $b2->setNext($b3);
     $this->assertNull(LinkedListIntersectionCheckerNoHashMap::getIntersectingNode($a1, $b1));
     $c1 = new Node("uno");
     $c2 = new Node("dos");
     $c3 = new Node("tres");
     $c1->setNext($c2);
     $c2->setNext($c3);
     $a5->setNext($c1);
     $b3->setNext($c1);
     $this->assertSame($c1, LinkedListIntersectionCheckerNoHashMap::getIntersectingNode($a1, $b1));
     // disconnect the first 4 nodes of the linked list.
     // now it begins @ $a5
     $a4->setNext(null);
     $this->assertSame($c1, LinkedListIntersectionCheckerNoHashMap::getIntersectingNode($a5, $b1));
 }
Beispiel #5
0
 /**
  * Helper Function for function buildXmlResult($vartable). Generates
  * an xml string for a single variable an their corresponding value.
  *
  * @param  String  $varname The variables name
  * @param  Node    $varvalue The value of the variable
  * @return String  The xml string
  */
 protected function _getBindingString($varname, $varvalue)
 {
     $binding = '<binding name="' . $varname . '">';
     $value = '<unbound/>';
     if ($varvalue instanceof BlankNode) {
         $value = '<bnode>' . $varvalue->getLabel() . '</bnode>';
     } else {
         if ($varvalue instanceof Resource) {
             $value = '<uri>' . $varvalue->getUri() . '</uri>';
         } else {
             if ($varvalue instanceof Literal) {
                 $label = htmlspecialchars($varvalue->getLabel());
                 $value = '<literal>' . $label . '</literal>';
                 if ($varvalue->getDatatype() != null) {
                     $value = '<literal datatype="' . $varvalue->getDatatype() . '">' . $label . '</literal>';
                 }
                 if ($varvalue->getLanguage() != null) {
                     $value = '<literal xml:lang="' . $varvalue->getLanguage() . '">' . $label . '</literal>';
                 }
             }
         }
     }
     $binding = $binding . $value . '</binding>';
     return $binding;
 }
Beispiel #6
0
 /**
  * Возвращает список меток для документа.
  */
 protected function getLabelsFor(Node $node)
 {
     if (!$node->id) {
         return array();
     }
     return array_unique((array) $node->getDB()->getResultsKV('id', 'name', "SELECT `id`, `name` FROM `node` " . "WHERE `class` = 'label' AND `deleted` = 0 AND `id` " . "IN (SELECT `tid` FROM `node__rel` WHERE `nid` = ? AND `key` = ?)", array($node->id, $this->value . '*')));
 }
Beispiel #7
0
 /**
  * Constructor.
  *
  * @param   Node    $parent     (optional) parent node
  */
 public function __construct($parent = null)
 {
     $this->parent = $parent;
     if (null !== $parent) {
         $this->level = 1 + $parent->getLevel();
     }
 }
 /**
  * Get editorial comments
  *
  * @ApiDoc(
  *     statusCodes={
  *         200="Returned when success",
  *     }
  * )
  *
  * @Route("/articles/{number}/{language}/editorial_comments/order/{order}.{_format}", defaults={"_format"="json", "order"="chrono"}, options={"expose"=true}, name="newscoop_gimme_articles_get_editorial_comments")
  * @Method("GET")
  * @View(serializerGroups={"list"})
  */
 public function getCommentsAction(Request $request, $number, $language, $order)
 {
     $em = $this->container->get('em');
     $editorialComments = $em->getRepository('Newscoop\\ArticlesBundle\\Entity\\EditorialComment')->getAllByArticleNumber($number)->getResult();
     if ($order == 'nested' && $editorialComments) {
         $root = new \Node(0, 0, '');
         $reSortedComments = array();
         foreach ($editorialComments as $comment) {
             $reSortedComments[$comment->getId()] = $comment;
         }
         ksort($reSortedComments);
         foreach ($reSortedComments as $comment) {
             if ($comment->getParent() instanceof EditorialComment) {
                 $node = new \Node($comment->getId(), $comment->getParent()->getId(), $comment);
             } else {
                 $node = new \Node($comment->getId(), 0, $comment);
             }
             $root->insertNode($node);
         }
         $editorialComments = $root->flatten(false);
     }
     $paginator = $this->get('newscoop.paginator.paginator_service');
     $paginator->setUsedRouteParams(array('number' => $number, 'language' => $language));
     $editorialComments = $paginator->paginate($editorialComments);
     return $editorialComments;
 }
 public function render(Node $node)
 {
     echo str_repeat('--', $node->getDepth()) . $node->getType() . "\n";
     foreach ($node->getChildren() as $child) {
         $this->render($child);
     }
 }
Beispiel #10
0
	public function interpret(Node &$node){
		$name = $node->getAttribute('#');
		$childs = $node->getChilds();
		
		if($name != ''){
			$ret = '<'.$name;
		}else{
			$ret = '<Node noname="true"';
		}
		
		foreach ($node->attrs as $k => $v){
			if(!in_array($k[0], array('#', '>', '@'))){
				$ret .= ' '.$k.'="'.$v.'"';
			}
		}
		
		for($i=0; $i<$node->atidx; ++$i){
			$ret .= ' attr'.$i.'="'.$node->attrs['@'.$i].'"';
		}
		$ret .='>';
		
		foreach ($childs as $child){			
			$ret .= $this->interpret($child);
		}
		
		if($name != ''){
			$ret .= '</'.$name.'>';
		}else{
			$ret .= '</Node>';
		}
		return $ret;
	}
 function On_PostAction_iterator_fetch($a_data)
 {
     // Find iterator in template
     $doc = new Template_Document($a_data->post['iterator_template']);
     function search_func($node, $args)
     {
         if ($node instanceof Template_TagNode) {
             return $node->getAttribute("name") == $args;
         } else {
             return false;
         }
     }
     $itrs = $doc->getElementsByFunc(search_func, $a_data->post['iterator_name']);
     $iterator = $itrs[0];
     // Generate id
     $id = Time("U") . substr((string) microtime(), 2, 6);
     // Build iterator template
     $node = new Node(-$id);
     $node->Build($iterator);
     // Pack JSON data
     $data = array();
     $data['id'] = $id;
     $data['content'] = Editor::$m_data['module_data'][-$id];
     print json_encode($data);
 }
 public function testGetIntersectingNode()
 {
     $a1 = new Node("one");
     $a2 = new Node("two");
     $a3 = new Node("three");
     $a4 = new Node("four");
     $a5 = new Node("five");
     $a1->setNext($a2);
     $a2->setNext($a3);
     $a3->setNext($a4);
     $a4->setNext($a5);
     $b1 = new Node("un");
     $b2 = new Node("deux");
     $b3 = new Node("trois");
     $b1->setNext($b2);
     $b2->setNext($b3);
     $this->assertNull(LinkedListIntersectionChecker::getIntersectingNode($a1, $b1));
     $c1 = new Node("uno");
     $c2 = new Node("dos");
     $c3 = new Node("tres");
     $c1->setNext($c2);
     $c2->setNext($c3);
     $a5->setNext($c1);
     $b3->setNext($c1);
     $this->assertSame($c1, LinkedListIntersectionChecker::getIntersectingNode($a1, $b1));
 }
Beispiel #13
0
 function createTextElement($text)
 {
     $node = new Node();
     $node->setType(TEXTELEMENT);
     $node->setValue($text);
     return $node;
 }
Beispiel #14
0
 /**
  * Attach a child node
  *
  * @param \Zend\Server\Reflection\Node $node
  * @return void
  */
 public function attachChild(Node $node)
 {
     $this->children[] = $node;
     if ($node->getParent() !== $this) {
         $node->setParent($this);
     }
 }
Beispiel #15
0
function get_categories_and_products($parent_id)
{
    $href_string = "javascript:set_return('productcatalog')";
    $nodes = array();
    if ($parent_id == '' or empty($parent_id)) {
        $query = "select id, name , 'category' type from product_categories where (parent_id is null or parent_id='') and deleted=0";
        $query .= " union select id, name , 'product' type from product_templates where (category_id is null or category_id='') and deleted=0";
    } else {
        $query = "select id, name , 'category' type from product_categories where parent_id ='{$parent_id}' and deleted=0";
        $query .= " union select id, name , 'product' type from product_templates where category_id ='{$parent_id}' and deleted=0";
    }
    $result = $GLOBALS['db']->query($query);
    // fetchByAssoc has been changed in version 7 and it does encoding of the string data.
    // for the treeview we do not encoding as it messes up the display of the folder labels,
    // hence we pass false as an additional parameter
    while (($row = $GLOBALS['db']->fetchByAssoc($result, false)) != null) {
        $node = new Node($row['id'], $row['name']);
        $node->set_property("href", $href_string);
        $node->set_property("type", $row['type']);
        if ($row['type'] == 'product') {
            $node->expanded = false;
            $node->dynamic_load = false;
        } else {
            $node->expanded = false;
            $node->dynamic_load = true;
        }
        $nodes[] = $node;
    }
    return $nodes;
}
Beispiel #16
0
	public function interpret(Node $node){
		$text = $node->getAttribute('@0');
		
		$ret = '<h1>'.$text.'</h1>';
		
		return $ret;
	}
 /**
  * Recursively inserts a path of nodes
  * 
  * @param Node $curr_node
  * @param string $path a slash delimited path of node names
  * @param array $array optional data array added to last node in the path
  */
 public function insertByPath(&$curr_node, $path = '', $array = null)
 {
     if (is_string($path)) {
         $p = explode('/', $path);
         $n = array_shift($p);
         if ($curr_node instanceof Node) {
             $curr_name = $curr_node->getName();
         }
         if ($curr_name === $n) {
             if (isset($p[0])) {
                 $n = $p[0];
             }
             if ($next_node = $curr_node->getNode($n)) {
                 $next_node = $next_node;
             } else {
                 $next_node = $curr_node;
             }
         } else {
             $new_node = self::build($n);
             $new_node->setData($array);
             $curr_node->insert($new_node);
             $next_node = $new_node;
         }
         if ($n !== '') {
             $remaining_path = implode('/', $p);
             while (count($p) > 0) {
                 return $this->insertByPath($next_node, $remaining_path, $array);
             }
         }
     }
 }
Beispiel #18
0
 public function remove($index)
 {
     $path = $this->getPath($index);
     $trie = new Trie();
     $trie->root = $this->root->put(null, $path);
     return $trie;
 }
Beispiel #19
0
 /**
  * @param Node $start
  * @param Node $goal
  * @return Node[]
  */
 public function run(Node $start, Node $goal)
 {
     $path = array();
     $this->clear();
     $start->setG(0);
     $start->setH($this->calculateEstimatedCost($start, $goal));
     $this->getOpenList()->add($start);
     while (!$this->getOpenList()->isEmpty()) {
         $currentNode = $this->getOpenList()->extractBest();
         $this->getClosedList()->add($currentNode);
         if ($currentNode->getID() === $goal->getID()) {
             $path = $this->generatePathFromStartNodeTo($currentNode);
             break;
         }
         $successors = $this->computeAdjacentNodes($currentNode, $goal);
         foreach ($successors as $successor) {
             if ($this->getOpenList()->contains($successor)) {
                 $successorInOpenList = $this->getOpenList()->get($successor);
                 if ($successor->getG() >= $successorInOpenList->getG()) {
                     continue;
                 }
             }
             if ($this->getClosedList()->contains($successor)) {
                 $successorInClosedList = $this->getClosedList()->get($successor);
                 if ($successor->getG() >= $successorInClosedList->getG()) {
                     continue;
                 }
             }
             $successor->setParent($currentNode);
             $this->getClosedList()->remove($successor);
             $this->getOpenList()->add($successor);
         }
     }
     return $path;
 }
 function isNodeOnMap(Node $node)
 {
     $position = $node->getPosition();
     $nodes = $this->getNodesAtPosition($position);
     $index = $this->nodeIndex($node, $nodes);
     return $index === false ? false : true;
 }
Beispiel #21
0
 /**
  * Dumps a node or array.
  *
  * @param array|Node $node Node or array to dump
  *
  * @return string Dumped value
  */
 public function dump($node)
 {
     if ($node instanceof Node) {
         $r = $node->getType() . '(';
     } elseif (is_array($node)) {
         $r = 'array(';
     } else {
         throw new \InvalidArgumentException('Can only dump nodes and arrays.');
     }
     foreach ($node as $key => $value) {
         $r .= "\n" . '    ' . $key . ': ';
         if (null === $value) {
             $r .= 'null';
         } elseif (false === $value) {
             $r .= 'false';
         } elseif (true === $value) {
             $r .= 'true';
         } elseif (is_scalar($value)) {
             $r .= $value;
         } else {
             $r .= str_replace("\n", "\n" . '    ', $this->dump($value));
         }
     }
     return $r . "\n" . ')';
 }
Beispiel #22
0
 protected function traverseNode(Node $node)
 {
     foreach ($node->getSubNodeNames() as $name) {
         $subNode =& $node->{$name};
         if (is_array($subNode)) {
             $subNode = $this->traverseArray($subNode);
         } elseif ($subNode instanceof Node) {
             $traverseChildren = true;
             foreach ($this->visitors as $visitor) {
                 $return = $visitor->enterNode($subNode);
                 if (self::DONT_TRAVERSE_CHILDREN === $return) {
                     $traverseChildren = false;
                 } else {
                     if (null !== $return) {
                         $subNode = $return;
                     }
                 }
             }
             if ($traverseChildren) {
                 $subNode = $this->traverseNode($subNode);
             }
             foreach ($this->visitors as $visitor) {
                 if (null !== ($return = $visitor->leaveNode($subNode))) {
                     if (is_array($return)) {
                         throw new \LogicException('leaveNode() may only return an array ' . 'if the parent structure is an array');
                     }
                     $subNode = $return;
                 }
             }
         }
     }
     return $node;
 }
Beispiel #23
0
 /**
  * 头插法
  * @param unknown_type $value
  */
 public function insertFirst($value)
 {
     $new = new Node(null, $value);
     $new->setValue($value);
     $new->next = $this->head->next;
     $this->head->next = $new;
 }
Beispiel #24
0
function get_product_categories($parent_id, $open_nodes_ids = array())
{
    $href_string = "javascript:set_return('productcategories')";
    reset($open_nodes_ids);
    $nodes = array();
    if ($parent_id == '') {
        $query = "select * from product_categories where (parent_id is null or parent_id='') and deleted=0 order by list_order";
    } else {
        $query = "select * from product_categories where parent_id ='{$parent_id}' and deleted=0 order by list_order";
    }
    $result = $GLOBALS['db']->query($query);
    while (($row = $GLOBALS['db']->fetchByAssoc($result)) != null) {
        $node = new Node($row['id'], $row['name']);
        $node->set_property("href", $href_string);
        if (count($open_nodes_ids) > 0 and $row['id'] == current($open_nodes_ids)) {
            $node->expanded = true;
            $node->dynamic_load = false;
            $current_id = current($open_nodes_ids);
            array_shift($open_nodes_ids);
            $child_nodes = get_product_categories($current_id, $open_nodes_ids);
            //add all returned node to current node.
            foreach ($child_nodes as $child_node) {
                $node->add_node($child_node);
            }
        } else {
            $node->expanded = false;
            $node->dynamic_load = true;
        }
        $nodes[] = $node;
    }
    return $nodes;
}
 public function preEdit(NodeRef $nodeRef, Node $node)
 {
     // node has no file
     if (!($originalFileTag = $node->getOutTag('#original'))) {
         return;
     }
     // node already has thumbnails that are going to be added
     if ($node->hasOutTags('#thumbnails')) {
         return;
     }
     $q = new NodeQuery();
     $q->setParameter('Elements.in', $nodeRef->Element->Slug)->setParameter('Slugs.in', $nodeRef->Slug)->setParameter('OutTags.exist', '#thumbnails')->setParameter('Count.only', true);
     // already has thumbnails
     if ($this->NodeService->findAll($q)->getTotalRecords()) {
         return;
     }
     $file = $this->FileService->retrieveFileFromNode($nodeRef->Element, new NodeRef($this->ElementService->getBySlug($originalFileTag->TagElement), $originalFileTag->TagSlug));
     if (!$file) {
         throw new ThumbnailsException('Could not retrieve original file!');
     }
     $originalFilePath = $file->getLocalPath();
     $thumbnailFileNodes = $this->ImageService->createInitialThumbnails($node, $originalFilePath);
     $newThumbnailTags = array();
     foreach ($thumbnailFileNodes as $size => $thumbnailFileNode) {
         $tag = new Tag($thumbnailFileNode->getElement()->getSlug(), $thumbnailFileNode->Slug, '#thumbnails', $size, $size);
         $newThumbnailTags[] = $tag;
     }
     $node->replaceOutTags('#thumbnails', $newThumbnailTags);
 }
Beispiel #26
0
 /**
  * @param \tomzx\HtmlParser\Node $node
  * @return array
  */
 protected function parseNode(Node $node)
 {
     $statements = $node->getChildren();
     foreach ($node->getChildren() as $child) {
         $statements[] = $this->parseNode($child);
     }
     return $statements;
 }
Beispiel #27
0
 function findParent(Node $node, $type = null)
 {
     if ($node->getType() == $type) {
         return $node;
     } else {
         findParent($node->getParent(), $type);
     }
 }
Beispiel #28
0
 /**
  * @see \Saft\Rdf\Node
  */
 public function equals(Node $toCompare)
 {
     // It only compares URIs, everything will be quit with false.
     if ($toCompare->isNamed()) {
         return $this->getUri() == $toCompare->getUri();
     }
     return false;
 }
Beispiel #29
0
 public function setRight(Node $right = null)
 {
     $this->right = $right;
     if (null !== $right && $this !== $right->getLeft()) {
         $right->setLeft($this);
     }
     return $this;
 }
Beispiel #30
0
 public function addChild($name, Node $node)
 {
     $this->children[$name] = $node;
     if ($this->namespace !== '') {
         $name = $this->namespace . '\\' . $name;
     }
     $node->setNamespace($name);
 }