@@ -978,6 +978,16 @@ public function toDataSource($mixins = [])
978
978
['show_season_id ' => $ this ->getID ()]
979
979
),
980
980
],
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
+ ],
981
991
'editlink ' => [
982
992
'display ' => 'icon ' ,
983
993
'value ' => 'pencil ' ,
@@ -1298,4 +1308,83 @@ public static function searchMeta($query, $string_keys = null, $effective_from =
1298
1308
);
1299
1309
return self ::resultSetToObjArray ($ r );
1300
1310
}
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
+ }
1301
1390
}
0 commit comments