Пример #1
0
 /**
  * @param $segmentTime
  * @param Episode $episode
  * @return bool
  */
 public static function isSegmentWithinEpisodeBounds($segmentTime, $episode)
 {
     $segmentDateTime = null;
     if ($segmentTime instanceof DateTime) {
         $segmentDateTime = $segmentTime;
     } else {
         $segmentDateTime = new DateTime("January 1, " . $segmentTime);
     }
     $segmentStartTimeInMinutes = self::getTimeInMinutesSinceMidnight($segmentDateTime);
     $episodeStartTime = $episode->getStartTime();
     $episodeStartTimeInMinutes = self::getTimeInMinutesSinceMidnight($episodeStartTime);
     $episodeStartDay = $episodeStartTime->format('N');
     $episodeEndTime = $episode->getEndTime();
     $episodeEndTimeInMinutes = self::getTimeInMinutesSinceMidnight($episodeEndTime);
     $episodeEndDay = $episodeEndTime->format('N');
     if ($episodeStartDay === $episodeEndDay) {
         if ($segmentStartTimeInMinutes >= $episodeStartTimeInMinutes && $segmentStartTimeInMinutes <= $episodeEndTimeInMinutes) {
             return true;
         }
     } else {
         if ($segmentStartTimeInMinutes + MINUTES_IN_DAY >= $episodeStartTimeInMinutes && $segmentStartTimeInMinutes <= $episodeEndTimeInMinutes || $segmentStartTimeInMinutes >= $episodeStartTimeInMinutes && $segmentStartTimeInMinutes <= $episodeEndTimeInMinutes + MINUTES_IN_DAY) {
             return true;
         }
     }
     return false;
 }
 /**
  * @param PDO $dbConn
  * @param Episode $episodeObject
  * @return null
  */
 public static function saveNewEpisode($dbConn, $episodeObject)
 {
     $startDateTimeObject = formatDateStringForDatabaseWrite($episodeObject->getStartTime());
     $endDateTimeObject = formatDateStringForDatabaseWrite($episodeObject->getEndTime());
     $columnNames = array(self::PLAYLIST_COLUMN_NAME, self::PROGRAM_COLUMN_NAME, self::PROGRAMMER_COLUMN_NAME, self::START_TIME_COLUMN_NAME, self::END_TIME_COLUMN_NAME, self::IS_PRERECORD_COLUMN_NAME, self::PRERECORD_COLUMN_NAME, self::IS_DRAFT_COLUMN_NAME);
     $values = array($episodeObject->getPlaylist()->getId(), $episodeObject->getProgram()->getId(), $episodeObject->getProgrammer()->getId(), $startDateTimeObject, $endDateTimeObject, $episodeObject->isPrerecord(), $episodeObject->getPrerecordDate(), true);
     return writeToDatabase::writeEntryToDatabase($dbConn, self::TABLE_NAME, $columnNames, $values);
 }
Пример #3
0
$adNumber = $_POST['ad_number'];
$author = $_POST['author'];
$album = $_POST['album'];
$category = $_POST['category'];
$canCon = isset($_POST['can_con']);
$newRelease = isset($_POST['new_release']);
$frenchVocalMusic = isset($_POST['french_vocal_music']);
$editSegment = isset($_POST['is_existing_segment']);
$segmentId = $_POST['segment_id'];
if (!isset($episodeId) || $episodeId <= 0) {
    outputErrorResponse("Invalid episode ID");
}
try {
    $db = connectToDatabase();
    $episode = new Episode($db, $episodeId);
    $episodeStartDateTime = $episode->getStartTime();
    $segmentTime = addDateToSegmentStartTime($episodeStartDateTime, $segmentTime);
    $playlistId = $episode->getPlaylistId();
    $segment = new Segment($db, $segmentId);
    $segment->setCategory($category);
    $segment->setPlaylistId($playlistId);
    $segment->setDuration(null);
    $segment->setStartTime($segmentTime);
    switch ($category) {
        case 2:
        case 3:
            $segment->setName($name);
            $segment->setAuthor($author);
            $segment->setAlbum($album);
            $segment->setCategory($category);
            $segment->setIsCanCon($canCon);