Skip to content

Commit c3f4a34

Browse files
authored
Merge pull request #1215 from UniversityRadioYork/colin-scheduler-changes-dev
2 parents 05c779e + aeba48a commit c3f4a34

9 files changed

+197
-2
lines changed

src/Classes/MyRadio/MyRadioNews.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,18 @@ public static function markNewsAsRead($newsentryid, MyRadio_User $user)
121121
}; //Can sometimes get duplicate key errors
122122
}
123123

124-
public static function addItem($feedid, $content)
124+
public static function addItem($feedid, $content, $memberid = 1)
125125
{
126+
// is there an active session?
127+
if (MyRadio_User::getCurrentUser() !== null) {
128+
$memberid = $_SESSION['memberid'];
129+
}
130+
126131
Database::getInstance()->query(
127132
'INSERT INTO public.news_feed'
128133
.' (feedid, memberid, content) VALUES'
129134
.' ($1, $2, $3)',
130-
[$feedid, $_SESSION['memberid'], $content]
135+
[$feedid, $memberid, $content]
131136
);
132137
}
133138

src/Classes/ServiceAPI/MyRadio_Season.php

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,16 @@ public function toDataSource($mixins = [])
978978
['show_season_id' => $this->getID()]
979979
),
980980
],
981+
'addEpisodesLink' => [
982+
'display' => 'icon',
983+
'value' => 'plus',
984+
'title' => 'Add Episodes',
985+
'url' => URLUtils::makeURL(
986+
'Scheduler',
987+
'addEpisode',
988+
['show_season_id' => $this->getID()]
989+
),
990+
],
981991
'editlink' => [
982992
'display' => 'icon',
983993
'value' => 'pencil',
@@ -1298,4 +1308,83 @@ public static function searchMeta($query, $string_keys = null, $effective_from =
12981308
);
12991309
return self::resultSetToObjArray($r);
13001310
}
1311+
1312+
public function getAddEpisodeForm()
1313+
{
1314+
$title = $this->getMeta('title');
1315+
return (new MyRadioForm(
1316+
'sched_add_episode',
1317+
'Scheduler',
1318+
'addEpisode',
1319+
[
1320+
'debug' => false,
1321+
'title' => 'Add Episode',
1322+
'subtitle' => "New Episode - $title"
1323+
]
1324+
))->addField(new MyRadioFormField(
1325+
'grp_info',
1326+
MyRadioFormField::TYPE_SECTION,
1327+
[
1328+
'label' => 'Create new episode',
1329+
'explanation' => 'Enter the time for the new episode in this season. Take care with the end time.'
1330+
]
1331+
))->addField(new MyRadioFormField(
1332+
'new_start_time',
1333+
MyRadioFormField::TYPE_DATETIME,
1334+
[
1335+
'label' => 'Episde Start Time',
1336+
'value' => date('d/m/Y H:i')
1337+
]
1338+
))->addField(new MyRadioFormField(
1339+
'new_end_time',
1340+
MyRadioFormField::TYPE_DATETIME,
1341+
[
1342+
'label' => 'Episode End Time',
1343+
'value' => date('d/m/Y H:i')
1344+
]
1345+
))->addField(new MyRadioFormField(
1346+
'grp_info_close',
1347+
MyRadioFormField::TYPE_SECTION_CLOSE,
1348+
[]
1349+
))->addField(new MyRadioFormField(
1350+
'show_season_id',
1351+
MyRadioFormField::TYPE_HIDDEN,
1352+
['value' => $this->getID()]
1353+
));
1354+
}
1355+
1356+
public function addEpisode($start_time, $end_time, $memberid = 1)
1357+
{
1358+
// If no active session we must have come through API so use placeholder user id
1359+
if (MyRadio_User::getCurrentUser() !== null) {
1360+
$memberid = MyRadio_User::getCurrentUser()->getID();
1361+
}
1362+
1363+
if(is_null($start_time) || is_null($end_time)) {
1364+
throw new MyRadioException('Start and end time must be set.', 400);
1365+
}
1366+
1367+
//Deal with the possibility of a show from 11pm to midnight etc. (taken from above)
1368+
if ($start_time < $end_time) {
1369+
$interval = CoreUtils::makeInterval($start_time, $end_time);
1370+
} else {
1371+
$interval = CoreUtils::makeInterval($start_time, $end_time + 86400);
1372+
}
1373+
1374+
$r = self::$db->query(
1375+
'INSERT INTO schedule.show_season_timeslot
1376+
(show_season_id, start_time, duration, memberid, approvedid)
1377+
VALUES ($1, $2, $3, $4, $4) RETURNING show_season_timeslot_id',
1378+
[
1379+
$this->getID(),
1380+
CoreUtils::getTimestamp($start_time),
1381+
$interval,
1382+
$memberid
1383+
]
1384+
);
1385+
if ($r) {
1386+
$this->updateCacheObject();
1387+
}
1388+
return $r;
1389+
}
13011390
}

src/Classes/ServiceAPI/MyRadio_Timeslot.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,16 @@ public function toDataSource($mixins = [])
385385
['show_season_timeslot_id' => $this->getID()]
386386
),
387387
],
388+
'movelink' => [
389+
'display' => 'icon',
390+
'value' => 'transfer',
391+
'title' => 'Move Episode',
392+
'url' => URLUtils::makeURL(
393+
'Scheduler',
394+
'moveEpisode',
395+
['show_season_timeslot_id' => $this->getID()]
396+
),
397+
]
388398
]
389399
);
390400
}
@@ -1049,6 +1059,9 @@ private function deleteTimeslot()
10491059
*/
10501060
public function moveTimeslot($newStart, $newEnd)
10511061
{
1062+
$oldStart = $this->getStartTime();
1063+
$oldEnd = $this->getEndTime();
1064+
10521065
$r = self::$db->query(
10531066
'UPDATE schedule.show_season_timeslot
10541067
SET start_time = $1, duration = $2
@@ -1060,7 +1073,20 @@ public function moveTimeslot($newStart, $newEnd)
10601073
]
10611074
);
10621075

1076+
$email = "Hi #NAME, \r\n\r\n Please note that an episode of your show, " . $this->getMeta('title')
1077+
. ' has been moved by our Programming Team. The affected episode was at '
1078+
. CoreUtils::happyTime($oldStart) . ' until ' . CoreUtils::happyTime($oldEnd)
1079+
. "\r\n"
1080+
. "It has been moved to " . CoreUtils::happyTime($newStart) . " until " . CoreUtils::happyTime($newEnd)
1081+
. "\r\n\r\n";
1082+
$email .= "Regards\r\n" . Config::$long_name . ' Programming Team';
1083+
10631084
self::$cache->purge();
1085+
MyRadioEmail::sendEmailToUserSet(
1086+
$this->getSeason()->getShow()->getCreditObjects(),
1087+
'Episode of ' . $this->getMeta('title') . ' Cancelled',
1088+
$email
1089+
);
10641090
return $r;
10651091
}
10661092

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* Presents a form to the user to enable them to move an Episode.
4+
*/
5+
use \MyRadio\Config;
6+
use MyRadio\MyRadio\AuthUtils;
7+
use \MyRadio\MyRadioException;
8+
use \MyRadio\MyRadio\URLUtils;
9+
use \MyRadio\ServiceAPI\MyRadio_Season;
10+
11+
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
12+
//Submitted
13+
// @todo this is a bit of a hack
14+
$season = MyRadio_Season::getInstance($_REQUEST['sched_add_episode-show_season_id']);
15+
//Get data
16+
$data = $season->getAddEpisodeForm()->readValues();
17+
18+
if ($data['new_start_time'] === $data['new_end_time']) {
19+
$message = 'You can\'t have an episode start and end at the same time.';
20+
URLUtils::backWithMessage($message);
21+
} else {
22+
// Move
23+
$result = $season->addEpisode(
24+
$data['new_start_time'],
25+
$data['new_end_time']
26+
);
27+
28+
if ($result) {
29+
$message = 'New episode created.';
30+
} else {
31+
$message = 'Something didn\'t work! Please ping Computing.';
32+
}
33+
34+
URLUtils::backWithMessage($message);
35+
}
36+
} else {
37+
//Not Submitted
38+
39+
if (!isset($_REQUEST['show_season_id'])) {
40+
throw new MyRadioException('No seasonid provided.', 400);
41+
}
42+
43+
$season = MyRadio_Season::getInstance($_REQUEST['show_season_id']);
44+
45+
$season->getAddEpisodeForm()->render();
46+
}

src/Public/js/myradio.scheduler.pending.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ $(".twig-datatable").dataTable({
8686
"sTitle": "# of Episodes",
8787
"bVisible": false
8888
},
89+
//addEpisodelink
90+
{
91+
"sTitle": "Add Episode",
92+
"bVisible": false
93+
},
8994
//allocatelink
9095
{
9196
"sTitle": "Allocate",

src/Public/js/myradio.scheduler.seasonlist.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ $(".twig-datatable").dataTable({
8686
{
8787
"sTitle": "# of Episodes"
8888
},
89+
//addEpisodelink
90+
{
91+
"sTitle": "Add Episode"
92+
},
8993
//allocatelink
9094
{
9195
"sTitle": "Allocate",

src/Public/js/myradio.scheduler.timeslotlist.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ $(".twig-datatable").dataTable({
9090
"sTitle": "# of Episodes",
9191
"bVisible": false
9292
},
93+
//addEpisodelink
94+
{
95+
"sTitle": "Add Episode",
96+
"bVisible": false
97+
},
9398
//allocatelink
9499
{
95100
"sTitle": "Allocate",
@@ -143,6 +148,11 @@ $(".twig-datatable").dataTable({
143148
{
144149
"sTitle": "Mixcloud Custom End Time",
145150
"bVisible": false
151+
},
152+
//moveLink
153+
{
154+
"sTitle": "Move Episode",
155+
"bSortable": false,
146156
}
147157
],
148158
"bPaginate": false

src/Public/js/myradio.stats.mostlistenedtimeslot.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ $(".twig-datatable").dataTable({
7474
"sTitle": "# of Episodes",
7575
"bVisible": true
7676
},
77+
//addEpisodelink
78+
{
79+
"sTitle": "Add Episode",
80+
"bVisible": false
81+
},
7782
//allocatelink
7883
{
7984
"sTitle": "Allocate",

src/Public/js/myradio.stats.mostmessagedtimeslot.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ $(".twig-datatable").dataTable({
8787
{
8888
"sTitle": "# of Episodes",
8989
},
90+
//addEpisodelink
91+
{
92+
"sTitle": "Add Episode",
93+
"bVisible": false
94+
},
9095
//allocatelink
9196
{
9297
"sTitle": "Allocate",

0 commit comments

Comments
 (0)