Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chuck-D-Norris committed Dec 16, 2024
1 parent af827f0 commit 4bde531
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 76 deletions.
1 change: 1 addition & 0 deletions app/src/app/Controllers/Admin/ContractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class ContractController
public function index($queryParams)
{
$contracts = Contract::findAll();

View::render([
'view' => 'Admin/Contracts',
'title' => 'Contracts',
Expand Down
46 changes: 9 additions & 37 deletions app/src/app/Controllers/Admin/EstadistiquesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,28 @@
namespace App\Controllers\Admin;

use App\Core\View;
use App\Models\Estadistiques;
use App\Models\Contract;
use App\Models\TreeType;

class EstadistiquesController
{
public function index($queryParams = [])

Check warning on line 11 in app/src/app/Controllers/Admin/EstadistiquesController.php

View check run for this annotation

Codecov / codecov/patch

app/src/app/Controllers/Admin/EstadistiquesController.php#L11

Added line #L11 was not covered by tests
{
// Obtenim les dades del model correcte
$grafiques = Estadistiques::findAll();

$totalContractes = Contract::count();
$totalTreeTypes = TreeType::count();

Check warning on line 15 in app/src/app/Controllers/Admin/EstadistiquesController.php

View check run for this annotation

Codecov / codecov/patch

app/src/app/Controllers/Admin/EstadistiquesController.php#L14-L15

Added lines #L14 - L15 were not covered by tests

// Comprova si $grafiques és null i assegura't que sigui un array
$contracts = $contracts = Estadistiques::findAll();


$contracts = Contract::findAll();

Check warning on line 20 in app/src/app/Controllers/Admin/EstadistiquesController.php

View check run for this annotation

Codecov / codecov/patch

app/src/app/Controllers/Admin/EstadistiquesController.php#L20

Added line #L20 was not covered by tests

// Renderitzem la vista amb les dades
View::render([
'view' => 'Admin/Grafics',
'title' => 'Grafiques',
'layout' => 'Admin/AdminLayout',
'contracts' => $contracts,
'data' => ['grafics' => $grafiques],
'data' => ['totalContractes' => $totalContractes, 'totalTreeTypes' => $totalTreeTypes],
]);

Check warning on line 28 in app/src/app/Controllers/Admin/EstadistiquesController.php

View check run for this annotation

Codecov / codecov/patch

app/src/app/Controllers/Admin/EstadistiquesController.php#L23-L28

Added lines #L23 - L28 were not covered by tests
}
}
namespace App\Models;

class BaseModel
{
public static function findAll($filters = [], $includeDeleted = false)
{
// Simulació d'una consulta a la base de dades
$result = static::queryDatabase($filters, $includeDeleted);

// Evita que $result sigui null abans de passar-ho a array_map
if (!is_array($result)) {
$result = []; // Inicialitza com a array buit si cal
}

return array_map(function ($item) {
return static::mapToModel($item);
}, $result);
}

private static function queryDatabase($filters, $includeDeleted)
{
// Aquí aniria la lògica per consultar la base de dades
return null; // Simulació d'un resultat null
}

private static function mapToModel($item)
{
// Lògica per mapejar una fila de la base de dades al model
return $item;
}
}
37 changes: 0 additions & 37 deletions app/src/app/Models/Estadistiques.php

This file was deleted.

6 changes: 4 additions & 2 deletions app/src/app/Views/Admin/Grafics.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
<?php else: ?>
<div class="dropdown-item text-gray-500">No hay contratos disponibles</div>
<?php endif; ?>
</div>
</div>
</div>
<div>
<p>Contractes: <?php echo $totalContractes; ?></p>
<p>Tipus: <?php echo $totalTreeTypes; ?></p>

Check warning on line 37 in app/src/app/Views/Admin/Grafics.php

View check run for this annotation

Codecov / codecov/patch

app/src/app/Views/Admin/Grafics.php#L31-L37

Added lines #L31 - L37 were not covered by tests
</div>

<!-- Charts Container -->
Expand Down

0 comments on commit 4bde531

Please sign in to comment.