예제 #1
0
파일: Image.php 프로젝트: augustmedia/eva
 public function setValue($value)
 {
     if (!$value instanceof Entity) {
         throw new \Exception('Значение должно быть экземпляром Entity');
     }
     if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/data/' . $this->dataPath . '/image/' . $value->getId() . 'thumb.jpg')) {
         $div = new Div();
         $div->setAttribute('class', 'clearfix photos-input');
         $this->append($div);
         $html = '
             <div class="pull-left">
             <div class="btn-group btn-group-sm">
             <a href="/' . $this->modulePath . '/удалить-изображение/id/' . $value->getId() . '" class="btn btn-default" title="Удалить изображение"><span class="glyphicon glyphicon-remove"></span></a></div>
             <img src="/data/' . $this->dataPath . '/image/' . $value->getId() . 'thumb.jpg" class="img-thumbnail">
             </div>
             ';
         $div->setText($html);
     }
     parent::setValue($value);
 }
예제 #2
0
파일: Photos.php 프로젝트: augustmedia/eva
 public function setValue($value)
 {
     if ($value instanceof \ArrayObject) {
         $div = new Div();
         $div->setAttribute('class', 'clearfix photos-input');
         $this->append($div);
         $html = '';
         foreach ($value as $entity) {
             /** @var \Eva\Entity\Entity $entity */
             $html .= '
             <div class="pull-left">
             <div class="btn-group btn-group-sm">
             <a href="/' . $this->modulePath . '/удалить-фото/id/' . $entity->getId() . '" class="btn btn-default" title="Удалить фото"><span class="glyphicon glyphicon-remove"></span></a></div>
             <img src="/data/' . $this->dataPath . '/photo/' . $entity->getId() . 'thumb.jpg" class="img-thumbnail">
             </div>
             ';
         }
         $div->setText($html);
     }
     parent::setValue($value);
 }
예제 #3
0
파일: Form.php 프로젝트: augustmedia/eva
 /**
  * @param \Eva\Form\Form $form
  */
 public function prepare($form)
 {
     $elements = $form->getElements();
     $preparedElements = array();
     foreach ($elements as $element) {
         if ($element->getElements()->count()) {
             $this->prepare($element);
         }
         /** @var \Eva\Form\ElementInterface $element */
         $type = $element->getAttribute('type');
         if ($element instanceof Input) {
             if (in_array($type, ['text', 'password'])) {
                 $element->appendAttribute('class', 'form-control');
                 $element->setAttribute('value', $element->getValue());
             } elseif ($type == 'hidden') {
                 $element->setAttribute('value', $element->getValue());
             } elseif ($type == 'submit') {
                 $element->appendAttribute('class', 'btn btn-primary');
             }
         } elseif ($element instanceof Select) {
             /** @var Select $element */
             $element->appendAttribute('class', 'form-control');
             $value = $element->getValue();
             if ($value instanceof Entity) {
                 $value = $value->getId();
             }
             if ($element->getEmptyOption() !== null) {
                 $optionElement = new Option();
                 $optionElement->setText($element->getEmptyOption());
                 $element->append($optionElement);
             }
             foreach ($element->getOptions() as $key => $option) {
                 $optionAttributes = [];
                 if (is_array($option)) {
                     $optionAttributes = $option['attributes'];
                     $option = $option['value'];
                 }
                 $optionElement = new Option();
                 $optionElement->setAttributes($optionAttributes);
                 if ($option instanceof Entity) {
                     $property = $element->getProperty() ?: 'name';
                     $getter = 'get' . ucfirst($property);
                     if (!is_callable(array($option, $getter))) {
                         throw new \RuntimeException(sprintf('Метода нет "%s::%s"', get_class($option), $getter));
                     }
                     $label = $option->{$getter}();
                     $optionValue = $option->getId();
                     $optionElement->setText($label);
                 } else {
                     $optionValue = $key;
                     $optionElement->setText($option);
                 }
                 $optionElement->setAttribute('value', $optionValue);
                 if ($optionValue == $value) {
                     $optionElement->setAttribute('selected', 'selected');
                 }
                 $element->append($optionElement);
             }
         } elseif ($element instanceof Textarea) {
             $element->appendAttribute('class', 'form-control');
             $element->setText($element->getValue());
         }
         if ($element instanceof ElementInterface) {
             $div = new Div();
             $label = $element->getLabel();
             $label->setAttribute('class', 'control-label');
             if ($type == 'checkbox') {
                 $clone = clone $element;
                 $clone->setAttribute('value', '1');
                 $element->setAttribute('type', 'hidden');
                 $element->setAttribute('value', '0');
                 $div->append($element);
                 $div->setAttributes(array('class' => 'checkbox'));
                 $label->append(clone $clone);
                 $div->append($label);
             } elseif ($type == 'hidden') {
                 $div->append($element);
             } else {
                 $div->setAttributes(['class' => 'form-group']);
                 if ($element->getLabel()->getText()) {
                     $div->append($element->getLabel());
                 }
                 $div->append($element);
             }
             if (!$element->isValid()) {
                 $div->appendAttribute('class', 'has-error');
                 $p = new P();
                 $p->setAttribute('class', 'help-block');
                 $p->setText($element->getErrorMessage());
                 $div->append($p);
             }
             $preparedElements[] = $div;
         } else {
             $preparedElements[] = $element;
         }
     }
     $form->getElements()->exchangeArray($preparedElements);
 }