<?php
/*
* Generated by CRUDigniter v3.2
* www.crudigniter.com
*/
class Ecritureplanning_model extends CI_Model
{
function __construct()
{
parent::__construct();
}
/*
* Get jourrepos by id
*/
function get_ecritureplanning($id)
{
return $this->db->get_where('ecritureplanning',array('id'=>$id))->row_array();
}
function get_all_ecritueplanning_by_date($datedebut, $datefin)
{
$this->db->where(date("Y-m-d",strtotime($datedebut)));
$this->db->where(date("Y-m-d",strtotime($datefin)));
$this->db->order_by("planning.id", "desc");
$this->db->select("*, planning.id as idplanning ");
$this->db->from('ecritureplanning');
$query = $this->db->get()->result_array();
return $query;
}
/*
* Get all jourrepos count
*/
function get_all_ecriture_count()
{
$this->db->from('ecritureplanning');
return $this->db->count_all_results();
}
function isferie($date){
$this->db->where("date",$date);
return $this->db->get("jourferie")->num_rows()>0;
}
/*
* Get all jourrepos
*/
function get_all_ecriture($params = array())
{
$this->db->order_by('planning.id', 'desc');
if(isset($params) && !empty($params))
{
$this->db->limit($params['limit'], $params['offset']);
}
$this->db->select("*, planning.id as idplanning");
$this->db->from('ecritureplanning');
$this->db->join('planning', 'planning.id = ecritureplanning.planning_id');
$this->db->group_by("planning_id");
return $this->db->get()->result_array();
}
/*
* function to add new jourrepos
*/
function is_ecriture_exist($jour){
$this->db->where("jour",$jour);
return $this->db->get("ecritureplanning")->num_rows()>0;
}
function get_ecriture_by_jour($jour){
$this->db->where("jour",$jour);
return $this->db->get("ecritureplanning")->row_array();
}
function add_ecriture($params)
{
$this->db->insert('ecritureplanning',$params);
return $this->db->insert_id();
}
function update_ecriture($id,$params)
{
$this->db->where('id',$id);
return $this->db->update('ecritureplanning',$params);
}
/*
* function to update jourrepos
*/
/*
* function to delete jourrepos
*/
function delete_by_periode($datedebut,$datefin)
{
return $this->db->delete('ecritureplanning',array('jour>='=>$datedebut,'jour<='=>$datefin));
}
function delete_by_planning($id)
{
return $this->db->delete('ecritureplanning',array('planning_id'=>$id));
}
function IsInTimeDemande($date,$id){
return $this->db->query("select * from ecritureplanning where ((STR_TO_DATE('".$date."', '%Y-%m-%d %T') >= cast(concat(jour, ' ', tempdebut) as datetime) and STR_TO_DATE('".$date."', '%Y-%m-%d %T') <= cast(concat(jour, ' ', pausedebut) as datetime) ) or (STR_TO_DATE('".$date."', '%Y-%m-%d %T') >= cast(concat(jour, ' ', pausefin) as datetime) and STR_TO_DATE('".$date."', '%Y-%m-%d %T') <= cast(concat(jour, ' ', tempfin) as datetime) )) and jour = STR_TO_DATE('".$date."', '%Y-%m-%d') and planning_id=".$id)->num_rows();
}
function get_count_ferie_in_periode($debut,$fin){
$jours =array();
$jours[] = date('Y-m-d', strtotime($debut));
$day = $debut;
$date1 = new DateTime($debut);
$date2 = new DateTime($fin);
$interval = $date1->diff($date2);
for($i=1;$i<=$interval->days;$i++){
$day = date('Y-m-d', strtotime('+1 day', strtotime($day)));
$jours[]= $day;
}
$count =0;
$user = $this->session->userdata("auth");
foreach($jours as $currentdate){
$count += $this->db->query("select * from ecritureplanning where STR_TO_DATE('".$currentdate."', '%Y-%m-%d') = jour and planning_id=".$user["planning_id"]." and (type = 3 or type=2) ")->num_rows();
}
return $count;
}
function isInPlanningDates($debut,$fin){
$count = $this->db->query("select id from ecritureplanning where cast(concat(jour, ' ', tempdebut) as datetime) <= STR_TO_DATE('".$debut."', '%Y-%m-%d %T ') and cast(concat(jour, ' ', tempfin) as datetime) >= STR_TO_DATE('".$fin."', '%Y-%m-%d %T ')")->num_rows();
return $count>0;
}
}