<?php

/*
 * PuzzleApp
 * Webemyos
 * Jérôme Oliva
 * GNU Licence
 */

namespace Apps\DownloadManager\Widget\DownloadManagerButton;

use Core\View\View;
use Apps\DownloadManager\Helper\DocumentHelper;

class DownloadManagerButton {

    function __construct($core = "", $documentId = "") {
        $this->Core       = $core;
        $this->DocumentId = $documentId;
    }

    /**
     * Rendu du bouton de téléchargement
     */
    function Render() {

        $document = DocumentHelper::GetDocument($this->Core, $this->DocumentId, true);
        $token    = DocumentHelper::GetDownloadToken($this->DocumentId);

        $view = new View(__DIR__ . "/View/index.tpl", $this->Core);
        $view->Set("DocumentName", $document["Name"]);
        $view->Set("DocumentId",   $this->DocumentId);
        $view->Set("Token",        $token);
        $view->Set("BtnLabel",     $this->Core->GetCode("DownloadManager.DownloadButton") . " " . $document["Name"]);

        return $view->Render();
    }
}

?>
