Created
September 23, 2015 09:23
-
-
Save brabijan/0ca48ca382fda4330b6e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Eshop; | |
use Brabijan\Images\ImageProvider; | |
use Doctrine\ORM\Mapping as ORM; | |
/** | |
* @ORM\Entity() | |
*/ | |
class Product implements ImageProvider | |
{ | |
/** | |
* @ORM\Column(name="id", type="integer") | |
* @ORM\Id | |
* @ORM\GeneratedValue(strategy="AUTO") | |
*/ | |
protected $id; | |
/** | |
* @ORM\OneToMany(targetEntity="ProductPhoto", mappedBy="product") | |
* @var ProductPhoto[]|ArrayCollection | |
*/ | |
protected $photos; | |
public function getDefaultPhoto() { | |
// returns default photo entity | |
} | |
/** | |
* @return string | |
*/ | |
public static function getNamespace() | |
{ | |
return $this->getDefaultPhoto()->getNamespace(); | |
} | |
/** | |
* @return string | |
*/ | |
public function getFilename() | |
{ | |
return $this->getDefaultPhoto()->getFilename(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<img n:img="$product, 200x200, fill"> | |
{foreach $product->getPhotos() as $photo} | |
<img n:if="!$photo->default" n:img="$photo, 100x100, fill"> | |
{/foreach} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Eshop; | |
use Brabijan\Images\ImageProvider; | |
use Doctrine\ORM\Mapping as ORM; | |
/** | |
* @ORM\Entity() | |
* @property $id | |
* @property $filename | |
* @property Product $product | |
*/ | |
class ProductPhoto implements ImageProvider | |
{ | |
/** | |
* @ORM\Column(name="id", type="integer") | |
* @ORM\Id | |
* @ORM\GeneratedValue(strategy="AUTO") | |
*/ | |
protected $id; | |
/** @ORM\Column(type="string") */ | |
protected $filename; | |
/** | |
* @ORM\ManyToOne(targetEntity="Product", inversedBy="photos") | |
* @var Product | |
*/ | |
protected $product; | |
/** @ORM\Column(type="boolean") */ | |
protected $default = FALSE; | |
/** | |
* @return string | |
*/ | |
public static function getNamespace() | |
{ | |
return "product-photo"; | |
} | |
/** | |
* @return string | |
*/ | |
public function getFilename() | |
{ | |
return $this->filename; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment