<?php

/*
 * Model's functions of Menu Entity
 */

/**
 * @author Messanga Landry <messangalandry@gmail.com>
 */
include APPLICATION_PATH . '/Models/Menu.php';

class MenuDAO {
    //put your code here
    
    function MenuDAO(){
        $registry = Zend_Registry::getInstance();
        $this->_em = $registry->entitymanager;
    }
    
    public function enregistrer($objet){
          // var_dump($profil);exit;
        $this->_em->persist($objet);
       //$this->_em->flush();
        $this->_em->flush();
            //var_dump($objmodif);exit;
        
    }
    
    public function editer($unMenu){
        $this->_em->merge($unMenu);
        $this->_em->flush();
    }
    
    public function obtenirMenu($id){
        $menu = $this->_em->getRepository('\Application\Models\Menu') ->find($id);
        return $menu;
    }
    
    public function listerTout(){
        $liste = $this->_em->getRepository('\Application\Models\Menu')
                ->findAll();
           return $liste;
    }
     public function listerMenuParents(){ //lister tous les menus parents
        $liste = $this->_em->getRepository('\Application\Models\Menu')
                ->findBy(array('idparent' => NULL),array('ordreapparition' => 'ASC'));
           return $liste;
    }
      public function listerSousMenus($unMenu){ //lister tous les sous-menus du menu en paramètre
        $liste = $this->_em->getRepository('\Application\Models\Menu')
                ->findBy(array('idparent' => $unMenu->getIdmenu(),"statut"=>1) , array('ordreapparition' => 'ASC'));
           return $liste;
    }
//      public function droitMenu($idProfil, $idMenu){ //dit si le profil a droit au menu
//        $ligne = $this->_em->getRepository('\Application\Models\LigneProfil')
//                ->findBy(array('idMenu' => $idMenu,'idProfil' => $idProfil));
//        if($ligne) return true;   
//        else return false;
//    }
}
