/** * @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; }
/** * @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(); }
private function generateDummyAdvs($count, $type) { $advs = []; for ($i = 0; $i < $count; $i++) { $newAdv = new Advertisment(); $newAdv->setTitle('Ваша реклама'); $attachment = new Attachment(); $attachment->setImage('/resources/images/adv-default.png'); $newAdv->addAttachment($attachment); $newAdv->setDescription('Тут може бути ваша реклама!'); $newAdv->setDummy(true); $newAdv->setType($type); $advs[] = $newAdv; } return $advs; }
/** * @param EntityManager $em * @param object $data * @param int $user_id * @return Advertisment */ public static function addNewAdv(EntityManager $em, $data, $user_id) { $user = $em->find('NaidusvoeBundle:User', $user_id); $category = $em->getRepository('NaidusvoeBundle:AdvertismentCategory')->find($data->categoryID); $priceType = $em->getRepository('NaidusvoeBundle:PriceType')->find($data->priceType); $advType = $em->getRepository('NaidusvoeBundle:AdvertismentType')->find($data->typeID); $region = $em->getRepository('NaidusvoeBundle:Region')->find($data->region); $adv = new Advertisment(); $adv->setUser($user); $adv->setDate(new \DateTime()); $adv->setPrice($data->price); $adv->setPriceType($priceType); $adv->setType($advType); $adv->setCategory($category); $adv->setRegion($region); if ($data->subCategoryID) { $subCategory = $em->getRepository('NaidusvoeBundle:AdvertismentSubCategory')->find($data->subCategoryID); $adv->setSubCategory($subCategory); } $adv->setTitle($data->title); $adv->setDescription($data->description); $adv->setContactPerson($data->contactPerson); $adv->setEmail($data->email); $adv->setTelephoneNumber($data->telephoneNumber); $adv->setSkype($data->skype); $adv->setCity($data->city); return $adv; }
/** * // TODO: check for expiration * @Route("/get-advs/{type}/{filter}", name="get-advs", options={"expose"=true}) * @param Request $request * @param string $type * @param int|null $filter * @return JsonResponse */ public function getAdvsAction(Request $request, $type = null, $filter = null) { $typeID = null; switch ($type) { case 'trade': $typeID = 1; break; case 'gift': $typeID = 3; break; case 'found': $typeID = 2; break; } /** @var EntityManager $em */ $em = $this->getDoctrine()->getManager(); $advs = Advertisment::getAdvs($em, $filter, $typeID); $paginator = new Paginator(); $pager = $paginator->getJsonResponse($advs, $request, 10); $categories = $em->getRepository('NaidusvoeBundle:AdvertismentCategory')->findBy(array('typeID' => $typeID)); $bests = $this->get('naidusvoe.advertisement')->getBestAdvs($typeID); return new JsonResponse(array('advs' => $pager, 'categories' => Functions::arrayToJson($categories), 'bests' => Functions::arrayToJson($bests))); }