Permalink
Browse files

initial slideshowblock

  • Loading branch information...
1 parent bbd0273 commit 228becde56b307422ff44508b2e0e0a391d81faf @elHornair elHornair committed Feb 11, 2013
@@ -0,0 +1,55 @@
+<?php
+
+namespace Symfony\Cmf\Bundle\BlockBundle\Block;
+
+use Symfony\Component\HttpFoundation\Response;
+use Sonata\BlockBundle\Model\BlockInterface;
+use Symfony\Cmf\Bundle\BlockBundle\Block\ContainerBlockService;
+
+class SlideshowBlockService extends ContainerBlockService
+{
+
+ /**
+ * @return string
+ */
+ protected function getTemplate()
+ {
+ return 'SymfonyCmfBlockBundle:Block:block_slideshow.html.twig';
+ }
+
+ /**
+ * @param BlockInterface $block
+ * @param null|Response $response
+ *
+ * @return Response
+ */
+ public function execute(BlockInterface $block, Response $response = null)
+ {
+ if (!$response) {
+ $response = new Response();
+ }
+
+ if ($block->getEnabled()) {
+ $childBlocks = array();
+ foreach ($block->getChildren()->getValues() as $childBlock) {
+ $expectedType = 'Symfony\Cmf\Bundle\BlockBundle\Document\SlideshowItemBlock';
+ if (get_class($childBlock) !== $expectedType) {
+ throw new \RuntimeException(sprintf('Expected block of type %s. Received block of type %s instead.', $expectedType, get_class($childBlock)));
+ }
+ $childBlocks[] = $childBlock;
+ }
+
+ if (!empty($childBlock)) {
+ return $this->renderResponse($this->getTemplate(), array(
+ 'block' => $block,
+ 'itemBlocks' => $childBlocks,
+ 'settings' => $this->getDefaultSettings()
+ ), $response);
+ }
+
+ }
+
+ return $response;
+ }
+
+}
@@ -0,0 +1,24 @@
+<?php
+
+namespace Symfony\Cmf\Bundle\BlockBundle\Document;
+
+use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
+use Symfony\Cmf\Bundle\BlockBundle\Document\ContainerBlock;
+
+/**
+ * Block that renders a slideshow of child items
+ *
+ * @PHPCRODM\Document(referenceable=true)
+ */
+class SlideshowBlock extends ContainerBlock
+{
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getType()
+ {
+ return 'symfony_cmf.block.slideshow';
+ }
+
+}
@@ -0,0 +1,63 @@
+<?php
+
+namespace Symfony\Cmf\Bundle\BlockBundle\Document;
+
+use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
+use Symfony\Cmf\Bundle\BlockBundle\Document\BaseBlock;
+
+/**
+ * Block that acts as an item of a SlideshowBlock
+ *
+ * @PHPCRODM\Document(referenceable=true)
+ */
+class SlideshowItemBlock extends BaseBlock
+{
+
+ /**
+ * Image file child
+ *
+ * @PHPCRODM\Child(name="image", cascade="persist")
+ */
+ protected $image;
+
+ /** @PHPCRODM\String */
+ protected $label;
+
+ /** @PHPCRODM\Node */
+ protected $node;
+
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getType()
+ {
+ return 'symfony_cmf.block.slideshow_item';
+ }
+
+ public function setLabel($label)
+ {
+ $this->label = $label;
+ }
+
+ public function getLabel()
+ {
+ return $this->label;
+ }
+
+ public function setImage($image)
+ {
+ $this->image = $image;
+ }
+
+ public function getImage()
+ {
+ return $this->image;
+ }
+
+ public function getNode()
+ {
+ return $this->node;
+ }
+
+}
@@ -41,5 +41,12 @@
<argument type="service" id="http_kernel" />
</service>
+ <service id="symfony_cmf.block.slideshow" class="Symfony\Cmf\Bundle\BlockBundle\Block\SlideshowBlockService">
+ <tag name="sonata.block" />
+ <argument>symfony_cmf.block.slideshow</argument>
+ <argument type="service" id="templating" />
+ <argument type="service" id="sonata.block.renderer" />
+ </service>
+
</services>
</container>
@@ -0,0 +1,14 @@
+{% extends 'SymfonyCmfBlockBundle:Block:block_base.html.twig' %}
+
+{% block block %}
+
+ <div class="slideshow">
+ <ul>
+ {% for item in itemBlocks %}
+ {# TODO: render image #}
+ <li>{{ item.label }}</li>
+ {% endfor %}
+ </ul>
+ </div>
+
+{% endblock %}

0 comments on commit 228becd

Please sign in to comment.