Se avanza en la pagina de inicio, falta los indicadores

This commit is contained in:
2020-05-12 11:07:58 -04:00
parent fbe1e4f7e5
commit 9084ea5edb
39 changed files with 1027 additions and 45 deletions

View File

@ -1,10 +1,10 @@
<?php
namespace ProVM\KI\Common\Controller\Web;
use Psr\Container\ContainerInterface as Container;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use Slim\Views\Blade as View;
use Psr\Container\ContainerInterface as Container;
use Carbon\Carbon;
class Base {
@ -13,6 +13,30 @@ class Base {
$fecha = ucwords(Carbon::today()->locale('es')->isoFormat('D MMMM'));
$hora = Carbon::now()->format('H:i a');
$visitas = $container->get('visitas');
return $view->render($response, 'home', compact('valor_uf', 'fecha', 'hora', 'visitas'));
$aviso = true;
$filename = implode(DIRECTORY_SEPARATOR, [
$container->get('folders.data'),
'avisos.json'
]);
$avisos = json_decode(trim(file_get_contents($filename)));
$filename = implode(DIRECTORY_SEPARATOR, [
$container->get('folders.data'),
'destacados.json'
]);
$destacados = json_decode(trim(file_get_contents($filename)));
$filename = implode(DIRECTORY_SEPARATOR, [
$container->get('folders.data'),
'segmentos.json'
]);
$segmentos = json_decode(trim(file_get_contents($filename)));
array_walk($segmentos, function(&$item) use ($container) {
if (!isset($item->imagen)) {
$item->imagen = '<div class="ui placeholder"><div class="square image"></div></div>';
return;
}
$item->imagen = '<img src="' . $container->get('urls')->images . '/' . $item->imagen . '" />';
});
$indicadores = ['uf' => 'UF', 'euro' => 'Euro', 'imacec' => 'IMACEC', 'dolar' => 'USD', 'ipc' => 'IPC', 'utm' => 'UTM', 'bitcoin' => 'BitCoin', 'libra_cobre' => 'Lb. Cu'];
return $view->render($response, 'home', compact('valor_uf', 'fecha', 'hora', 'visitas', 'aviso', 'avisos', 'destacados', 'segmentos', 'indicadores'));
}
}

View File

@ -0,0 +1,23 @@
<?php
namespace ProVM\KI\Common\Controller\Web;
use Psr\Container\ContainerInterface as Container;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use Carbon\Carbon;
use ProVM\KI\Common\Service\Indicadores as Service;
class Indicadores {
public function get(Request $request, Response $response, Container $container, Service $service, $indicador) {
$valor = $service->get($indicador, Carbon::today());
$output = [
'sim' => $indicador,
'valor' => $valor
];
$response->getBody()->write(json_encode($output));
return $response
->withHeader('Content-Type', 'application/json')
->withStatus(201);
}
}

View File

@ -0,0 +1,50 @@
<?php
namespace ProVM\KI\Common\Controller\Web;
use Psr\Container\ContainerInterface as Container;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use Slim\Views\Blade as View;
class Proyectos {
public function destacados(Request $request, Response $response, Container $container, $page): Response {
$filename = implode(DIRECTORY_SEPARATOR, [
$container->get('folders.data'),
'destacados.json'
]);
$destacados = json_decode(trim(file_get_contents($filename)));
$max = ceil(count($destacados) / 4);
$output = [
'information' => [
'page' => $page
],
'destacados' => []
];
for ($i = ($page - 1) * 4; $i < $page * 4; $i ++) {
$output['destacados'] []= $destacados[$i];
}
$response->getBody()->write(json_encode($output));
return $response
->withHeader('Content-Type', 'application/json')
->withStatus(201);
}
public function ficha(Request $request, Response $response, Container $container, View $view, $proyecto): Response {
$filename = implode(DIRECTORY_SEPARATOR, [
$container->get('folders.data'),
'proyectos.json'
]);
$proyectos = json_decode(trim(file_get_contents($filename)));
$filename = implode(DIRECTORY_SEPARATOR, [
$container->get('folders.data'),
'destacados.json'
]);
$destacados = json_decode(trim(file_get_contents($filename)));
$destacado = false;
if (array_search($proyecto, $destacados) !== false) {
$destacado = true;
}
$proyecto = $proyectos[$proyecto];
$proyecto->destacado = $destacado;
return $view->render($response, 'home.destacados.ficha', compact('proyecto'));
}
}

View File

@ -34,7 +34,7 @@ class Visits {
if ($ipd->ip == $ip and $ipd->fwd == $fwd) {
$t = Carbon::parse($ipd->time);
if ($t->diffInSeconds($login) > $this->time) {
$file->ips[$i]->time = $t->format('Y-m-d H:i:s');
$file->ips[$i]->time = $login->format('Y-m-d H:i:s');
$file->visits ++;
}
$found = true;

View File

@ -0,0 +1,34 @@
<?php
namespace ProVM\KI\Common\Service;
use GuzzleHttp\Client;
class Indicadores {
//protected $cliente;
protected $base_uri;
public function __construct(string $indicadores_url) {
$this->base_uri = $indicadores_url;
}
public function get(string $indicador, \DateTime $fecha) {
$url = implode('/', [
$this->base_uri,
$indicador,
$fecha->format('d-m-Y')
]);
if ( ini_get('allow_url_fopen') ) {
$json = file_get_contents($url);
} else {
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$json = curl_exec($curl);
curl_close($curl);
}
$data = json_decode($json);
$valor = 0;
if (isset($data->serie[0])) {
$valor = $data->serie[0]->valor;
}
return $valor;
}
}