Created
January 19, 2013 04:53
-
-
Save jmather/4570840 to your computer and use it in GitHub Desktop.
Load in file assets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Demo\Bundle\WebsiteBundle\DataFixtures\ORM; | |
use Doctrine\Common\DataFixtures\AbstractFixture; | |
use Doctrine\Common\DataFixtures\OrderedFixtureInterface; | |
use Doctrine\Common\Persistence\ObjectManager; | |
use Doctrine\Common\DataFixtures\FixtureInterface; | |
use Application\Sonata\UserBundle\Entity\User; | |
use Symfony\Component\DependencyInjection\ContainerAwareInterface; | |
use Symfony\Component\DependencyInjection\ContainerInterface; | |
use Pff\Bundle\CmsBundle\Entity\Page; | |
use Pff\Bundle\CmsBundle\Entity\SliderImage; | |
use Symfony\Component\HttpFoundation\File\UploadedFile; | |
class LoadWebsiteSpecificData extends AbstractFixture implements ContainerAwareInterface | |
{ | |
/** | |
* @var ContainerInterface | |
*/ | |
private $container; | |
/** | |
* {@inheritDoc} | |
*/ | |
public function setContainer(ContainerInterface $container = null) | |
{ | |
$this->container = $container; | |
} | |
/** | |
* {@inheritDoc} | |
*/ | |
public function load(ObjectManager $manager) | |
{ | |
$kernel = $this->container->get('kernel'); | |
$basedir = $kernel->locateResource('@DemoWebsiteBundle/Resources/demo-sliders').'/'; | |
$files = glob($basedir.'/*.jpeg'); | |
foreach($files as $file) { | |
$tmpfile = tempnam('/tmp', 'upload'); | |
copy($file, $tmpfile); | |
$file = new UploadedFile($tmpfile, basename($file), 'image/jpeg', filesize($file), UPLOAD_ERR_OK, true); | |
$img = new SliderImage(); | |
$img->setImage($file); | |
$img->setName(basename($file)); | |
$img->setEnabled(true); | |
$img->setAltText(basename($file)); | |
$img->setUrl('#'); | |
$manager->persist($img); | |
} | |
$manager->flush(); | |
$manager->flush(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment