Commit 99ed7a09 authored by Hermann Mayer's avatar Hermann Mayer

Implemented Feature #24. Comments can now be written anonymously.

parent fbab8945
......@@ -121,6 +121,7 @@ class BlogController extends Controller
* @param mixed $comment Prebuild Comment which fill the form
* @param mixed $form Prebuild Form which will be used
* @param mixed $action Action URI for the form
* @param boolean $anonymous Render the anonymous fields of the form
* @param boolean $renderFormTag Render the HTML form tags
* @param boolean $visible Should the form be visible by default
*
......@@ -131,6 +132,7 @@ class BlogController extends Controller
$comment = null,
$form = null,
$action = null,
$anonymous = true,
$renderFormTag = true,
$visible = true)
{
......@@ -138,7 +140,9 @@ class BlogController extends Controller
$form = $this
->createForm(
new CommentType(),
new CommentType(
($anonymous) ? true : false
),
(!$comment) ? new Comment() : $comment
)
->createView();
......@@ -157,16 +161,28 @@ class BlogController extends Controller
*
* Creates a new Comment entity.
*
* @param Request $request Request Object
* @param mixed $id Id of the article to connect the comment to
* @param Request $request Request Object
* @param mixed $id Id of the article to connect the comment to
* @param mixed $anonymous Should be validated as anonymously commited
*
* @access public
* @return Response
*/
public function createCommentAction(Request $request, $id)
public function createCommentAction(Request $request, $id, $anonymous)
{
$entity = new Comment();
$form = $this->createForm(new CommentType(), $entity);
if ($anonymous) {
$form = $this->createForm(new CommentType(), $entity, array(
'validation_groups' => array('anonymous')
));
} else {
$form = $this->createForm(new CommentType(), $entity);
}
$form->bind($request);
$em = $this->getDoctrine()->getManager();
......@@ -204,8 +220,8 @@ class BlogController extends Controller
);
}
return $this->render('JityHomepageBundle:Blog:show.html.twig', array(
'article' => $article,
return $this->render('JityHomepageBundle:Blog:show_article.html.twig', array(
'article' => $article,
'form_new' => $form->createView(),
));
}
......@@ -244,7 +260,7 @@ class BlogController extends Controller
$entity = new Comment();
$form = $this->createForm(new CommentType(), $entity);
return $this->render('JityHomepageBundle:Blog:show.html.twig', array(
return $this->render('JityHomepageBundle:Blog:show_article.html.twig', array(
'article' => $entity->getArticle()
));
}
......@@ -310,9 +326,9 @@ class BlogController extends Controller
);
}
return $this->render('JityHomepageBundle:Blog:show.html.twig', array(
'article' => $entity->getArticle(),
'form_edit' => $form->createView(),
return $this->render('JityHomepageBundle:Blog:show_article.html.twig', array(
'article' => $entity->getArticle(),
'form_edit' => $form->createView(),
));
}
}
......
......@@ -42,17 +42,37 @@ class Comment
**/
protected $article;
/**
* @ORM\Column(type="text")
*/
protected $content;
/**
* @ORM\ManyToOne(targetEntity="User", inversedBy="comments")
* @ORM\JoinColumn(name="author_id", referencedColumnName="id")
**/
protected $author;
/**
* @ORM\Column(type="string", nullable=true)
*/
protected $authorName;
/**
* @ORM\Column(type="string", nullable=true)
*/
protected $authorEmail;
/**
* @ORM\Column(type="string", nullable=true)
*/
protected $authorWebsite;
/**
* @ORM\Column(type="string", nullable=true)
*/
protected $authorTwitterNickname;
/**
* @ORM\Column(type="text")
*/
protected $content;
/**
* @Gedmo\Timestampable(on="create")
* @ORM\Column(type="datetime")
......@@ -228,5 +248,125 @@ class Comment
{
return $this->author;
}
/**
* setAuthorName
*
* Set the anonymous author name of the entity.
*
* @param string $name Name of the anonymous author
*
* @access public
* @return Comment
*/
public function setAuthorName($name)
{
$this->authorName = $name;
return $this;
}
/**
* getAuthorName
*
* Get the anonymous author name of the entity.
*
* @access public
* @return string
*/
public function getAuthorName()
{
return $this->authorName;
}
/**
* setAuthorEmail
*
* Set the anonymous author email of the entity.
*
* @param string $email Email address of the anonymous author
*
* @access public
* @return Comment
*/
public function setAuthorEmail($email)
{
$this->authorEmail = $email;
return $this;
}
/**
* getAuthorEmail
*
* Get the anonymous author email of the entity.
*
* @access public
* @return string
*/
public function getAuthorEmail()
{
return $this->authorEmail;
}
/**
* setAuthorWebsite
*
* Set the anonymous author website of the entity.
*
* @param string $website Website of the anonymous author
*
* @access public
* @return Comment
*/
public function setAuthorWebsite($website)
{
$this->authorWebsite = $website;
return $this;
}
/**
* getAuthorWebsite
*
* Get the anonymous author website of the entity.
*
* @access public
* @return string
*/
public function getAuthorWebsite()
{
return $this->authorWebsite;
}
/**
* setAuthorTwitterNickname
*
* Set the anonymous author twitter nickname of the entity.
*
* @param string $twitterNickname Twitter Nickname of the anonymous author
*
* @access public
* @return Comment
*/
public function setAuthorTwitterNickname($twitterNickname)
{
$this->authorTwitterNickname = $twitterNickname;
return $this;
}
/**
* getAuthorTwitterNickname
*
* Get the anonymous author twitter nickname of the entity.
*
* @access public
* @return string
*/
public function getAuthorTwitterNickname()
{
return $this->authorTwitterNickname;
}
}
......@@ -26,6 +26,23 @@ use Jity\HomepageBundle\Form\UserType,
*/
class CommentType extends AbstractType
{
private $anonymous;
/**
* __construct
*
* Initalize a new CommentType instance.
*
* @param int $anonymous Show anonymous fields
*
* @access public
* @return void
*/
public function __construct($anonymous = true)
{
$this->anonymous = $anonymous;
}
/**
* buildForm
*
......@@ -39,13 +56,47 @@ class CommentType extends AbstractType
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
if (true === $this->anonymous) {
$builder
->add('authorName', null, array(
'attr' => array(
'class' => 'span4',
'placeholder' => 'Ihr Name'
),
'label' => false
))
->add('authorEmail', null, array(
'attr' => array(
'class' => 'span4',
'placeholder' => 'Ihre Email Adresse (Wird nicht veröffentlicht)'
),
'label' => false
))
->add('authorWebsite', null, array(
'attr' => array(
'class' => 'span4',
'placeholder' => 'Ihre Website'
),
'label' => false
))
->add('authorTwitterNickname', null, array(
'attr' => array(
'class' => 'span4',
'placeholder' => 'Ihr Twittername'
),
'label' => false
));
}
$builder
->add('content', null, array(
'attr' => array(
'rows' => '3',
'class' => 'span4',
'data-target' => '#editor_modal',
'data-toggle' => 'modal'
'data-toggle' => 'modal',
'placeholder' => 'Ihr neuer Kommentar..'
),
'label' => false,
));
......
......@@ -28,3 +28,4 @@ author_article_delete:
pattern: /{id}/delete
defaults: { _controller: "JityHomepageBundle:Article:delete" }
requirements: { _method: post }
......@@ -5,8 +5,8 @@ article:
_format: html|rss
article_comment_create:
pattern: /comment/{id}/create
defaults: { _controller: "JityHomepageBundle:Blog:createComment" }
pattern: /comment/{id}/create/anonymous/{anonymous}
defaults: { _controller: "JityHomepageBundle:Blog:createComment", anonymous: true }
requirements: { _method: post }
article_comment_delete:
......
......@@ -36,6 +36,12 @@ Jity\HomepageBundle\Entity\AbstractPage:
Jity\HomepageBundle\Entity\Comment:
properties:
authorName:
- NotBlank: { groups: [anonymous], message: "Diese Angabe muss noch ausgefüllt werden." }
- Length: { groups: [anonymous], min: 2, minMessage: "Diese Angabe muss mindestens {{ limit }} Zeichen lang sein." }
authorEmail:
- NotBlank: { groups: [anonymous], message: "Diese Angabe muss noch ausgefüllt werden." }
- Email: { groups: [anonymous], checkMX: true, message: "Die angegebene Email Adresse ist nicht valid." }
content:
- NotBlank: { message: "Diese Angabe muss noch ausgefüllt werden." }
- Length: { min: 2, minMessage: "Diese Angabe muss mindestens {{ limit }} Zeichen lang sein." }
......
......@@ -54,8 +54,21 @@
{% for comment in article.comments %}
<div class="blog-article-comments-section-wrapper">
{% set editGranted = false %}
{% if app.user %}
{% if (comment.author.email == app.user.email) or (is_granted('ROLE_AUTHOR')) %}
{% if is_granted('ROLE_AUTHOR') %}
{% set editGranted = true %}
{% endif %}
{% if comment.author and editGranted == false %}
{% if comment.author.email == app.user.email %}
{% set editGranted = true %}
{% endif %}
{% endif %}
{% endif %}
{% if true == editGranted %}
<div class="controllpanel">
<a class="btn btn-primary btn-edit" title="Bearbeiten" href="#">
......@@ -69,7 +82,6 @@
{% render 'JityHomepageBundle:Blog:deleteCommentForm' with {id: comment.id, renderForm: true, action: path('article_comment_delete', {id: comment.id}) } %}
{% endif %}
{% endif %}
<div class="blog-article-comments-section">
......@@ -77,6 +89,14 @@
<h4>
{% if comment.author %}
{{ comment.author.firstName ~ " " ~ comment.author.lastName }}
{% elseif comment.authorName is not empty %}
{{ comment.authorName }}
{% if comment.authorTwitterNickname is not empty %}
<small>(<i class="icon-white icon-user"></i> <a href="http://twitter.com/{{ comment.authorTwitterNickname }}">{{ comment.authorTwitterNickname }}</a>)</small>
{% endif %}
{% else %}
Anonymous
{% endif %}
......@@ -97,28 +117,22 @@
</p>
</span>
{% if app.user %}
{% if (comment.author.email == app.user.email) or (is_granted('ROLE_AUTHOR')) %}
<form action="{{ path('article_comment_update', {id: comment.id}) }}#new-comment" method="post" style="display: none">
<form action="{{ path('article_comment_update', {id: comment.id}) }}#new-comment" method="post" style="display: none">
{% if form_edit is not defined %}
{% render 'JityHomepageBundle:Blog:createCommentForm' with {renderFormTag: false, comment: comment} %}
{% else %}
{% render 'JityHomepageBundle:Blog:createCommentForm' with {renderFormTag: false, form: form_edit} %}
{% endif %}
<div class="form-actions">
<button type="submit" class="btn btn-primary">
<i class="icon-pencil icon-white"></i>
Speichern
</button>
</div>
{% if form_edit is not defined %}
{% render 'JityHomepageBundle:Blog:createCommentForm' with {renderFormTag: false, comment: comment} %}
{% else %}
{% render 'JityHomepageBundle:Blog:createCommentForm' with {renderFormTag: false, form: form_edit} %}
{% endif %}
</form>
<div class="form-actions">
<button type="submit" class="btn btn-primary">
<i class="icon-pencil icon-white"></i>
Speichern
</button>
</div>
{% endif %}
{% endif %}
</form>
</div>
</div>
......@@ -127,34 +141,52 @@
<div class="blog-article-comments-new-section">
{% set anonymous = true %}
{% set anonymousParam = 1 %}
{% if app.user %}
{% if is_granted('ROLE_USER') %}
{% set anonymous = false %}
{% set anonymousParam = 0 %}
{% endif %}
{% endif %}
<a name="new-comment"></a>
<form action="{{ path('article_comment_create', {id: article.id}) }}#new-comment" method="post">
<form action="{{ path('article_comment_create', {id: article.id, anonymous: anonymousParam}) }}#new-comment" method="post">
<legend class="h2">Neuen Kommentar verfassen</legend>
{% if not is_granted('ROLE_USER') %}
<p>
Um einen neuen Kommentar verfassen zu können füllen
Sie das folgende Formular mit Ihren Daten aus.
</p>
<p>Um einen neuen Kommentar verfassen zu können loggen Sie sich mittels externer Dienste
oder mit Ihrem Account von dieser Seite ein.</p>
{% if form_new is not defined %}
{% render 'JityHomepageBundle:Blog:createCommentForm' with {renderFormTag: false, anonymous: anonymous} %}
{% else %}
{% render 'JityHomepageBundle:Blog:createCommentForm' with {renderFormTag: false, anonymous: anonymous, form: form_new} %}
{% endif %}
<div class="center">
{% render 'JityHomepageBundle:Security:renderLoginLinks' with {destination: path('article', {slug: article.slug}) ~ "#new-comment" } %}
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">
<i class="icon-pencil icon-white"></i>
Schreiben
</button>
</div>
{% else %}
{% if not is_granted('ROLE_USER') %}
<legend class="h2">Einloggen um einen Kommentar zu verfassen</legend>
{% if form_new is not defined %}
{% render 'JityHomepageBundle:Blog:createCommentForm' with {renderFormTag: false} %}
{% else %}
{% render 'JityHomepageBundle:Blog:createCommentForm' with {renderFormTag: false, form: form_new} %}
{% endif %}
<p>
Alternativ können Sie sich mittels externer Dienste
oder mit Ihrem Account von dieser Seite einloggen.
Dieser Schritt erspart Ihnen das angeben ihrer Daten.
</p>
<div class="form-actions">
<button type="submit" class="btn btn-primary">
<i class="icon-pencil icon-white"></i>
Schreiben
</button>
<div class="center">
{% render 'JityHomepageBundle:Security:renderLoginLinks' with {destination: path('article', {slug: article.slug}) ~ "#new-comment" } %}
</div>
{% endif %}
......@@ -234,7 +266,7 @@ $(document).ready(function() {
if ((position > navbarHeight) && (position < maxTop)) {
// User cant see the top and isnt near to the bottom
var curTop = $('.row:first').position().top - navbarHeight;
var curTop = $('.wrapper .row:first').position().top - navbarHeight;
// Reset Style in favor of getting clean left-value (resize)
helper.attr('style', '');
......
......@@ -42,6 +42,8 @@
&mdash; <small>
{% if comment.author %}
{{ comment.author.firstName ~ " " ~ comment.author.lastName }}
{% elseif comment.authorName is not empty %}
{{ comment.authorName }}
{% else %}
Anonymous
{% endif %}
......
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