示例#1
1
 /**
  * @param EntityManager $em
  * @param array $imagesArray
  * @param Advertisment $adv
  * @return array
  */
 public static function uploadImages(EntityManager $em, $imagesArray, $adv)
 {
     $dummyImage = '/resources/images/adv-default.png';
     $basePath = 'uploads/' . $adv->getId();
     $uploadedImages = array();
     $adv = $em->getRepository('NaidusvoeBundle:Advertisment')->find($adv->getId());
     $fs = new Filesystem();
     $counter = 1;
     if ($imagesArray) {
         foreach ($imagesArray as $image) {
             $image = (object) $image;
             if ($image->image !== null) {
                 $imagePath = $basePath . '/' . $counter . '.jpg';
                 $image = explode(',', $image->image);
                 $image = base64_decode($image[1]);
                 $fs->dumpFile($imagePath, $image);
                 $attachment = new Attachment();
                 $attachment->setAdvertisment($adv);
                 $attachment->setImage($imagePath);
                 $em->persist($attachment);
                 $uploadedImages[] = $attachment;
                 $counter++;
             }
         }
     }
     if ($counter === 1) {
         $attachment = new Attachment();
         $attachment->setAdvertisment($adv);
         $attachment->setImage($dummyImage);
         $em->persist($attachment);
         $uploadedImages[] = $attachment;
     }
     return $uploadedImages;
 }
示例#2
0
 /**
  * @param null|Advertisment $adv
  * @param null|User $user
  */
 public function __construct($adv = null, $user = null)
 {
     $this->advertisment = $adv;
     $this->user = $user;
     $this->userID = $user->getId();
     $this->advertismentID = $adv->getId();
 }