Ejemplo n.º 1
0
 /**
  * Update the sorting property values of all models.
  *
  * @return void
  */
 private function updateSorting()
 {
     $ids = $this->getModelIds();
     // If no "next" sibling, simply increment the sorting as we are at the end of the list.
     if (!$this->marker) {
         foreach ($this->results as $model) {
             $this->position += 128;
             /** @var ModelInterface $model */
             $model->setProperty($this->getSortingProperty(), $this->position);
         }
         return;
     }
     $delta = $this->determineDelta();
     // Loop over all models and increment sorting value.
     foreach ($this->results as $model) {
         $this->position += $delta;
         /** @var ModelInterface $model */
         $model->setProperty($this->getSortingProperty(), $this->position);
     }
     // When the sorting exceeds the sorting of the "next" sibling, we need to push the remaining siblings to the
     // end of the list.
     if ($this->marker->getProperty($this->getSortingProperty()) <= $this->position) {
         do {
             // Skip models about to be pasted.
             if (in_array($this->marker->getId(), $ids)) {
                 $this->marker = $this->siblingsCopy->shift();
                 continue;
             }
             $this->position += $delta;
             $this->marker->setProperty($this->getSortingProperty(), $this->position);
             $this->results->push($this->marker);
             $this->marker = $this->siblingsCopy->shift();
         } while ($this->marker);
     }
 }
Ejemplo n.º 2
0
 /**
  * Calculate the resulting list.
  *
  * @return void
  */
 protected function calculate()
 {
     if (isset($this->results) || $this->models->length() == 0) {
         return;
     }
     $ids = $this->getModelIds();
     $this->results = clone $this->models;
     $this->siblingsCopy = clone $this->siblings;
     $this->scanToDesiredPosition();
     // If no "next" sibling, simply increment the sorting as we are at the end of the list.
     if (!$this->marker) {
         foreach ($this->results as $model) {
             $this->position += 128;
             /** @var ModelInterface $model */
             $model->setProperty($this->getSortingProperty(), $this->position);
         }
         return;
     }
     // Determine delta value: ((next sorting - current sorting) / amount of insert models).
     $delta = ($this->marker->getProperty($this->getSortingProperty()) - $this->position) / $this->results->length();
     // If delta too narrow, we need to make room.
     if ($delta < 2) {
         $delta = 128;
     }
     // Loop over all models and increment sorting value.
     foreach ($this->results as $model) {
         $this->position += $delta;
         /** @var ModelInterface $model */
         $model->setProperty($this->getSortingProperty(), $this->position);
     }
     // When the sorting exceeds the sorting of the "next" sibling, we need to push the remaining siblings to the
     // end of the list.
     if ($this->marker->getProperty($this->getSortingProperty()) <= $this->position) {
         do {
             // Skip models about to be pasted.
             if (in_array($this->marker->getId(), $ids)) {
                 $this->marker = $this->siblingsCopy->shift();
                 continue;
             }
             $this->position += $delta;
             $this->marker->setProperty($this->getSortingProperty(), $this->position);
             $this->results->push($this->marker);
             $this->marker = $this->siblingsCopy->shift();
         } while ($this->marker);
     }
 }
Ejemplo n.º 3
0
 /**
  * Load property values.
  *
  * @return void
  */
 private function loadPropertyValues()
 {
     $flatten = $this->flatten($this->getData());
     $this->propertyValues = new PropertyValueBag($flatten);
     $this->model->setPropertiesAsArray($flatten);
     foreach ($this->getForms() as $form) {
         foreach ($form->getFields() as $field) {
             $defintion = $this->environment->getDataDefinition()->getPropertiesDefinition();
             $defintion->addProperty($field);
             if (!$this->isSubmit()) {
                 continue;
             }
             $value = $this->environment->getInputProvider()->getValue($field->getName(), true);
             // Set value to property values and to model. If validation failed, the widget manager loads data
             // from the model.
             $this->model->setProperty($field->getName(), $value);
             $this->propertyValues->setPropertyValue($field->getName(), $value);
         }
     }
 }
 /**
  * Handle a property in a cloned model.
  *
  * @param ModelInterface        $model        The cloned model.
  *
  * @param PropertyInterface     $property     The property to handle.
  *
  * @param DataProviderInterface $dataProvider The data provider the model originates from.
  *
  * @return void
  */
 private function handleClonedModelProperty(ModelInterface $model, PropertyInterface $property, DataProviderInterface $dataProvider)
 {
     $extra = $property->getExtra();
     $propName = $property->getName();
     // Check doNotCopy.
     if (isset($extra['doNotCopy']) && $extra['doNotCopy'] === true) {
         $model->setProperty($propName, null);
         return;
     }
     // Check uniqueness.
     if (isset($extra['unique']) && $extra['unique'] === true && !$dataProvider->isUniqueValue($propName, $model->getProperty($propName))) {
         // Implicit "do not copy" unique values, they cannot be unique anymore.
         $model->setProperty($propName, null);
     }
 }
Ejemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function __set($name, $value)
 {
     $this->model->setProperty($name, $value);
 }