themes/bases/Campussuite2015/widgets/AlertBanner/WidgetProcessor.php line 57

Open in your IDE?
  1. <?php
  2. namespace Cms\Widgets\AlertBanner;
  3. use Cms\ContentBundle\Service\FrontendRenderer;
  4. use Cms\CoreBundle\Service\Slugger;
  5. use Cms\CoreBundle\Service\StringUtils\LoremIpsumGenerator;
  6. use Cms\CoreBundle\Util\DateTimeUtils;
  7. use Cms\ModuleBundle\Model\AbstractModuleListWidgetProcessor;
  8. use Cms\Modules\AlertBundle\Entity\Alert\AlertProxy;
  9. use Cms\Modules\AlertBundle\Entity\ModuleSettings;
  10. use Cms\Modules\AlertBundle\Model\Alert\AlertData;
  11. use Cms\WidgetBundle\Model\ModuleCascadingSharesWidgetProcessorTrait;
  12. use Cms\WidgetBundle\Model\ModuleLimitedListWidgetProcessorInterface;
  13. use Cms\WidgetBundle\Model\ModuleLimitedListWidgetProcessorTrait;
  14. use Cms\WidgetBundle\Model\WidgetObject;
  15. /**
  16.  * Class WidgetProcessor
  17.  * @package Cms\Widgets\AlertBanner
  18.  */
  19. final class WidgetProcessor extends AbstractModuleListWidgetProcessor implements ModuleLimitedListWidgetProcessorInterface
  20. {
  21.     use ModuleLimitedListWidgetProcessorTrait;
  22.     use ModuleCascadingSharesWidgetProcessorTrait;
  23.     const LIMITS__MAX 6;
  24.     const LIMITS__DEFAULT self::LIMITS__MAX;
  25.     /**
  26.      * {@inheritdoc}
  27.      * @param AlertBanner $object
  28.      */
  29.     public function process(WidgetObject $objectFrontendRenderer $renderer)
  30.     {
  31.         // get the containers and stuff for this
  32.         $containers $this->determineContainers($object$renderer->peekGlobals());
  33.         $container $containers[0];
  34.         // determine if finding stuff or using sample data
  35.         if ( ! empty($object->getId())) {
  36.             // make the query
  37.             $qb $this->qb(
  38.                 AlertProxy::class,
  39.                 $this->flattenContainers($containerModuleSettings::class),
  40.                 $object->getTags()
  41.             )
  42.                 ->andWhere('proxy.data_startDate <= :now')
  43.                 ->andWhere('proxy.data_expiryDate >= :now')
  44.                 ->setParameter('now'DateTimeUtils::now())
  45.                 ->addOrderBy('proxy.data_level''ASC')
  46.                 ->addOrderBy('proxy.data_startDate''ASC')
  47.                 ->addOrderBy('proxy.data_expiryDate''ASC');
  48.             // query based on limit
  49.             $items $this->query(AlertProxy::class, $qb$object);
  50.         } else {
  51.             // use sample data
  52.             $items $this->samples(
  53.                 AlertProxy::class,
  54.                 function (AlertProxy $proxy$index) use ($container) {
  55.                     return $proxy
  56.                         ->setContainer($container)
  57.                         ->getData()
  58.                             ->setAbstract($this->lipsum->words(15))
  59.                             ->setContent($this->lipsum->paragraphs(1LoremIpsumGenerator::MODIFIERS__P_WRAPPING))
  60.                             ->setTitle($this->lipsum->words(6LoremIpsumGenerator::MODIFIERS__CAMEL_CASE))
  61.                             ->setStartDate(DateTimeUtils::current())
  62.                             ->setExpiryDate(DateTimeUtils::afterCurrent(sprintf('PT%sH'$index)))
  63.                             ->setSlug(Slugger::slug($proxy->getData()->getTitle()))
  64.                         ->entity();
  65.                 },
  66.                 $this->getLimit($object)
  67.             );
  68.         }
  69.         // add extra html class if there are items, will help with certain themes
  70.         if (count($items) > 0) {
  71.             $renderer->peekGlobals()->getAssetsOrganizer()->getHtmlTag()->append(
  72.                 'class',
  73.                 'cs-alert-banner-active'
  74.             );
  75.         }
  76.         // get a list of popups
  77.         // TODO: can use like a callback and array filtering function for this...
  78.         $popups = [];
  79.         foreach ($items as $item) {
  80.             if ($item->getData()->getBehavior() === AlertData::BEHAVIORS__POPUP) {
  81.                 $popups[] = $item;
  82.             }
  83.         }
  84.         // done
  85.         return array(
  86.             'containers' => $containers,
  87.             'container' => $container,
  88.             'items' => $items,
  89.             'popups' => $popups,
  90.         );
  91.     }
  92.     /**
  93.      * {@inheritdoc}
  94.      * @param AlertBanner $object
  95.      */
  96.     public function plugin(WidgetObject $objectFrontendRenderer $renderer)
  97.     {
  98.         return array(
  99.             'autoplay' => ($object->getAutoplay() === true),
  100.             'speed' => ( ! empty($object->getSpeed())) ? intval($object->getSpeed()) : 5000,
  101.             'loop' => ($object->getLoop() === true),
  102.         );
  103.     }
  104. }