BBnepal-Accounts/application/models/Parent_driver_model.php
Sampanna Rimal 9cd05ef3cb commitall
2024-07-10 18:28:19 +05:45

152 lines
5.2 KiB
PHP

<?php
defined('BASEPATH') or exit('No direct script access allowed');
use Nilambar\NepaliDate\NepaliDate;
require_once 'vendor/autoload.php';
class Parent_driver_model extends CI_Model
{
public function __construct()
{
$this->load->database();
$this->load->helper('common_helper');
$this->nepaliDateObject = new NepaliDate();
$this->nepali_current_date = cuurentNepaliDate($this->nepaliDateObject);
}
public function parentlogin($uname, $pwd)
{
$pwd = md5($pwd);
$sql = $this->db->query("SELECT * FROM students WHERE parent_username='$uname' AND parent_password='$pwd'");
// echo $this->db->last_query($sql);
if ($sql->num_rows() > 0) {
if ($sql->row()->is_active == 'yes') {
return $sql->row_object();
} else {
return false;
}
} else {
return false;
}
}
// to get application fee by shivu -start
public function get_query_result($sqlQry)
{
if ($sqlQry != '')
$query = $this->db->query($sqlQry);
return $query->result_array();
}
public function get_query_row($sqlQry)
{
if ($sqlQry != '')
$query = $this->db->query($sqlQry);
return $query->row_array();
}
//Driver Login
public function driverlogin($uname, $pwd)
{
$bus_db = $this->load->database('erisnClassroom_bts', TRUE);
$pwd = md5($pwd);
$sql = $bus_db->query("SELECT * FROM bt_drivers WHERE driver_id='$uname' AND password='$pwd'");
// echo $this->db->last_query($sql);
if ($sql->num_rows() > 0) {
if ($sql->row()) {
return $sql->row_object();
} else {
return false;
}
} else {
return false;
}
}
public function getDriverPickPoint($id)
{
$bus_db = $this->load->database('erisnClassroom_bts', TRUE);
$sql = $bus_db->query("SELECT pickup_start as start_time, place_name as stat_point, working_id, br.id as route_id FROM bt_drivers bd,bt_routes br, bt_routes_details brd WHERE br.id='$id' and bd.id = br.driver_id and br.id = brd.route_id order by route_order asc limit 1")->row_array();
return $sql;
}
public function getDriverDropPoint($id)
{
$bus_db = $this->load->database('erisnClassroom_bts', TRUE);
$sql = $bus_db->query("SELECT drop_start as start_time, place_name as stat_point, working_id, br.id as route_id FROM bt_drivers bd,bt_routes br, bt_routes_details brd WHERE br.id='$id' and bd.id = br.driver_id and br.id = brd.route_id order by route_order desc limit 1")->row_array();
return $sql;
}
public function get_query_result_bus_tracking($sqlQry)
{
$bus_db = $this->load->database('erisnClassroom_bts', TRUE);
if ($sqlQry != '')
$query = $bus_db->query($sqlQry);
return $query->result_array();
}
public function get_query_row_bus_tracking($sqlQry)
{
$bus_db = $this->load->database('erisnClassroom_bts', TRUE);
if ($sqlQry != '')
$query = $bus_db->query($sqlQry);
return $query->row_array();
}
public function get_Count_Student_routes_details($pick_id)
{
$bus_db = $this->load->database('erisnClassroom_bts', TRUE);
$query = $bus_db->query('select count(id) as student_count from bt_students_bus_route_details where pick_up_id ='.$pick_id);
return $query->row_array();
}
public function get_Count_Student_trip_details($id)
{
$bus_db = $this->load->database('erisnClassroom_bts', TRUE);
$query = $bus_db->query("select count(bst.id) as student_count from bt_students_trip bst, bt_trips bt where bst.trip_id =$id and bst.trip_id = bt.id");
return $query->row_array();
}
public function getDriverId($id)
{
$bus_db = $this->load->database('erisnClassroom_bts', TRUE);
$result = $bus_db->query('select id from bt_drivers where driver_id = "'. $id . '"')->row_array();
return $result;
}
public function checkTripCompletion($route_id, $trip_type)
{
$bus_db = $this->load->database('erisnClassroom_bts', TRUE);
$result = $bus_db->query('SELECT bt.*,br.stops FROM bt_trips bt , bt_routes br WHERE bt.route_id = '.$route_id.' AND trip_type="'.$trip_type.'" AND DATE(bt.created) = "'.date('Y-m-d', strtotime($this->nepali_current_date)) .'" AND bt.route_id = br.id group by bt.id order by bt.id DESC');
if ($result->num_rows() > 0) {
$data = $result->row_array();
$count = $bus_db->query('SELECT count(bt.id) as count FROM bt_trips bt , bt_routes br WHERE br.id = '.$route_id.' AND DATE(bt.created) = "'.date('Y-m-d', strtotime($this->nepali_current_date)) .'"')->row_array();
if ($data['stops'] == $count['count']) {
if (strtolower($data['status']) == 'completed')
return 2;
else
return 1;
}
else{
return 1;
}
} else {
return 0;
}
return $result;
}
}