plugin/exo/Serializer/Item/Type/OrderingQuestionSerializer.php
private function deserializeItems(OrderingQuestion $question, array $items, array $solutions, array $options = [])
    {
        $itemEntities = $question->getItems()->toArray();

        foreach ($items as $itemData) {
            $item = null;

            // Searches for an existing item entity.
            foreach ($itemEntities as $entityIndex => $entityItem) {
                /** @var OrderingItem $entityItem */
                if ($entityItem->getUuid() === $itemData['id']) {
                    $item = $entityItem;
                    unset($itemEntities[$entityIndex]);
                    break;
                }
            }

            $item = $item ?: new OrderingItem();
            $item->setUuid($itemData['id']);

            // Deserialize item content
            $item = $this->contentSerializer->deserialize($itemData, $item, $options);

            // Set item score feedback and order
            foreach ($solutions as $solution) {
                if ($solution['itemId'] === $itemData['id']) {
                    $item->setScore($solution['score']);

                    if (isset($solution['feedback'])) {
                        $item->setFeedback($solution['feedback']);
                    }

                    if (isset($solution['position'])) {
                        $item->setPosition($solution['position']);
                    }
                    break;
                }
            }

            $question->addItem($item);
        }

        // Remaining items are no longer in the Question
        foreach ($itemEntities as $itemToRemove) {
            $question->removeItem($itemToRemove);
        }
    }
private function deserializeItems(OrderingQuestion $question, array $items, array $solutions, array $options = [])
    {
        $itemEntities = $question->getItems()->toArray();

        foreach ($items as $itemData) {
            $item = null;

            // Searches for an existing item entity.
            foreach ($itemEntities as $entityIndex => $entityItem) {
                /** @var OrderingItem $entityItem */
                if ($entityItem->getUuid() === $itemData['id']) {
                    $item = $entityItem;
                    unset($itemEntities[$entityIndex]);
                    break;
                }
            }

            $item = $item ?: new OrderingItem();
            $item->setUuid($itemData['id']);

            // Deserialize item content
            $item = $this->contentSerializer->deserialize($itemData, $item, $options);

            // Set item score feedback and order
            foreach ($solutions as $solution) {
                if ($solution['itemId'] === $itemData['id']) {
                    $item->setScore($solution['score']);

                    if (isset($solution['feedback'])) {
                        $item->setFeedback($solution['feedback']);
                    }

                    if (isset($solution['position'])) {
                        $item->setPosition($solution['position']);
                    }
                    break;
                }
            }

            $question->addItem($item);
        }

        // Remaining items are no longer in the Question
        foreach ($itemEntities as $itemToRemove) {
            $question->removeItem($itemToRemove);
        }
    }
private function deserializeItems ( OrderingQuestion $ question , array $ items , array $ solutions , array $ options = [ ] ) { $ itemEntities = $ question -> getItems ( ) -> toArray ( ) ; foreach ( $ items as $ itemData ) { $ item = null ; // Searches for an existing item entity. foreach ( $ itemEntities as $ entityIndex => $ entityItem ) { /** @var OrderingItem $entityItem */ if ( $ entityItem -> getUuid ( ) === $ itemData [ 'id' ] ) { $ item = $ entityItem ; unset ( $ itemEntities [ $ entityIndex ] ) ; break ; } } $ item = $ item ? : new OrderingItem ( ) ; $ item -> setUuid ( $ itemData [ 'id' ] ) ; // Deserialize item content $ item = $ this -> contentSerializer -> deserialize ( $ itemData , $ item , $ options ) ; // Set item score feedback and order foreach ( $ solutions as $ solution ) { if ( $ solution [ 'itemId' ] === $ itemData [ 'id' ] ) { $ item -> setScore ( $ solution [ 'score' ] ) ; if ( isset ( $ solution [ 'feedback' ] ) ) { $ item -> setFeedback ( $ solution [ 'feedback' ] ) ; } if ( isset ( $ solution [ 'position' ] ) ) { $ item -> setPosition ( $ solution [ 'position' ] ) ; } break ; } } $ question -> addItem ( $ item ) ; } // Remaining items are no longer in the Question foreach ( $ itemEntities as $ itemToRemove ) { $ question -> removeItem ( $ itemToRemove ) ; } }
Deserializes Question items.

@param OrderingQuestion $question
@param array            $items
@param array            $solutions
@param array            $options
Deserializes Question items .