function testAddAndRemovePlaylist()
 {
     // Create a playlist
     $playlist = new Playlist();
     $playlist->create("Scheduler Unit Test " . uniqid());
     $result = $playlist->addAudioClip($this->storedFile->getId());
     $result = $playlist->addAudioClip($this->storedFile2->getId());
     $result = $playlist->addAudioClip($this->storedFile2->getId());
     $i = new ScheduleGroup();
     $this->groupIdCreated = $i->add('2010-11-11 01:30:23', null, $playlist->getId());
     if (PEAR::isError($this->groupIdCreated)) {
         $this->fail("Failed to create scheduled item: " . $this->groupIdCreated->getMessage());
     }
     $group = new ScheduleGroup($this->groupIdCreated);
     if ($group->count() != 3) {
         $this->fail("Wrong number of items added.");
     }
     $items = $group->getItems();
     if (!is_array($items) || $items[1]["starts"] != "2010-11-11 01:30:34.231") {
         $this->fail("Wrong start time for 2nd item.");
     }
     $result = $group->remove();
     if ($result != 1) {
         $this->fail("Did not remove item.");
     }
     Playlist::Delete($playlist->getId());
 }
 function setup()
 {
     global $CC_CONFIG, $CC_DBC;
     // Clear the files table
     $sql = "DELETE FROM " . $CC_CONFIG["filesTable"];
     $CC_DBC->query($sql);
     // Add a file
     $values = array("filepath" => dirname(__FILE__) . "/test10001.mp3");
     $this->storedFile = StoredFile::Insert($values, false);
     // Add a file
     $values = array("filepath" => dirname(__FILE__) . "/test10002.mp3");
     $this->storedFile2 = StoredFile::Insert($values, false);
     // Clear the schedule table
     $sql = "DELETE FROM " . $CC_CONFIG["scheduleTable"];
     $CC_DBC->query($sql);
     // Create a playlist
     $playlist = new Playlist();
     $playlist->create("Scheduler Unit Test");
     $result = $playlist->addAudioClip($this->storedFile->getId());
     $result = $playlist->addAudioClip($this->storedFile2->getId());
     $result = $playlist->addAudioClip($this->storedFile2->getId());
     // Schedule it
     $i = new ScheduleGroup();
     $this->groupIdCreated = $i->add('2010-11-11 01:30:23', null, $playlist->getId());
 }
echo "done.\n";
// Create a new playlist
echo "Creating new playlist '{$playlistName}'...";
$pl = new Playlist();
$pl->create($playlistName);
$mediaFile = StoredFile::findByOriginalName("Peter_Rudenko_-_Opening.mp3");
if (is_null($mediaFile)) {
    echo "Adding test audio clip to the database.\n";
    $v = array("filepath" => __DIR__ . "/../../../audio_samples/vorbis.com/Hydrate-Kenny_Beltrey.ogg");
    $mediaFile = StoredFile::Insert($v);
    if (PEAR::isError($mediaFile)) {
        var_dump($mediaFile);
        exit;
    }
}
$pl->addAudioClip($mediaFile->getId());
echo "done.\n";
//$pl2 = Playlist::findPlaylistByName("pypo_playlist_test");
//var_dump($pl2);
// Get current time
// In the format YYYY-MM-DD HH:MM:SS.nnnnnn
$startTime = date("Y-m-d H:i:s");
$endTime = date("Y-m-d H:i:s", time() + 60 * 60);
echo "Removing everything from the scheduler between {$startTime} and {$endTime}...";
// Check for succces
$scheduleClear = Schedule::isScheduleEmptyInRange($startTime, "01:00:00");
if (!$scheduleClear) {
    echo "\nERROR: Schedule could not be cleared.\n\n";
    var_dump(Schedule::GetItems($startTime, $endTime));
    exit;
}