Skip to content

Commit

Permalink
Changing blog-post-entities
Browse files Browse the repository at this point in the history
  • Loading branch information
Petra Dreiskamper committed Feb 12, 2014
1 parent 4aff6f2 commit b99826a
Show file tree
Hide file tree
Showing 5 changed files with 370 additions and 45 deletions.
9 changes: 5 additions & 4 deletions src/PHPWomen/BlogBundle/Controller/DefaultController.php
Expand Up @@ -50,7 +50,7 @@ public function showAction($id)
}

var_dump($post); die;
// ... do something, like pass the $post object into a template

}

/**
Expand All @@ -73,10 +73,11 @@ public function latestAction()
public function createAction()
{
$post = new Post();
$post->setTitle('A Foo Bar');
//$post->setAuthor();
$post->setTitle('The PHPwomen first blog post');
$post->setIntro('With a one line introduction');
$post->setAuthor();
$post->setText('Lorem ipsum dolor');
$post->setTags('php, first');


$em = $this->getDoctrine()->getManager();
$em->persist($post);
Expand Down
5 changes: 3 additions & 2 deletions src/PHPWomen/BlogBundle/Entity/Category.php
Expand Up @@ -6,10 +6,11 @@
namespace PHPWomen\BlogBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use PHPWomen\BlogBundle\Entity\Post;

/**
* @ORM\Entity
* @ORM\Table(name="category")
* @ORM\Table(name="blog_categories")
*/
class Category
{
Expand All @@ -26,7 +27,7 @@ class Category
protected $name;

/**
* @ORM\ManyToMany(targetEntity="Post", mappedBy="categories")
* @ORM\OneToMany(targetEntity="\PHPWomen\BlogBundle\Entity\Post", mappedBy="category")
**/
protected $posts;

Expand Down
203 changes: 164 additions & 39 deletions src/PHPWomen/BlogBundle/Entity/Post.php
Expand Up @@ -6,10 +6,12 @@
namespace PHPWomen\BlogBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use PHPWomen\BlogBundle\Entity\Category;
use PHPWomen\BlogBundle\Entity\Tag;

/**
* @ORM\Entity
* @ORM\Table(name="post")
* @ORM\Table(name="blog_posts")
* @ORM\Entity(repositoryClass="PHPWomen\BlogBundle\Entity\PostRepository")
*/
class Post
{
Expand All @@ -30,28 +32,51 @@ class Post
*/
protected $title;

/**
* @ORM\Column(length=255)
*/
protected $intro;

/**
* @ORM\Column(type="text")
*/
protected $text;

/**
* @ORM\Column(length=140)
* @var \DateTime
*
* @ORM\Column(name="date", type="date")
*/
protected $tags;
private $date;

/**
* @ORM\ManyToMany(targetEntity="Category", inversedBy="posts")
**/
protected $categories;
* @var \DateTime
*
* @ORM\Column(name="created_on", type="datetime")
*/
protected $createdOn;

/**
* Constructor
* @var \DateTime
*
* @ORM\Column(name="updated_on", type="datetime")
*/
public function __construct()
{
$this->categories = new \Doctrine\Common\Collections\ArrayCollection();
}
protected $updatedOn;

/**
* @var Category
*
* @ORM\ManyToOne(targetEntity="PHPWomen\BlogBundle\Entity\Category", inversedBy="posts")
* @ORM\JoinColumn(name="category_id", referencedColumnName="id")
*/
protected $category;

/**
* @var Tag[] $tags
*
* @ORM\ManyToMany(targetEntity="Tag", mappedBy="posts")
*/
private $tags;

/**
* Get id
Expand Down Expand Up @@ -110,81 +135,181 @@ public function getText()
}

/**
* Set tags
* Set author
*
* @param string $tags
* @param \PHPWomen\UserBundle\Entity\User $author
* @return Post
*/
public function setTags($tags)
public function setAuthor(\PHPWomen\UserBundle\Entity\User $author = null)
{
$this->tags = $tags;
$this->author = $author;

return $this;
}

/**
* Get tags
* Get author
*
* @return string
* @return \PHPWomen\UserBundle\Entity\User
*/
public function getTags()
public function getAuthor()
{
return $this->tags;
return $this->author;
}

/**
* Set author
* Set date
*
* @param \PHPWomen\UserBundle\Entity\User $author
* @param \DateTime $date
* @return Post
*/
public function setAuthor(\PHPWomen\UserBundle\Entity\User $author = null)
public function setDate($date)
{
$this->author = $author;
$this->date = $date;

return $this;
}

/**
* Get author
* Get date
*
* @return \PHPWomen\UserBundle\Entity\User
* @return \DateTime
*/
public function getAuthor()
public function getDate()
{
return $this->author;
return $this->date;
}

/**
* Set createdOn
*
* @param \DateTime $createdOn
* @return Post
*/
public function setCreatedOn($createdOn)
{
$this->createdOn = $createdOn;

return $this;
}

/**
* Add categories
* Get createdOn
*
* @param \PHPWomen\BlogBundle\Entity\Category $categories
* @return \DateTime
*/
public function getCreatedOn()
{
return $this->createdOn;
}

/**
* Set updatedOn
*
* @param \DateTime $updatedOn
* @return Post
*/
public function addCategory(\PHPWomen\BlogBundle\Entity\Category $categories)
public function setUpdatedOn($updatedOn)
{
$this->categories[] = $categories;
$this->updatedOn = $updatedOn;

return $this;
}

/**
* Remove categories
* Get updatedOn
*
* @param \PHPWomen\BlogBundle\Entity\Category $categories
* @return \DateTime
*/
public function removeCategory(\PHPWomen\BlogBundle\Entity\Category $categories)
public function getUpdatedOn()
{
$this->categories->removeElement($categories);
return $this->updatedOn;
}

/**
* Get categories
* Set category
*
* @param \PHPWomen\BlogBundle\Entity\Category $category
* @return Post
*/
public function setCategory(\PHPWomen\BlogBundle\Entity\Category $category = null)
{
$this->category = $category;

return $this;
}

/**
* Get category
*
* @return \PHPWomen\BlogBundle\Entity\Category
*/
public function getCategory()
{
return $this->category;
}

/**
* Set intro
*
* @param string $intro
* @return Post
*/
public function setIntro($intro)
{
$this->intro = $intro;

return $this;
}

/**
* Get intro
*
* @return string
*/
public function getIntro()
{
return $this->intro;
}

/**
* Constructor
*/
public function __construct()
{
$this->tags = new \Doctrine\Common\Collections\ArrayCollection();
}

/**
* Add tags
*
* @param \PHPWomen\BlogBundle\Entity\Tag $tags
* @return Post
*/
public function addTag(\PHPWomen\BlogBundle\Entity\Tag $tags)
{
$this->tags[] = $tags;

return $this;
}

/**
* Remove tags
*
* @param \PHPWomen\BlogBundle\Entity\Tag $tags
*/
public function removeTag(\PHPWomen\BlogBundle\Entity\Tag $tags)
{
$this->tags->removeElement($tags);
}

/**
* Get tags
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getCategories()
public function getTags()
{
return $this->categories;
return $this->tags;
}
}

0 comments on commit b99826a

Please sign in to comment.