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: // dependencies from `charcoal-core`
  6: use Charcoal\Loader\CollectionLoader;
  7: 
  8: // PHP dependencies
  9: use DateTime;
 10: 
 11: /**
 12:  * News Loader
 13:  */
 14: class NewsLoader extends AbstractLoader
 15: {
 16:     /**
 17:      * @var string $median The median between upcoming and archive entries.
 18:      */
 19:     protected $median;
 20: 
 21:     /**
 22:      * @var object $objType The object to load.
 23:      */
 24:     protected $objType;
 25: 
 26:     /**
 27:      * @return CollectionLoader
 28:      */
 29:     public function all()
 30:     {
 31:         $proto = $this->newsProto();
 32:         $loader = $this->collectionLoader()->setModel($proto);
 33:         $loader->addFilter('active', true);
 34: 
 35:         return $loader;
 36:     }
 37: 
 38:     public function newsProto()
 39:     {
 40:         return $this->modelFactory()->get($this->objType());
 41:     }
 42: 
 43:     /**
 44:      * @return CollectionLoader
 45:      */
 46:     public function published()
 47:     {
 48:         $now = new DateTime();
 49:         $loader = $this->all();
 50:         $loader->addFilter('publish_date', $now->format('Y-m-d H:i:s'), [ 'operator' => '<=' ])
 51:             ->addFilter('expiry_date', $now->format('Y-m-d H:i:s'), [ 'operator' => '>=' ]);
 52: 
 53:         return $loader;
 54:     }
 55: 
 56:     /**
 57:      * @return CollectionLoader
 58:      */
 59:     public function expired()
 60:     {
 61:         $now = new DateTime();
 62:         $loader = $this->all();
 63:         $loader->addFilter('publish_date', $now->format('Y-m-d H:i:s'), [ 'operator' => '<=' ])
 64:             ->addFilter('expiry_date', $now->format('Y-m-d H:i:s'), [ 'operator' => '<=' ]);
 65: 
 66:         return $loader;
 67:     }
 68: 
 69:     /**
 70:      * Fetch upcoming entries based on the median or now.
 71:      * @return CollectionLoader
 72:      */
 73:     public function upcoming()
 74:     {
 75:         $loader = $this->published();
 76: 
 77:         return $loader;
 78:     }
 79: 
 80:     /**
 81:      * Fetch upcoming entries based on the median or now.
 82:      * @return CollectionLoader
 83:      */
 84:     public function archive()
 85:     {
 86:         $loader = $this->expired();
 87: 
 88:         return $loader;
 89:     }
 90: 
 91:     // ==========================================================================
 92:     // GETTERS
 93:     // ==========================================================================
 94: 
 95:     /**
 96:      * @return mixed
 97:      */
 98:     public function median()
 99:     {
100:         return $this->median;
101:     }
102: 
103:     /**
104:      * @return object
105:      */
106:     public function objType()
107:     {
108:         return $this->objType;
109:     }
110: 
111:     // ==========================================================================
112:     // SETTERS
113:     // ==========================================================================
114: 
115:     /**
116:      * @param string $median The median between upcoming and archive.
117:      * @return self
118:      */
119:     public function setMedian($median)
120:     {
121:         $this->median = $median;
122: 
123:         return $this;
124:     }
125: 
126:     /**
127:      * @param object $objType The object type.
128:      * @return self
129:      */
130:     public function setObjType($objType)
131:     {
132:         $this->objType = $objType;
133: 
134:         return $this;
135:     }
136: }
137: 
API documentation generated by ApiGen