plugin/exo/Serializer/Item/Type/GridQuestionSerializer.php
private function deserializeCells(GridQuestion $gridQuestion, array $cells, array $solutions, array $options = [])
    {
        $cellEntities = $gridQuestion->getCells()->toArray();

        foreach ($cells as $cellData) {
            $cell = null;

            // Searches for an existing cell entity.
            foreach ($cellEntities as $entityIndex => $entityCell) {
                /* @var Cell $entityCell */
                if ($entityCell->getUuid() === $cellData['id']) {
                    $cell = $entityCell;
                    unset($cellEntities[$entityIndex]);
                    break;
                }
            }

            $cell = $cell ?: new Cell();
            $cell->setUuid($cellData['id']);
            $cell->setCoordsX($cellData['coordinates'][0]);
            $cell->setCoordsY($cellData['coordinates'][1]);
            $cell->setColor($cellData['color']);
            $cell->setBackground($cellData['background']);

            if (!empty($cellData['data'])) {
                $cell->setData($cellData['data']);
            }
            if (!empty($cellData['choices'])) {
                $cell->setSelector(true);
            } else {
                $cell->setSelector(false);
            }
            $hasSolution = false;

            foreach ($solutions as $solution) {
                if ($solution['cellId'] === $cellData['id']) {
                    $this->deserializeCellChoices($cell, $solution['answers'], $options);
                    $hasSolution = true;
                    break;
                }
            }
            if (!$hasSolution) {
                $this->deserializeCellChoices($cell, [], $options);
            }
            $cell->setInput($hasSolution);

            $gridQuestion->addCell($cell);
        }

        // Remaining cells are no longer in the Question
        foreach ($cellEntities as $cellToRemove) {
            $gridQuestion->removeCell($cellToRemove);
        }
    }
private function deserializeCells(GridQuestion $gridQuestion, array $cells, array $solutions, array $options = [])
    {
        $cellEntities = $gridQuestion->getCells()->toArray();

        foreach ($cells as $cellData) {
            $cell = null;

            // Searches for an existing cell entity.
            foreach ($cellEntities as $entityIndex => $entityCell) {
                /* @var Cell $entityCell */
                if ($entityCell->getUuid() === $cellData['id']) {
                    $cell = $entityCell;
                    unset($cellEntities[$entityIndex]);
                    break;
                }
            }

            $cell = $cell ?: new Cell();
            $cell->setUuid($cellData['id']);
            $cell->setCoordsX($cellData['coordinates'][0]);
            $cell->setCoordsY($cellData['coordinates'][1]);
            $cell->setColor($cellData['color']);
            $cell->setBackground($cellData['background']);

            if (!empty($cellData['data'])) {
                $cell->setData($cellData['data']);
            }
            if (!empty($cellData['choices'])) {
                $cell->setSelector(true);
            } else {
                $cell->setSelector(false);
            }
            $hasSolution = false;

            foreach ($solutions as $solution) {
                if ($solution['cellId'] === $cellData['id']) {
                    $this->deserializeCellChoices($cell, $solution['answers'], $options);
                    $hasSolution = true;
                    break;
                }
            }
            if (!$hasSolution) {
                $this->deserializeCellChoices($cell, [], $options);
            }
            $cell->setInput($hasSolution);

            $gridQuestion->addCell($cell);
        }

        // Remaining cells are no longer in the Question
        foreach ($cellEntities as $cellToRemove) {
            $gridQuestion->removeCell($cellToRemove);
        }
    }
private function deserializeCells ( GridQuestion $ gridQuestion , array $ cells , array $ solutions , array $ options = [ ] ) { $ cellEntities = $ gridQuestion -> getCells ( ) -> toArray ( ) ; foreach ( $ cells as $ cellData ) { $ cell = null ; // Searches for an existing cell entity. foreach ( $ cellEntities as $ entityIndex => $ entityCell ) { /* @var Cell $entityCell */ if ( $ entityCell -> getUuid ( ) === $ cellData [ 'id' ] ) { $ cell = $ entityCell ; unset ( $ cellEntities [ $ entityIndex ] ) ; break ; } } $ cell = $ cell ? : new Cell ( ) ; $ cell -> setUuid ( $ cellData [ 'id' ] ) ; $ cell -> setCoordsX ( $ cellData [ 'coordinates' ] [ 0 ] ) ; $ cell -> setCoordsY ( $ cellData [ 'coordinates' ] [ 1 ] ) ; $ cell -> setColor ( $ cellData [ 'color' ] ) ; $ cell -> setBackground ( $ cellData [ 'background' ] ) ; if ( ! empty ( $ cellData [ 'data' ] ) ) { $ cell -> setData ( $ cellData [ 'data' ] ) ; } if ( ! empty ( $ cellData [ 'choices' ] ) ) { $ cell -> setSelector ( true ) ; } else { $ cell -> setSelector ( false ) ; } $ hasSolution = false ; foreach ( $ solutions as $ solution ) { if ( $ solution [ 'cellId' ] === $ cellData [ 'id' ] ) { $ this -> deserializeCellChoices ( $ cell , $ solution [ 'answers' ] , $ options ) ; $ hasSolution = true ; break ; } } if ( ! $ hasSolution ) { $ this -> deserializeCellChoices ( $ cell , [ ] , $ options ) ; } $ cell -> setInput ( $ hasSolution ) ; $ gridQuestion -> addCell ( $ cell ) ; } // Remaining cells are no longer in the Question foreach ( $ cellEntities as $ cellToRemove ) { $ gridQuestion -> removeCell ( $ cellToRemove ) ; } }
Deserializes Question cells.

@param GridQuestion $gridQuestion
@param array        $cells
@param array        $solutions
@param array        $options
Deserializes Question cells .