public function __construct($bandName)
 {
     $db = mysql_connect("localhost", "root", "root");
     mysql_select_db("test");
     $sql = "select CD.id, CD.band, CD.title, tracks.tracknum, tracks.title as tracktitle ";
     $sql .= "from CD left join tracks on CD.id = tracks.cid ";
     $sql .= "where band = '" . mysql_real_escape_string($bandName) . "' ";
     $sql .= "order by tracks.tracknum";
     $results = mysql_query($sql);
     $cdID = 0;
     $cd = NULL;
     while ($result = mysql_fetch_array($results)) {
         if ($result["id"] !== $cdID) {
             if (!is_null($cd)) {
                 $this->_CDs[] = $cd;
             }
             $cdID = $result['id'];
             $cd = new CD($result['band'], $result['title']);
         }
         $cd->addTrack($result['tracktitle']);
     }
     $this->_CDs[] = $cd;
 }
Beispiel #2
0
    public function getTrackList()
    {
        $output = '';
        foreach ($this->trackList as $num => $track) {
            $output .= $num + 1 . ") {$track}. ";
        }
        return $output;
    }
}
class CDTrackListDecoratorCaps
{
    private $__cd;
    public function __construct(CD $cd)
    {
        $this->__cd = $cd;
    }
    public function makeCaps()
    {
        foreach ($this->__cd->trackList as &$track) {
            $track = strtoupper($track);
        }
    }
}
$tracksFromExternalSource = array('What It Means', 'Brr', 'Goodbye');
$myCD = new CD();
foreach ($tracksFromExternalSource as $track) {
    $myCD->addTrack($track);
}
$myCDCaps = new CDTrackListDecoratorCaps($myCD);
$myCDCaps->makeCaps();
print "The CD contains the following tracks: " . $myCD->getTrackList();
Beispiel #3
0
    {
        $this->band = $band;
    }
    public function addTrack($track)
    {
        $this->tracks[] = $track;
    }
}
$title = 'Waste of a Rib';
$band = 'Never Again';
$tracksFromExternalSource = array('What It Means', 'Brrr', 'Goodbye');
$cd = new CD();
$cd->setTitle($title);
$cd->setBand($band);
foreach ($tracksFromExternalSource as $track) {
    $cd->addTrack($track);
}
class enhancedCD
{
    public $title = '';
    public $band = '';
    public $tracks = array();
    public function __construct()
    {
        $this->tracks[] = 'DATA TRACK';
    }
    public function setTitle($title)
    {
        $this->title = $title;
    }
    public function setBand($band)