src/Widgets/SavedSearchWidget.php
public function getResults(array $options = []) : ?SavedSearch
    {
        $this->setContainerId($options['entity']);

        $table = TableRegistry::get('Search.SavedSearches');

        /** @var \Search\Model\Entity\SavedSearch|null */
        $savedSearch = $table->find()
            ->where(['id' => $this->widget->get('widget_id')])
            ->enableHydration(true)
            ->first();

        if (null === $savedSearch) {
            $this->errors[] = 'No data found for this entity';

            return null;
        }

        /** @var \Cake\Datasource\RepositoryInterface */
        $table = TableRegistry::get($savedSearch->get('model'));

        $search = new Search($table, $options['user']);
        // keeps backward compatibility
        $entity = $search->reset($savedSearch);
        if (null === $entity) {
            $this->errors[] = 'Failed to reset entity';

            return null;
        }
        $content = $entity->get('content');
        $content['saved'] = Validator::validateData($table, $content['saved'], $options['user']);
        $entity->set('content', $content);

        $this->options['fields'] = Utility::instance()->getSearchableFields($table, $options['user']);
        $this->options['associationLabels'] = Utility::instance()->getAssociationLabels($table);

        $this->data = $entity;

        return $this->data;
    }
public function getResults(array $options = []) : ?SavedSearch
    {
        $this->setContainerId($options['entity']);

        $table = TableRegistry::get('Search.SavedSearches');

        /** @var \Search\Model\Entity\SavedSearch|null */
        $savedSearch = $table->find()
            ->where(['id' => $this->widget->get('widget_id')])
            ->enableHydration(true)
            ->first();

        if (null === $savedSearch) {
            $this->errors[] = 'No data found for this entity';

            return null;
        }

        /** @var \Cake\Datasource\RepositoryInterface */
        $table = TableRegistry::get($savedSearch->get('model'));

        $search = new Search($table, $options['user']);
        // keeps backward compatibility
        $entity = $search->reset($savedSearch);
        if (null === $entity) {
            $this->errors[] = 'Failed to reset entity';

            return null;
        }
        $content = $entity->get('content');
        $content['saved'] = Validator::validateData($table, $content['saved'], $options['user']);
        $entity->set('content', $content);

        $this->options['fields'] = Utility::instance()->getSearchableFields($table, $options['user']);
        $this->options['associationLabels'] = Utility::instance()->getAssociationLabels($table);

        $this->data = $entity;

        return $this->data;
    }
public function getResults ( array $ options = [ ] ) : ? SavedSearch { $ this -> setContainerId ( $ options [ 'entity' ] ) ; $ table = TableRegistry :: get ( 'Search.SavedSearches' ) ; /** @var \Search\Model\Entity\SavedSearch|null */ $ savedSearch = $ table -> find ( ) -> where ( [ 'id' => $ this -> widget -> get ( 'widget_id' ) ] ) -> enableHydration ( true ) -> first ( ) ; if ( null === $ savedSearch ) { $ this -> errors [ ] = 'No data found for this entity' ; return null ; } /** @var \Cake\Datasource\RepositoryInterface */ $ table = TableRegistry :: get ( $ savedSearch -> get ( 'model' ) ) ; $ search = new Search ( $ table , $ options [ 'user' ] ) ; // keeps backward compatibility $ entity = $ search -> reset ( $ savedSearch ) ; if ( null === $ entity ) { $ this -> errors [ ] = 'Failed to reset entity' ; return null ; } $ content = $ entity -> get ( 'content' ) ; $ content [ 'saved' ] = Validator :: validateData ( $ table , $ content [ 'saved' ] , $ options [ 'user' ] ) ; $ entity -> set ( 'content' , $ content ) ; $ this -> options [ 'fields' ] = Utility :: instance ( ) -> getSearchableFields ( $ table , $ options [ 'user' ] ) ; $ this -> options [ 'associationLabels' ] = Utility :: instance ( ) -> getAssociationLabels ( $ table ) ; $ this -> data = $ entity ; return $ this -> data ; }
Retrieve SavedSearch results for the widget

@param array $options containing entity and view params.
@return \Search\Model\Entity\SavedSearch|null
Retrieve SavedSearch results for the widget