syzygypl/kunstmaan-feed-bundle

3.2.4 2018-08-14 12:46 UTC

README

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require syzygypl/kunstmaan-feed-bundle

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new  SZG\KunstmaanFeedBundle\KunstmaanFeedBundle(),
        );

        // ...
    }

    // ...
}

Usage

article below represents an indexed type. It may be define as search_type in page configuration.

kunstmaan_node:
    pages:
        'AppBundle\Entity\Pages\ArticlePage':
            ...
            indexable: true
            search_type: article

TWIG

Most recent 100 articles:
{# Short notation, use defaults #}
{% set articles = get_article_feed() %}

{# Simple notation #}
{% set articles = get_recent_article_feed({ limit: 100 }) %}

{# full notation #}
{% set articles = get_feed_items('article', { limit: 100, feed: 'recent' }) %}
Random product:
{% set random_product = get_random_product_feed({ limit: 1 }) %}

PHP :

Most recent 100 articles:
<?php
// ...

$articles = $this->get('szg_feed.elastic_search_items_provider')->getFeedItems('article', [
    'feed' => 'recent',
    'limit' => 100
]);
Random product:
<?php
// ...

$articles = $this->get('szg_feed.elastic_search_items_provider')->getFeedItems('product', [
    'feed' => 'random',
    'limit' => 1
]);

Options reference

Defining custom feed types

Sort single field custom feed:

Configure custom feeds in config.yml

kunstmaan_feed:
    custom: 
        title : 'desc'
            

Advanced custom feed:

1. Implement FeedElasticSearchInterface

Implement SZG\KunstmaanFeedBundle\Feed\ElasticSearch\Interfaces\FeedElasticSearchInterface.

<?php
// ...
class TitleDesc extends FeedElasticSearchInterface
{

   /**
    * @param QueryDefinition $queryDefinition
    */
   public function modifyQuery(QueryDefinition $queryDefinition)
   {
        $queryDefinition->getQuery()->addSort(['title' => ['order' => 'desc']]);
   }

}

2. Register custom feed service:

szg_feed.feed.title:
    class: AppBundle\Feed\TitleDesc
    tags:
      - { name: szg_feed.feed, alias: title }

Use custom feed

{% set articlesByTitle = get_title_article_feed() %}