Commit 06a7145a authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

UP : Ajout d'un champ "type-full" pour la génération de document contenant...

UP : Ajout d'un champ "type-full" pour la génération de document contenant l'arboresence du type d'activité
parent 35b578a0
Loading
Loading
Loading
Loading
Loading
+58 −52
Original line number Diff line number Diff line
@@ -192,6 +192,7 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
    {
        $this->activityRequestService = $activityRequestService;
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    public function apiUiAction()
    {
@@ -491,8 +492,12 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif

        return [
            'asAdmin' => $asAdmin,
            'rolesPerson' => $this->getPersonService()->getAvailableRolesPersonActivity(OscarFormatterConst::FORMAT_ARRAY_ID_VALUE),
            'rolesOrganisation' => $this->getOrganizationService()->getAvailableRolesOrganisationActivity(OscarFormatterConst::FORMAT_ARRAY_ID_VALUE)
            'rolesPerson' => $this->getPersonService()->getAvailableRolesPersonActivity(
                OscarFormatterConst::FORMAT_ARRAY_ID_VALUE
            ),
            'rolesOrganisation' => $this->getOrganizationService()->getAvailableRolesOrganisationActivity(
                OscarFormatterConst::FORMAT_ARRAY_ID_VALUE
            )
        ];
    }

@@ -758,12 +763,14 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
        $id = $this->params()->fromRoute('id');
        $doc = $this->params()->fromRoute('doc');
        $baseDatas = $this->getProjectGrantService()->getBaseDataTemplate();

        $activity = $this->getProjectGrantService()->getGrant($id);
        $documentDatas = $activity->documentDatas($baseDatas);
        $documentDatas["type-full"] = $this->getActivityTypeService()->getActivityTypeChainFormatted(
            $activity->getActivityType()
        );
        if ($doc == "dump") {

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

        $activity = $this->getProjectGrantService()->getGrant($id);

        Settings::setOutputEscapingEnabled(true);
        $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor($config['template']);


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

        foreach ($documentDatas as $key => $value) {
            if (is_array($value)) {
            } else {
@@ -1032,13 +1034,14 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
            try {
                $this->getTimesheetService()->removeTimesheetActivity($activity);
            } catch (\Exception $e) {
                throw new OscarException("Impossible de supprimer les créneaux pour cette activité : " . $e->getMessage());
                throw new OscarException(
                    "Impossible de supprimer les créneaux pour cette activité : " . $e->getMessage()
                );
            }

            // Suppression des documents
            $documents = $activity->getDocuments();
            if (count($documents)) {

                $documentPathRoot = $this->getOscarConfigurationService()->getDocumentDropLocation();

                /** @var ContractDocument $d */
@@ -1337,7 +1340,8 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif

        if (!$this->getOscarUserContextService()->hasPrivileges(Privileges::ACTIVITY_CREATE)) {
            if (!$this->getOscarUserContextService()->hasPrivilegeInOrganizations(
                Privileges::ACTIVITY_CREATE)) {
                Privileges::ACTIVITY_CREATE
            )) {
                throw new UnAuthorizedException(_("Vous n'avez pas les droits pour créer une nouvelle activité"));
            }
            $organisationsUser = $this->getOscarUserContextService()->getCurrentUserOrganisationWithPrivilege(
@@ -1384,7 +1388,6 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
        /** @var Request $request */
        $request = $this->getRequest();
        if ($request->isPost()) {

            $validOrganizationForm = true;

            if ($withOrganization) {
@@ -1898,7 +1901,6 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
        }



        return $this->jsonOutput($out);
    }

@@ -2368,10 +2370,12 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
            return $this->getResponseBadRequest($e->getMessage());
        }

        $view = new ViewModel([
        $view = new ViewModel(
            [
                'search' => $search,
                'activities' => $activities,
        ]);
            ]
        );
        $view->setTemplate('oscar/activity/search.phtml');
        return $view;
    }
@@ -2716,7 +2720,8 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif

                    // Filtre sur les activités ayant des feuilles de temps (Lot de travail)
                    case 'fdt' :
                        $ids = $this->getProjectGrantService()->getActivityRepository()->getActivityIdsWithWorkpackage();
                        $ids = $this->getProjectGrantService()->getActivityRepository()->getActivityIdsWithWorkpackage(
                        );
                        break;

                    // Personne (plusieurs)
@@ -2830,7 +2835,6 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
                            $organizations[$organization->getId()] = $organization;
                            $crit['val1Label'] = (string)$organization;
                        } catch (\Exception $e) {

                        }

                        if ($value2 > 0) {
@@ -3306,7 +3310,6 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
        $this->getOscarUserContextService()->check(Privileges::ACTIVITY_TIMESHEET_VIEW, $activity);

        if ($this->isAjax()) {

            $action = $this->getRequest()->getQuery()->get('a', null);

            if ($this->getRequest()->isDelete() || $action == 'd') {
@@ -3341,7 +3344,10 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
                $this->url()
            );
            $response['validations'] = $this->getTimesheetService()->getDatasActivityValidations($activity);
            $response['validators_editable'] = $this->getOscarUserContextService()->hasPrivileges(Privileges::ACTIVITY_EDIT, $activity);
            $response['validators_editable'] = $this->getOscarUserContextService()->hasPrivileges(
                Privileges::ACTIVITY_EDIT,
                $activity
            );

            return $this->jsonOutput($response);
        }
+25 −4
Original line number Diff line number Diff line
@@ -99,16 +99,16 @@ class ActivityTypeService implements UseEntityManager
     * @throws \Doctrine\ORM\NoResultException
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
    public function getActivityTypeChain($activity)
    public function getActivityTypeChain($activityType)
    {
        if ($activity === null) {
        if ($activityType === null) {
            return [];
        }
        $chain = $this->getBaseQuery()
            ->where('t.lft <= :lft AND t.rgt >= :rgt')
            ->setParameters([
                'lft' => $activity->getLft(),
                'rgt' => $activity->getRgt(),
                'lft' => $activityType->getLft(),
                'rgt' => $activityType->getRgt(),
            ])
            ->getQuery()
            ->getResult();
@@ -116,6 +116,27 @@ class ActivityTypeService implements UseEntityManager
        return $chain;
    }

    public function getActivityTypeChainFormatted($activityType) :string
    {
        $output = [];
        if ( $activityType ){
            $chain = $this->getActivityTypeChain($activityType);
            /** @var ActivityType $node */
            foreach ($chain as $node) {
                if( $node->getLabel() == 'ROOT' ){
                    continue;
                }
                $output[] = $node->getLabel();
            }
        }

        if( count($output) == 0 ){
            return "Pas de type";
        } else {
            return implode(" > ", $output);
        }
    }

    public function getActivityTypesPcru()
    {
        //$activity