| Server IP : 188.114.97.2 / Your IP : 104.23.243.201 Web Server : Apache/2.4.59 (Debian) System : Linux EDL-STRETCH 4.19.0-27-amd64 #1 SMP Debian 4.19.316-1 (2024-06-25) x86_64 User : edlftp ( 1002) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/nicolasj/www/sms.formationlangues.be/application/models/ |
Upload File : |
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Dashboard_model extends CI_Model {
function __construct() {
parent::__construct();
//$this->_ci =& get_instance();
$this->load->model('crud_model');
}
function chart_course($s,$e){
$start = strtotime($s);
$end = strtotime($e);
$diff_d = ceil(abs($end - $start) / 86400);
$this->db->order_by('LessonDate', 'ASC');
$this->db->where('LessonDate >=',$s);
$this->db->where('LessonDate <=',$e);
$this->db->from('course_scheduled_new');
$data = $this->db->get()->result_array();
$chart_data = [];
$current_day = $s;
$current_courses = [];
$current_courses_nb = 0;
$current_hours = [];
$current_hours_nb = 0;
foreach ($data as $key => $d) {
if( $current_day != $d['LessonDate']){
//set data
$chart_data[$current_day]['courses'] = $current_courses_nb;
$chart_data[$current_day]['hours'] = $current_hours_nb;
//new date
$current_day = $d['LessonDate'];
//reset
$current_courses = [];
$current_courses_nb = 0;
//$current_hours = [];
$current_hours_nb = 0;
}
if(!in_array($d['CourseID'],$current_courses)){
//push course
array_push($current_courses,$d['CourseID']);
$current_courses_nb++;
}
$current_hours_nb++;
}
return $chart_data;
/*
switch ($diff_d) {
case <30:
$this->db->order_by('LessonDate', 'ASC');
$data = $this->db->get_where('course_scheduled_new', array('CourseID' => $course_id),1)->result_array();
break;
case <365:
// code...
break;
case >365:
// code...
break;
default:
// code...
break;
}*/
}
function chart_profit($s,$e){
$start = strtotime($s);
$end = strtotime($e);
$diff_d = ceil(abs($end - $start) / 86400);
$this->db->order_by('LessonDate', 'ASC');
$this->db->where('LessonDate >=',$s);
$this->db->where('LessonDate <=',$e);
$this->db->from('course_scheduled_new');
$data = $this->db->get()->result_array();
$chart_data = [];
$current_day = $s;
$current_courses = [];
$current_courses_nb = 0;
$current_hours = [];
$current_hours_nb = 0;
$current_sell = 0;
$current_cost = 0;
foreach ($data as $key => $d) {
if( $current_day != $d['LessonDate']){
//set data
$chart_data[$current_day]['courses'] = $current_courses_nb;
$chart_data[$current_day]['hours'] = $current_hours_nb;
$chart_data[$current_day]['profit'] = $current_sell - $current_cost ;
//new date
$current_day = $d['LessonDate'];
//reset
$current_courses = [];
$current_courses_nb = 0;
//$current_hours = [];
$current_hours_nb = 0;
$current_sell = 0;
$current_cost = 0;
}
if(!in_array($d['CourseID'],$current_courses)){
//push course
array_push($current_courses,$d['CourseID']);
$current_courses_nb++;
}
$current_hours_nb++;
$lesson_duration = $this->crud_model->get_lesson_duration($d['ID']);
//sell
$student_nb = count($this->crud_model->get_lesson_students($d['ID']));
$lesson_price = $this->crud_model->get_course_price($d['CourseID']);
$current_sell = $student_nb * $lesson_price * $lesson_duration;
//cost
$teacher = $this->crud_model->get_lesson_teacher($d['ID'])[0];
$teacher_price = $this->crud_model->get_teacher_contract($d['CourseID'],$teacher);
$current_cost = $lesson_duration * $teacher_price;
}
return $chart_data;
}
}
?>