| Server IP : 188.114.97.2 / Your IP : 104.23.243.200 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 Dash_model extends CI_Model
{
public function __construct()
{
parent::__construct();
//$this->_ci =& get_instance();
$this->load->model('crud_model');
$this->load->model('course_model');
}
public function clear_cache()
{
$this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
$this->output->set_header('Pragma: no-cache');
}
public function fetch_calendar2($start, $end, $role, $filter)
{
if(isset($start) && isset($end)) {
$jsonHours = "";
if($role == 'parent') {
$childs = $this->crud_model->get_child_list($this->session->userdata('userID'));
//var_dump($childs);
foreach ($childs as $key => $r) {
$target = $r["student_id"];
$sql = "SELECT * FROM (SELECT * FROM `course_scheduled_new` WHERE LessonDate >= '".$start."' AND LessonDate <= '".$end."') as c INNER JOIN `course_student_new` ON (c.`ID` = `course_student_new`.`lesson_id`) AND course_student_new.student_id = '".$target."' ORDER BY `LessonDate` DESC;";
//echo $sql;
$courses = $this->db->query($sql)->result_array();
foreach ($courses as $key => $row) {
//var_dump($row);
$array = $this->crud_model->get_lesson_teacher($row['ID']);
//var_dump($array);
$teachers = array();
//var_dump($array);
foreach ($array as $key2 => $row2) {
//echo $row2;
array_push($teachers, $this->crud_model->get_teacher_name($row2));
}
$teacherList = implode(",", $teachers);
$duration = (strtotime($row['LessonEnd']) - strtotime($row['LessonStart'])) / 3600;
$jsonHours = $jsonHours . "{\"id\":\"".$row['CourseID']."\",\"groupId\":\"".$row['ID']."\",\"title\":\"".$this->crud_model->get_course_name($row['CourseID']);
$jsonHours = $jsonHours . "\",\"description\":\"[".$this->crud_model->get_course_name($row['CourseID'])."] \\nTeacher(s): $teacherList\\nClassroom: ".$this->crud_model->get_course_classroom($row['CourseID'])."\\nStudent nb: ".$this->crud_model->get_students_count($row['CourseID'])."\\n Duration: $duration H\\n [".$this->crud_model->get_course_language($row['CourseID'])."]\",\"courseId\":\"".$row['CourseID'];
$jsonHours = $jsonHours . "\",\"color\":\"".$this->color_course($this->crud_model->get_course_local($row['CourseID']))."\",\"teacher\":\"".$teacherList."\",\"start\":\"".$row['LessonDate']."T".$row['LessonStart']."\",\"end\":\"".$row['LessonDate']."T".$row['LessonEnd']."\",\"done\":\"".$row['LessonDone']."\",\"comment\":\"".$row['LessonComment']."\"},";
}
//// DEBUG:
//$jsonHours = "[".rtrim($jsonHours,',')."]";
//return $jsonHours;
}
}
$jsonHours = "[".rtrim($jsonHours, ',')."]";
return $jsonHours;
//$sql= "'SELECT * FROM (SELECT * FROM `course_scheduled_new` WHERE LessonDate >= '$start' AND LessonDate <= '$end') as c INNER JOIN `course_student_new` ON (c.`ID` = `course_student_new`.`student_id`) AND course_student_new.student_id = '$target' ORDER BY `LessonDate` DESC;'");
}
}
public function fetch_calendar($start, $end, $role, $filter)
{
if(isset($start) && isset($end)) {
$this->db->select('*');
$this->db->from('course_scheduled_new');
$this->db->where('LessonDate <=', $end);
$this->db->where('LessonDate >=', $start);
$data = $this->db->get();
$courses = $data->result_array();
$jsonHours = "";
foreach ($courses as $key => $row) {
$array = $this->crud_model->get_lesson_teacher($row['ID']);
$teachers = array();
foreach ($array as $key2 => $row2) {
array_push($teachers, $this->crud_model->get_teacher_name($row2));
}
$teacherList = implode(",", $teachers);
$duration = (strtotime($row['LessonEnd']) - strtotime($row['LessonStart'])) / 3600;
//return substr($filter,0,7);
if($role == "teacher" && $this->crud_model->check_teacher($row['CourseID'], $this->userInfo['user_id'])) {
if($filter == 'null' || $this->crud_model->get_course_local($row['CourseID']) == $filter) {
$jsonHours = $jsonHours . "{\"id\":\"".$row['CourseID']."\",\"groupId\":\"".$row['ID']."\",\"title\":\"".$this->crud_model->get_course_name($row['CourseID']);
$jsonHours = $jsonHours . "\",\"description\":\"[".$this->crud_model->get_course_name($row['CourseID'])."] \\nTeacher(s): $teacherList\\nClassroom: ".$this->crud_model->get_course_classroom($row['CourseID'])."\\nStudent nb: ".$this->crud_model->get_students_count($row['CourseID'])."\\n Duration: $duration H\\n [".$this->crud_model->get_course_language($row['CourseID'])."]\",\"courseId\":\"".$row['CourseID'];
$jsonHours = $jsonHours . "\",\"color\":\"".$this->color_course($this->crud_model->get_course_local($row['CourseID']))."\",\"teacher\":\"".$teacherList."\",\"start\":\"".$row['LessonDate']."T".$row['LessonStart']."\",\"end\":\"".$row['LessonDate']."T".$row['LessonEnd']."\",\"done\":\"".$row['LessonDone']."\",\"comment\":\"".$row['LessonComment']."\"},";
}
} elseif(($role == "student" || $role == "group") && $this->crud_model->check_student($row['CourseID'], $this->userInfo['user_id'])) {
if ($filter == 'null' || $this->crud_model->get_course_local($row['CourseID']) == $filter) {
$jsonHours = $jsonHours . "{\"id\":\"".$row['CourseID']."\",\"groupId\":\"".$row['ID']."\",\"title\":\"".$this->crud_model->get_course_name($row['CourseID']);
$jsonHours = $jsonHours . "\",\"description\":\"[".$this->crud_model->get_course_name($row['CourseID'])."] \\nTeacher(s): $teacherList\\nClassroom: ".$this->crud_model->get_course_classroom($row['CourseID'])."\\nStudent nb: ".$this->crud_model->get_students_count($row['CourseID'])."\\n Duration: $duration H\\n [".$this->crud_model->get_course_language($row['CourseID'])."]\",\"courseId\":\"".$row['CourseID'];
$jsonHours = $jsonHours . "\",\"color\":\"".$this->color_course($this->crud_model->get_course_local($row['CourseID']))."\",\"teacher\":\"".$teacherList."\",\"start\":\"".$row['LessonDate']."T".$row['LessonStart']."\",\"end\":\"".$row['LessonDate']."T".$row['LessonEnd']."\",\"done\":\"".$row['LessonDone']."\",\"comment\":\"".$row['LessonComment']."\"},";
}
} elseif($role == "parent") {
$childs = $this->crud_model->get_child_list($this->session->userdata('userID'));
if($this->crud_model->check_childs($row['CourseID'], $childs)) {
$jsonHours = $jsonHours . "{\"id\":\"".$row['CourseID']."\",\"groupId\":\"".$row['ID']."\",\"title\":\"".$this->crud_model->get_course_name($row['CourseID']);
$jsonHours = $jsonHours . "\",\"description\":\"[".$this->crud_model->get_course_name($row['CourseID'])."] \\nTeacher(s): $teacherList\\nClassroom: ".$this->crud_model->get_course_classroom($row['CourseID'])."\\nStudent nb: ".$this->crud_model->get_students_count($row['CourseID'])."\\n Duration: $duration H\\n [".$this->crud_model->get_course_language($row['CourseID'])."]\",\"courseId\":\"".$row['CourseID'];
$jsonHours = $jsonHours . "\",\"color\":\"".$this->color_course($this->crud_model->get_course_local($row['CourseID']))."\",\"teacher\":\"".$teacherList."\",\"start\":\"".$row['LessonDate']."T".$row['LessonStart']."\",\"end\":\"".$row['LessonDate']."T".$row['LessonEnd']."\",\"done\":\"".$row['LessonDone']."\",\"comment\":\"".$row['LessonComment']."\"},";
}
} elseif($role == "admin") {
if($filter == "c") {
if ($filter == 'null' || $this->crud_model->get_course_local($row['CourseID']) == "1" || $this->crud_model->get_course_local($row['CourseID']) == "2" || $this->crud_model->get_course_local($row['CourseID']) == "5") {
$jsonHours = $jsonHours . "{\"id\":\"".$row['CourseID']."\",\"groupId\":\"".$row['ID']."\",\"title\":\"".$this->crud_model->get_course_name($row['CourseID']);
$jsonHours = $jsonHours . "\",\"description\":\"[".$this->crud_model->get_course_name($row['CourseID'])."] \\nTeacher(s): $teacherList\\nClassroom: ".$this->crud_model->get_local_name($this->crud_model->get_course_local($row['CourseID']))."\\nStudent nb: ".$this->crud_model->get_students_count($row['CourseID'])."\\n Duration: $duration H\\n [".$this->crud_model->get_course_language($row['CourseID'])."]\",\"courseId\":\"".$row['CourseID'];
$jsonHours = $jsonHours . "\",\"color\":\"".$this->color_course($this->crud_model->get_course_local($row['CourseID']))."\",\"teacher\":\"".$teacherList."\",\"start\":\"".$row['LessonDate']."T".$row['LessonStart']."\",\"end\":\"".$row['LessonDate']."T".$row['LessonEnd']."\",\"done\":\"".$row['LessonDone']."\",\"comment\":\"".$row['LessonComment']."\"},";
}
} elseif(substr($filter, 0, 7) == "search:") {
$search = strtolower(urldecode(substr($filter, 7)));
$title = strtolower($this->crud_model->get_course_name($row['CourseID']));
$teachers = strtolower($teacherList);
//$jsonHours = $jsonHours .$this->search_students($row['CourseID'],$search);
if($this->search_students($row['CourseID'], $search) || $this->search_data($title, $search) || $this->search_data($teachers, $search)) {
$jsonHours = $jsonHours . "{\"id\":\"".$row['CourseID']."\",\"groupId\":\"".$row['ID']."\",\"title\":\"".$this->crud_model->get_course_name($row['CourseID']);
$jsonHours = $jsonHours . "\",\"description\":\"[".$this->crud_model->get_course_name($row['CourseID'])."] \\nTeacher(s): $teacherList\\nClassroom: ".$this->crud_model->get_local_name($this->crud_model->get_course_local($row['CourseID']))."\\nStudent nb: ".$this->crud_model->get_students_count($row['CourseID'])."\\n Duration: $duration H\\n [".$this->crud_model->get_course_language($row['CourseID'])."]\",\"courseId\":\"".$row['CourseID'];
$jsonHours = $jsonHours . "\",\"color\":\"".$this->color_course($this->crud_model->get_course_local($row['CourseID']))."\",\"teacher\":\"".$teacherList."\",\"start\":\"".$row['LessonDate']."T".$row['LessonStart']."\",\"end\":\"".$row['LessonDate']."T".$row['LessonEnd']."\",\"done\":\"".$row['LessonDone']."\",\"comment\":\"".$row['LessonComment']."\"},";
}
} else {
if($filter == 'null' || $this->crud_model->get_course_local($row['CourseID']) == $filter) {
$jsonHours = $jsonHours . "{\"id\":\"".$row['CourseID']."\",\"groupId\":\"".$row['ID']."\",\"title\":\"".$this->crud_model->get_course_name($row['CourseID']);
$jsonHours = $jsonHours . "\",\"description\":\"[".$this->crud_model->get_course_name($row['CourseID'])."] \\nTeacher(s): $teacherList\\nClassroom: ".$this->crud_model->get_local_name($this->crud_model->get_course_local($row['CourseID']))."\\nStudent nb: ".$this->crud_model->get_students_count($row['CourseID'])."\\n Duration: $duration H\\n [".$this->crud_model->get_course_language($row['CourseID'])."]\",\"courseId\":\"".$row['CourseID'];
$jsonHours = $jsonHours . "\",\"color\":\"".$this->color_course($this->crud_model->get_course_local($row['CourseID']))."\",\"teacher\":\"".$teacherList."\",\"start\":\"".$row['LessonDate']."T".$row['LessonStart']."\",\"end\":\"".$row['LessonDate']."T".$row['LessonEnd']."\",\"done\":\"".$row['LessonDone']."\",\"comment\":\"".$row['LessonComment']."\"},";
}
}
}
}
$jsonHours = "[".rtrim($jsonHours, ',')."]";
}
return $jsonHours;
}
/**
* Return events (lessons) for calendar
*
* REMOVE THIS: {
*
* id: "1407"
* groupId: "25966"
* title: "BF Sept Oct 23 - FR BOTA "
* description: "[BF Sept Oct 23 - FR BOTA ]"
* courseId: "1407"
* color: "#5b9bd5"
* teacher: "Martine Vanhulle"
* start: "2023-09-25T13:00:00"
* end: "2023-09-25T14:30:00"
* done: ""
* comment: null
* }
*
* @param Datetime $start
* @param Datetime $end
* @param string $role
* @param string $filter
* @return Array
*/
public function get_teacher_courses_calendar(int $teacher_id, Datetime $start, Datetime $end, string $filter): array
{
$teacher_lessons = [];
$query = "SELECT *, COUNT(cst.id) AS students_count FROM `course_teacher` ct
LEFT JOIN `course_scheduled_new` cs ON cs.ID = ct.lesson_id
LEFT JOIN `course_new` c ON c.ID = cs.courseID
LEFT JOIN `course_local` cl ON cl.course_local_id = c.CourseLocal
LEFT JOIN `user` u ON u.user_id = ct.teacher_id
LEFT JOIN `course_student_new` cst ON cst.lesson_id = ct.lesson_id
WHERE ct.teacher_id = $teacher_id AND cs.LessonDate >= CAST('{$start->format('Y-m-d')}' AS DATE) AND cs.LessonDate <= CAST('{$end->format('Y-m-d')}' AS DATE)";
if ($filter != 'null') {
$query .= " AND CourseLocal = " . (int) $filter;
}
$query .= " GROUP BY ct.lesson_id";
$lessons_raw = $this->db->query($query)->result_array();
$languages = [];
foreach ($this->crud_model->get_languages() as $language) {
$languages[(int) $language['course_language_id']] = $language['code'];
}
foreach ($lessons_raw as $lesson) {
$duration = (strtotime($lesson['LessonEnd']) - strtotime($lesson['LessonStart'])) / 3600;
$teacher_lessons[] = [
'id' => $lesson['CourseID'],
'groupId' => $lesson['ID'],
'title' => ucfirst($lesson['CourseName']),
'description' => "[" . ucfirst($lesson['CourseName']) . "]\n" .
"Teacher(s): " . ucfirst($lesson['first_name']) . ' ' . ucfirst($lesson['last_name']) . "\n" .
"Classroom:\n" .
"Student nb: " . $lesson['students_count'] . "\n" .
"Duration: $duration H \n" .
"[" . $languages[(int) $lesson['CourseLanguage']] . "]",
'courseId' => null,
'color' => $lesson['color'],
'teacher' => [ucfirst($lesson['first_name']) . ' ' . ucfirst($lesson['last_name'])],
'start' => $lesson['LessonDate']."T".$lesson['LessonStart'],
'end' => $lesson['LessonDate']."T".$lesson['LessonEnd'],
'done' => $lesson['LessonDone'],
'comment' => $lesson['LessonComment'],
];
}
return $teacher_lessons;
}
public function color_course($id)
{
$color = $this->crud_model->get_bgColor($id);
//$bgColor
//$n = crc32($id);
//$n &= 0xffffffff;
//return("#".substr("000000".dechex($n),-6));
return $color;
}
public function get_icon($id)
{
// $icon = $this->crud_model->get_bgIcon($id);
return $icon;
}
public function search_students($course, $search)
{
$students = $this->crud_model->get_course_students_n($course);
foreach ($students as $key => $student) {
$name = strtolower($this->crud_model->get_student_name($student));
if (strpos($name, $search) !== false) {
return true;
}
}
return false;
}
public function search_data($data, $search)
{
if (strpos($data, $search) !== false) {
return true;
} else {
return false;
}
}
}