add deprecated post feature
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/deployment/woodpecker Pipeline was successful

This commit is contained in:
Simon Vieille 2023-09-10 22:49:31 +02:00
parent bad87d913e
commit 3d6acca60a
Signed by: deblan
GPG key ID: 579388D585F70417
6 changed files with 115 additions and 17 deletions

View file

@ -1363,3 +1363,18 @@ $links: (
} }
} }
} }
.deprecated {
color: #fff;
background: #3abff8;
padding: 1rem;
border-radius: var(--rounded-box, 1rem);
text-align: center;
svg {
display: inline-block;
height: 25px;
vertical-align: top;
margin-right: 8px;
}
}

View file

@ -90,11 +90,18 @@ class Post implements EntityInterface
#[ORM\Column(type: 'array')] #[ORM\Column(type: 'array')]
private $parameters = []; private $parameters = [];
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'deprecatedPosts')]
private $recommandedPost;
#[ORM\OneToMany(mappedBy: 'recommandedPost', targetEntity: self::class)]
private $deprecatedPosts;
public function __construct() public function __construct()
{ {
$this->categories = new ArrayCollection(); $this->categories = new ArrayCollection();
$this->comments = new ArrayCollection(); $this->comments = new ArrayCollection();
$this->postFollows = new ArrayCollection(); $this->postFollows = new ArrayCollection();
$this->deprecatedPosts = new ArrayCollection();
} }
public function getId(): ?int public function getId(): ?int
@ -475,4 +482,46 @@ class Post implements EntityInterface
} }
)[0]['value'] ?? null; )[0]['value'] ?? null;
} }
public function getRecommandedPost(): ?self
{
return $this->recommandedPost;
}
public function setRecommandedPost(?self $recommandedPost): self
{
$this->recommandedPost = $recommandedPost;
return $this;
}
/**
* @return Collection<int, self>
*/
public function getDeprecatedPosts(): Collection
{
return $this->deprecatedPosts;
}
public function addDeprecatedPost(self $deprecatedPost): self
{
if (!$this->deprecatedPosts->contains($deprecatedPost)) {
$this->deprecatedPosts[] = $deprecatedPost;
$deprecatedPost->setRecommandedPost($this);
}
return $this;
}
public function removeDeprecatedPost(self $deprecatedPost): self
{
if ($this->deprecatedPosts->removeElement($deprecatedPost)) {
// set the owning side to null (unless already changed)
if ($deprecatedPost->getRecommandedPost() === $this) {
$deprecatedPost->setRecommandedPost(null);
}
}
return $this;
}
} }

View file

@ -113,6 +113,28 @@ class PostType extends AbstractType
] ]
); );
$builder->add(
'recommandedPost',
EntityType::class,
[
'label' => 'Article recommandé',
'class' => Post::class,
'choice_label' => 'title',
'required' => false,
'multiple' => false,
'attr' => [
'data-jschoice' => '',
],
'query_builder' => function (EntityRepository $repo) {
return $repo->createQueryBuilder('a')
->orderBy('a.title', 'ASC')
;
},
'constraints' => [
],
]
);
$builder->add( $builder->add(
'status', 'status',
ChoiceType::class, ChoiceType::class,
@ -301,19 +323,19 @@ class PostType extends AbstractType
] ]
); );
$builder->add( // $builder->add(
'parameters', // 'parameters',
MurphCollectionType::class, // MurphCollectionType::class,
[ // [
'label' => 'Paramètres', // 'label' => 'Paramètres',
'entry_type' => PostParameterType::class, // 'entry_type' => PostParameterType::class,
'by_reference' => false, // 'by_reference' => false,
'allow_add' => true, // 'allow_add' => true,
'allow_delete' => true, // 'allow_delete' => true,
'prototype' => true, // 'prototype' => true,
'row_attr' => ['class' => 'mb-3'], // 'row_attr' => ['class' => 'mb-3'],
] // ]
); // );
} }
public function configureOptions(OptionsResolver $resolver) public function configureOptions(OptionsResolver $resolver)

View file

@ -1,7 +1,7 @@
<div class="row"> <div class="row">
<div class="col-md-3 p-3"> <div class="col-md-3 p-3">
<div class="row"> <div class="row">
{% for item in ['categories', 'slug'] %} {% for item in ['categories', 'slug', 'recommandedPost'] %}
<div class="col-md-12"> <div class="col-md-12">
{{ form_row(form[item]) }} {{ form_row(form[item]) }}
</div> </div>
@ -38,7 +38,7 @@
</span> </span>
</div> </div>
{% for item in ['image', 'image2', 'parameters', 'status', 'contentFormat', 'publishedAt'] %} {% for item in ['image', 'image2', 'status', 'contentFormat', 'publishedAt'] %}
<div class="col-md-12"> <div class="col-md-12">
{{ form_row(form[item]) }} {{ form_row(form[item]) }}
</div> </div>

View file

@ -3,7 +3,7 @@
{% block list_item_actions_before %} {% block list_item_actions_before %}
{% if configuration.action(context, 'analytic_stats', true) %} {% if configuration.action(context, 'analytic_stats', true) %}
{% set analytics = path( {% set analytics = path(
configuration.pageRoute('analytic_stats'), configuration.pageRoute('analytic_stats'),
{entity: item.id}|merge(configuration.pageRouteParams('analytic_stats')) {entity: item.id}|merge(configuration.pageRouteParams('analytic_stats'))
) %} ) %}

View file

@ -38,7 +38,19 @@
</div> </div>
{% endif %} {% endif %}
<div class="body-content {% if post.parameter('podcast') %}is-podcast{% endif %}"> <div class="body-content">
{%- if post.recommandedPost -%}
<div class="deprecated">
<svg stroke-width="2" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" color="#ffffff"><path d="M20.043 21H3.957c-1.538 0-2.5-1.664-1.734-2.997l8.043-13.988c.77-1.337 2.699-1.337 3.468 0l8.043 13.988C22.543 19.336 21.58 21 20.043 21zM12 9v4" stroke="#ffffff" stroke-width="2" stroke-linecap="round"></path><path d="M12 17.01l.01-.011" stroke="#ffffff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>
<strong>Cet article est déprécié</strong><br>
Article recommandé : <a href="{{ safe_path('blog_menu_post', {
post: post.recommandedPost.id,
slug: post.recommandedPost.slug,
_domain: _domain})
}}"><strong>{{ post.recommandedPost.title }}</strong></a>
</div>
{%- endif -%}
{% if post.contentFormat == 'html' %} {% if post.contentFormat == 'html' %}
{{- post.content|murph_url|file_attributes|post -}} {{- post.content|murph_url|file_attributes|post -}}
{% elseif post.contentFormat == 'markdown' %} {% elseif post.contentFormat == 'markdown' %}