食品エンティティ
<?php
namespace Food\AdminBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Food
*
* @ORM\Table(name="food")
* @ORM\Entity(repositoryClass="Food\AdminBundle\Repository\FoodRepository")
*/
class Food
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255, nullable=true)
*/
private $name;
/**
* @var string
*
* @ORM\Column(name="contents", type="string", length=500, nullable=true)
*/
private $contents;
/**
* @var string
*
* @ORM\Column(name="price", type="integer", nullable=true)
*/
private $price;
/**
* @var bool
*
* @ORM\Column(name="approve", type="boolean")
*/
private $approve;
/**
* @var \Food\AdminBundle\Entity\Category
*
* @ORM\ManyToOne(targetEntity="Food\AdminBundle\Entity\Category")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="category_id", referencedColumnName="id", onDelete="CASCADE")
* })
*/
private $category;
/**
* @var \Food\AdminBundle\Entity\Resturant
*
* @ORM\ManyToOne(targetEntity="Food\AdminBundle\Entity\Resturant")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="resturant_id", referencedColumnName="id", onDelete="CASCADE")
* })
*/
private $resturant;
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
*
* @return Food
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set contents
*
* @param string $contents
*
* @return Food
*/
public function setContents($contents)
{
$this->contents = $contents;
return $this;
}
/**
* Get contents
*
* @return string
*/
public function getContents()
{
return $this->contents;
}
/**
* Set approve
*
* @param boolean $approve
*
* @return Food
*/
public function setApprove($approve)
{
$this->approve = $approve;
return $this;
}
/**
* Get approve
*
* @return bool
*/
public function getApprove()
{
return $this->approve;
}
/**
* Set category
*
* @param \Food\AdminBundle\Entity\Category $category
*
* @return Food
*/
public function setCategory(\Food\AdminBundle\Entity\Category $category = null)
{
$this->category = $category;
return $this;
}
/**
* Get category
*
* @return \Food\AdminBundle\Entity\Category
*/
public function getCategory()
{
return $this->category;
}
/**
* Set resturant
*
* @param \Food\AdminBundle\Entity\Resturant $resturant
*
* @return Food
*/
public function setResturant(\Food\AdminBundle\Entity\Resturant $resturant = null)
{
$this->resturant = $resturant;
return $this;
}
/**
* Get resturant
*
* @return \Food\AdminBundle\Entity\Resturant
*/
public function getResturant()
{
return $this->resturant;
}
/**
* Set price
*
* @param integer $price
*
* @return Food
*/
public function setPrice($price)
{
$this->price = $price;
return $this;
}
/**
* Get price
*
* @return integer
*/
public function getPrice()
{
return $this->price;
}
}
Resturantのエンティティ
<?php
namespace Food\AdminBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\HttpFoundation\File\UploadedFile;
/**
* Resturant
*
* @ORM\Table(name="resturant")
* @ORM\Entity(repositoryClass="Food\AdminBundle\Repository\ResturantRepository")
*/
class Resturant
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=50)
*/
private $name;
/**
* @var string
*
* @ORM\Column(name="logo", type="string", length=30, nullable=true)
*/
private $logo;
/**
* @var string
*
* @ORM\Column(name="duration", type="string", length=150, nullable=true)
*/
private $duration;
/**
* @var string
*
* @ORM\Column(name="address", type="string", length=800, nullable=true)
*/
private $address;
/**
* @var int
*
* @ORM\Column(name="minimal", type="integer")
*/
private $minimal;
/**
* @var int
*
* @ORM\Column(name="delivery", type="integer")
*/
private $delivery;
/**
* @var int
*
* @ORM\Column(name="score", type="integer", nullable=true)
*/
private $score;
/**
* @var int
*
* @ORM\Column(name="cost", type="integer")
*/
private $cost;
/**
* @var int
*
* @ORM\Column(name="startlunch", type="time", nullable=true)
*/
private $startlunch;
/**
* @var int
*
* @ORM\Column(name="endlunch", type="time", nullable=true)
*/
private $endlunch;
/**
* @var int
*
* @ORM\Column(name="startdinner", type="time", nullable=true)
*/
private $startdinner;
/**
* @var int
*
* @ORM\Column(name="enddinner", type="time", nullable=true)
*/
private $enddinner;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\ManyToMany(targetEntity="Food\AdminBundle\Entity\Zone", inversedBy="Resturant")
* @ORM\JoinTable(name="resturant_has_zone",
* joinColumns={
* @ORM\JoinColumn(name="resturant_id", referencedColumnName="id")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="zone_id", referencedColumnName="id")
* }
*)
*/
private $zone;
/**
* @ORM\OneToMany(targetEntity="Food\AdminBundle\Entity\Food", mappedBy="Resturant")
*/
private $food;
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
*
* @return Resturant
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set logo
*
* @param string $logo
*
* @return Resturant
*/
public function setLogo($logo)
{
$this->logo = $logo;
return $this;
}
/**
* Get logo
*
* @return string
*/
public function getLogo()
{
return $this->logo;
}
/**
* Set duration
*
* @param string $duration
*
* @return Resturant
*/
public function setDuration($duration)
{
$this->duration = $duration;
return $this;
}
/**
* Get duration
*
* @return string
*/
public function getDuration()
{
return $this->duration;
}
/**
* Set address
*
* @param string $address
*
* @return Resturant
*/
public function setAddress($address)
{
$this->address = $address;
return $this;
}
/**
* Get address
*
* @return string
*/
public function getAddress()
{
return $this->address;
}
/**
* Set minimal
*
* @param integer $minimal
*
* @return Resturant
*/
public function setMinimal($minimal)
{
$this->minimal = $minimal;
return $this;
}
/**
* Get minimal
*
* @return int
*/
public function getMinimal()
{
return $this->minimal;
}
/**
* Set delivery
*
* @param integer $delivery
*
* @return Resturant
*/
public function setDelivery($delivery)
{
$this->delivery = $delivery;
return $this;
}
/**
* Get delivery
*
* @return int
*/
public function getDelivery()
{
return $this->delivery;
}
/**
* Set score
*
* @param integer $score
*
* @return Resturant
*/
public function setScore($score)
{
$this->score = $score;
return $this;
}
/**
* Get score
*
* @return int
*/
public function getScore()
{
return $this->score;
}
/**
* Set cost
*
* @param integer $cost
*
* @return Resturant
*/
public function setCost($cost)
{
$this->cost = $cost;
return $this;
}
/**
* Get cost
*
* @return int
*/
public function getCost()
{
return $this->cost;
}
/**
* Set startlunch
*
* @param \DateTime $startlunch
*
* @return Resturant
*/
public function setStartlunch($startlunch)
{
$this->startlunch = $startlunch;
return $this;
}
/**
* Get startlunch
*
* @return \DateTime
*/
public function getStartlunch()
{
return $this->startlunch;
}
/**
* Set endlunch
*
* @param \DateTime $endlunch
*
* @return Resturant
*/
public function setEndlunch($endlunch)
{
$this->endlunch = $endlunch;
return $this;
}
/**
* Get endlunch
*
* @return \DateTime
*/
public function getEndlunch()
{
return $this->endlunch;
}
/**
* Set startdinner
*
* @param \DateTime $startdinner
*
* @return Resturant
*/
public function setStartdinner($startdinner)
{
$this->startdinner = $startdinner;
return $this;
}
/**
* Get startdinner
*
* @return \DateTime
*/
public function getStartdinner()
{
return $this->startdinner;
}
/**
* Set enddinner
*
* @param \DateTime $enddinner
*
* @return Resturant
*/
public function setEnddinner($enddinner)
{
$this->enddinner = $enddinner;
return $this;
}
/**
* Get enddinner
*
* @return \DateTime
*/
public function getEnddinner()
{
return $this->enddinner;
}
/**
* Constructor
*/
public function __construct()
{
$this->zone = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add zone
*
* @param \Food\AdminBundle\Entity\Zone $zone
*
* @return Resturant
*/
public function addZone(\Food\AdminBundle\Entity\Zone $zone)
{
$this->zone[] = $zone;
return $this;
}
/**
* Remove zone
*
* @param \Food\AdminBundle\Entity\Zone $zone
*/
public function removeZone(\Food\AdminBundle\Entity\Zone $zone)
{
$this->zone->removeElement($zone);
}
/**
* Get zone
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getZone()
{
return $this->zone;
}
/**
* Add food
*
* @param \Food\AdminBundle\Entity\Food $food
*
* @return Resturant
*/
public function addFood(\Food\AdminBundle\Entity\Food $food)
{
$this->food[] = $food;
return $this;
}
/**
* Remove food
*
* @param \Food\AdminBundle\Entity\Food $food
*/
public function removeFood(\Food\AdminBundle\Entity\Food $food)
{
$this->food->removeElement($food);
}
/**
* Get food
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getFood()
{
return $this->food;
}
/**
* @Assert\File(
* maxSize="2m",
* mimeTypes = {"image/jpeg", "image/png"},
* mimeTypesMessage = "Please upload a valid Image File"
*
*)
*/
private $file;
// Uploading File LOL
/**
* Sets file.
*
* @param UploadedFile $file
*/
public function setFile(UploadedFile $file = null)
{
$this->file = $file;
}
/**
* Get file.
*
* @return UploadedFile
*/
public function getFile()
{
return $this->file;
}
public function getAbsolutePath()
{
return null === $this->logo
? null
: $this->getUploadRootDir() . '/' . $this->logo;
}
public function getWebPath()
{
return null === $this->picture
? null
: $this->getUploadDir() . '/' . $this->logo;
}
protected function getUploadRootDir()
{
// the absolute directory path where uploaded
// documents should be saved
return __DIR__ . '/../../../../web/' . $this->getUploadDir();
}
protected function getUploadDir()
{
// get rid of the __DIR__ so it doesn't screw up
// when displaying uploaded doc/image in the view.
return 'upload/resturant/logo';
}
public function upload()
{
// the file property can be empty if the field is not required
if (null === $this->getFile()) {
return;
}
// use the original file name here but you should
// sanitize it at least to avoid any security issues
// move takes the target directory and then the
// target filename to move to
$stringArray = explode(".", $this->getFile()->getClientOriginalName());
$suffix = $stringArray[count($stringArray) - 1];
$this->logo = $this->random_string() . '.' . $suffix;
$this->getFile()->move(
$this->getUploadRootDir(),
$this->logo
);
// clean up the file property as you won't need it anymore
$this->file = null;
}
private function random_string($hashstring = null, $randLengh = null)
{
$string = $hashstring;
$randLengh = 15;
if ($string == null) {
$string = 'abcdefghijklmnopqrstuvwxyz';
}
$charactersLength = strlen($string);
$randomString = '';
for ($i = 0; $i < $randLengh; $i++) {
$randomString .= $string[rand(0, $charactersLength - 1)];
}
return $randomString;
}
public function __toString()
{
return $this->getName();
}
}
とゾーンエンティティと関係が
<?php
namespace Food\AdminBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Zone
*
* @ORM\Table(name="zone")
* @ORM\Entity(repositoryClass="Food\AdminBundle\Repository\ZoneRepository")
*/
class Zone
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=100, unique=true)
*/
private $name;
/**
* @var bool
*
* @ORM\Column(name="approve", type="boolean")
*/
private $approve;
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
*
* @return Zone
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set approve
*
* @param boolean $approve
*
* @return Zone
*/
public function setApprove($approve)
{
$this->approve = $approve;
return $this;
}
/**
* Get approve
*
* @return bool
*/
public function getApprove()
{
return $this->approve;
}
public function __toString()
{
return $this->getName();
}
}
'\'食べ物を左結合\ '。\'食べ物\ 'オン 'はタイプミスですか?それとも 'LEFT JOIN \' food \ 'ON'ですか? – Arulkumar
Sory '' 'LEFT JOIN' food' ON'''はOkです –
あなたは2つのテーブルにしか参加していないようです。あなたの教義の関係をあなたの質問に加えた場合、大いに役立ちます。 – Richard