Commit fefa335a authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Fix : Impossible de trouver des activités dans le moteur de recherche de la...

Fix : Impossible de trouver des activités dans le moteur de recherche de la fiche projet (affectation d'activité)
parent 4f4d03d5
Loading
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -702,6 +702,7 @@ class ProjectController extends AbstractOscarController
     * Lance la recherche sur la requête envoyée.
     *
     * @return array
     * @throws OscarException
     */
    public function searchAction()
    {
@@ -715,7 +716,7 @@ class ProjectController extends AbstractOscarController

        $search = $this->params()->fromQuery('q', '');
        if (strlen($search) < 2) {
            return $this->getResponseBadRequest("Not enough chars (4 required");
            return $this->getResponseBadRequest("Not enough chars (2 required");
        }
        $datas = $this->getProjectService()->search($search)->getQuery()->getResult();

+15 −5
Original line number Diff line number Diff line
@@ -2608,15 +2608,25 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
     * @return ViewModel
     * @throws Exception
     */
    public function applyAdvancedSearch($qb): ViewModel
    public function applyAdvancedSearch(): ViewModel
    {
        $view = new ViewModel(
            $this->getProjectGrantSearchService()->searchFromRequest(
        $datas = $this->getProjectGrantSearchService()->searchFromRequest(
            $this->getRequest(),
            $this->getOrganizationPerimeter()
            )
        );
        if( $this->isAjax() || $this->getRequest()->getQuery('f') === 'json' ){
            $activities = [];
            foreach ($datas['activities'] as $activity) {
                $activities[] = $activity->toArray();
            }
            $datas['activities'] = $activities;
            $view = new JsonModel($datas);
        } else {
            $view = new ViewModel(
                $datas
            );
            $view->setTemplate('oscar/project-grant/advanced-search.phtml');
        }
        return $view;
    }

@@ -2628,7 +2638,7 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
     */
    public function advancedSearchAction(): array|ViewModel
    {
        return $this->applyAdvancedSearch($qb);
        return $this->applyAdvancedSearch();
    }

    /**
+0 −5
Original line number Diff line number Diff line
@@ -1108,11 +1108,6 @@ class ProjectGrantSearchService implements UseEntityManager, UsePersonService, U

        $output['took'] = intval(($time_end - $time_start) * 1000);

        if ($params['format'] == 'json') {
            echo json_encode($output, JSON_PRETTY_PRINT);
            die();
        }

        return $output;
    }

+3 −6
Original line number Diff line number Diff line
@@ -154,18 +154,17 @@ h2.tv-serie-label { border-bottom: none; }
                            var formatRepo, formatRepoSelection;

                            formatRepo = function (repo) {
                                console.log('Format');
                                if (repo.loading) return repo.text;

                                var markup = '<div class="clearfix">';
                                markup += ( (repo.num?'<strong>['+repo.num+']</strong> ':'') + repo.label) || repo.text;
                                markup += ( (repo.numOscar?'<strong>['+repo.numOscar+']</strong> ':'') + repo.label) || repo.text;
                                markup += '</div>';

                                return markup;
                            };

                            formatRepoSelection = function (repo) {
                                return ( (repo.num?'<strong>['+repo.num+']</strong> ':'') + repo.label) || repo.text;
                                return ( (repo.numOscar?'<strong>['+repo.numOscar+']</strong> ':'') + repo.label) || repo.text;
                            };

                            $('#activities-choose').select2({
@@ -177,15 +176,13 @@ h2.tv-serie-label { border-bottom: none; }
                                    dataType: 'json',
                                    delay: 250,
                                    data: function (params) {
                                        console.log(params);
                                        return {
                                            q: params.term, // search term
                                            page: params.page
                                        };
                                    },
                                    processResults: function (data, page) {
                                        console.log('Données', data);
                                        return {results: data.datas};
                                        return {results: data.activities};
                                    },
                                    cache: true
                                },