Source of file ElementPodcast.php
Size: 4,507 Bytes - Last Modified: 2021-12-24T07:04:57+00:00
/var/www/docs.ssmods.com/process/src/src/Elements/ElementPodcast.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 | <?php namespace Kraftausdruck\Elements; use SilverStripe\Forms\LiteralField; use SilverStripe\Forms\DropdownField; use Kraftausdruck\Models\PodcastSeries; use Kraftausdruck\Models\PodcastEpisode; use DNADesign\Elemental\Models\BaseElement; class ElementPodcast extends BaseElement { private static $db = [ 'Primary' => 'Boolean', 'NoPodcasts' => 'HTMLText' ]; private static $has_one = [ 'PodcastSeries' => PodcastSeries::class ]; private static $defaults = [ 'AvailableGlobally' => 0 ]; private static $table_name = 'ElementPodcast'; private static $title = 'Podcast Element'; private static $inline_editable = false; private static $icon = 'font-icon-block-podcast'; public function getCMSFields() { $fields = parent::getCMSFields(); $fields->removeByName([ 'isFullWidth', 'AvailableGlobally', 'PodcastSeries' ]); if ($AvailableGloballyField = $fields->dataFieldByName('AvailableGlobally')) { $AvailableGloballyField->setDisabled(true); } if ($PrimaryField = $fields->dataFieldByName('Primary')) { if (!$this->Primary && $this->ClassName::get()->filter(['Primary' => 1])->count()) { $PrimaryPodcastElement = $this->ClassName::get()->filter(['Primary' => 1])->first()->AbsoluteLink(); $PrimaryField = LiteralField::create( 'PrimaryIs', sprintf( '<p class="alert alert-info">Primary Podcast Element is %s</p>', $PrimaryPodcastElement ) ); } $fields->addFieldToTab('Root.Settings', $PrimaryField); $PrimaryField->setTitle(_t(__CLASS__ . '.PRIMARY', 'false')); } if ($PodcastSeriesField = $fields->dataFieldByName('PodcastSeriesID')) { // Dropdownfield doesn't behave if selected item isn't in $source // we allow PodcastSeries to be linked just once, to maintain single URL $selected = $this->PodcastSeriesID; $excludedCosChoosen = array_unique($this->ClassName::get()->Column('PodcastSeriesID')); unset($excludedCosChoosen[array_search($this->PodcastSeriesID, $excludedCosChoosen)]); $source = PodcastSeries::get(); if(count($excludedCosChoosen)) { $source = $source->exclude(['ID' => $excludedCosChoosen]); // ->map('Title', 'ID') } $PodcastSeriesField = DropdownField::create('PodcastSeriesID', _t(__CLASS__ . '.PODCASTSERIES', 'Podcast Series'), $source); $PodcastSeriesField->setEmptyString(_t(__CLASS__ . '.EmptyPodcastSeriesString', '--')); $PodcastSeriesField->setHasEmptyDefault(true); $PodcastSeriesField->setDescription(_t(__CLASS__ . '.PodcastSeriesDescription', 'Podcast series should be linked only once!')); $fields->replaceField('PodcastSeriesID', $PodcastSeriesField); } if ($TextEditor = $fields->dataFieldByName('NoPodcasts')) { $TextEditor->setRows(10); $TextEditor->addExtraClass('stacked'); } $message = _t(__CLASS__ . '.EditPodcastEpisodeHint', '<a href="/admin/podcasts">Create & edit</a> podcasts.'); $fields->unshift( LiteralField::create( 'EditPodcast', sprintf( '<p class="alert alert-info">%s</p>', $message ) ) ); return $fields; } public function getItems() { $podcasts = PodcastEpisode::get()->filter(['Active' => 1, 'PodcastSeriesID' => $this->PodcastSeriesID])->filterByCallback(function ($record) { return $record->canView(); }); return $podcasts; } // first one should be primary unless selected differently public function populateDefaults() { $this->NoPodcasts = '<p>' . _t(__CLASS__ . '.DEFAULTNoPodcasts', 'Thank you for your interest. Currently there are no podcasts available.') . '</p>'; $this->Primary = 1; if ($podcastElements = $this->ClassName::get()->filter('Primary', 1)->count()) { $this->Primary = 0; } parent::populateDefaults(); } public function getType() { return _t(__CLASS__ . '.BlockType', 'Podcast Element'); } } |