Exemplo n.º 1
0
 protected function createAdvertDetailsForm(Advertisement $advert, $fill = false)
 {
     $adModel = $this->get(C::MODEL_ADVERTISEMENT);
     $options[C::FORM_ATTRIBUTE_LIST] = $adModel->getAttributesByProductId($advert->getProduct()->getId());
     if ($fill) {
         foreach ($advert->getAttributes() as $attribute) {
             $options[AbstractAttribute::FORM_PREFIX . $attribute->getAttribute()->getId()] = $attribute->getValue();
         }
     }
     $form = $this->createForm(FillAdvertForm::class, $options);
     return $form;
 }
Exemplo n.º 2
0
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $data = $options['data'];
     $builder->add(C::FORM_PRODUCT, ChoiceType::class, ['label' => 'Раздел', 'choices' => $data[C::FORM_PRODUCT_LIST], 'required' => true]);
     $builder->add(C::FORM_CURRENCY, ChoiceType::class, ['label' => 'Валюта', 'choices' => Advertisement::getCurrencyList(true), 'required' => true]);
     $builder->add(C::FORM_TITLE, TextType::class, ['label' => "Название", 'required' => true]);
     $builder->add(C::FORM_PRICE, TextType::class, ['label' => "Цена", 'required' => true]);
     $builder->add(C::FORM_DESCRIPTION, TextareaType::class, ['label' => "Описание", 'required' => false]);
     $builder->add(C::FORM_PHOTO, FileType::class, ['label' => "Фотография", 'required' => false]);
     $builder->add(C::FORM_SUBMIT, SubmitType::class, ['label' => 'Готово']);
 }
Exemplo n.º 3
0
 /**
  * @param Advertisement $advertisement
  * @return array
  * возвращает ассоциаптиыный массив для страницы просмотра advert ['attrName' => attrValue]
  */
 public function getAdvertAttributesArray(Advertisement $advertisement)
 {
     $result = [];
     $allAttributes = $this->getAttributesByProductId($advertisement->getProduct()->getId());
     foreach ($allAttributes as $attribute) {
         $result[$attribute->getName()] = 'Не указано';
     }
     foreach ($advertisement->getAttributes() as $advertAttribute) {
         $attrName = $advertAttribute->getAttribute()->getName();
         if ($advertAttribute->getAttribute()->getType() === ProductAttribute::ATTRIBUTE_TYPE_REFERENCE) {
             $result[$attrName] = is_null($advertAttribute->getValue()) ? 'Не указано' : $this->getReferenceItem($advertAttribute->getValue())->getName();
         } else {
             $result[$attrName] = is_null($advertAttribute->getValue()) ? 'Не указано' : $advertAttribute->getValue();
         }
     }
     return $result;
 }