Bonjour,
S'il vous plaît est ce que quelqu'un peut m'aider
je rencontre un petit problème avec mon code.

Ce que je fais

Décrivez ici votre code ou ce que vous cherchez à faire

Entourez votre code p<?php
global $rep, $vues;
require_once ($rep . "Configuration/config.php");
require_once $rep . 'Modele/Planification.class.php';
global $config;

require ($rep . $vues['header']);
$parametrage = new Parametrage();

$debHour = $parametrage->__get(Parametrage::PARAM_PREMIERE_HEURE);
$FinHour = $parametrage->__get(Parametrage::PARAM_DERNIERE_HEURE);

$selected = Planification::getCurrentWeek();

$jours = array(

        'Lundi',

        'Mardi',

        'Mercredi',

        'Jeudi',

        'Vendredi',

        'Samedi'

);

if (isset($_GET['type'])) {
    $action = $_GET['type'];
    $planifDate = $_GET['date' . $action];
    $_GET['planifDate'] = $planifDate;

}

if (isset($_GET['planifDate']) && is_numeric($_GET['planifDate'])) {

    $selected = $_GET['planifDate'];

}
$listeDate = Planification::getListeDateForWeek($selected);
$listeUser = Planification::getListeUser();
$planificationUser = $_SESSION['id'];

if (isset($_GET['planifUser']) && is_numeric($_GET['planifUser'])) {
 $planificationUser = $_GET['planifUser'];
}
our bien le mettre en forme

Ce que je veux

Je veux veux afficher l'interface de la fiche de souhait

Ce que j'obtiens

Fatal error: Call to undefined method Planification::getCurrentWeek() in /www/edt/NEW/s/Vue/ficheSouhait.php on line 13

4 réponses


Lartak
Réponse acceptée

Bonjour.
L'erreur te dit tout simplement que la méthode getCurrentWeek de ta classe Planification n'est pas définie et sans voir la classe ou du moins la méthode concernée, ça va être difficile de t'aider plus précisément.

MBarr
Auteur
Réponse acceptée

Voici ma classe Planification merci d'avance à vous!

<?php

require_once 'BDD.php';

class Planification{

const TABLE = "planification";
const TABLE_PERIPHERIQUE = "peripherie";
const TABLE_UTILISATEUR = "membre";
const TABLE_HEURES_TRAVAIL = "heures_travail";
const TABLE_DATES_TRAVAIL = "dates_travail";
const TABLE_ID = "id";
const TABLE_USER = "id_user";
const TABLE_HEURE_DEB = "id_heure_deb";
const TABLE_HEURE_FIN = "id_heure_fin";
const TABLE_DATE = "id_date";
const TABLE_PERI = "id_peri";

private $id = null;
private $id_user = null;
private $id_heure_deb = null;
private $id_heure_fin = null;
private $id_date = null;
private $id_peri = null;

public function __construct($action = "new",$param = array()){
    if($action == "new"){
        if(isset($param[self::TABLE_ID])) { $this->id =  $param[self::TABLE_ID]; }
        if(isset($param[self::TABLE_USER])) { $this->id_user =  $param[self::TABLE_USER]; }
        if(isset($param[self::TABLE_HEURE_DEB])) { $this->id_heure_deb =  $param[self::TABLE_HEURE_DEB]; }
        if(isset($param[self::TABLE_HEURE_FIN])) { $this->id_heure_fin =  $param[self::TABLE_HEURE_FIN]; }
        if(isset($param[self::TABLE_DATE])) { $this->id_date =  $param[self::TABLE_DATE]; }
        if(isset($param[self::TABLE_PERI])) { $this->id_peri =  $param[self::TABLE_PERI]; }
    }else if ($action == "get"){

        $pid = (isset($param) && isset($param[self::TABLE_ID]) && $param[self::TABLE_ID] > 0) ? $param[self::TABLE_ID] : 
        ((isset($param) && isset($param[0]) && $param[0] > 0) ? $param[0] : null);

        if(isset($pid)){
            $db = new BDD();
            $db->getInstance();
            $requete = "SELECT * FROM ".self::TABLE ." WHERE ".self::TABLE_ID ." = ".$pid;
            if($db->executeQuery($requete)){
                $result = $db->getResult();
                foreach ($result as $planif){
                    $this->id = $planif[self::TABLE_ID];
                    $this->id_user = $planif[self::TABLE_USER];
                    $this->id_heure_deb = $planif[self::TABLE_HEURE_DEB];
                    $this->id_heure_fin = $planif[self::TABLE_HEURE_FIN];
                    $this->id_date = $planif[self::TABLE_DATE];
                    $this->id_peri = $planif[self::TABLE_ID];
                }
            }
        }
    }else{
        return null;
    }
}

public static function getAllProgrammeForUser($id_user = null,$date = null){
    $allPlanif = array();
    if(isset($id_user) && $id_user > 0){
        try {
            $dateReq = "";
            if(isset($date) && is_numeric($date)){
                $dateReq = " AND dt.dates_t = ".$date;
            }
            $db = new BDD();
            $db->getInstance();
            $requete = "SELECT * FROM ".Planification::TABLE ." p INNER JOIN ".Planification::TABLE_UTILISATEUR
            ." u ON (u.id = p.".Planification::TABLE_USER." AND u.id = ".$id_user.") ".
            "INNER JOIN ".Planification::TABLE_PERIPHERIQUE. " pr ON (pr.id = p.".Planification::TABLE_PERI.") ".
            "INNER JOIN ".Planification::TABLE_HEURES_TRAVAIL. " ht ON (ht.id = p.".Planification::TABLE_HEURE_DEB.") ".
            "INNER JOIN ".Planification::TABLE_HEURES_TRAVAIL. " ht ON (ht.id = p.".Planification::TABLE_HEURE_FIN.") ".
            "INNER JOIN ".Planification::TABLE_DATES_TRAVAIL. " dt ON (dt.id = p.".Planification::TABLE_DATE.$dateReq." )
             ORDER BY dt.dates_t";
            if($db->executeQuery($requete)){
                return $db->getResult();
            }
        } catch (Exception $e) {
        }
    }
    return $allPlanif;
}

public function __get($var){
    return $this->$var;
}

public function __set($var,$value){
    $this->$var = $value;
}

public function save(){
    try {
        if(isset($this->id_user) && isset($this->id_date) && isset($this->id_heure) && isset($this->id_peri)){
            $db = new BDD();
            $db->getInstance();
            $requete = null;
            if(isset($this->id) && $this->id > 0){
                // modification horaires
                $requete = "UPDATE ".self::TABLE." SET ".
                        self::TABLE_DATE." = " . $this->id_date ." , ".
                        self::TABLE_HEURE_DEB." = " . $this->id_heure_deb ." , ".
                        self::TABLE_HEURE_FIN." = " . $this->id_heure_fin ." , ".
                        self::TABLE_PERI." = " . $this->id_peri ." , ".
                        self::TABLE_USER." = " . $this->id_user .
                        " WHERE ". self::TABLE_ID ." = " . $this->id;
            }else{
                // ajout horaires
                $requete = "INSERT INTO ".self::TABLE." VALUES(NULL,".$this->id_user.",".$this->id_heure_deb.",".$this->id_heure_fin.",".$this->id_date.",".$this->id_peri.");";
            }
            return $db->executeQuery($requete);
        }
    } catch (Exception $e) {
        return false;
    }
    return false;
}

public static function addNewDate(){

    $date = Planification::encodeDate(Planification::getActualDate());
    $requete = "INSERT INTO ".Planification::TABLE_DATES_TRAVAIL." VALUES(NULL,".$date.");";
    $db = new BDD();
    $db->getInstance();
    $db->executeQuery("SELECT * FROM ".Planification::TABLE_DATES_TRAVAIL." WHERE dates_t = ".$date);
    $result = $db->getResult();
    if(!is_array($result) || count($result) <= 0){
        $db->executeQuery($requete);
    }

    $dateC = Planification::getActualDate('Y-m-d');

    for ($i = 1; $i < 31; $i++) {
        $intVal = 'P'.$i.'D';
        $date = new DateTime($dateC);
        $date->add(new DateInterval($intVal));
        $newDate = Planification::encodeDate($date->format('d/m/Y'));
        $requete = "INSERT INTO ".Planification::TABLE_DATES_TRAVAIL." VALUES(NULL,".$newDate.");";
        $db->executeQuery("SELECT * FROM ".Planification::TABLE_DATES_TRAVAIL." WHERE dates_t = ".$newDate);
        $result = $db->getResult();
        if(!is_array($result) || count($result) <= 0){
            $db->executeQuery($requete);
        }
    }
}

public static function updateHours(){

    $param = new Parametrage();

    $debHour = $param->__get(Parametrage::PARAM_PREMIERE_HEURE);
    $FinHour = $param->__get(Parametrage::PARAM_DERNIERE_HEURE);

    if($debHour <= $FinHour){
        $db = new BDD();
        $db->getInstance();
        for ($i = $debHour; $i <= $FinHour; $i++) {
            $requete = "INSERT INTO ".Planification::TABLE_HEURES_TRAVAIL." VALUES(NULL,".$i.");";
            $db->executeQuery("SELECT * FROM ".Planification::TABLE_HEURES_TRAVAIL." WHERE heure = ".$i);
            $result = $db->getResult();
            if(!is_array($result) || count($result) <= 0){
                $db->executeQuery($requete);
            }
        }
    }
}

/*
 * Prend les dates a partir de 30 jours en arrieres
 */
public static function getListeDate(){
    $db = new BDD();
    $db->getInstance();
    $dateC = Planification::getActualDate('Y-m-d');
    $date = new DateTime($dateC);
    $date->sub(new DateInterval('P30D'));
    $newDate = Planification::encodeDate($date->format('d/m/Y'));
    $db->executeQuery("SELECT * FROM ".Planification::TABLE_DATES_TRAVAIL." WHERE dates_t >= ".$newDate." ORDER BY dates_t");
    return $db->getResult();
}

/**
 * Encode la date vers le format aaaammdd
 *
 * @param string $date
 * @return int
 */
public static function encodeDate($date = null)
{
    if (isset($date) && strlen($date) == 10) {
        $annee = substr($date, 6, 4);
        $mois = substr($date, 3, 2);
        $jour = substr($date, 0, 2);
        return $annee . $mois . $jour;
    } else {
        // retourne la date d'aujourdhui
        return date('Y') . date('m') . date('d');
    }
}

/**
 * Decode la date vers le format dd/mm/aaaa
 *
 * @param int $date
 * @return string
 */
public static function decodeDate($date)
{
    if (isset($date) && strlen($date) == 8) {
        $jour = substr($date, 6, 2);
        $mois = substr($date, 4, 2);
        $annee = substr($date, 0, 4);
        return $jour . '/' . $mois . '/' . $annee;
    } else {
        return '';
    }
}

public static function getActualDate($format = 'd/m/Y')
{
    return date($format);
}

}

Lartak
Réponse acceptée

Il n'y a donc pas de méthode qui se nomme getCurrentWeek dans ta classe Planification.

MBarr
Auteur

Oui je vois il faut donc que j'appel la méthode de la semaine courante dans ma classe Planification

$selected = Planification::getCurrentWeek();