summaryrefslogtreecommitdiffstats
path: root/src/data.php
diff options
context:
space:
mode:
authorMaksymilian Jopek <maks@jopek.eu>2022-03-16 23:20:59 +0100
committerMaksymilian Jopek <maks@jopek.eu>2022-03-16 23:20:59 +0100
commitbf7852bccce954aff2d7c94161f4d301a0f29684 (patch)
treefc3f2aac4f843990b02992e02903df22857a1928 /src/data.php
downloadmlos-bf7852bccce954aff2d7c94161f4d301a0f29684.tar.gz
mlos-bf7852bccce954aff2d7c94161f4d301a0f29684.tar.zst
mlos-bf7852bccce954aff2d7c94161f4d301a0f29684.zip
Initial commit w/ v1.0.0
Diffstat (limited to 'src/data.php')
-rw-r--r--src/data.php38
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);