<?php

namespace Apps\Immo\Decorator;

use Apps\Immo\Entity\ImmoProjectEvent;
use Apps\Immo\Entity\ImmoProjectAnnonce;

use Apps\Annonce\Entity\AnnonceAnnonce;


class ProjectDecorator {

    public function __construct($core) {
        $this->Core = $core;
    }

    /** **
     *  Evenements sur un porjet
     */
    public function GetEventsMember($projet) {
        $event = new ImmoProjectEvent($this->Core);
        $events = $event->Find("ProjectId=" . $projet->IdEntite . " order by DateEvent desc, HourEvent asc");

        //Les informations que l'annocne s
        $view = $this->GetAnnonceMember($projet);
        
        $view .= "<div class='full-seco'><h2>Les évenements</h2>";    
        $view .= "<ul>";

        foreach ($events as $event) {
            $view .= "<li class='block-first'>";
            $view .= "<h2>" . $event->Name->Value . "</h2>";
            $view .= "<p>" . $event->DateEvent->Value . " " . $event->HourEvent->Value . "</p>";
            $view .= "<p>" . $event->Description->Value. "</p>";
         
            if($event->Result->Value != ""){
              $view .= "<div class='block-terc'>";
              $view .= "<h3>".$this->Core->GetCode("Immo.Report")."</h3>";
              $view .= "<p>". $event->Result->Value. "</p>";
              $view .= "</div>";
              
            }
            
            $view .= "</li>";
        }

        $view .= "</ul>";
        $view .= "</div>";

        return $view;
    }
    
    /***
     * Affiche les informations des annonces
     */
    function GetAnnonceMember($projet){
        
        $annonce = new AnnonceAnnonce($this->Core); 
        $annonce->Join("ImmoProjectAnnonce", "ImmoProjectAnnonce", "Inner", "ImmoProjectAnnonce.AnnonceId = AnnonceAnnonce.Id" );
        $annonces = $annonce->Find("ImmoProjectAnnonce.ProjectId=" .$projet->IdEntite);
      
        $view ="<div class='full-seco' ><h2>Annonce</h2>";
        
        foreach($annonces as $annonce){
            $view .= "<div class='block-first'>";
            $view .= "<a target='_blank' href='".$this->Core->GetPath("/Annonce/Annonce/".$annonce->Code->Value)."'> " .$annonce->Title->Value. "</a>";
            $view .= "<p>".$annonce->Description->Value."</p>";
            
            $view .= $annonce->GetClickTrackStat();
            $view .= "</div>";
        }
        
        $view .= "</div>";
        
        return $view;
        
    }
}
