@@ -13,7 +13,7 @@ class State
1313{
1414 use TStateSchemaMigrations;
1515
16- CONST VERSION = 6 ; # The version of the schema for this commit.
16+ CONST VERSION = 8 ; # The version of the schema for this commit.
1717
1818 protected Main $ main ;
1919 protected $ state_file_path ;
@@ -457,6 +457,64 @@ public function getItemAdSections(int $item_id): array
457457 return is_array ($ sections ) ? $ sections : [];
458458 }
459459
460+ public function addSegment (int $ item_id , int $ file_id , float $ start , float $ end , bool $ has_sponsor = false ): int
461+ {
462+ $ sql = 'INSERT INTO segments (item_id, file_id, start, end, has_sponsor) VALUES (:item_id, :file_id, :start, :end, :has_sponsor) ' ;
463+ $ this ->query ($ sql , [
464+ 'item_id ' => $ item_id ,
465+ 'file_id ' => $ file_id ,
466+ 'start ' => $ start ,
467+ 'end ' => $ end ,
468+ 'has_sponsor ' => $ has_sponsor ? 1 : 0
469+ ]);
470+ return intval ($ this ->pdo ->lastInsertId ());
471+ }
472+
473+ public function getSegmentsForItem (int $ item_id ): array
474+ {
475+ $ sql = 'SELECT * FROM segments WHERE item_id = :item_id ORDER BY start ' ;
476+ $ result = $ this ->query ($ sql , ['item_id ' => $ item_id ]);
477+ return $ result && is_array ($ result ) ? $ result : [];
478+ }
479+
480+ public function getSegment (int $ segment_id ): array
481+ {
482+ $ sql = 'SELECT * FROM segments WHERE id = :id ' ;
483+ $ result = $ this ->query ($ sql , ['id ' => $ segment_id ]);
484+ return $ result && isset ($ result [0 ]) ? $ result [0 ] : [];
485+ }
486+
487+ public function deleteSegment (int $ segment_id ): void
488+ {
489+ $ sql = 'DELETE FROM segments WHERE id = :id ' ;
490+ $ this ->query ($ sql , ['id ' => $ segment_id ]);
491+ }
492+
493+ public function addClip (int $ segment_id , int $ file_id , bool $ has_sponsor = false , ?int $ spectrogram_file = null ): int
494+ {
495+ $ sql = 'INSERT INTO clips (segment_id, file_id, has_sponsor, spectrogram_file) VALUES (:segment_id, :file_id, :has_sponsor, :spectrogram_file) ' ;
496+ $ this ->query ($ sql , [
497+ 'segment_id ' => $ segment_id ,
498+ 'file_id ' => $ file_id ,
499+ 'has_sponsor ' => $ has_sponsor ? 1 : 0 ,
500+ 'spectrogram_file ' => $ spectrogram_file
501+ ]);
502+ return intval ($ this ->pdo ->lastInsertId ());
503+ }
504+
505+ public function getClipsForSegment (int $ segment_id ): array
506+ {
507+ $ sql = 'SELECT * FROM clips WHERE segment_id = :segment_id ' ;
508+ $ result = $ this ->query ($ sql , ['segment_id ' => $ segment_id ]);
509+ return $ result && is_array ($ result ) ? $ result : [];
510+ }
511+
512+ public function deleteClip (int $ clip_id ): void
513+ {
514+ $ sql = 'DELETE FROM clips WHERE id = :id ' ;
515+ $ this ->query ($ sql , ['id ' => $ clip_id ]);
516+ }
517+
460518 protected function loadFile (string $ filename ): string
461519 {
462520 $ contents = false ;
0 commit comments