Commit f13ea9b7 authored by Emma's avatar Emma

give categories sidebars and descriptions

parent 5904abc4
......@@ -45,6 +45,16 @@ class ForumCategory {
*/
private $title;
/**
* @ORM\Column(type="text")
*/
private $description;
/**
* @ORM\Column(type="text")
*/
private $sidebar;
/**
* @ORM\OneToMany(targetEntity="Forum", mappedBy="category")
* @ORM\OrderBy({"normalizedName": "ASC"})
......@@ -53,9 +63,11 @@ class ForumCategory {
*/
private $forums;
public function __construct(string $name, string $title) {
public function __construct(string $name, string $title, string $description, string $sidebar) {
$this->setName($name);
$this->title = $title;
$this->description = $description;
$this->sidebar = $sidebar;
$this->forums = new ArrayCollection();
}
......@@ -85,6 +97,22 @@ class ForumCategory {
$this->title = $title;
}
public function getDescription(): string {
return $this->description;
}
public function setDescription(string $description): void {
$this->description = $description;
}
public function getSidebar(): string {
return $this->sidebar;
}
public function setSidebar(string $sidebar): void {
$this->sidebar = $sidebar;
}
/**
* @return Collection|Selectable|Forum[]
*/
......
......@@ -5,6 +5,7 @@ namespace App\Form;
use App\Form\Model\ForumCategoryData;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
......@@ -16,6 +17,12 @@ class ForumCategoryType extends AbstractType {
])
->add('title', TextType::class, [
'label' => 'label.title',
])
->add('description', TextareaType::class, [
'label' => 'label.description',
])
->add('sidebar', TextareaType::class, [
'label' => 'label.sidebar',
]);
}
......
......@@ -38,21 +38,46 @@ final class ForumCategoryData {
*/
private $title;
/**
* @Assert\Length(max=300)
* @Assert\NotBlank()
*
* @var string|null
*/
private $description;
/**
* @Assert\Length(max=1500)
* @Assert\NotBlank()
*
* @var string|null
*/
private $sidebar;
public function __construct(ForumCategory $forumCategory = null) {
if ($forumCategory) {
$this->entityId = $forumCategory->getId();
$this->setName($forumCategory->getName());
$this->title = $forumCategory->getTitle();
$this->description = $forumCategory->getDescription();
$this->sidebar = $forumCategory->getSidebar();
}
}
public function toForumCategory(): ForumCategory {
return new ForumCategory($this->name, $this->title);
return new ForumCategory(
$this->name,
$this->title,
$this->description,
$this->sidebar
);
}
public function updateForumCategory(ForumCategory $category): void {
$category->setName($this->name);
$category->setTitle($this->title);
$category->setDescription($this->description);
$category->setSidebar($this->sidebar);
}
public function getEntityId(): ?int {
......@@ -81,4 +106,20 @@ final class ForumCategoryData {
public function setTitle(?string $title): void {
$this->title = $title;
}
public function getDescription(): ?string {
return $this->description;
}
public function setDescription(?string $description): void {
$this->description = $description;
}
public function getSidebar(): ?string {
return $this->sidebar;
}
public function setSidebar(?string $sidebar): void {
$this->sidebar = $sidebar;
}
}
<?php
namespace DoctrineMigrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
class Version20180421163300 extends AbstractMigration {
public function up(Schema $schema) {
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE forum_categories ADD description TEXT');
$this->addSql('UPDATE forum_categories SET description = title');
$this->addSql('ALTER TABLE forum_categories ALTER description SET NOT NULL');
$this->addSql('ALTER TABLE forum_categories ADD sidebar TEXT');
$this->addSql('UPDATE forum_categories SET sidebar = title');
$this->addSql('ALTER TABLE forum_categories ALTER sidebar SET NOT NULL');
}
public function down(Schema $schema) {
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE forum_categories DROP description');
$this->addSql('ALTER TABLE forum_categories DROP sidebar');
}
}
......@@ -16,7 +16,9 @@
{% for category in forum_categories %}
<li class="forum-group">
<h1 class="forum-group-heading">
<a href="{{ path('forum_category', {name: category.name}) }}">{{ category.title }}</a>
<a href="{{ path('forum_category', {name: category.name}) }}" title="{{ category.description }}">
{{- category.title -}}
</a>
</h1>
<ul class="forum-group-list">
......
......@@ -10,6 +10,10 @@
{{ form_row(form.title) }}
{{ form_row(form.description) }}
{{ form_row(form.sidebar, { attr: { rows: 8 } }) }}
<div class="form__row form__button-row">
<button class="button">{{ (editing ? 'action.edit' : 'action.create')|trans }}</button>
</div>
......
......@@ -5,10 +5,32 @@
{% block page_classes 'forum-category-page' %}
{% block title 'heading.category'|trans({'%category%': category.title}) %}
{% block head %}
{{ parent() }}
<meta name="description" content="{{ category.description }}">
{% endblock %}
{% block sidebar %}
<section class="sidebar__section">
<h2 class="sidebar__title">/c/{{ category.name }}</h2>
{{ category.sidebar|cached_markdown|raw }}
{% if is_granted('ROLE_ADMIN') %}
<nav>
<p>
<a href="{{ path('edit_forum_category', {name: category.name}) }}"
class="button button--inline">
{{- 'action.edit'|trans -}}
</a>
</p>
</nav>
{% endif %}
</section>
<section class="sidebar__section">
<h2 class="sidebar__title">{{ 'label.forums_in_this_category'|trans }}</h2>
<ul>
{% for forum in forums %}
<li><a href="{{ path('forum', {forum_name: forum}) }}">{{ forum }}</a></li>
......@@ -18,14 +40,14 @@
{% endblock %}
{% block body %}
<h1 class="page-heading">{{ 'heading.category'|trans({'%category%': category.title}) }}</h1>
<nav class="tabs submission-sort">
<ul class="tabs__bar">
{{- submission_sort(sort_by) -}}
</ul>
</nav>
<h1 class="page-heading">{{ 'heading.category'|trans({'%category%': category.title}) }}</h1>
{% for submission in submissions %}
{{ submission(submission) }}
{% endfor %}
......
......@@ -290,6 +290,8 @@ label:
event.edit_submission: Edit submission
event.new_comment: New comment
event.edit_comment: Edit comment
forums_in_this_category: Forums in this category
description: Description
log:
comment_deletion: '%user% deleted comment by %author% in "%submission%"'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment