Skip to content
This repository was archived by the owner on Sep 16, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/Core/Content/Blog/Author/AuthorDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Magefan\Blog\Core\Content\Blog\Author;

use Magefan\Blog\Core\Content\Blog\Author\AuthorTranslation\AuthorTranslationDefinition;
use Magefan\Blog\Core\Content\Blog\Post\PostDefinition;
use Shopware\Core\Content\Media\MediaDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition;
Expand Down Expand Up @@ -61,11 +62,10 @@ protected function defineFields(): FieldCollection
return new FieldCollection([
(new IdField('id', 'id'))->addFlags(new Required(), new PrimaryKey()),
(new IdField('admin_user_id', 'adminUserId'))->addFlags(new Required()),
(new BoolField('is_active', 'isActive')),
new FkField('media_id', 'mediaId', MediaDefinition::class),

(new StringField('firstname', 'firstname')),
(new StringField('lastname', 'lastname')),
(new StringField('email', 'email')),
(new StringField('role', 'role')),
(new StringField('facebook_page_url', 'facebookPageUrl')),
(new StringField('twitter_page_url', 'twitterPageUrl')),
(new StringField('instagram_page_url', 'instagramPageUrl')),
Expand All @@ -79,6 +79,9 @@ protected function defineFields(): FieldCollection
(new LongTextField('content', 'content')),
(new LongTextField('short_content', 'short_content')),
(new StringField('featured_img', 'featuredImg')),
(new BoolField('is_active', 'isActive')),
(new StringField('email', 'email')),
(new StringField('role', 'role')),
(new StringField('page_layout', 'pageLayout')),
(new StringField('layout_update_xml', 'layoutUpdateXml')),
(new StringField('custom_theme', 'customTheme')),
Expand All @@ -91,7 +94,8 @@ protected function defineFields(): FieldCollection
(new IdField('media_id', 'mediaId')),
(new StringField('created_at', 'createdAt')),
(new StringField('updated_at', 'updatedAt')),
new FkField('media_id', 'mediaId', MediaDefinition::class),

// associations
new OneToManyAssociationField('authorPosts', PostDefinition::class, 'author_id'),
(new OneToOneAssociationField('media', 'media_id', 'id', MediaDefinition::class, true))->addFlags(new ApiAware()),
]);
Expand Down
29 changes: 19 additions & 10 deletions src/Core/Content/Blog/Category/CategoryDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@

namespace Magefan\Blog\Core\Content\Blog\Category;

use Magefan\Blog\Core\Content\Blog\Category\CategoryTranslation\CategoryTranslationDefinition;
use Magefan\Blog\Core\Content\Blog\Post\PostDefinition;
use Magefan\Blog\Core\Content\Blog\PostCategory\PostCategoryDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\Field\DateField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\ApiAware;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\CascadeDelete;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\Inherited;
use Shopware\Core\Framework\DataAbstractionLayer\Field\IntField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\LongTextField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\ManyToManyAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\OneToOneAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\TranslatedField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\TranslationsAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection;
use Shopware\Core\Framework\DataAbstractionLayer\Field\BoolField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\PrimaryKey;
Expand Down Expand Up @@ -59,16 +63,18 @@ protected function defineFields(): FieldCollection
{
return new FieldCollection([
(new IdField('id', 'id'))->addFlags(new Required(), new PrimaryKey()),
(new StringField('title', 'title'))->addFlags(new Required()),
(new StringField('meta_title', 'metaTitle')),
(new StringField('meta_keywords', 'metaKeywords')),
(new StringField('meta_description', 'metaDescription')),
(new StringField('identifier', 'identifier')),
(new LongTextField('content_heading', 'contentHeading')),
(new LongTextField('content', 'content')),
(new StringField('path', 'path')),

//translations
(new TranslatedField('title'))->addFlags(new ApiAware(), new Inherited()),
(new TranslatedField('metaTitle'))->addFlags(new ApiAware(), new Inherited()),
(new TranslatedField('metaKeywords'))->addFlags(new ApiAware(), new Inherited()),
(new TranslatedField('metaDescription'))->addFlags(new ApiAware(), new Inherited()),
(new TranslatedField('contentHeading'))->addFlags(new ApiAware(), new Inherited()),
(new TranslatedField('content'))->addFlags(new ApiAware(), new Inherited()),
(new TranslatedField('path'))->addFlags(new ApiAware(), new Inherited()),
(new TranslatedField('identifier'))->addFlags(new ApiAware(), new Inherited()),

(new IntField('position', 'position')),
(new StringField('path', 'path')),
(new StringField('posts_sort_by', 'postsSortBy')),
(new BoolField('include_in_menu', 'includeInMenu')),
(new BoolField('is_active', 'isActive')),
Expand All @@ -84,7 +90,10 @@ protected function defineFields(): FieldCollection
(new StringField('posts_list_template', 'postsListTemplate')),
(new StringField('created_at', 'createdAt')),
(new StringField('updated_at', 'updatedAt')),

// associations
(new OneToOneAssociationField('blogCategories', 'id', 'category_id', PostCategoryDefinition::class, false))->addFlags(new CascadeDelete()), new ManyToManyAssociationField('blogPosts', PostDefinition::class, PostCategoryDefinition::class, 'category_id', 'post_id'),
(new TranslationsAssociationField(CategoryTranslationDefinition::class, 'magefanblog_category_id'))->addFlags(new ApiAware(), new Required())
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* Copyright © Magefan (support@magefan.com). All rights reserved.
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
*/

declare(strict_types=1);

namespace Magefan\Blog\Core\Content\Blog\Category\CategoryTranslation;

use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;

/**
* @method void add(CategoryTranslationEntity $entity)
* @method void set(string $key, CategoryTranslationEntity $entity)
* @method CategoryTranslationEntity[] getIterator()
* @method CategoryTranslationEntity[] getElements()
* @method CategoryTranslationEntity|null get(string $key)
* @method CategoryTranslationEntity|null first()
* @method CategoryTranslationEntity|null last()
*/
class CategoryTranslationCollection extends EntityCollection
{
/**
* @return string
*/
protected function getExpectedClass(): string
{
return CategoryTranslationEntity::class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
/**
* Copyright © Magefan (support@magefan.com). All rights reserved.
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
*/

declare(strict_types=1);

namespace Magefan\Blog\Core\Content\Blog\Category\CategoryTranslation;

use Magefan\Blog\Core\Content\Blog\Category\CategoryDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\EntityTranslationDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\Field\FkField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\ApiAware;
use Shopware\Core\Framework\DataAbstractionLayer\Field\LongTextField;
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\Required;
use Shopware\Core\Framework\DataAbstractionLayer\Field\StringField;
use Shopware\Core\System\Language\LanguageDefinition;

class CategoryTranslationDefinition extends EntityTranslationDefinition
{
public const ENTITY_NAME = 'magefanblog_category_translation';

/**
* @return string
*/
public function getEntityName(): string
{
return self::ENTITY_NAME;
}

/**
* @return string
*/
public function getEntityClass(): string
{
return CategoryTranslationEntity::class;
}

/**
* @return string
*/
public function getCollectionClass(): string
{
return CategoryTranslationCollection::class;
}

protected function getParentDefinitionClass(): string
{
return CategoryDefinition::class;
}

/**
* @return FieldCollection
*/
protected function defineFields(): FieldCollection
{
return new FieldCollection([
(new FkField('language_id', 'languageId', LanguageDefinition::class))->addFlags(new ApiAware(), new Required()),
(new StringField('title', 'title'))->addFlags(new Required()),
(new StringField('meta_title', 'metaTitle')),
(new StringField('meta_keywords', 'metaKeywords')),
(new StringField('meta_description', 'metaDescription')),
(new LongTextField('content_heading', 'contentHeading')),
(new LongTextField('content', 'content')),
(new StringField('identifier', 'identifier')),
(new StringField('path', 'path')),
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* Copyright © Magefan (support@magefan.com). All rights reserved.
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
*/

declare(strict_types=1);

namespace Magefan\Blog\Core\Content\Blog\Category\CategoryTranslation;

use DateTimeInterface;
use Shopware\Core\Framework\DataAbstractionLayer\EntityIdTrait;
use Shopware\Core\Framework\DataAbstractionLayer\TranslationEntity;

class CategoryTranslationEntity extends TranslationEntity
{
use EntityIdTrait;
}
5 changes: 3 additions & 2 deletions src/Core/Content/Blog/DataResolver/BlogCategoryResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function __construct(
public function getCategory($identifier, $context)
{
$criteria = (new Criteria([]))
->addFilter(new EqualsFilter('identifier', $identifier))
->addFilter(new EqualsFilter('id', $identifier))
->addFilter(new EqualsFilter('isActive', 1))
->addAssociation('blogCategories')
->addAssociation('blogPosts');
Expand Down Expand Up @@ -97,8 +97,9 @@ public function getPostsByCategory($category, $request, $context): EntityCollect
->addAssociation('blogCategories')
->addAssociation('postTags')
->addAssociation('postAuthor')
->addFilter(new EqualsFilter('isActive', 1))
->addSorting(new FieldSorting('postTags'. '.' . $sortBy, $sorting))
->addFilter(new EqualsFilter('postCategories.identifier', $category->getIdentifier()))
->addFilter(new EqualsFilter('postCategories.id', $category->getId()))
->setLimit((bool)$category->getPostsPerPage() ? $category->getPostsPerPage() : $limit)
->setOffset($pageOffset);

Expand Down
9 changes: 0 additions & 9 deletions src/Core/Content/Blog/DataResolver/BlogListResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@

class BlogListResolver
{
/**
* @var EntityRepositoryInterface
*/
private EntityRepositoryInterface $blogAuthorRepository;

/**
* @var EntityRepositoryInterface
*/
private EntityRepositoryInterface $blogCategoryRepository;

/**
* @var SystemConfigService
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Content/Blog/DataResolver/BlogPostResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct(
public function getPost($identifier, $context)
{
$postCriteria = (new Criteria([]))
->addFilter(new EqualsFilter('identifier', $identifier))
->addFilter(new EqualsFilter('id', $identifier))
->addFilter(new EqualsFilter('isActive', 1))
->addAssociation('postCategories')
->addAssociation('postTags')
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Content/Blog/DataResolver/BlogTagResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function getTag($tagId, $context)
{
$criteria = (new Criteria([]))
->addFilter(new EqualsFilter('isActive', 1))
->addFilter(new EqualsFilter('identifier', $tagId))
->addFilter(new EqualsFilter('id', $tagId))
->addAssociation('postTags');

$author = $this->blogTagRepository->search($criteria, $context->getContext())->getEntities()->first();
Expand Down
42 changes: 26 additions & 16 deletions src/Core/Content/Blog/Post/PostDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Magefan\Blog\Core\Content\Blog\Author\AuthorDefinition;
use Magefan\Blog\Core\Content\Blog\Category\CategoryDefinition;
use Magefan\Blog\Core\Content\Blog\Comment\CommentDefinition;
use Magefan\Blog\Core\Content\Blog\Post\PostTranslation\PostTranslationDefinition;
use Magefan\Blog\Core\Content\Blog\PostCategory\PostCategoryDefinition;
use Magefan\Blog\Core\Content\Blog\PostTag\PostTagDefinition;
use Magefan\Blog\Core\Content\Blog\Tag\TagDefinition;
Expand All @@ -20,12 +21,14 @@
use Shopware\Core\Framework\DataAbstractionLayer\Field\FkField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\AllowHtml;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\ApiAware;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\Inherited;
use Shopware\Core\Framework\DataAbstractionLayer\Field\IntField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\LongTextField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\ManyToManyAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\ManyToOneAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\OneToManyAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\OneToOneAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\TranslatedField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\TranslationsAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection;
use Shopware\Core\Framework\DataAbstractionLayer\Field\BoolField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\PrimaryKey;
Expand Down Expand Up @@ -68,33 +71,40 @@ protected function defineFields(): FieldCollection
{
return new FieldCollection([
(new IdField('id', 'id'))->addFlags(new Required(), new PrimaryKey()),
(new StringField('title', 'title'))->addFlags(new Required()),
(new StringField('meta_title', 'metaTitle')),
(new StringField('meta_keywords', 'metaKeywords')),
(new StringField('meta_description', 'metaDescription')),
(new LongTextField('content_heading', 'contentHeading'))->addFlags(new AllowHtml()),
(new LongTextField('content', 'content'))->addFlags(new AllowHtml()),
(new StringField('identifier', 'identifier'))->addFlags(new Required()),
new FkField('media_id', 'mediaId', MediaDefinition::class),
new FkField('author_id', 'authorId', AuthorDefinition::class),

//translations
(new TranslatedField('title'))->addFlags(new ApiAware(), new Inherited()),
(new TranslatedField('metaTitle'))->addFlags(new ApiAware(), new Inherited()),
(new TranslatedField('metaKeywords'))->addFlags(new ApiAware(), new Inherited()),
(new TranslatedField('metaDescription'))->addFlags(new ApiAware(), new Inherited()),
(new TranslatedField('contentHeading'))->addFlags(new ApiAware(), new AllowHtml()),
(new TranslatedField('content'))->addFlags(new ApiAware(), new AllowHtml()),
(new TranslatedField('featuredImg'))->addFlags(new ApiAware(), new Inherited()),
(new TranslatedField('featuredImgAlt'))->addFlags(new ApiAware(), new Inherited()),
(new TranslatedField('ogTitle'))->addFlags(new ApiAware(), new Inherited()),
(new TranslatedField('ogDescription'))->addFlags(new ApiAware(), new Inherited()),
(new TranslatedField('ogImg'))->addFlags(new ApiAware(), new Inherited()),
(new TranslatedField('ogType'))->addFlags(new ApiAware(), new Inherited()),
(new TranslatedField('identifier'))->addFlags(new ApiAware(), new Inherited()),

(new IntField('position', 'position')),
(new StringField('featured_img', 'featuredImg')),
(new StringField('featured_img_alt', 'featuredImgAlt')),
(new BoolField('include_in_recent', 'includeInRecent')),
(new StringField('og_title', 'ogTitle')),
(new StringField('og_description', 'ogDescription')),
(new IdField('og_img', 'ogImg')),
(new StringField('og_type', 'ogType')),
(new DateTimeField('publish_time', 'publishTime')),
(new StringField('created_at', 'createdAt')),
(new StringField('updated_at', 'updatedAt')),
(new DateTimeField('publish_time', 'publishTime')),
(new BoolField('is_active', 'isActive')),
new FkField('media_id', 'mediaId', MediaDefinition::class),

// associations
(new OneToOneAssociationField('media', 'media_id', 'id', MediaDefinition::class, true))->addFlags(new ApiAware()),
new FkField('author_id', 'authorId', AuthorDefinition::class),
new ManyToOneAssociationField('postAuthor', 'author_id', AuthorDefinition::class, 'id'),
new ManyToManyAssociationField('postTags', TagDefinition::class, PostTagDefinition::class, 'post_id', 'tag_id'),
new ManyToManyAssociationField('postCategories', CategoryDefinition::class, PostCategoryDefinition::class, 'post_id', 'category_id'),
new OneToManyAssociationField('postComments', CommentDefinition::class, 'post_id')
new OneToManyAssociationField('postComments', CommentDefinition::class, 'post_id'),
(new TranslationsAssociationField(PostTranslationDefinition::class, 'magefanblog_post_id'))->addFlags(new ApiAware(), new Required())
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* Copyright © Magefan (support@magefan.com). All rights reserved.
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
*/

declare(strict_types=1);

namespace Magefan\Blog\Core\Content\Blog\Post\PostTranslation;

use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;

/**
* @method void add(PostTranslationEntity $entity)
* @method void set(string $key, PostTranslationEntity $entity)
* @method PostTranslationEntity[] getIterator()
* @method PostTranslationEntity[] getElements()
* @method PostTranslationEntity|null get(string $key)
* @method PostTranslationEntity|null first()
* @method PostTranslationEntity|null last()
*/
class PostTranslationCollection extends EntityCollection
{
/**
* @return string
*/
protected function getExpectedClass(): string
{
return PostTranslationEntity::class;
}
}
Loading