diff --git a/www/internals/adventofcode.php b/www/internals/adventofcode.php index 1e64e18..6727462 100644 --- a/www/internals/adventofcode.php +++ b/www/internals/adventofcode.php @@ -71,7 +71,7 @@ class AdventOfCode return array_keys($this->staticData); } - public static function readSingle($year, $a) + private static function readSingle($year, $a) { $yeardata = self::YEARS[$year]; diff --git a/www/internals/books.php b/www/internals/books.php index b2199ea..01fcddd 100644 --- a/www/internals/books.php +++ b/www/internals/books.php @@ -19,7 +19,7 @@ class Books $this->staticData = array_map(function($a){return self::readSingle($a);}, $all); } - public static function readSingle($a) + private static function readSingle($a) { $a['imgfront_url'] = '/data/images/book_img/' . $a['id'] . '_front.png'; $a['imgfront_path'] = __DIR__ . '/../data/images/book_img/' . $a['id'] . '_front.png'; diff --git a/www/internals/euler.php b/www/internals/euler.php index a3c0dcc..66b4b13 100644 --- a/www/internals/euler.php +++ b/www/internals/euler.php @@ -1,8 +1,25 @@ load(); + } + + private function load() + { + $all = require (__DIR__ . '/../statics/blog/__all.php'); + + $this->staticData = array_map(function($a){return self::readSingle($a);}, $all); + } + + private static function readSingle($a) { $n3p = str_pad($a['number'], 3, '0', STR_PAD_LEFT); $a['number3'] = $n3p; @@ -25,33 +42,7 @@ class Euler return $a; } - public static function listAll() - { - $all = require (__DIR__ . '/../statics/euler/__all.php'); - - return array_map('self::readSingle', $all); - } - - public static function getEulerProblemFromStrIdent($ident) - { - $e = explode('-', $ident, 2); // problem-xxx - if (count($e)!==2) return null; - - $i = intval($e[1], 10); - if ($i == 0) return null; - - return self::getEulerProblem($i); - } - - public static function getEulerProblem($num) - { - foreach (self::listAll() as $ep) { - if ($ep['number'] == $num) return $ep; - } - return null; - } - - public static function rateTime($problem) + private static function rateTime($problem) { if ($problem['time'] < 100) // < 100ms return 0; @@ -68,14 +59,40 @@ class Euler return 4; } - public static function checkConsistency() + public function listAll() + { + return $this->staticData; + } + + public function getEulerProblemFromStrIdent($ident) + { + $e = explode('-', $ident, 2); // problem-xxx + if (count($e)!==2) return null; + + $i = intval($e[1], 10); + if ($i == 0) return null; + + return self::getEulerProblem($i); + } + + public function getEulerProblem($num) + { + foreach (self::listAll() as $ep) { + if ($ep['number'] == $num) return $ep; + } + return null; + } + + public function checkConsistency() { $warn = null; + $this->load(); + $numbers = []; $realname = []; - foreach (self::listAll() as $ep) + foreach ($this->staticData as $ep) { if (in_array($ep['number'], $numbers)) return ['result'=>'err', 'message' => 'Duplicate number ' . $ep['number']]; $numbers []= $ep['number']; diff --git a/www/internals/website.php b/www/internals/website.php index ca91737..ded064f 100644 --- a/www/internals/website.php +++ b/www/internals/website.php @@ -21,6 +21,7 @@ class Website /** @var AdventOfCode|null */ private $adventOfCode = null; /** @var Blog|null */ private $blog = null; /** @var Books|null */ private $books = null; + /** @var Euler|null */ private $euler = null; public function init() { @@ -182,6 +183,12 @@ class Website return $this->books; } + public function Euler() + { + if ($this->euler === null) { require_once 'euler.php'; $this->euler = new Euler(); } + return $this->euler; + } + /**