Skip to content
Snippets Groups Projects
Commit a3ddec89 authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

audio tracks at bokeh core

parent 6b7104be
Branches
Tags
No related merge requests found
Pipeline #18055 failed with stage
in 17 minutes and 6 seconds
......@@ -27,7 +27,7 @@ class NoticeAjaxController extends ZendAfi_Controller_Action {
public function getPlugins() {
return ['ZendAfi_Controller_Plugin_Template_Jumbotron'];
return [ZendAfi_Controller_Plugin_Template_Jumbotron::class];
}
......@@ -48,9 +48,7 @@ class NoticeAjaxController extends ZendAfi_Controller_Action {
protected function extractNoticeFromRequest() {
$id_notice = str_replace('N','', $this->_request->getParam('id', $this->_getParam('id_notice')));
if (!$notice = Class_Notice::find($id_notice))
$notice = new Class_Notice();
return $notice;
return Class_Notice::find($id_notice) ?? new Class_Notice;
}
......@@ -589,7 +587,7 @@ class NoticeAjaxController extends ZendAfi_Controller_Action {
public function tracksAction() {
session_write_close();
$tracks = (new Intonation_Library_Tracks($this->notice))->collection();
$tracks = Class_Notice_AudioTracks::newFor($this->notice)->collection();
$this->_ajaxResponseWithScript($this->view->renderTracks($tracks));
}
......@@ -598,7 +596,7 @@ class NoticeAjaxController extends ZendAfi_Controller_Action {
public function mediaAction() {
session_write_close();
$tracks = (new Intonation_Library_Tracks($this->notice))->collection();
$tracks = Class_Notice_AudioTracks::newFor($this->notice)->collection();
$trailers = (new Intonation_Library_Trailers)
->setModel($this->notice)
......@@ -621,19 +619,13 @@ class NoticeAjaxController extends ZendAfi_Controller_Action {
$html = array_filter($html);
$html = array_map(function($row)
{
return $this->view->div(['class' => 'col-12'], $row);
}, $html);
$html = array_map(fn($row) => $this->view->div(['class' => 'col-12'], $row),
$html);
if (empty($html))
$html = $this->view->renderEmptyMedia();
return $this->_helper->ajax(function() use ($html)
{
if ($html)
return $this->view->grid($html);
});
return $this->_helper->ajax(fn() => $html ? $this->view->grid($html) : null);
}
......
......@@ -20,7 +20,7 @@
*/
class Intonation_Library_Track {
class Class_Notice_AudioTrack {
protected
$_title,
$_duration,
......
<?php
/**
* Copyright (c) 2012-2019, Agence Française Informatique (AFI). All rights reserved.
* Copyright (c) 2012-2022, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
......@@ -20,72 +20,52 @@
*/
class Intonation_Library_Tracks {
abstract class Class_Notice_AudioTracks {
protected Class_Notice $_record;
protected ?Intonation_Library_TracksAbstract $_tracks;
protected string $_zone = '';
protected string $_title_field = '';
protected string $_url_field = '';
protected string $_source = '';
protected ?Storm_Collection $_tracks;
public function __construct(Class_Notice $record) {
$this->_record = $record;
$this->_tracks = null;
}
public static function newFor(Class_Notice $record) : self {
if (!$record->isTypeDocSonore())
return new Class_Notice_AudioTracksEmpty($record);
public function collection() : Storm_Model_Collection {
return new Storm_Model_Collection($this->tracks());
}
if ($record->isGam())
return new Class_Notice_AudioTracksGam($record);
if ($record->isCvs())
return new Class_Notice_AudioTracksCvs($record);
public function tracks() : array {
return $this->_getTracks()->tracks();
return new Class_Notice_AudioTracksBase($record);
}
public function hasContent() : bool {
return $this->_getTracks()->hasContent();
public function __construct(Class_Notice $record) {
$this->_record = $record;
$this->_tracks = null;
}
protected function _getTracks() : Intonation_Library_TracksAbstract {
public function collection() : Storm_Collection {
if ($this->_tracks)
return $this->_tracks;
if (!$this->_record->isTypeDocSonore())
return $this->_tracks = new Intonation_Library_TracksEmpty($this->_record);
if ($this->_record->isGam())
return $this->_tracks = new Intonation_Library_TracksGam($this->_record);
if ($this->_record->isCvs())
return $this->_tracks = new Intonation_Library_TracksCvs($this->_record);
return $this->_tracks = new Intonation_Library_TracksBase($this->_record);
}
}
abstract class Intonation_Library_TracksAbstract {
protected Class_Notice $_record;
protected string $_zone = '';
protected string $_title_field = '';
protected string $_url_field = '';
protected string $_source = '';
public function __construct(Class_Notice $record) {
$this->_record = $record;
return $this->_tracks = $this->_loadTracks();
}
public function hasContent() : bool {
return ! empty($this->_record->get_subfield($this->_zone));
return $this->_zone && !empty($this->_record->get_subfield($this->_zone));
}
public function tracks() : array {
public function _loadTracks() : Storm_Collection {
return (new Storm_Collection($this->_record->get_subfield($this->_zone)))
->collect(fn($subfield) => $this->_record->get_zone($this->_zone, $subfield))
......@@ -93,19 +73,12 @@ abstract class Intonation_Library_TracksAbstract {
->select(fn($zone) => ($zone->firstValueOf($this->_title_field)
&& $zone->firstValueOf($this->_url_field)))
->collect(fn($zone) => $this->_newTrack($zone))
->getArrayCopy();
}
public function setRecord(Class_Notice $record) : self {
$this->_record = $record;
return $this;
->collect(fn($zone) => $this->_newTrack($zone));
}
protected function _newTrack(Class_NoticeUnimarc_Zone $zone) : Intonation_Library_Track {
return (new Intonation_Library_Track)
protected function _newTrack(Class_NoticeUnimarc_Zone $zone) : Class_Notice_AudioTrack {
return (new Class_Notice_AudioTrack)
->setTitle($zone->firstValueOf($this->_title_field))
->setUrl($zone->firstValueOf($this->_url_field))
->setSource($this->_source);
......@@ -115,21 +88,21 @@ abstract class Intonation_Library_TracksAbstract {
class Intonation_Library_TracksEmpty extends Intonation_Library_TracksAbstract {
class Class_Notice_AudioTracksEmpty extends Class_Notice_AudioTracks {
public function hasContent() : bool {
return false;
}
public function tracks() : array {
return [];
public function collection() : Storm_Collection {
return new Storm_Collection;
}
}
class Intonation_Library_TracksBase extends Intonation_Library_TracksAbstract {
class Class_Notice_AudioTracksBase extends Class_Notice_AudioTracks {
protected string $_zone = '464';
protected string $_title_field = 't';
protected string $_url_field = '3';
......@@ -139,7 +112,7 @@ class Intonation_Library_TracksBase extends Intonation_Library_TracksAbstract {
class Intonation_Library_TracksGam extends Intonation_Library_TracksAbstract {
class Class_Notice_AudioTracksGam extends Class_Notice_AudioTracks {
protected string $_zone = '858';
protected string $_title_field = 'z';
protected string $_url_field = 'u';
......@@ -156,7 +129,7 @@ class Intonation_Library_TracksGam extends Intonation_Library_TracksAbstract {
class Intonation_Library_TracksCvs extends Intonation_Library_TracksAbstract {
class Class_Notice_AudioTracksCvs extends Class_Notice_AudioTracks {
protected string $_zone = '856';
protected string $_title_field = 'a';
protected string $_url_field = 'u';
......
......@@ -88,7 +88,7 @@ class Intonation_View_RenderTracks extends ZendAfi_View_Helper_BaseHelper {
}
protected function _audioTrack(Intonation_Library_Track $track) : string {
protected function _audioTrack(Class_Notice_AudioTrack $track) : string {
$html = [$this->_trackIcon(),
$this->_tag('span', $track->getTitle(), ['class' => 'track_title'])];
......@@ -111,7 +111,7 @@ class Intonation_View_RenderTracks extends ZendAfi_View_Helper_BaseHelper {
}
protected function _youtubeTrack(Intonation_Library_Track $track) {
protected function _youtubeTrack(Class_Notice_AudioTrack $track) {
$html = [$this->_youtubeIcon(),
$this->_tag('span',
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment