From 2aaedb8f59f5fe25e6785dcf1d35429a2b04e8cc Mon Sep 17 00:00:00 2001 From: "R. Eric Wheeler" Date: Mon, 22 May 2017 06:00:13 -0700 Subject: [PATCH] fixed background-contain --- app/Resources/views/base.html.twig | 5 +- app/config/config_dev.yml | 11 +- app/config/services.yml | 4 +- .../Controller/GalleryController.php | 5 + .../Pager/View/UIkitTemplate.php | 119 +++++++++++++++++- .../Resources/views/Image/index.html.twig | 9 +- 6 files changed, 135 insertions(+), 18 deletions(-) diff --git a/app/Resources/views/base.html.twig b/app/Resources/views/base.html.twig index 08997c9..cf8a85f 100644 --- a/app/Resources/views/base.html.twig +++ b/app/Resources/views/base.html.twig @@ -1,8 +1,11 @@ {% if form is defined %} {% form_theme form with [_self, 'form_errors.html.twig'] %} {% endif %} - +{% if app.environment == 'dev' %} +{% set bucket = '' %} +{% else %} {% set bucket = 'https://storage.googleapis.com/zgluzzkwodfky2m0ytbhmjhmmzqzntq2ngy3ndjmntyxmzg4' %} +{% endif %} diff --git a/app/config/config_dev.yml b/app/config/config_dev.yml index c1addb4..dcea776 100644 --- a/app/config/config_dev.yml +++ b/app/config/config_dev.yml @@ -37,16 +37,11 @@ monolog: # type: chromephp # level: info vich_uploader: - storage: gaufrette + storage: file_system mappings: gallery_image: - upload_destination: cloud - uri_prefix: / - #storage: file_system - #mappings: - # gallery_image: - # uri_prefix: /images/gallery - # upload_destination: '%kernel.root_dir%/../web/images/gallery' + uri_prefix: /images/gallery + upload_destination: '%kernel.root_dir%/../web/gallery/images/gallery' swiftmailer: transport: null diff --git a/app/config/services.yml b/app/config/services.yml index 8aca29e..330f6d8 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -57,8 +57,10 @@ services: arguments: ['@router', '@monolog.logger'] doughnutwedding.uikit.template: class: Sikofitt\DoughnutWeddingBundle\Pager\View\UIkitTemplate + arguments: ['@service_container'] pagerfanta.view.default: class: Pagerfanta\View\DefaultView arguments: ['@doughnutwedding.uikit.template'] public: false - tags: [{ name: pagerfanta.view, alias: default }] \ No newline at end of file + tags: [{ name: pagerfanta.view, alias: default }] + diff --git a/src/Sikofitt/DoughnutWeddingBundle/Controller/GalleryController.php b/src/Sikofitt/DoughnutWeddingBundle/Controller/GalleryController.php index 62ce298..6ab4016 100644 --- a/src/Sikofitt/DoughnutWeddingBundle/Controller/GalleryController.php +++ b/src/Sikofitt/DoughnutWeddingBundle/Controller/GalleryController.php @@ -261,9 +261,12 @@ class GalleryController extends Controller ->get('doctrine.orm.entity_manager') ->getRepository('SikofittDoughnutWeddingBundle:Image') ->findImageByTag($tag); + + $adapter = new ArrayAdapter($images); $pager = new Pagerfanta($adapter); $pager->setMaxPerPage(12); + $pager->setCurrentPage($number); $chunks = array_chunk($images, 12); return $this @@ -291,9 +294,11 @@ class GalleryController extends Controller ->getRepository('SikofittDoughnutWeddingBundle:Image') ->findImageByCategory($category); + $adapter = new ArrayAdapter($images); $pager = new Pagerfanta($adapter); $pager->setMaxPerPage(12); + $pager->setCurrentPage($number); $chunks = array_chunk($images, 12); return $this diff --git a/src/Sikofitt/DoughnutWeddingBundle/Pager/View/UIkitTemplate.php b/src/Sikofitt/DoughnutWeddingBundle/Pager/View/UIkitTemplate.php index 882224c..52b3cb4 100644 --- a/src/Sikofitt/DoughnutWeddingBundle/Pager/View/UIkitTemplate.php +++ b/src/Sikofitt/DoughnutWeddingBundle/Pager/View/UIkitTemplate.php @@ -21,6 +21,7 @@ namespace Sikofitt\DoughnutWeddingBundle\Pager\View; use Pagerfanta\View\Template\Template; +use Symfony\Component\DependencyInjection\ContainerInterface; class UIkitTemplate extends Template { @@ -39,7 +40,15 @@ class UIkitTemplate extends Template 'rel_next' => 'next', ]; - /** + private $serviceContainer; + + public function __construct(ContainerInterface $serviceContainer) + { + $this->serviceContainer = $serviceContainer; + parent::__construct(); + } + + /** * Renders the container for the pagination. * * The %pages% placeholder will be replaced by the rendering of pages @@ -51,6 +60,81 @@ class UIkitTemplate extends Template return sprintf('', static::$defaultOptions['css_container_class'], '%pages%'); } + public function categoryPage($page, $path) { + $args = explode('/', $path); + array_shift($args); + + if(is_int(count($args)-1)) { + $args[count($args)-1] = $page; + } + if((int)$args[count($args) - 1] === 1) { + array_pop($args); + } + $path = implode('/', $args); + return sprintf('
  • %s
  • ', $path, $page); + } + + public function categoryPageNext($page, $path) { + $args = explode('/', $path); + array_shift($args); + $args[count($args) - 1] = $page; + $path = implode('/', $args); + return sprintf('
  • Next
  • ', $path); + } + + public function categoryPagePrevious($page, $path) { + $args = explode('/', $path); + array_shift($args); + if (1 === (int) $page) { + array_pop($args); + $path = implode('/', $args); + return '
  • Previous
  • '; + } + $args[count($args)-1] = $page; + $path = implode('/', $args); + return '
  • Previous
  • '; + } + + public function tagPage($page, $path) { + $args = explode('/', $path); + array_shift($args); + + if(count($args) === 3) { + $args[] = $page; + } elseif(count($args) === 4) { + $args[count($args) -1] = $page; + } + if(1 === $page) { + array_pop($args); + } + $path = implode('/', $args); + return sprintf('
  • %s
  • ', $path, $page); + } + public function tagPageNext($page, $path) { + $args = explode('/', $path); + array_shift($args); + if(count($args) === 3) { + $args[] = $page; + } else { + $args[count($args) - 1] = $page; + } + $path = implode('/', $args); + return sprintf('
  • Next
  • ', $path); + } + + public function tagPagePrevious($page, $path) { + $args = explode('/', $path); + array_shift($args); + if (1 === (int) $page) { + array_pop($args); + $path = implode('/', $args); + return '
  • Previous
  • '; + } + $args[count($args)-1] = $page; + $path = implode('/', $args); + return '
  • Previous
  • '; + } + /** * Renders a given page. * @@ -60,12 +144,21 @@ class UIkitTemplate extends Template */ public function page($page) { - if (1 === (int) $page) { - return '
  • '.$page.'
  • '; + $path = $this->serviceContainer->get('request_stack')->getCurrentRequest()->getRequestUri(); + if( + false !== strpos($path, 'tag') || + false !== strpos($path, 'category') + ) { + return $this->tagPage($page, $path); + } + + if (1 === (int)$page) { + return '
  • ' . $page . '
  • '; } - return '
  • '.$page.'
  • '; - } + return '
  • ' . $page . '
  • '; + } + /** * Renders a given page with a specified text. @@ -99,6 +192,14 @@ class UIkitTemplate extends Template */ public function previousEnabled($page) { + $path = $this->serviceContainer->get('request_stack')->getCurrentRequest()->getRequestUri(); + if( + false !== strpos($path, 'tag') || + false !== strpos($path, 'category') + ) { + return $this->tagPagePrevious($page, $path); + } + if (1 === (int) $page) { return '
  • Previous
  • '; } @@ -125,6 +226,14 @@ class UIkitTemplate extends Template */ public function nextEnabled($page) { + $path = $this->serviceContainer->get('request_stack')->getCurrentRequest()->getRequestUri(); + if( + false !== strpos($path, 'tag') || + false !== strpos($path, 'category') + ) { + return $this->tagPageNext($page, $path); + } + return '
  • Next
  • '; } diff --git a/src/Sikofitt/DoughnutWeddingBundle/Resources/views/Image/index.html.twig b/src/Sikofitt/DoughnutWeddingBundle/Resources/views/Image/index.html.twig index 4acb318..c96f03e 100644 --- a/src/Sikofitt/DoughnutWeddingBundle/Resources/views/Image/index.html.twig +++ b/src/Sikofitt/DoughnutWeddingBundle/Resources/views/Image/index.html.twig @@ -15,9 +15,12 @@
    {% if images is not null and images is not empty %} {% for image in images %} - - {% set imageUrl = bucket ~ '/gallery/' ~ vich_uploader_asset(image, 'imageFile')|trim('/', 'left') %} -
    + {% if app.environment == 'dev' %} + {% set imageUrl = '/gallery/' ~ vich_uploader_asset(image, 'imageFile')|trim('/', 'left') %} + {% else %} + {% set imageUrl = bucket ~ '/gallery/' ~ vich_uploader_asset(image, 'imageFile')|trim('/', 'left') %} + {% endif %} +