Overview

Namespaces

  • Charcoal
    • Admin
      • Widget
        • Cms
    • Cms
      • Config
      • Mixin
        • Traits
      • Route
      • Section
      • Service
        • Loader
        • Manager
      • ServiceProvider
      • Support
        • Helpers
        • Interfaces
        • Traits
    • Property

Classes

  • Charcoal\Admin\Widget\Cms\HierarchicalSectionTableWidget
  • Charcoal\Admin\Widget\Cms\SectionTableWidget
  • Charcoal\Cms\AbstractDocument
  • Charcoal\Cms\AbstractEvent
  • Charcoal\Cms\AbstractFaq
  • Charcoal\Cms\AbstractImage
  • Charcoal\Cms\AbstractNews
  • Charcoal\Cms\AbstractSection
  • Charcoal\Cms\AbstractText
  • Charcoal\Cms\AbstractVideo
  • Charcoal\Cms\Config
  • Charcoal\Cms\Config\CmsConfig
  • Charcoal\Cms\Config\EventConfig
  • Charcoal\Cms\Config\NewsConfig
  • Charcoal\Cms\Config\SectionConfig
  • Charcoal\Cms\Document
  • Charcoal\Cms\DocumentCategory
  • Charcoal\Cms\EmptySection
  • Charcoal\Cms\Event
  • Charcoal\Cms\EventCategory
  • Charcoal\Cms\ExternalSection
  • Charcoal\Cms\Faq
  • Charcoal\Cms\FaqCategory
  • Charcoal\Cms\Image
  • Charcoal\Cms\ImageCategory
  • Charcoal\Cms\News
  • Charcoal\Cms\NewsCategory
  • Charcoal\Cms\Route\EventRoute
  • Charcoal\Cms\Route\GenericRoute
  • Charcoal\Cms\Route\NewsRoute
  • Charcoal\Cms\Route\SectionRoute
  • Charcoal\Cms\Section
  • Charcoal\Cms\Section\BlocksSection
  • Charcoal\Cms\Section\ContentSection
  • Charcoal\Cms\Service\Loader\AbstractLoader
  • Charcoal\Cms\Service\Loader\EventLoader
  • Charcoal\Cms\Service\Loader\NewsLoader
  • Charcoal\Cms\Service\Loader\SectionLoader
  • Charcoal\Cms\Service\Manager\AbstractManager
  • Charcoal\Cms\Service\Manager\EventManager
  • Charcoal\Cms\Service\Manager\NewsManager
  • Charcoal\Cms\ServiceProvider\CmsServiceProvider
  • Charcoal\Cms\Support\Helpers\DateHelper
  • Charcoal\Cms\Tag
  • Charcoal\Cms\Text
  • Charcoal\Cms\TextCategory
  • Charcoal\Cms\Video
  • Charcoal\Cms\VideoCategory
  • Charcoal\Property\TemplateOptionsProperty
  • Charcoal\Property\TemplateProperty

Interfaces

  • Charcoal\Cms\DocumentInterface
  • Charcoal\Cms\EventInterface
  • Charcoal\Cms\FaqInterface
  • Charcoal\Cms\ImageInterface
  • Charcoal\Cms\MetatagInterface
  • Charcoal\Cms\Mixin\HasContentBlocksInterface
  • Charcoal\Cms\NewsInterface
  • Charcoal\Cms\SearchableInterface
  • Charcoal\Cms\SectionInterface
  • Charcoal\Cms\Support\Interfaces\EventManagerAwareInterface
  • Charcoal\Cms\Support\Interfaces\NewsManagerAwareInterface
  • Charcoal\Cms\Support\Interfaces\SectionLoaderAwareInterface
  • Charcoal\Cms\TemplateableInterface
  • Charcoal\Cms\TextInterface
  • Charcoal\Cms\VideoInterface

Traits

  • Charcoal\Admin\Widget\Cms\SectionTableTrait
  • Charcoal\Cms\MetatagTrait
  • Charcoal\Cms\Mixin\Traits\HasContentBlocksTrait
  • Charcoal\Cms\SearchableTrait
  • Charcoal\Cms\Support\Traits\DateHelperAwareTrait
  • Charcoal\Cms\Support\Traits\EventManagerAwareTrait
  • Charcoal\Cms\Support\Traits\NewsManagerAwareTrait
  • Charcoal\Cms\Support\Traits\SectionLoaderAwareTrait
  • Charcoal\Cms\TemplateableTrait
  • Overview
  • Namespace
  • Class
  1: <?php
  2: 
  3: namespace Charcoal\Cms\Service\Loader;
  4: 
  5: use Charcoal\Loader\CollectionLoader;
  6: use DateTime;
  7: use DateTimeInterface;
  8: 
  9: /**
 10:  * Event Loader
 11:  */
 12: class EventLoader extends AbstractLoader
 13: {
 14:     /**
 15:      * Event prototype.
 16:      * @var ModelInterface $proto
 17:      */
 18:     private $proto;
 19: 
 20:     /**
 21:      * @var string $lifespan The lifespan of events.
 22:      */
 23:     private $lifespan;
 24: 
 25:     /**
 26:      * [proto description]
 27:      * @return [type] [description]
 28:      */
 29:     public function proto()
 30:     {
 31:         if (!$this->proto) {
 32:             $this->proto = $this->modelFactory()->get($this->objType());
 33:         }
 34: 
 35:         return $this->proto;
 36:     }
 37: 
 38:     /**
 39:      * @return CollectionLoader
 40:      */
 41:     public function all()
 42:     {
 43:         $proto = $this->proto();
 44:         $loader = $this->collectionLoader()->setModel($proto);
 45:         $loader->addFilter('active', true);
 46: 
 47:         return $loader;
 48:     }
 49: 
 50:     /**
 51:      * @return CollectionLoader
 52:      */
 53:     public function published()
 54:     {
 55:         $now = new DateTime();
 56:         $loader = $this->all();
 57:         $loader->addFilter('publish_date', $now->format('Y-m-d H:i:s'), [ 'operator' => '<=' ])
 58:             ->addOrder('start_date', 'asc');
 59: 
 60:         return $loader;
 61:     }
 62: 
 63:     /**
 64:      * Fetch upcoming entries based on the lifespan or now.
 65:      * @return CollectionLoader
 66:      */
 67:     public function upcoming()
 68:     {
 69:         $lifespan = $this->lifespan();
 70:         $date = is_string($lifespan) ? new DateTime($lifespan) : new DateTime();
 71: 
 72:         return $this->since($date);
 73:     }
 74: 
 75:     /**
 76:      * Fetch upcoming entries based on the lifespan or now.
 77:      * @return CollectionLoader
 78:      */
 79:     public function archive()
 80:     {
 81:         $lifespan = $this->lifespan();
 82:         $date = is_string($lifespan) ? new DateTime($lifespan) : new DateTime();
 83: 
 84:         return $this->to($date);
 85:     }
 86: 
 87:     /**
 88:      * @param mixed $date The news date to filter
 89:      *                    [startDate, endDate]
 90:      *                    DateTimeInterface
 91:      *                    string.
 92:      * @return CollectionLoader
 93:      */
 94:     public function since($date)
 95:     {
 96:         $date = $this->parseAsDate($date);
 97:         $loader = $this->published();
 98:         $loader->addFilter('end_date', $date->format('Y-m-d H:i:s'), [ 'operator' => '>=' ]);
 99: 
100:         return $loader;
101:     }
102: 
103:     /**
104:      * @param mixed $date The news date to filter
105:      *                    [startDate, endDate]
106:      *                    DateTimeInterface
107:      *                    string.
108:      * @return CollectionLoader
109:      */
110:     public function to($date)
111:     {
112:         $date = $this->parseAsDate($date);
113:         $loader = $this->published();
114:         $loader->addFilter('end_date', $date->format('Y-m-d H:i:s'), [ 'operator' => '<' ]);
115: 
116:         return $loader;
117:     }
118: 
119:     // ==========================================================================
120:     // GETTERS
121:     // ==========================================================================
122: 
123:     /**
124:      * @return mixed
125:      */
126:     public function lifespan()
127:     {
128:         return $this->lifespan;
129:     }
130: 
131:     /**
132:      * @return object
133:      */
134:     public function objType()
135:     {
136:         return $this->objType;
137:     }
138: 
139:     // ==========================================================================
140:     // SETTERS
141:     // ==========================================================================
142: 
143:     /**
144:      * @param string $lifespan The lifespan of events.
145:      * @return self Chainable
146:      */
147:     public function setLifespan($lifespan)
148:     {
149:         $this->lifespan = $lifespan;
150: 
151:         return $this;
152:     }
153: 
154:     /**
155:      * @param object $objType The object type.
156:      * @return self Chainable
157:      */
158:     public function setObjType($objType)
159:     {
160:         $this->objType = $objType;
161: 
162:         return $this;
163:     }
164: 
165:     // ==========================================================================
166:     // UTILS
167:     // ==========================================================================
168: 
169:     /**
170:      * @param mixed $date The date to convert.
171:      * @return DateTime
172:      */
173:     private function parseAsDate($date)
174:     {
175:         if ($date instanceof DateTimeInterface) {
176:             return $date;
177:         }
178: 
179:         return new DateTime($date);
180:     }
181: }
182: 
API documentation generated by ApiGen