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\Support\Traits;
  4: 
  5: use Charcoal\Cms\EventInterface;
  6: use Charcoal\Cms\Service\Manager\EventManager;
  7: use Charcoal\Object\CategoryInterface;
  8: use Slim\Exception\ContainerException;
  9: 
 10: trait EventManagerAwareTrait
 11: {
 12:     /**
 13:      * Currently displayed event.
 14:      * @var array $event City/Object/Event
 15:      */
 16:     private $currentEvent;
 17: 
 18:     /**
 19:      * @var EventManager $eventManager
 20:      */
 21:     private $eventManager;
 22: 
 23:     // ==========================================================================
 24:     // FUNCTIONS
 25:     // ==========================================================================
 26: 
 27:     /**
 28:      * Formatted event list
 29:      * Return the entries for the current page
 30:      * @return \Generator|void
 31:      */
 32:     public function eventsList()
 33:     {
 34:         $eventList = $this->eventManager()->entries();
 35:         foreach ($eventList as $event) {
 36:             yield $this->eventFormatShort($event);
 37:         }
 38:     }
 39: 
 40:     /**
 41:      * Formatted event archive list
 42:      * Returns the entries for the current page.
 43:      * @return \Generator|void
 44:      */
 45:     public function eventArchiveList()
 46:     {
 47:         $entries = $this->eventManager()->archive();
 48:         foreach ($entries as $entry) {
 49:             yield $this->eventFormatShort($entry);
 50:         }
 51:     }
 52: 
 53:     /**
 54:      * Current event.
 55:      * @return array The properties of the current event.
 56:      */
 57:     public function currentEvent()
 58:     {
 59:         if ($this->currentEvent) {
 60:             return $this->currentEvent;
 61:         }
 62: 
 63:         // The the current event
 64:         $event = $this->eventManager()->entry();
 65: 
 66:         // Format the event
 67:         if ($event) {
 68:             $this->currentEvent = $this->eventFormatFull($event);
 69:         }
 70: 
 71:         return $this->currentEvent;
 72:     }
 73: 
 74:     /**
 75:      * @return mixed
 76:      */
 77:     public function featEvents()
 78:     {
 79:         $entries = $this->eventManager()->featList();
 80: 
 81:         if (!$entries) {
 82:             return;
 83:         }
 84: 
 85:         foreach ($entries as $entry) {
 86:             if ($entry->id()) {
 87:                 yield $this->eventFormatFull($entry);
 88:             }
 89:         }
 90:     }
 91: 
 92:     /**
 93:      * Next event in list.
 94:      * @return array The next event properties.
 95:      */
 96:     public function nextEvent()
 97:     {
 98:         $next = $this->eventManager()->next();
 99: 
100:         if (!$next) {
101:             return null;
102:         }
103: 
104:         return $this->eventFormatNav($next);
105:     }
106: 
107:     /**
108:      * Next event in list.
109:      * @return array The next event properties.
110:      */
111:     public function prevEvent()
112:     {
113:         $prev = $this->eventManager()->prev();
114: 
115:         if (!$prev) {
116:             return null;
117:         }
118: 
119:         return $this->eventFormatNav($prev);
120:     }
121: 
122:     /**
123:      * Amount of events (total)
124:      * @return integer How many events?
125:      */
126:     public function numEvent()
127:     {
128:         return $this->eventManager()->numEvent();
129:     }
130: 
131:     /**
132:      * @return float
133:      */
134:     public function numEventPages()
135:     {
136:         return $this->eventManager()->numPages();
137:     }
138: 
139:     /**
140:      * @return boolean
141:      */
142:     public function eventHasPager()
143:     {
144:         return $this->eventManager()->hasPager();
145:     }
146: 
147:     /**
148:      * @return \Generator
149:      */
150:     public function eventCategoryList()
151:     {
152:         $cats = $this->eventManager()->categoryItems();
153:         foreach ($cats as $cat) {
154:             yield $this->eventFormatCategory($cat);
155:         }
156:     }
157: 
158:     /**
159:      * @param EventInterface $event Charcoal\Cms\EventInterface.
160:      * @return CategoryInterface
161:      */
162:     protected function eventCategory(EventInterface $event)
163:     {
164:         $id = $event->category();
165: 
166:         return $this->eventManager()->categoryItem($id);
167:     }
168: 
169:     // ==========================================================================
170:     // FORMATTER
171:     // ==========================================================================
172: 
173:     /**
174:      * @param EventInterface $event Charcoal\Cms\EventInterface.
175:      * @return string
176:      */
177:     protected function getEventStartDateFormat(EventInterface $event)
178:     {
179:         return $this->dateHelper()->formatDate(
180:             $event->startDate()
181:         );
182:     }
183: 
184:     /**
185:      * @param EventInterface $event Charcoal\Cms\EventInterface.
186:      * @return string
187:      */
188:     protected function getEventEndDateFormat(EventInterface $event)
189:     {
190:         return $this->dateHelper()->formatDate(
191:             $event->endDate()
192:         );
193:     }
194: 
195:     /**
196:      * @param EventInterface $event Charcoal\Cms\EventInterface.
197:      * @return string
198:      */
199:     protected function getEventDateFormat(EventInterface $event)
200:     {
201:         return $this->dateHelper()->formatDate([
202:             $event->startDate(),
203:             $event->endDate()
204:         ]);
205:     }
206: 
207:     /**
208:      * @param EventInterface $event Charcoal\Cms\EventInterface.
209:      * @return string
210:      */
211:     protected function getEventTimeFormat(EventInterface $event)
212:     {
213:         if ($event->dateNotes() != '') {
214:             return $event->dateNotes();
215:         }
216: 
217:         if (!$event->displayHours()) {
218:             return null;
219:         }
220: 
221:         return $this->dateHelper()->formatTime([
222:             $event->startDate(),
223:             $event->endDate(),
224:         ]);
225:     }
226: 
227:     /**
228:      * Formatting expected in templates
229:      * @param EventInterface $event Charcoal\Cms\EventInterface.
230:      * @return array The needed event properties.
231:      */
232:     protected function eventFormatShort(EventInterface $event)
233:     {
234:         return [
235:             'title'     => (string)$event->title(),
236:             'url'       => (string)$event->url(),
237:             'startDate' => $this->getEventStartDateFormat($event),
238:             'endDate'   => $this->getEventEndDateFormat($event),
239:             'date'      => $this->getEventDateFormat($event),
240:             'time'      => $this->getEventTimeFormat($event),
241:             'active'    => ($this->currentEvent() && ($this->currentEvent()['id'] == $event->id()))
242:         ];
243:     }
244: 
245:     /**
246:      * Formatting expected in templates
247:      * @param EventInterface $event Charcoal\Cms\EventInterface.
248:      * @return array The needed event properties.
249:      */
250:     protected function eventFormatNav(EventInterface $event)
251:     {
252:         return [
253:             'startDate' => $this->getEventStartDateFormat($event),
254:             'endDate'   => $this->getEventEndDateFormat($event),
255:             'date'      => $this->getEventDateFormat($event),
256:             'time'      => $this->getEventTimeFormat($event),
257:             'title'     => (string)$event->title(),
258:             'url'       => $event->url()
259:         ];
260:     }
261: 
262:     /**
263:      * @param EventInterface $event The current event.
264:      * @return array The needed properties.
265:      */
266:     protected function eventFormatFull(EventInterface $event)
267:     {
268:         $contentBlocks = $event->attachments('content-blocks');
269:         $gallery = $event->attachments('image-gallery');
270:         $documents = $event->attachments('document');
271: 
272:         return [
273:             'id'               => $event->id(),
274:             'title'            => (string)$event->title(),
275:             'summary'          => (string)$event->summary(),
276:             'content'          => (string)$event->content(),
277:             'image'            => $event->image(),
278:             'startDate'        => $this->getEventStartDateFormat($event),
279:             'endDate'          => $this->getEventEndDateFormat($event),
280:             'date'             => $this->getEventDateFormat($event),
281:             'time'             => $this->getEventTimeFormat($event),
282:             'contentBlocks'    => $contentBlocks,
283:             'hasContentBlocks' => !!(count($contentBlocks)),
284:             'documents'        => $documents,
285:             'hasDocuments'     => !!(count($documents)),
286:             'gallery'          => $gallery,
287:             'hasGallery'       => !!(count($gallery)),
288:             'url'              => $event->url(),
289:             'metaTitle'        => (string)$event->metaTitle(),
290:             'locationName'     => (string)$event->locationName(),
291:             'dateNotes'        => (string)$event->dateNotes(),
292:             'category'         => $event->category()
293:         ];
294:     }
295: 
296:     /**
297:      * @param CategoryInterface $category The category item.
298:      * @return array The formatted category item.
299:      */
300:     protected function eventFormatCategory(CategoryInterface $category)
301:     {
302:         return [
303:             'id'   => $category->id(),
304:             'name' => (string)$category->name(),
305:         ];
306:     }
307: 
308:     // ==========================================================================
309:     // DEPENDENCIES
310:     // ==========================================================================
311: 
312:     /**
313:      * @return EventManager
314:      * @throws ContainerException When dependency is missing.
315:      */
316:     protected function eventManager()
317:     {
318:         if (!$this->eventManager instanceof EventManager) {
319:             throw new ContainerException(sprintf(
320:                 'Missing dependency for %s: %s',
321:                 get_called_class(),
322:                 EventManager::class
323:             ));
324:         }
325: 
326:         return $this->eventManager;
327:     }
328: 
329:     /**
330:      * @param EventManager $eventManager The event Manager class.
331:      * @return self
332:      */
333:     protected function setEventManager(EventManager $eventManager)
334:     {
335:         $this->eventManager = $eventManager;
336: 
337:         return $this;
338:     }
339: 
340:     /**
341:      * dateHelperAwareTrait dependency
342:      * @return mixed
343:      */
344:     abstract protected function dateHelper();
345: }
346: 
API documentation generated by ApiGen