app\models\Song::updateSingle PHP 메소드

updateSingle() 공개 메소드

Update a single song's info.
public updateSingle ( string $title, string $albumName, string $artistName, string $lyrics, integer $track, integer $compilationState ) : self
$title string
$albumName string
$artistName string
$lyrics string
$track integer
$compilationState integer
리턴 self
    public function updateSingle($title, $albumName, $artistName, $lyrics, $track, $compilationState)
    {
        // If the artist name is "Various Artists", it's a compilation song no matter what.
        if ($artistName === Artist::VARIOUS_NAME) {
            $compilationState = 1;
        }
        // If the compilation state is "no change," we determine it via the current
        // "contributing_artist_id" field value.
        if ($compilationState === 2) {
            $compilationState = $this->contributing_artist_id ? 1 : 0;
        }
        $album = null;
        if ($compilationState === 0) {
            // Not a compilation song
            $this->contributing_artist_id = null;
            $albumArtist = Artist::get($artistName);
            $album = Album::get($albumArtist, $albumName, false);
        } else {
            $contributingArtist = Artist::get($artistName);
            $this->contributing_artist_id = $contributingArtist->id;
            $album = Album::get(Artist::getVarious(), $albumName, true);
        }
        $this->album_id = $album->id;
        $this->title = $title;
        $this->lyrics = $lyrics;
        $this->track = $track;
        $this->save();
        // Get the updated record, with album and all.
        $updatedSong = self::with('album', 'album.artist', 'contributingArtist')->find($this->id);
        // Make sure lyrics is included in the returned JSON.
        $updatedSong->makeVisible('lyrics');
        return $updatedSong;
    }