Commit 55888f58 authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

FIX : Les variables des templates sont remplacées par du vide quand elles ne...

FIX : Les variables des templates sont remplacées par du vide quand elles ne sont pas renseignées dans l'activités
UP : Les numérotations personnalisées sont disponibles dans les templates sour la forme "num-numerotation-clef" (nom mis en minuscule et espaces remplacés par des tirets)
parent 42905773
Loading
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -680,11 +680,12 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
    {
        $id = $this->params()->fromRoute('id');
        $doc = $this->params()->fromRoute('doc');
        $baseDatas = $this->getProjectGrantService()->getBaseDataTemplate();

        if ($doc == "dump") {
            echo "<table border='1'>";
            $activity = $this->getProjectGrantService()->getGrant($id);
            foreach ($activity->documentDatas() as $key => $value) {
            foreach ($activity->documentDatas($baseDatas) as $key => $value) {
                echo "<tr>";
                if (is_array($value)) {
                    echo "<th>$key</th><td><small>[LIST]</small></td><td>" . implode(", ", $value) . "</td>";
@@ -705,7 +706,8 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
        $activity = $this->getProjectGrantService()->getGrant($id);

        $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor($config['template']);
        $documentDatas = $activity->documentDatas();

        $documentDatas = $activity->documentDatas($baseDatas);

        foreach ($documentDatas as $key => $value) {
            if (is_array($value)) {
+21 −25
Original line number Diff line number Diff line
@@ -2128,33 +2128,26 @@ class Activity implements ResourceInterface
    /**
     * Retourne les données préparées pour le génération des documents
     */
    public function documentDatas()
    public function documentDatas($datas)
    {
        //
        $datas = [
            'id' => $this->getId(),
            'acronym' => htmlspecialchars($this->getAcronym()),
            'amount' => $this->getAmount(),
            'pfi' => $this->getCodeEOTP(),
            'oscar' => $this->getOscarNum(),
            'montant' => number_format(
                    (double)$this->getAmount(),
                    2,
                    ',',
                    ' '
                ) . $this->getCurrency()->getSymbol(),
            'annee-debut' => $this->getDateStartStr('Y'),
            'annee-fin' => $this->getDateEndStr('Y'),
            'debut' => $this->getDateStartStr('d/m/Y'),
            'fin' => $this->getDateEndStr('d/m/Y'),
            'intitule' => htmlspecialchars($this->getLabel()),
            'label' => htmlspecialchars($this->getLabel()),
            'tva' => $this->getTva() ? (string)$this->getTva() : '',
            'assiette-subventionnable' => (string)$this->getAssietteSubventionnable(),
            'note-financiere' => $this->getNoteFinanciere(),

            'type' => (string)$this->getActivityType(),
        ];
        $datas['id'] = $this->getId();
        $datas['acronym'] = htmlspecialchars($this->getAcronym());
        $datas['amount'] = $this->getAmount();
        $datas['pfi'] = $this->getCodeEOTP();
        $datas['oscar'] = $this->getOscarNum();
        $datas['montant'] = number_format((double)$this->getAmount(),2,',',' ') . $this->getCurrency()->getSymbol();
        $datas['annee-debut'] = $this->getDateStartStr('Y');
        $datas['annee-fin'] = $this->getDateEndStr('Y');
        $datas['debut'] = $this->getDateStartStr('d/m/Y');
        $datas['fin'] = $this->getDateEndStr('d/m/Y');
        $datas['intitule'] = htmlspecialchars($this->getLabel());
        $datas['label'] = htmlspecialchars($this->getLabel());
        $datas['tva'] = $this->getTva() ? (string)$this->getTva() : '';
        $datas['assiette-subventionnable'] = (string)$this->getAssietteSubventionnable();
        $datas['note-financiere'] = $this->getNoteFinanciere();

        $datas['type'] = (string)$this->getActivityType();

        $sluger = Slugify::create();

@@ -2246,6 +2239,9 @@ class Activity implements ResourceInterface
        $datas['versement-effectue-montant'] = $versementsEffectues;
        $datas['versement-effectue-date'] = $versementsEffectuesDate;

        foreach ($this->getNumbers() as $key => $value) {
            $datas['num-'.$sluger->slugify($key)] = $value;
        }

        return $datas;
    }
+23 −2
Original line number Diff line number Diff line
@@ -13,7 +13,8 @@ use Doctrine\ORM\NoResultException;

class OrganizationRoleRepository extends EntityRepository
{
    public function getRoleByRoleIdOrCreate( $roleId ){
    public function getRoleByRoleIdOrCreate($roleId)
    {
        try {
            return $this->createQueryBuilder('r')
                ->select('r')
@@ -29,4 +30,24 @@ class OrganizationRoleRepository extends EntityRepository
            return $role;
        }
    }

    public function getRolesAvailableInActivityArray(): array
    {
        $out = [];
        foreach ($this->getRolesAvailableInActivity() as $organizationRole) {
            $out[$organizationRole->getId()] = $organizationRole->getRoleId();
        }
        return $out;
    }

    /**
     * @return OrganizationRole[]
     */
    public function getRolesAvailableInActivity(): array
    {
        return $this->createQueryBuilder('r')
            ->select('r')
            ->getQuery()
            ->getResult();
    }
}
 No newline at end of file
+17 −0
Original line number Diff line number Diff line
@@ -90,6 +90,23 @@ class RoleRepository extends EntityRepository
        return $this->getRolesAtLevel(Role::LEVEL_ORGANIZATION)->getQuery()->getResult();
    }

    public function getRolesAvailableForPersonInActivity() :array
    {
        return $this->getRolesAtLevel(Role::LEVEL_ACTIVITY)->getQuery()->getResult();
    }

    public function getRolesAvailableForPersonInActivityArray() :array
    {
        static $rolesActivity;
        if( $rolesActivity === null ){
            $rolesActivity = [];
            foreach( $this->getRolesAvailableForPersonInActivity() as $role ){
                $rolesActivity[$role->getId()] = $role->getRoleId();
            }
        }
        return $rolesActivity;
    }

    /**
     * Retourne la liste des rôles au niveau spécifié.
     *
Loading