Subversion-Projekte lars-tiefland.medien

Revision

Revision 67 | Zur aktuellen Revision | Blame | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

<?
        class CD_Track
        {
                var $id;
                var $cd_id;
                var $t_id;
                var $track_no;
                
                function __construct($id)
                {
                        global $db, $prefix;
                        if ($id)
                        {
                                $sql="SELECT * FROM $prefix"."cd_tracks WHERE t_id=$id";
                                $res=$db->query($sql);
                                $row=$res->fetchRow();
                                $this->id=$id;
                                $this->cd_id=$row["cd_id"];
                                $this->track_no=sprintf("%02d", $row["track_no"]);
                                $this->t_id=$row["t_id"];
                        }
                        else
                        {
                                $this->id=0;
                                $this->cd_id=0;
                                $this->t_id=0;
                                $this->track_no=0;
                        }
                        return $this;
                }
                
                function CD_Track($id)
                {
                        $this->__construct($id);
                }
                
                function update($id, $cd_id, $t_id, $track_no)
                {
                                $this->id=$id;
                                $this->cd_id=$cd_id;
                                $this->t_id=$t_id;
                                $this->track_no=$track_no;
                }
                
                function save($mode)
                {
                        global $db, $prefix;
                        switch($mode)
                        {
                                case "save":
                                        $sql="INSERT INTO $prefix"."cd_tracks (cd_id, t_id, track_no) VALUE($this->cd_id, $this->t_id, $this->track_no)";
                                        break;
                                case "update":
                                        $sql="UPDATE $prefix"."cd_tracks SET cd_id=$this->cd_id, t_id=$this->t_id, track_no=$this->track_no WHERE id=$this->id";
                                        break;
                                case "delete":
                                        $sql="DELETE FROM $prefix"."cd_tracks WHERE id=$this->id";
                                        break;
                        }
                        return $db->query($sql);
                }
                
                function Liste($start=0,$anz=0)
                {
                        global $db, $prefix;
                        $sql="SELECT * FROM $prefix"."cd_tracks";
                        if ($anz > 0)
                        {
                                $res=$db->limitquery($sql,$start,$anz);
                                $id=0;
                                $ret=array(array());
                                while ($row=$res->fetchRow())
                                {
                                        $ret[$id]["link_id"]=$row["t_id"];
                                        $t=new Track($t_id);
                                        $ret[$id]["t_name"]=stripslashes($t->name);
                                        $ret[$id]["t_dur"]=stripslashes($t->dur);
                                        $g=new Genre($t->genre);
                                        $a=new Artist($t->artist);
                                        $ret[$id]["t_genre"] =$g->name;
                                        $ret[$id]["t_artist"]="$a->fname $a->name";
                                        $id++;
                                }
                                return $ret;
                        }
                        else
                        {
                                $res=$db->query($sql);
                                return $res->numRows();
                        }
                }
        }
?>