| Server IP : 188.114.96.2 / Your IP : 104.23.197.231 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 Archive_model extends CI_Model
{
public function __construct()
{
parent::__construct();
$this->load->model('crud_model');
}
public function archive_course($id)
{
$this->db->set('Archived', '1');
$this->db->where('ID', $id);
$this->db->update('course_new');
return true;
}
public function unarchive_course($id)
{
$this->db->set('Archived', '2');
$this->db->where('ID', $id);
$this->db->update('course_new');
return true;
}
public function unarchive_user($id)
{
$this->db->set('Archived', '2');
$this->db->where('user_id', $id);
$this->db->update('user');
return true;
}
public function archive_courses()
{
//$this->db->order_by('ID', 'DESC');
//$query = $this->db->get('course_new');
//$query = $query->result_array();
$courses = $this->crud_model->get_courses();
$debug = array();
foreach ($courses as $course) {
/*
$this->db->set('Archived','0');
$this->db->where('ID',$course["ID"]);
$this->db->update('course_new');
*/
$endDate = $this->crud_model->get_course_end($course["ID"]);
if(($this->checkArchived($endDate, "courses") == true) && ($this->checkArchiveState("ucourse", $row['ID'])== false)) {
$this->db->set('Archived', '1');
$this->db->where('ID', $course["ID"]);
$this->db->update('course_new');
array_push($debug, array("course"=>$course["ID"],"course"=>$course["CourseName"],"to-archive"=>"yes","end-date"=>$endDate,"debug"=>$this->checkArchived($endDate, "courses")));
} elseif (($this->checkArchived($endDate, "courses") == false)&&($this->checkArchiveState("ucourse", $row['ID']) == false)) {
$this->db->set('Archived', '0');
$this->db->where('ID', $course["ID"]);
$this->db->update('course_new');
//array_push($debug,array("course"=>$course["ID"],"archived"=>"no"));
} else {
}
}
return $debug;
//return true;
}
public function archive_parents()
{
$this->db->from('parent');
$this->db->order_by("parent_id", "desc");
$query = $this->db->get();
$query = $query->result_array();
$currentId = "";
foreach ($query as $row) {
$childs = $this->crud_model->get_child_list($row['parent_id']);
if(!empty($childs)) {
foreach($childs as $child) {
$history = $this->crud_model->getLastAssignedS($child['student_id']);
$creation = $this->crud_model->getCreation($child['student_id']);
if($history != null) {
if($this->checkArchived($history, "student")) {
if ($currentId != $row['parent_id']) {
$this->db->set('Archived', '1');
$this->db->where('user_id', $row['parent_id']);
$this->db->update('user');
$currentId = $row['parent_id'];
}
}
} else {
if($this->checkArchived($creation, "student")) {
if ($currentId != $row['parent_id']) {
$this->db->set('Archived', '1');
$this->db->where('user_id', $row['parent_id']);
$this->db->update('user');
$currentId = $row['parent_id'];
}
}
}
}
} else {
$creation = $this->crud_model->getCreation($row['parent_id']);
if($this->checkArchived($creation, "student")) { //exception on parent rule
$this->db->set('Archived', '1');
$this->db->where('user_id', $row['parent_id']);
$this->db->update('user');
}
}
}
return true;
}
public function archive_teachers()
{
$this->db->from('teacher');
$this->db->order_by("teacher_id", "desc");
$query = $this->db->get();
$query = $query->result_array();
$result = array();
foreach ($query as $row) {
$history = $this->crud_model->getLastAssignedT($row['teacher_id']);
$creation = $this->crud_model->getCreation($row['teacher_id']);
if($history != null) {
if($this->checkArchived($history, "teacher")) {
$this->db->set('Archived', '1');
$this->db->where('user_id', $row['teacher_id']);
$this->db->update('user');
}
} else {
if($this->checkArchived($creation, "teacher")) {
$this->db->set('Archived', '1');
$this->db->where('user_id', $row['student_id']);
$this->db->update('user');
}
}
}
return true;
}
public function archive_student()
{
$query = $this->db->query("SELECT `student_id`,`dob` FROM `student` UNION SELECT `group_id`,`dob` FROM `group` ORDER BY `student_id`");
$query = $query->result_array();
$debug = array();
$result = array();
foreach ($query as $row) {
$history = $this->crud_model->getLastAssignedS($row['student_id']);
$creation = $this->crud_model->getCreation($row['student_id']);
if($history != null) {
if($this->checkArchived($history, "student")) {
$this->db->set('Archived', '1');
$this->db->where('user_id', $row['student_id']);
$this->db->update('user');
//array_push($debug,array("user"=>$course["student_id"],"to-archive"=>"yes","end-date"=>$endDate,"debug"=>$this->checkArchived($endDate,"courses")));
}
} else {
if($this->checkArchived($creation, "student")) {
$this->db->set('Archived', '1');
$this->db->where('user_id', $row['student_id']);
$this->db->update('user');
}
}
}
return true;
}
public function get_archived_courses()
{
$this->db->order_by('ID', 'DESC');
$query = $this->db->get('course_new');
$query = $query->result_array();
$result = array();
foreach ($query as $row) {
if($this->checkArchiveState($row['ID'], "courses")) {
array_push($result, $row);
}
}
return $result;
}
public function get_archived_users()
{
$this->db->order_by('user_id', 'DESC');
$query = $this->db->get('user');
$query = $query->result_array();
$result = array();
foreach ($query as $row) {
if($this->checkArchiveState($row['user_id'], "user")) {
array_push($result, $row);
}
}
return $result;
}
public function get_archive_prop()
{
$limit = date("Y-m-d", strtotime("-3 months"));
$this->db->order_by('CourseCreation', 'ASC');
$this->db->where('CourseCreation <=', $limit);
$query = $this->db->get('course_new');
$query = $query->result_array();
$result = array();
foreach ($query as $row) {
if(!$this->checkArchiveState($row['ID'], "courses")) {
array_push($result, $row);
}
}
return $result;
}
public function checkArchived($date, $param)
{
if($date == "n/a") {
return false;
}
$end = date("d-m-Y", strtotime(str_replace("/", "-", $date)));
if(strtotime($end) >= strtotime($this->archivedTime($param))) {
return false;
} else {
return true;
}
}
public function archivedTime($param)
{
$query = $this->db->get_where('admin_archive', array('Archived_param'=>$param));
$query = $query->result_array();
foreach ($query as $row) {
return date("d-m-Y", strtotime("-".$row['Archived_period']." months"));
}
}
public function checkArchiveState($id, $param)
{
if($param == "courses") {
$query = $this->db->get_where('course_new', array('ID' => $id));
$query = $query->result_array();
foreach ($query as $row) {
if($row['Archived'] == 1) {
return true;
} else {
return false;
}
}
} elseif($param == "ucourses") {
$query = $this->db->get_where('course_new', array('ID' => $id));
$query = $query->result_array();
foreach ($query as $row) {
if($row['Archived'] == 2) {
return true; // return true if already unarchived
} else {
return false;
}
}
} elseif($param == "user") {
$query = $this->db->get_where('user', array('user_id' => $id));
$query = $query->result_array();
foreach ($query as $row) {
if($row['Archived'] == 1) {
return true;
} else {
return false;
}
}
} else {
return false;
}
}
}