tstat_be/app/Models/FlightTripsModel.php

65 lines
1.5 KiB
PHP

<?php
namespace App\Models;
use CodeIgniter\Model;
class FlightTripsModel extends Model
{
protected $table = 'cc_flight_trips';
protected $primaryKey = 'flight_trip_id';
protected $allowedFields = [
'flight_id',
'class',
'from_place',
'to_place',
'date',
'time',
'is_this_exceptional',
'created_by',
'updated_by',
'is_active'
];
protected $useTimestamps = false; // Manual timestamps as per the table design
protected $createdField = 'created_on';
protected $updatedField = 'updated_on';
// Get all active flight trips
public function getActiveTrips()
{
return $this->where('is_active', 1)->findAll();
}
// Get a specific flight trip by ID
public function getTripById($tripId)
{
return $this->where('flight_trip_id', $tripId)->first();
}
// Get trips by flight ID
public function getTripsByFlightId($flightId)
{
return $this->where('flight_id', $flightId)->where('is_active', 1)->findAll();
}
// Insert a new flight trip
public function insertTrip($data)
{
return $this->insert($data);
}
// Update an existing flight trip
public function updateTrip($tripId, $data)
{
return $this->where('flight_trip_id', $tripId)->set($data)->update();
}
// Soft delete (deactivate) a flight trip
public function deactivateTrip($tripId)
{
return $this->where('flight_trip_id', $tripId)->set(['is_active' => 0])->update();
}
}