getValue() 공개 메소드

Returns control's value.
public getValue ( ) : mixed
리턴 mixed
예제 #1
0
 /**
  * @param object         $object
  * @param string         $fieldName
  * @param BaseControl    $control
  * @param IClassMetadata $classMetadata
  * @throws \NForms\Exceptions\UnexpectedTypeException
  * @return bool
  */
 public function save($object, $fieldName, BaseControl $control, IClassMetadata $classMetadata)
 {
     if ($control->isOmitted() || $control->isDisabled()) {
         return TRUE;
     }
     $value = $control->getValue();
     if ($classMetadata->hasAssociation($fieldName) && $value !== NULL) {
         if ($classMetadata->isSingleValuedAssociation($fieldName)) {
             $value = $this->objectManager->find($classMetadata->getAssociationTargetClass($fieldName), $value);
         } else {
             if (!is_array($value) && (!$value instanceof \ArrayAccess || !$value instanceof \Iterator)) {
                 throw new UnexpectedTypeException("In mapping association {$classMetadata->getClass()}::\${$fieldName} - expected array or ArrayAccess and Iterator instance, given " . get_class($value) . ".");
             }
             $collection = array();
             foreach ($value as $id) {
                 $collection[] = $this->objectManager->find($classMetadata->getAssociationTargetClass($fieldName), $id);
             }
             $value = $collection;
         }
     }
     if ($classMetadata->hasAssociation($fieldName)) {
         $classMetadata->setAssociationValue($object, $fieldName, $value);
     } else {
         if ($control instanceof Nette\Forms\Controls\TextBase && $value === '') {
             $value = NULL;
         }
         $classMetadata->setFieldValue($object, $fieldName, $value);
     }
     return TRUE;
 }
예제 #2
0
 public function toPropertyValue(\Nette\Forms\Controls\BaseControl $control, Builder\Metadata $metadata)
 {
     $value = $control->getValue();
     if ($value !== null) {
         $value = $metadata->type === 'float' ? (double) $value : (int) $value;
     }
     return $value;
 }
예제 #3
0
 /**
  * Returns control's value.
  *
  * @return int|\DateTime
  */
 public function getValue()
 {
     if ($this->type === self::DATETIME) {
         return parent::getValue();
     } else {
         return parent::getValue()->getTimestamp();
     }
 }
예제 #4
0
 private function addNominalDiscountControl(BaseControl $priceControl)
 {
     $errorMessage = 'Nominal discount must be between 0 and original price.';
     $control = $this->addText('nominalDiscount', 'Nominal discount');
     $control->setType('number')->setAttribute('step', 'any')->setDefaultValue(0)->addRule(self::FLOAT, $errorMessage)->addRule(function (TextInput $input) use($priceControl) {
         return $input->getValue() >= 0 && $input->getValue() < $priceControl->getValue();
     }, $errorMessage);
     if ($this->editedProduct !== null) {
         $control->setDefaultValue($this->editedProduct->getNominalDiscount());
     }
 }
예제 #5
0
 /**
  * @return mixed
  */
 public function getRawValue()
 {
     return parent::getValue();
 }
예제 #6
0
 public function toPropertyValue(\Nette\Forms\Controls\BaseControl $control, Builder\Metadata $metadata)
 {
     return $control->getValue();
 }