add new ststs feature
Deploy to Shared Hosting / Shared hosting deploy (push) Failing after 51s
Tests / PHPUnit (push) Successful in 1m25s

This commit is contained in:
root
2026-09-13 02:20:14 -04:00
parent 1787144f27
commit c3a30989b2
16 changed files with 1395 additions and 84 deletions
@@ -0,0 +1,64 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class RenameAndGrantSchoolStatisticsNavItem extends Migration
{
private string $url = 'administrator/stats';
public function up(): void
{
$navItemId = $this->rename('School Statistics');
if ($navItemId <= 0 || ! $this->db->tableExists('role_nav_items')) {
return;
}
foreach (['administrator', 'admin', 'principal', 'vice_principal', 'administrative staff', 'head of department (education)'] as $role) {
$roleRow = $this->db->table('roles')
->select('id')
->where('LOWER(name)', strtolower($role))
->get()
->getRowArray();
if ($roleRow === null) {
continue;
}
$roleId = (int) $roleRow['id'];
$exists = $this->db->table('role_nav_items')
->where('role_id', $roleId)
->where('nav_item_id', $navItemId)
->countAllResults() > 0;
if (! $exists) {
$this->db->table('role_nav_items')->insert([
'role_id' => $roleId,
'nav_item_id' => $navItemId,
'created_at' => date('Y-m-d H:i:s'),
]);
}
}
}
public function down(): void
{
$this->rename('Academic Statistics');
}
private function rename(string $label): int
{
if (! $this->db->tableExists('nav_items')) {
return 0;
}
$row = $this->db->table('nav_items')->select('id')->where('url', $this->url)->get()->getRowArray();
if ($row === null) {
return 0;
}
$navItemId = (int) $row['id'];
$this->db->table('nav_items')->where('id', $navItemId)->update(['label' => $label]);
return $navItemId;
}
}