<?php 

//include_once APPLICATION_PATH . '/DAO/UtilisateurRaccourciDAO.php';

        if ( isset($_SESSION["codeUser"])){
            $codeUser=$_SESSION["codeUser"]; 
        }else{
            $this->_helper->redirector('index' , 'Index');
        }
         $authDao = new AuthorisationDAO();
         $roleAuthDao = new RoleAuthorisationDAO();
         $listeParent = $authDao->listAuthParent();
         $userDao = new UtilisateurDAO();
         $user = $userDao->getUtilisateurByCode($codeUser);
         $list=$roleAuthDao->listRoleAuthorisationByRole($user->getRole());
            
         $result = [];
            
         foreach($listeParent as $parent){
             if($roleAuthDao->roleAuth($user->getRole(),$parent)){
                  $result[$parent->getCode()][] = array("code"=>$parent->getCode(),"label"=>$parent->getLabel(),"action"=>$parent->getAction(),"parent"=>NULL,"icon"=>$parent->getIcon());
//                foreach($list as $elem){
//                    if ($parent == $elem->getAuthorisation()->getParent()){
//                          $result[$parent->getCode()][] = array("code"=>$elem->getAuthorisation()->getCode(),"label"=>$elem->getAuthorisation()->getLabel(),"action"=>$elem->getAuthorisation()->getAction(),"parent"=>$parent->getCode(),"icon"=>$elem->getAuthorisation()->getIcon(),"controler"=>$elem->getAuthorisation()->getControleur());
//                     }
//                  }
             }
           
                
          }
        

       
?> 
            <div class="sidebar-left open rtl-ps-none" data-perfect-scrollbar="" data-suppress-scroll-x="true">
                <ul class="navigation-left" >
                     <?php 
                        //on parcours la liste des menus parents
                        foreach ($listeParent as $parent)
                        {
                              if($roleAuthDao->roleAuth($user->getRole(),$parent)){ 
                        ?> 
                    <li class="nav-item" data-item="<?php echo $parent->getCode();?>"><a class="nav-item-hold" href="#"><i class="nav-icon <?php echo $parent->getIcon();?>"></i><span class="nav-text"><?php echo $parent->getLabel();?></span></a>
                        <div class="triangle"></div>
                    </li>
                        <?php }  }?>
                   
                </ul>
            </div>

            <div class="sidebar-left-secondary rtl-ps-none" data-perfect-scrollbar="" data-suppress-scroll-x="true">
                <!-- Submenu Dashboards-->
                 <?php 
                        //on parcours la liste des menus parents
                         foreach($list as $elem){
                             if(is_object($elem->getAuthorisation()->getParent())){
                        ?> 
                <ul class="childNav" data-parent="<?php echo $elem->getAuthorisation()->getParent()->getCode();?>">
                    <li class="nav-item"><a href="<?php echo $this->url(array('controller' => $elem->getAuthorisation()->getControleur(), 'action' => $elem->getAuthorisation()->getAction()),null , true); ?>"><i class="nav-icon <?php echo $elem->getAuthorisation()->getIcon();?>"></i><span class="item-name"><?php echo $elem->getAuthorisation()->getLabel();?></span></a></li>
                    
                </ul>
                             <?php }  }?>
            </div>
                   
                       
                       
                  
            




