Exemplo n.º 1
0
 /**
  * Remove lyric of this object
  * through the artist_lyric cross reference table.
  *
  * @param ChildLyric $lyric
  * @return ChildArtist The current object (for fluent API support)
  */
 public function removeLyric(ChildLyric $lyric)
 {
     if ($this->getLyrics()->contains($lyric)) {
         $artistLyric = new ArtistLyric();
         $artistLyric->setLyric($lyric);
         if ($lyric->isArtistsLoaded()) {
             //remove the back reference if available
             $lyric->getArtists()->removeObject($this);
         }
         $artistLyric->setArtist($this);
         $this->removeArtistLyric(clone $artistLyric);
         $artistLyric->clear();
         $this->collLyrics->remove($this->collLyrics->search($lyric));
         if (null === $this->lyricsScheduledForDeletion) {
             $this->lyricsScheduledForDeletion = clone $this->collLyrics;
             $this->lyricsScheduledForDeletion->clear();
         }
         $this->lyricsScheduledForDeletion->push($lyric);
     }
     return $this;
 }
Exemplo n.º 2
0
 /**
  * Update artists to given array of ids.
  * Order is the same as keys in the array
  * @param array $artistsIds
  * @throws \Exception
  */
 public function setArtistsIds(array $artistsIds)
 {
     $artistLyrics = new \Propel\Runtime\Collection\Collection();
     $artistOrder = 1;
     foreach ($artistsIds as $artistId) {
         $artistQuery = new \Tekstove\ApiBundle\Model\ArtistQuery();
         $artist = $artistQuery->findOneById($artistId);
         if ($artist === null) {
             throw new \Exception("Can not find artist #{$artistId}");
         }
         $artistFound = false;
         foreach ($this->getArtistLyrics() as $artistLyricExisting) {
             if ($artistLyricExisting->getArtist()->getId() == $artistId) {
                 $artistLyricExisting->setOrder($artistOrder);
                 $artistLyrics->append($artistLyricExisting);
                 $artistFound = true;
                 break;
             }
         }
         if (!$artistFound) {
             $artistLyric = new ArtistLyric();
             $artistLyric->setLyric($this);
             $artistLyric->setArtist($artist);
             $artistLyric->setOrder($artistOrder);
             $artistLyrics->append($artistLyric);
         }
         $artistOrder++;
     }
     $this->setArtistLyrics($artistLyrics);
 }