diff options
Diffstat (limited to 'src/data.php')
| -rw-r--r-- | src/data.php | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/data.php b/src/data.php new file mode 100644 index 0000000..aaf9d88 --- /dev/null +++ b/src/data.php @@ -0,0 +1,38 @@ +<?php +function get_node_value($from, string $name): string +{ + return $from->getElementsByTagName($name)->item(0)->nodeValue; +} +function get_doc(): DOMDocument +{ + $doc = new DOMDocument(); + $path = "/home/maks/school/clientApps/mlos/src/db.xml"; + $doc->load($path); + return $doc; +} +function get_data(): array +{ + $doc = get_doc(); + $out = []; + $games = $doc->getElementsByTagName("game"); + $i = 0; + while ($game = $games->item($i++)) { + $out[] = [ + "id" => $game->getAttribute("id"), + "order" => $game->getAttribute("order"), + "name" => get_node_value($game, "name"), + "thumbnail" => get_node_value($game, "thumbnail"), + "author" => get_node_value($game, "author"), + "magazine" => get_node_value($game, "magazine"), + ]; + } + usort($out, function ($a, $b) { + return $a["order"] - $b["order"]; + }); + return [$out, $doc->getElementsByTagName("count")->item(0)->nodeValue]; +} + +$doc = get_doc(); +$xpath = new DOMXpath($doc); +$game = $xpath->query('//game[@id="2"]/name')->item(0); +// var_dump($game); |
