Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/sulu/SuluArticleBundle
Browse files Browse the repository at this point in the history
  • Loading branch information
wachterjohannes committed Feb 10, 2017
2 parents a2e3b66 + a828ce5 commit bcd4348
Show file tree
Hide file tree
Showing 11 changed files with 341 additions and 130 deletions.
1 change: 1 addition & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ disabled:
- phpdoc_indent
- phpdoc_to_comment
- blankline_after_open_tag
- single_line_class_definition
44 changes: 36 additions & 8 deletions Content/ArticleDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use ONGR\ElasticsearchDSL\Query\MatchAllQuery;
use ONGR\ElasticsearchDSL\Query\TermQuery;
use ONGR\ElasticsearchDSL\Search;
use ONGR\ElasticsearchDSL\Sort\FieldSort;
use ProxyManager\Factory\LazyLoadingValueHolderFactory;
use ProxyManager\Proxy\LazyLoadingInterface;
use Sulu\Bundle\ArticleBundle\Document\ArticleDocument;
Expand Down Expand Up @@ -108,15 +109,17 @@ public function resolveDataItems(
$filters['type'] = $type;
}

$queryResult = $this->getSearchResult($filters, $limit, $page, $pageSize);

$result = [];
$uuids = [];
/** @var ArticleViewDocumentInterface $document */
foreach ($this->getSearchResult($filters, $limit, $page, $pageSize) as $document) {
foreach ($queryResult as $document) {
$uuids[] = $document->getUuid();
$result[] = new ArticleDataItem($document->getUuid(), $document->getTitle(), $document);
}

return new DataProviderResult($result, false, $uuids);
return new DataProviderResult($result, $this->hasNextPage($queryResult, $limit, $page, $pageSize), $uuids);
}

/**
Expand All @@ -134,18 +137,20 @@ public function resolveResourceItems(
$filters['type'] = $type;
}

$queryResult = $this->getSearchResult($filters, $limit, $page, $pageSize);

$result = [];
$uuids = [];
/** @var ArticleViewDocumentInterface $document */
foreach ($this->getSearchResult($filters, $limit, $page, $pageSize) as $document) {
foreach ($queryResult as $document) {
$uuids[] = $document->getUuid();
$result[] = new ArticleResourceItem(
$document,
$this->getResource($document->getUuid(), $document->getLocale())
);
}

return new DataProviderResult($result, false, $uuids);
return new DataProviderResult($result, $this->hasNextPage($queryResult, $limit, $page, $pageSize), $uuids);
}

/**
Expand All @@ -156,6 +161,27 @@ public function resolveDatasource($datasource, array $propertyParameter, array $
return;
}

/**
* Returns flag "hasNextPage".
* It combines the limit/query-count with the page and page-size.
*
* @param DocumentIterator $queryResult
* @param int $limit
* @param int $page
* @param int $pageSize
*
* @return bool
*/
private function hasNextPage(DocumentIterator $queryResult, $limit, $page, $pageSize)
{
$count = $queryResult->count();
if ($limit && $limit < $count) {
$count = $limit;
}

return $count > ($page * $pageSize);
}

/**
* Creates search for filters and returns search-result.
*
Expand All @@ -175,14 +201,14 @@ private function getSearchResult(array $filters, $limit, $page, $pageSize)

$queriesCount = 0;
$operator = $this->getFilter($filters, 'tagOperator', 'or');
$this->addBoolQuery('tags', $filters, 'excerpt.tags', $operator, $query, $queriesCount);
$this->addBoolQuery('tags', $filters, 'excerpt.tags.id', $operator, $query, $queriesCount);
$operator = $this->getFilter($filters, 'websiteTagsOperator', 'or');
$this->addBoolQuery('websiteTags', $filters, 'excerpt.tags', $operator, $query, $queriesCount);
$this->addBoolQuery('websiteTags', $filters, 'excerpt.tags.id', $operator, $query, $queriesCount);

$operator = $this->getFilter($filters, 'categoryOperator', 'or');
$this->addBoolQuery('categories', $filters, 'excerpt.categories', $operator, $query, $queriesCount);
$this->addBoolQuery('categories', $filters, 'excerpt.categories.id', $operator, $query, $queriesCount);
$operator = $this->getFilter($filters, 'websiteCategoriesOperator', 'or');
$this->addBoolQuery('websiteCategories', $filters, 'excerpt.categories', $operator, $query, $queriesCount);
$this->addBoolQuery('websiteCategories', $filters, 'excerpt.categories.id', $operator, $query, $queriesCount);

if (array_key_exists('type', $filters)) {
$query->add(new TermQuery('type', $filters['type']));
Expand All @@ -201,6 +227,8 @@ private function getSearchResult(array $filters, $limit, $page, $pageSize)
$search->setSize($limit);
}

$search->addSort(new FieldSort('title'));

return $repository->execute($search);
}

Expand Down
20 changes: 20 additions & 0 deletions Content/ArticleResourceItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,26 @@ public function getSeo()
return $this->article->getSeo();
}

/**
* Returns route-path.
*
* @return string
*/
public function getRoutePath()
{
return $this->article->getRoutePath();
}

/**
* Returns view-object.
*
* @return ArticleViewDocumentInterface
*/
public function getContent()
{
return $this->article;
}

/**
* {@inheritdoc}
*/
Expand Down
5 changes: 5 additions & 0 deletions DependencyInjection/SuluArticleExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,10 @@ public function load(array $configs, ContainerBuilder $container)

$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.xml');

$bundles = $container->getParameter('kernel.bundles');
if (array_key_exists('SuluAutomationBundle', $bundles)) {
$loader->load('automation.xml');
}
}
}
163 changes: 46 additions & 117 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,121 +1,50 @@
# SuluArticleBundle

[![Build Status](https://travis-ci.org/sulu/SuluArticleBundle.svg?branch=master)](https://travis-ci.org/sulu/SuluArticleBundle)
[![StyleCI](https://styleci.io/repos/61883398/shield?branch=develop)](https://styleci.io/repos/61883398)

The SuluArticleBundle adds support for managing articles in Sulu. Articles can be used in a lot of different ways to
manage unstructured data with an own URL in an admin-list. Most of the features, which can be used in pages, can also
be used on articles - like templates, versioning, drafting, publishing and automation.

Additional features included:

* Build in view-layer with elasticsearch
* Segmentation of article-templates (called article-types)
* Define URL schemas per type

## Status

This repository will become version 1.0 of SuluArticleBundle. It is under **heavy development** and currently its APIs
and code are not stable yet (pre 1.0).

## Requirements

* Composer
* PHP `^5.5 || ^7.0`
* Sulu `^1.4`
* Elasticsearch `^2.2`

For detailed requirements see [composer.json](https://github.com/sulu/SuluArticleBundle/blob/master/composer.json).

## Documentation

The the Documentation is stored in the
[Resources/doc/](https://github.com/sulu/SuluArticleBundle/blob/master/Resources/doc) folder.

## Installation

Install ElasticSearch

Install bundle over composer:

```bash
composer require sulu/article-bundle
```

Possible bundle configurations:

```yml
sulu_article:
documents:
article:
view: Sulu\Bundle\ArticleBundle\Document\ArticleViewDocument
types:

# Prototype
name:
translation_key: ~

# Display tab 'all' in list view
display_tab_all: true
```
Configure the bundles:
```yml
sulu_route:
mappings:
Sulu\Bundle\ArticleBundle\Document\ArticleDocument:
generator: schema
options:
route_schema: /articles/{object.getTitle()}

sulu_core:
content:
structure:
default_type:
article: "article_default"
paths:
article:
path: "%kernel.root_dir%/Resources/templates/articles"
type: "article"

ongr_elasticsearch:
connections:
default:
index_name: su_articles
live:
index_name: su_articles_live
managers:
default:
connection: default
mappings:
- SuluArticleBundle
live:
connection: live
mappings:
- SuluArticleBundle
```
Add xml template for structure in configured folder:
```
%kernel.root_dir%/Resources/templates/articles/article_default.xml
```

Example is located in Bundle:

```
Resources/doc/article_default.xml
```

Add template for article type in configured folder:

```
%kernel.root_dir%/Resources/views/articles/article_default.html.twig
```

Example is located in Bundle:

```
Resources/doc/article_default.html.twig
```

Configure the routing

```yml
sulu_arictle_api:
resource: "@SuluArticleBundle/Resources/config/routing_api.xml"
type: rest
prefix: /admin/api

sulu_article:
resource: "@SuluArticleBundle/Resources/config/routing.xml"
prefix: /admin/articles
```
Add bundle to AbstractKernel:
```php
new Sulu\Bundle\ArticleBundle\SuluArticleBundle(),
new ONGR\ElasticsearchBundle\ONGRElasticsearchBundle(),
```

Create required phpcr nodes:

```bash
bin/console sulu:document:init
```

Create elasticsearch index:

```bash
bin/console ongr:es:index:create
```
All the installation instructions are located in the
[Documentation](https://github.com/sulu/SuluArticleBundle/blob/master/Resources/doc/installation.md).

## License

This bundle is under the MIT license. See the complete license [in the bundle](LICENSE)

## Reporting an issue or a feature request

Issues and feature requests are tracked in the [Github issue tracker](https://github.com/Sulu/SuluArticleBundle/issues).

When reporting a bug, it may be a good idea to reproduce it in a basic project built using the
[Sulu Minimal Edition](https://github.com/sulu/sulu-minimal) to allow developers of the bundle to reproduce the issue
by simply cloning it and following some steps.
20 changes: 20 additions & 0 deletions Resources/config/automation.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<parameters>
<parameter key="sulu_article.article_document.class">Sulu\Bundle\ArticleBundle\Document\ArticleDocument</parameter>
</parameters>

<services>
<service id="sulu_article.automation.content_navigation_provider"
class="Sulu\Bundle\AutomationBundle\Admin\AutomationContentNavigationProvider">
<argument type="service" id="sulu_security.security_checker"/>
<argument type="service" id="sulu.repository.task"/>
<argument type="string">%sulu_article.article_document.class%</argument>

<tag name="sulu_admin.content_navigation" alias="article"/>
<tag name="sulu.context" context="admin"/>
</service>
</services>
</container>
Loading

0 comments on commit bcd4348

Please sign in to comment.