Skip to content

Commit

Permalink
Added filter for author/creator (#46)
Browse files Browse the repository at this point in the history
* First init

* Added new fields to es

* Fixed function

* Code clean up

* Code clean up

* Code clean up

* Code clean up

* Code clean up
  • Loading branch information
trickreich authored and wachterjohannes committed Mar 13, 2017
1 parent 0f407b3 commit 46584a4
Show file tree
Hide file tree
Showing 10 changed files with 427 additions and 22 deletions.
10 changes: 10 additions & 0 deletions Controller/ArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
use FOS\RestBundle\Routing\ClassResourceInterface;
use JMS\Serializer\SerializationContext;
use ONGR\ElasticsearchBundle\Service\Manager;
use ONGR\ElasticsearchDSL\Query\BoolQuery;
use ONGR\ElasticsearchDSL\Query\IdsQuery;
use ONGR\ElasticsearchDSL\Query\MatchAllQuery;
use ONGR\ElasticsearchDSL\Query\MatchQuery;
use ONGR\ElasticsearchDSL\Query\MultiMatchQuery;
use ONGR\ElasticsearchDSL\Query\TermQuery;
use ONGR\ElasticsearchDSL\Sort\FieldSort;
Expand Down Expand Up @@ -123,6 +125,14 @@ public function cgetAction(Request $request)
$search->addQuery(new TermQuery('type', $type));
}

if (null !== ($contactId = $request->get('contactId'))) {
$boolQuery = new BoolQuery();
$boolQuery->add(new MatchQuery('changer_contact_id', $contactId), BoolQuery::SHOULD);
$boolQuery->add(new MatchQuery('creator_contact_id', $contactId), BoolQuery::SHOULD);
$boolQuery->add(new MatchQuery('author_id', $contactId), BoolQuery::SHOULD);
$search->addQuery($boolQuery);
}

if (null === $search->getQueries()) {
$search->addQuery(new MatchAllQuery());
}
Expand Down
75 changes: 75 additions & 0 deletions Document/ArticleViewDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,27 @@ class ArticleViewDocument implements ArticleViewDocumentInterface
*/
protected $localizationState;

/**
* @var string
*
* @Property(type="string")
*/
protected $authorId;

/**
* @var string
*
* @Property(type="string")
*/
protected $creatorContactId;

/**
* @var string
*
* @Property(type="string")
*/
protected $changerContactId;

/**
* @param string $uuid
*/
Expand Down Expand Up @@ -607,4 +628,58 @@ public function setLocalizationState(LocalizationStateViewObject $localizationSt

return $this;
}

/**
* {@inheritdoc}
*/
public function setAuthorId($authorId)
{
$this->authorId = $authorId;

return $this;
}

/**
* {@inheritdoc}
*/
public function getAuthorId()
{
return $this->authorId;
}

/**
* {@inheritdoc}
*/
public function setCreatorContactId($creatorContactId)
{
$this->creatorContactId = $creatorContactId;

return $this;
}

/**
* {@inheritdoc}
*/
public function getCreatorContactId()
{
return $this->creatorContactId;
}

/**
* {@inheritdoc}
*/
public function setChangerContactId($changerContactId)
{
$this->changerContactId = $changerContactId;

return $this;
}

/**
* {@inheritdoc}
*/
public function getChangerContactId()
{
return $this->changerContactId;
}
}
52 changes: 50 additions & 2 deletions Document/ArticleViewDocumentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public function setTeaserMediaId($teaserMediaId);
/**
* Get published.
*
* @return $this
* @return \DateTime
*/
public function getPublished();

Expand All @@ -323,7 +323,7 @@ public function setPublished(\DateTime $published = null);
/**
* Get published state.
*
* @return $this
* @return bool
*/
public function getPublishedState();

Expand Down Expand Up @@ -351,4 +351,52 @@ public function getLocalizationState();
* @return $this
*/
public function setLocalizationState(LocalizationStateViewObject $localizationState);

/**
* Set author id.
*
* @param string $authorId
*
* @return $this
*/
public function setAuthorId($authorId);

/**
* Get author id.
*
* @return string
*/
public function getAuthorId();

/**
* Set creator contact id.
*
* @param string $creatorContactId
*
* @return $this
*/
public function setCreatorContactId($creatorContactId);

/**
* Get creator contact id.
*
* @return string
*/
public function getCreatorContactId();

/**
* Set creator contact id.
*
* @param string $changerContactId
*
* @return $this
*/
public function setChangerContactId($changerContactId);

/**
* Get changer contact id.
*
* @return string
*/
public function getChangerContactId();
}
23 changes: 20 additions & 3 deletions Document/Index/ArticleIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
use Sulu\Bundle\ArticleBundle\Event\IndexEvent;
use Sulu\Bundle\ArticleBundle\Metadata\ArticleTypeTrait;
use Sulu\Bundle\ArticleBundle\Metadata\ArticleViewDocumentIdTrait;
use Sulu\Bundle\ContactBundle\Entity\Contact;
use Sulu\Bundle\ContactBundle\Entity\ContactRepository;
use Sulu\Bundle\SecurityBundle\Entity\User;
use Sulu\Bundle\SecurityBundle\UserManager\UserManager;
use Sulu\Component\Content\Document\LocalizationState;
use Sulu\Component\Content\Document\WorkflowStage;
Expand Down Expand Up @@ -199,13 +201,28 @@ protected function createOrUpdateArticle(
$article->setCreated($document->getCreated());
$article->setAuthored($document->getAuthored());
if ($document->getAuthor()) {
$article->setAuthorFullName($this->contactRepository->findById($document->getAuthor())->getFullName());
/** @var Contact $author */
$author = $this->contactRepository->findById($document->getAuthor());
if ($author) {
$article->setAuthorFullName($author->getFullName());
$article->setAuthorId($author->getId());
}
}
if ($document->getChanger()) {
$article->setChangerFullName($this->userManager->getFullNameByUserId($document->getChanger()));
/** @var User $changer */
$changer = $this->userManager->getUserById($document->getChanger());
if ($changer) {
$article->setChangerFullName($changer->getFullName());
$article->setChangerContactId($changer->getContact()->getId());
}
}
if ($document->getCreator()) {
$article->setCreatorFullName($this->userManager->getFullNameByUserId($document->getCreator()));
/** @var User $creator */
$creator = $this->userManager->getUserById($document->getCreator());
if ($creator) {
$article->setCreatorFullName($creator->getFullName());
$article->setCreatorContactId($creator->getContact()->getId());
}
}
$article->setType($this->getType($structureMetadata));
$article->setStructureType($document->getStructureType());
Expand Down
3 changes: 3 additions & 0 deletions Resources/config/serializer/Document.ArticleViewDocument.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@
<property name="published" type="DateTime" expose="true"/>
<property name="publishedState" type="boolean" expose="true"/>
<property name="localizationState" type="Sulu\Bundle\ArticleBundle\Document\LocalizationStateViewObject" expose="true"/>
<property name="authorId" type="string" expose="true"/>
<property name="creatorContactId" type="string" expose="true"/>
<property name="changerContactId" type="string" expose="true"/>
</class>
</serializer>
2 changes: 1 addition & 1 deletion Resources/public/dist/components/articles/list/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 46584a4

Please sign in to comment.