Example #1
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);
 }
Example #2
0
function createProduct($faker, Thelia\Model\Category $category, $position, $template, $brandIdList, &$productIdList, &$virtualProductList)
{
    $product = new Thelia\Model\Product();
    $product->setRef($category->getId() . '_' . $position . '_' . $faker->randomNumber(8));
    $product->addCategory($category);
    $product->setVisible(1);
    $productCategories = $product->getProductCategories();
    $collection = new \Propel\Runtime\Collection\Collection();
    $collection->prepend($productCategories[0]->setDefaultCategory(1));
    $product->setProductCategories($collection);
    $product->setVirtual(mt_rand(1, 5) > 1 ? 0 : 1);
    $product->setVisible(1);
    $product->setPosition($position);
    $product->setTaxRuleId(1);
    $product->setTemplate($template);
    $product->setBrandId($brandIdList[array_rand($brandIdList, 1)]);
    setI18n($product);
    $product->save();
    $productId = $product->getId();
    $productIdList[] = $productId;
    $image = new \Thelia\Model\ProductImage();
    $image->setProductId($productId);
    generate_image($image, 'product', $productId);
    $document = new \Thelia\Model\ProductDocument();
    $document->setProductId($productId);
    generate_document($document, 'product', $productId);
    if ($product->getVirtual() == 1) {
        $virtualProductList[$productId] = $document->getId();
    }
    return $product;
}