| Server IP : 188.114.97.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/libraries/ |
Upload File : |
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
class DataTable {
protected $mode=NULL;
protected $localConfig=array('join'=>array(),'conditions'=>array());
protected $count=NULL;
protected $fullConfig=array('from'=>'','select'=>array(),'order'=>array());
function __construct($config=array()){
if (!empty($config['count'])){
$this->count=$config['count'];
}
$this->total();
}
protected function loadMode($mode){
if ($this->mode!=$mode){
$this->fullConfig[$mode]=$this->localConfig;
}
$this->mode=$mode;
return $this;
}
function total(){
$this->loadMode('total');
return $this;
}
function filter(){
$this->loadMode('filtered');
return $this;
}
public function from($table){
$this->fullConfig['from']=$table;
return $this;
}
public function join($table, $cond, $type = '', $escape = NULL){
$this->fullConfig[$this->mode]['join'][]=array($table, $cond, $type, $escape);
return $this;
}
public function group_start(){
$this->fullConfig[$this->mode]['conditions'][]=array('group_start');
return $this;
}
public function or_group_start(){
$this->fullConfig[$this->mode]['conditions'][]=array('or_group_start');
return $this;
}
public function group_end(){
$this->fullConfig[$this->mode]['conditions'][]=array('group_end');
return $this;
}
public function where($key, $value = NULL, $escape = NULL){
$this->fullConfig[$this->mode]['conditions'][]=array('where',$key, $value, $escape);
return $this;
}
public function like($field, $match = '', $side = 'both', $escape = NULL){
$this->fullConfig[$this->mode]['conditions'][]=array('like',$field,$match,$side,$escape);
return $this;
}
public function or_like($field, $match = '', $side = 'both', $escape = NULL){
$this->fullConfig[$this->mode]['conditions'][]=array('or_like',$field,$match,$side,$escape);
return $this;
}
public function select($select = '*', $escape = NULL){
$this->fullConfig['select'][]=array($select,$escape);
return $this;
}
public function order_by($orderby, $direction = '', $escape = NULL){
$this->fullConfig['order'][]=array($orderby, $direction, $escape);
return $this;
}
public function run(&$target){
$CI=& get_instance();
$CI->db->start_cache();
$CI->db->from($this->fullConfig['from']);
$modes=array('total','filtered');
foreach ($modes AS $m){
$CI->db->start_cache();
if (!empty($this->fullConfig[$m])){
if (!empty($this->fullConfig[$m]['join'])){
foreach($this->fullConfig[$m]['join'] AS $j){
$CI->db->join($j[0],$j[1],$j[2],$j[3]);
}
}
if (!empty($this->fullConfig[$m]['conditions'])){
foreach($this->fullConfig[$m]['conditions'] AS $c){
switch($c[0]){
case 'where':
$CI->db->where($c[1],$c[2],$c[3]);
break;
case 'like':
case 'or_like':
$CI->db->{$c[0]}($c[1],$c[2],$c[3]);//,$c[4]);
break;
case 'group_start';
case 'or_group_start':
case 'group_end':
$CI->db->{$c[0]}();
break;
}
}
}
}
$CI->db->stop_cache();
$target[$m]=$CI->db->select('COUNT('.$this->count.') AS total')->get()->row()->total;
}
$start=$CI->input->post('start')*1;
$length=$CI->input->post('length')*1;
if (!empty($this->fullConfig['select'])){
foreach($this->fullConfig['select'] AS $s){
$CI->db->select($s[0],$s[1]);
}
}
if (!empty($this->fullConfig['order'])){
foreach($this->fullConfig['order'] AS $o){
$CI->db->order_by($o[0],$o[1],$o[2]);
}
}
//$target['datatable_config']=$this->fullConfig;
$target['entries']=$CI->db
->limit($length,$start)
->get()->result_array();
//$target['queries']=$CI->db->queries;
$CI->db->flush_cache();
//$target=$this->fullConfig;
}
public function runhwe(&$target){
//lucky
$CI=& get_instance();
$CI->db->start_cache();
$CI->db->from($this->fullConfig['from']);
$modes=array('total','filtered');
foreach ($modes AS $m){
$CI->db->start_cache();
if (!empty($this->fullConfig[$m])){
if (!empty($this->fullConfig[$m]['join'])){
foreach($this->fullConfig[$m]['join'] AS $j){
$CI->db->join($j[0],$j[1],$j[2],$j[3]);
}
}
if (!empty($this->fullConfig[$m]['conditions'])){
foreach($this->fullConfig[$m]['conditions'] AS $c){
switch($c[0]){
case 'where':
$CI->db->where($c[1],$c[2],$c[3]);
break;
case 'like':
case 'or_like':
$CI->db->{$c[0]}($c[1],$c[2],$c[3]);//,$c[4]);
break;
case 'group_start';
case 'or_group_start':
case 'group_end':
$CI->db->{$c[0]}();
break;
}
}
}
}
$CI->db->stop_cache();
$target[$m]=$CI->db->select('COUNT('.$this->count.') AS total')->get()->row()->total;
}
$start=$CI->input->post('start')*1;
$length=$CI->input->post('length')*1;
if (!empty($this->fullConfig['select'])){
foreach($this->fullConfig['select'] AS $s){
$CI->db->select($s[0],$s[1]);
}
}
if (!empty($this->fullConfig['order'])){
foreach($this->fullConfig['order'] AS $o){
$CI->db->order_by($o[0],$o[1],$o[2]);
}
}
//$target['datatable_config']=$this->fullConfig;
$target['entries']=$CI->db
->limit($length,$start)
->get()->result_array();
//$target['queries']=$CI->db->queries;
$i=0;
foreach($target['entries'] as $value)
{
$courseid= $value['course_id'];
$query = $CI->db->query('SELECT * FROM course_student where course_id="'.$courseid.'"');
$studenttotal=$query->num_rows();
$target['entries'][$i]['totalstudent']=$studenttotal;
$i++;
}
$CI->db->flush_cache();
//$target=$this->fullConfig;
}
public function rungetcoursename(&$target){
$CI=& get_instance();
$CI->db->start_cache();
$CI->db->from($this->fullConfig['from']);
$modes=array('total','filtered');
foreach ($modes AS $m){
$CI->db->start_cache();
if (!empty($this->fullConfig[$m])){
if (!empty($this->fullConfig[$m]['join'])){
foreach($this->fullConfig[$m]['join'] AS $j){
$CI->db->join($j[0],$j[1],$j[2],$j[3]);
}
}
if (!empty($this->fullConfig[$m]['conditions'])){
foreach($this->fullConfig[$m]['conditions'] AS $c){
switch($c[0]){
case 'where':
$CI->db->where($c[1],$c[2],$c[3]);
break;
case 'like':
case 'or_like':
$CI->db->{$c[0]}($c[1],$c[2],$c[3]);//,$c[4]);
break;
case 'group_start';
case 'or_group_start':
case 'group_end':
$CI->db->{$c[0]}();
break;
}
}
}
}
$CI->db->stop_cache();
$target[$m]=$CI->db->select('COUNT('.$this->count.') AS total')->get()->row()->total;
}
$start=$CI->input->post('start')*1;
$length=$CI->input->post('length')*1;
if (!empty($this->fullConfig['select'])){
foreach($this->fullConfig['select'] AS $s){
$CI->db->select($s[0],$s[1]);
}
}
if (!empty($this->fullConfig['order'])){
foreach($this->fullConfig['order'] AS $o){
$CI->db->order_by($o[0],$o[1],$o[2]);
}
}
//$target['datatable_config']=$this->fullConfig;
$target['entries']=$CI->db
->limit($length,$start)
->get()->result_array();
$i=0;
foreach($target['entries'] as $value)
{
$student_id= $value['student_id'];
$dob= $value['dob'];
$diff = (date('Y') - date('Y',strtotime($dob)));
$target['entries'][$i]['age']=$diff;
$query = $CI->db->query('SELECT * FROM course where course_id IN(select course_id from course_student where student_id="'.$student_id.'" )');
$coursename=array();
$teachername=array();
foreach ($query->result() as $row)
{
array_push($coursename,"<a href='".NS_BASE_URL."/course/view/".$row->course_id."'>".$row->name."</a>");
$teacherid=$row->teacher_id;
//echo 'SELECT * FROM user where user_id="'.$teacherid.'"';
//echo "<hr>";
$queryset = $CI->db->query('SELECT * FROM user where user_id="'.$teacherid.'"');
foreach ($queryset->result() as $value)
{
array_push($teachername,"<a href='".NS_BASE_URL."/teacher/view/".$teacherid."'>".$value->first_name." ".$value->last_name."</a>");
}
}
$cournamelist=implode(",",$coursename);
$target['entries'][$i]['coursename']=$cournamelist;
$teachername=implode(",",$teachername);
$target['entries'][$i]['teachername']=$teachername;
$i++;
}
/* print_r($target['entries']);
die();
*/
//$target['queries']=$CI->db->queries;
$CI->db->flush_cache();
//$target=$this->fullConfig;
}
}
?>