Added blog post view functionality
Signed-off-by: Gergely Polonkai <polesz@w00d5t0ck.info>
This commit is contained in:
parent
6747a48332
commit
764951f73c
31
app/DoctrineMigrations/Version20120827162130.php
Normal file
31
app/DoctrineMigrations/Version20120827162130.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Application\Migrations;
|
||||
|
||||
use Doctrine\DBAL\Migrations\AbstractMigration,
|
||||
Doctrine\DBAL\Schema\Schema;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your need!
|
||||
*/
|
||||
class Version20120827162130 extends AbstractMigration
|
||||
{
|
||||
public function up(Schema $schema)
|
||||
{
|
||||
// this up() migration is autogenerated, please modify it to your needs
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql");
|
||||
|
||||
$this->addSql("CREATE TABLE blog_posts (id INT AUTO_INCREMENT NOT NULL, group_id INT DEFAULT NULL, created_by_id INT NOT NULL, updated_by_id INT DEFAULT NULL, published TINYINT(1) NOT NULL, title VARCHAR(150) NOT NULL, slug VARCHAR(150) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME DEFAULT NULL, update_reason VARCHAR(255) DEFAULT NULL, content LONGTEXT NOT NULL, INDEX IDX_78B2F932FE54D947 (group_id), INDEX IDX_78B2F932B03A8386 (created_by_id), INDEX IDX_78B2F932896DBBDE (updated_by_id), PRIMARY KEY(id)) ENGINE = InnoDB");
|
||||
$this->addSql("ALTER TABLE blog_posts ADD CONSTRAINT FK_78B2F932FE54D947 FOREIGN KEY (group_id) REFERENCES groups (id)");
|
||||
$this->addSql("ALTER TABLE blog_posts ADD CONSTRAINT FK_78B2F932B03A8386 FOREIGN KEY (created_by_id) REFERENCES users (id)");
|
||||
$this->addSql("ALTER TABLE blog_posts ADD CONSTRAINT FK_78B2F932896DBBDE FOREIGN KEY (updated_by_id) REFERENCES users (id)");
|
||||
}
|
||||
|
||||
public function down(Schema $schema)
|
||||
{
|
||||
// this down() migration is autogenerated, please modify it to your needs
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql");
|
||||
|
||||
$this->addSql("DROP TABLE blog_posts");
|
||||
}
|
||||
}
|
57
src/KekRozsak/FrontBundle/Controller/BlogController.php
Normal file
57
src/KekRozsak/FrontBundle/Controller/BlogController.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
namespace KekRozsak\FrontBundle\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
|
||||
|
||||
/**
|
||||
* @Route("/blog")
|
||||
*/
|
||||
class BlogController extends Controller
|
||||
{
|
||||
/**
|
||||
* @Route("/", name="KekRozsakFrontBundle_blogList")
|
||||
* @Template()
|
||||
*/
|
||||
public function listAction()
|
||||
{
|
||||
$query = $this
|
||||
->getDoctrine()
|
||||
->getEntityManager()
|
||||
->createQuery('
|
||||
SELECT
|
||||
p
|
||||
FROM
|
||||
KekRozsakFrontBundle:BlogPost p
|
||||
LEFT JOIN
|
||||
p.group g
|
||||
LEFT JOIN
|
||||
g.members m
|
||||
WHERE
|
||||
(
|
||||
(
|
||||
p.group IS NULL
|
||||
OR m.user = :user
|
||||
)
|
||||
AND p.published = true
|
||||
)
|
||||
OR p.createdBy = :user
|
||||
');
|
||||
$query->
|
||||
setParameter(
|
||||
'user',
|
||||
$this
|
||||
->get('security.context')
|
||||
->getToken()
|
||||
->getUser()
|
||||
->getId()
|
||||
);
|
||||
$blogPosts = $query->getResult();
|
||||
|
||||
return array(
|
||||
'posts' => $blogPosts,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,347 @@
|
||||
<?php
|
||||
/*
|
||||
* id
|
||||
* title
|
||||
* slug
|
||||
* createdBy
|
||||
* createdAt
|
||||
* updatedBy
|
||||
* updatedAt
|
||||
* updateReason
|
||||
* lead(?)
|
||||
* content
|
||||
* public
|
||||
* Group (can be NULL)
|
||||
namespace KekRozsak\FrontBundle\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use KekRozsak\SecurityBundle\Entity\User;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="blog_posts")
|
||||
*/
|
||||
class BlogPost
|
||||
{
|
||||
/**
|
||||
* The ID of the BlogPost
|
||||
*
|
||||
* var integer $id
|
||||
*
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* Get id
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* True if the BlogPost is published. If not, only the author and the
|
||||
* administrators can see it.
|
||||
*
|
||||
* @var boolean $published
|
||||
*
|
||||
* @ORM\Column(type="boolean", nullable=false)
|
||||
*/
|
||||
protected $published;
|
||||
|
||||
/**
|
||||
* Set published
|
||||
*
|
||||
* @param boolean $published
|
||||
* @return BlogPost
|
||||
*/
|
||||
public function setPublished($published)
|
||||
{
|
||||
// TODO: Check if parameter is boolean!
|
||||
$this->published = $published;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get published
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isPublished()
|
||||
{
|
||||
return $this->published;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Group which this BlogPost is associated with
|
||||
*
|
||||
* @var KekRozsak\FrontBundle\Entity\Group $group
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="KekRozsak\FrontBundle\Entity\Group")
|
||||
* @ORM\JoinColumn(name="group_id", nullable=true)
|
||||
*/
|
||||
protected $group;
|
||||
|
||||
/**
|
||||
* Set group
|
||||
*
|
||||
* @param KekRozsak\FrontBundle\Entity\Group $group
|
||||
* @return BlogPost
|
||||
*/
|
||||
public function setGroup(Group $group)
|
||||
{
|
||||
$this->group = $group;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get group
|
||||
*
|
||||
* @return KekRozsak\FrontBundle\Entity\Group
|
||||
*/
|
||||
public function getGroup()
|
||||
{
|
||||
return $this->group;
|
||||
}
|
||||
|
||||
/**
|
||||
* The title of the BlogPost
|
||||
*
|
||||
* @var strinct $title
|
||||
*
|
||||
* @ORM\Column(type="string", length=150, nullable=false)
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* Set title
|
||||
*
|
||||
* @param string $title
|
||||
* @return BlogPost
|
||||
*/
|
||||
public function setTitle($title)
|
||||
{
|
||||
// TODO: Check if not null nor empty!
|
||||
$this->title = $title;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* The slugified title of the BlogPost
|
||||
*
|
||||
* @var string $slug
|
||||
*
|
||||
* @ORM\Column(type="string", length=150, nullable=false)
|
||||
*/
|
||||
protected $slug;
|
||||
|
||||
/**
|
||||
* Set slug
|
||||
*
|
||||
* @param string $slug
|
||||
* @return BlogPost
|
||||
*/
|
||||
public function setSlug($slug)
|
||||
{
|
||||
// TODO: Check if not null nor empty!
|
||||
$this->slug = $slug;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get slug
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSlug()
|
||||
{
|
||||
return $this->slug;
|
||||
}
|
||||
|
||||
/**
|
||||
* The User who created this BlogPost
|
||||
*
|
||||
* @var KekRozsak\SecurityBundle\Entity\User $createdBy
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="KekRozsak\SecurityBundle\Entity\User")
|
||||
* @ORM\JoinColumn(name="created_by_id", nullable=false)
|
||||
*/
|
||||
protected $createdBy;
|
||||
|
||||
/**
|
||||
* Set createdBy
|
||||
*
|
||||
* @param KekRozsak\SecurityBundle\Entity\User $createdBy
|
||||
* @return BlogPost
|
||||
*/
|
||||
public function setCreatedBy(User $createdBy)
|
||||
{
|
||||
// TODO: Check if not null!
|
||||
$this->createdBy = $createdBy;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get createdBy
|
||||
*
|
||||
* @return KekRozsak\SecurityBundle\Entity\User
|
||||
*/
|
||||
public function getCreatedBy()
|
||||
{
|
||||
return $this->createdBy();
|
||||
}
|
||||
|
||||
/**
|
||||
* The timestamp when this BlogPost was created
|
||||
*
|
||||
* @var DateTime $createdAt
|
||||
*
|
||||
* @ORM\Column(type="datetime", name="created_at", nullable=false)
|
||||
*/
|
||||
protected $createdAt;
|
||||
|
||||
/**
|
||||
* Set createdAt
|
||||
*
|
||||
* @param DateTime $createdAt
|
||||
* @return BlogPost
|
||||
*/
|
||||
public function setCreatedAt(\DataTime $createdAt)
|
||||
{
|
||||
// TODO: Check if not null!
|
||||
$this->createdAt = $createdAt;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get createdAt
|
||||
*
|
||||
* @return DateTime
|
||||
*/
|
||||
public function getCreatedAt()
|
||||
{
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* The User who last updated this BlogPost, or NULL if it is unmodified
|
||||
*
|
||||
* @var KekRozsak\SecurityBundle\Entity\User $updatedBy
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="KekRozsak\SecurityBundle\Entity\User")
|
||||
* @ORM\JoinColumn(name="updated_by_id", nullable=true)
|
||||
*/
|
||||
protected $updatedBy;
|
||||
|
||||
/**
|
||||
* Set updatedBy
|
||||
*
|
||||
* @param KekRozsak\SecurityBundle\Entity\User $updatedBy
|
||||
* @return BlogPost
|
||||
*/
|
||||
public function setUpdatedBy(User $updatedBy)
|
||||
{
|
||||
$this->updatedBy = $updatedBy;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get updatedBy
|
||||
*
|
||||
* @return KekRozsak\SecurityBundle\Entity\User
|
||||
*/
|
||||
public function getUpdatedBy()
|
||||
{
|
||||
return $this->updatedBy;
|
||||
}
|
||||
|
||||
/**
|
||||
* The timestamp when this BlogPost was last modified, or null if it is not
|
||||
* modified
|
||||
*
|
||||
* @var DateTime $updatedAt
|
||||
*
|
||||
* @ORM\Column(type="datetime", name="updated_at", nullable=true)
|
||||
*/
|
||||
protected $updatedAt;
|
||||
|
||||
/**
|
||||
* Set updatedAt
|
||||
*
|
||||
* @param DateTime $updatedAt
|
||||
* @return BlogPost
|
||||
*/
|
||||
public function setUpdatedAt(\DateTime $updatedAt)
|
||||
{
|
||||
$this->updatedAt = $updatedAt;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* The reason of the last update, or null if the object is not modified
|
||||
*
|
||||
* @var string $updateReason
|
||||
*
|
||||
* @ORM\Column(type="string", length=255, name="update_reason", nullable=true)
|
||||
*/
|
||||
protected $updateReason;
|
||||
|
||||
/**
|
||||
* Set updateReason
|
||||
*
|
||||
* @param string $updateReason
|
||||
* @return BlogPost
|
||||
*/
|
||||
public function setUpdateReason($updateReason)
|
||||
{
|
||||
if (trim($updateReason) == '') {
|
||||
$updateReason = null;
|
||||
}
|
||||
$this->updateReason = $updateReason;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get updateReason
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUpdateReason()
|
||||
{
|
||||
return $this->updateReason;
|
||||
}
|
||||
|
||||
/**
|
||||
* The content of this BlogPost
|
||||
*
|
||||
* @var string $content
|
||||
*
|
||||
* @ORM\Column(type="text", nullable=false)
|
||||
*/
|
||||
protected $content;
|
||||
|
||||
/**
|
||||
* Set content
|
||||
*
|
||||
* @param string $content
|
||||
* @return BlogPost
|
||||
*/
|
||||
public function setContent($content)
|
||||
{
|
||||
// TODO: Check if not null nor empty!
|
||||
$this->content = $content;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContent()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
{# vim: ft=htmljinja
|
||||
#}
|
||||
{% extends 'KekRozsakFrontBundle:Default:main_template.html.twig' %}
|
||||
{% block content %}
|
||||
<h3>Blog</h3>
|
||||
{% for post in posts %}
|
||||
<h4>{{ post.title }}</h4>
|
||||
{{ post.createdAt|date('Y-m-d H:i') }}<br />
|
||||
{% if not post.published %}
|
||||
inaktív<br />
|
||||
{% endif %}
|
||||
{{ post.content }}
|
||||
<hr />
|
||||
{% else %}
|
||||
Nincs bejegyzés.
|
||||
{% endfor %}
|
||||
{% endblock %}
|
Loading…
Reference in New Issue
Block a user