Added popup functionality and Library

* doPopup() JavaScript call creates a centered popup div with user
    defined width, height, title, content, and calls an optional
    callback function

* Library with currently non-modifiable book list, and a popup with the
    books' details

Signed-off-by: Gergely Polonkai <polesz@w00d5t0ck.info>
This commit is contained in:
Polonkai Gergely
2012-08-08 22:15:51 +02:00
parent 624e56389e
commit 55cde1594b
19 changed files with 1128 additions and 12 deletions

View File

@@ -0,0 +1,299 @@
<?php
namespace KekRozsak\FrontBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints as DoctrineAssert;
use Doctrine\Common\Collections\ArrayCollection;
use KekRozsak\SecurityBundle\Entity\User;
/**
* KekRozsak\FrontBundle\Entity\Book
*
* @ORM\Entity
* @ORM\Table(name="books")
*
* @DoctrineAssert\UniqueEntity(fields={"author", "title", "year"})
*/
class Book
{
public function __construct()
{
$this->copies = new ArrayCollection();
$this->wouldBorrow = new ArrayCollection();
$this->wouldBuy = new ArrayCollection();
}
/**
* @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;
}
/**
* @var Doctrine\Common\Collections\ArrayCollection $copies
*
* @ORM\OneToMany(targetEntity="BookCopy", mappedBy="book")
*/
protected $copies;
/**
* Remove a copy
*
* @param KekRozsak\FrontBundle\Entity\BookCopy $copy
* @return Book
*/
public function removeCopy(BookCopy $copy)
{
$this->copies->removeElement($copy);
}
/**
* Get copies
*
* @return Doctrine\Common\Collections\ArrayCollection
*/
public function getCopies()
{
return $this->copies;
}
public function getCopiesBorrowed()
{
return $this->copies->filter(function($copy) {
return ($copy->getBorrower() !== null);
});
}
public function getCopiesBorrowedByUser(User $user)
{
return $this->copies->filter(function($copy) use ($user) {
return ($copy->getBorrower() == $user);
});
}
public function getCopiesBorrowedReturnedByUser(User $user)
{
return $this->copies->filter(function($copy) use ($user) {
return ($copy->getBorrower() == $user) && ($copy->isBorrowerReturned());
});
}
public function getCopiesBorrowable()
{
return $this->copies->filter(function($copy) {
return $copy->isBorrowable();
});
}
public function getUsersCopies(User $user)
{
return $this->copies->filter(function ($copy) use ($user) {
return ($copy->getOwner() == $user);
});
}
public function getUsersCopiesBorrowable(User $user)
{
return $this->copies->filter(function($copy) use ($user) {
return (($copy->getOwner() == $user) && $copy->isBorrowable());
});
}
public function getUsersCopiesBuyable(User $user)
{
return $this->copies->filter(function($copy) use ($user) {
return (($copy->getOwner() == $user) && $copy->isBuyable());
});
}
/**
* @var string $author
*
* @ORM\Column(type="string", length=100, nullable=false)
*/
protected $author;
/**
* Set author
*
* @param string $author
* @return Book
*/
public function setAuthor($author)
{
$this->author = $author;
return $this;
}
/**
* Get author
*
* @return string
*/
public function getAuthor()
{
return $this->author;
}
/**
* @var string $title
*
* @ORM\Column(type="string", length=100, nullable=false)
*/
protected $title;
/**
* Set title
*
* @param string $title
* @return Book
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* @var integer $year
*
* @ORM\Column(type="integer", nullable=false)
*/
protected $year;
/**
* Set year
*
* @param integer $year
* @return Book
*/
public function setYear($year)
{
$this->year = $year;
return $this;
}
/**
* Get year
*
* @return integer
*/
public function getYear()
{
return $this->year;
}
/**
* @var boolean $commentable
*
* @ORM\Column(type="boolean", nullable=false)
*/
protected $commentable;
/**
* @var Doctrine\Common\Collections\ArrayCollection $wouldBorrow
*
* @ORM\ManyToMany(targetEntity="KekRozsak\SecurityBundle\Entity\User")
* @ORM\JoinTable(name="book_would_borrow")
*/
protected $wouldBorrow;
/**
* Add a user for want-to-borrowers
*
* @param KekRozsak\SecurityBundle\Entity\User $user
* @return Book
*/
public function addWouldBorrow(User $user)
{
$this->wouldBorrow->add($user);
return $this;
}
/**
* Get wouldBorrow list
*
* @return Doctrine\Common\Collections\ArrayCollection
*/
public function getWouldBorrow()
{
return $this->wouldBorrow;
}
/**
* Check if specified user would borrow this book
*
* @param KekRozsak\SecurityBundle\Entity\User $user
* @return boolean
*/
public function userWouldBorrow(User $user)
{
return $this->wouldBorrow->contains($user);
}
/**
* @var Doctrine\Common\Collections\ArrayCollection $wouldBuy
*
* @ORM\ManyToMany(targetEntity="KekRozsak\SecurityBundle\Entity\User")
* @ORM\JoinTable(name="book_would_buy")
*/
protected $wouldBuy;
/**
* Add a user for want-to-buyers
*
* @param KekRozsak\SecurityBundle\Entity\User $user
* @return Book
*/
public function addWouldBuy(User $user)
{
$this->wouldBuy->add($user);
return $this;
}
/**
* Get wouldBuy list
*
* @return Doctrine\Common\Collections\ArrayCollection
*/
public function getWouldBuy()
{
return $this->wouldBuy;
}
/**
* Check if specified user would buy this book
*
* @param KekRozsak\SecurityBundle\Entity\User $user
* @return boolean
*/
public function userWouldBuy(User $user)
{
return $this->wouldBuy->contains($user);
}
}

View File

@@ -0,0 +1,165 @@
<?php
namespace KekRozsak\FrontBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints as DoctrineAssert;
use KekRozsak\FrontBundle\Entity\Book;
use KekRozsak\SecurityBundle\Entity\User;
/**
* KekRozsak\FrontBundle\Entity\BookCopy
* @ORM\Entity
* @ORM\Table(name="book_copies", uniqueConstraints={
* @ORM\UniqueConstraint(columns={"owner_id", "book_id"})
* })
*
* @DoctrineAssert\UniqueEntity(fields={"owner_id", "book_id"})
*/
class BookCopy
{
public function __construct(Book $book, User $owner)
{
$this->book = $book;
$this->owner = $owner;
$this->borrowable = false;
$this->buyable = false;
$this->borrower = null;
$this->borrowerReturned = true;
}
/**
* @var integer $id
*
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*/
protected $id;
/**
* @var KekRozsak\FrontBundle\Entity\Book $book
*
* @ORM\ManyToOne(targetEntity="Book", inversedBy="copies")
* @ORM\JoinColumn(nullable=false)
*/
protected $book;
/**
* @var KekRozsak\SecurityBundle\Entity\User $owner
*
* @ORM\ManyToOne(targetEntity="KekRozsak\SecurityBundle\Entity\User")
* @ORM\JoinColumn(nullable=false)
*/
protected $owner;
/**
* Get owner
*
* @return KekRozsak\SecurityBundle\Entity\User
*/
public function getOwner()
{
return $this->owner;
}
/**
* @var string $ownerComment
*
* @ORM\Column(type="text", name="owner_comment", nullable=true)
*/
protected $ownerComment;
/**
* @var boolean $borrowable
*
* @ORM\Column(type="boolean", nullable=false)
*/
protected $borrowable;
/**
* Set borrowable
*
* @param boolean $borrowable
* @return BookCopy
*/
public function setBorrowable($borrowable)
{
$this->borrowable = $borrowable;
return $this;
}
/**
* Get borrowable
*
* @return boolean
*/
public function isBorrowable()
{
return $this->borrowable;
}
/**
* @var boolean $buyable
*
* @ORM\Column(type="boolean", nullable=false)
*/
protected $buyable;
/**
* Set buyable
*
* @param boolean $buyable
* @return BookCopy
*/
public function setBuyable($buyable)
{
$this->buyable = $buyable;
return $this;
}
/**
* Get borrowable
*
* @return boolean
*/
public function isBuyable()
{
return $this->buyable;
}
/**
* @var KekRozsak\SecurityBundle\Entity\User $borrower
*
* @ORM\OneToOne(targetEntity="KekRozsak\SecurityBundle\Entity\User")
*/
protected $borrower;
/**
* Get borrower
*
* @return KekRozsak\SecurityBundle\Entity\User
*/
public function getBorrower()
{
return $this->borrower;
}
/**
* @var boolean $borrowerReturned
*
* @ORM\Column(type="boolean", nullable=false, name="borrower_returned")
*/
protected $borrowerReturned;
/**
* Get borrowerReturned
*
* @return boolean
*/
public function isBorrowerReturned()
{
return $this->borrowerReturned();
}
}