public function injectContainer() { $container = $this->slim->getContainer(); // Register component on container // inject config $container["config_folder"] = $this->configFolder; $container["config"] = function (ContainerInterface $container) { $files = scandir($container["config_folder"]); $configs = []; foreach ($files as $item) { $path = $container["config_folder"] . "/" . $item; if (is_file($path)) { $name = basename($path, ".php"); $configs[$name] = (include $path); } } return $configs; }; // injection aura/session $container["session"] = function (ContainerInterface $container) { $session_factory = new SessionFactory(); return $session_factory->newInstance($_COOKIE); }; // injection twig-view template engine $container["view"] = function (ContainerInterface $container) { // get aura session add global to twig-view $session = $container["session"]; $segment = $session->getSegment("login"); // new instance twig-view $view = new \Slim\Views\Twig($container["config"]["twig"]["templates"], []); $view->getEnvironment()->addGlobal('login', $segment); // add extension slim $view->addExtension(new \Slim\Views\TwigExtension($container["router"], $container["request"]->getUri())); $view->addExtension(new \Twig_Extension_Debug()); return $view; }; // injection medoo database libary $container["medoo"] = function (ContainerInterface $container) { return new \medoo($container["config"]["medoo"]); }; // ser xml resourcePath XMLService::setResourcePath($container->config["config"]["resource_path"] . "/resource/"); }
public function buildItem(&$item) { $container = $this->slim->getContainer(); $db = $container->medoo; $dateRegex = "/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])\$/"; $item["age"] = preg_match($dateRegex, $item["birth_date"]) ? \DateTime::createFromFormat('Y-m-d', $item["birth_date"])->diff(new \DateTime('now'))->y : null; $item["die_date"] = preg_match($dateRegex, $item["die_date"]) ? $this->budDate($item["die_date"]) : null; $item["reg_date"] = preg_match($dateRegex, $item["reg_date"]) ? $this->budDate($item["reg_date"]) : null; $item["birth_date"] = preg_match($dateRegex, $item["birth_date"]) ? $this->budDate($item["birth_date"]) : null; $oldersService = XMLService::getInstance("olders"); $cripplesService = new CrippleService($db); $disavantagedsService = new DisavantagedService($db); $scholarsService = new ScholarService($db); $item["older"] = $oldersService->getBy(["min[<=]" => $item["age"], "max[>=]" => $item["age"]]); $item["cripple"] = $db->select("person_cripple", ["[>]cripple_type" => ["cripple_id" => "id"]], "*", ["person_id" => $item["id"]]); $item["disavantaged"] = $db->select("person_disavantaged", ["[>]disavantaged_type" => ["disavantaged_id" => "id"]], "*", ["person_id" => $item["id"]]); $item["scholar"] = $db->select("person_scholar", ["[>]scholar_type" => ["scholar_id" => "id"]], "*", ["person_id" => $item["id"]]); $item["total_allowance"] = 0; $item["total_allowance"] += $item["is_older"] ? @$item["older"]["allowance"] : 0; // foreach($item["cripple"] as $val) { // $item["total_allowance"] += $val["allowance"]; // } // foreach($item["disavantaged"] as $val) { // $item["total_allowance"] += $val["allowance"]; // } // foreach($item["scholar"] as $val) { // $item["total_allowance"] += $val["allowance"]; // } $item["total_allowance"] += count($item["cripple"]) > 0 ? 800 : 0; $item["total_allowance"] += count($item["disavantaged"]) > 0 ? 500 : 0; // $item["total_allowance"] += count($item["scholar"]); }
public function older(Request $req, Response $res) { $container = $this->slim->getContainer(); $db = $container->medoo; $oldersService = XMLService::getInstance("olders"); $olders = $oldersService->gets(); foreach ($olders as &$older) { $dateMin = new \DateTime('now'); $dateMax = new \DateTime('now'); $where = []; $dateMin->sub(new \DateInterval('P' . $older["min"] . 'Y')); $where["birth_date[<=]"] = $dateMin->format("Y-m-d"); if ($older["min"] < 90) { $dateMax->sub(new \DateInterval('P' . ($older["max"] + 1) . 'Y')); $where["birth_date[>]"] = $dateMax->format("Y-m-d"); } $where = ["AND" => $where]; $older["count"] = $db->count("person", ["AND" => $where]); } return $container->view->render($res, "report/older.twig", ["olders" => $olders, "today" => $this->getToday()]); }