@param array  $data
@param string $rootPath
@param User   $owner

@return Blog
164104
public function importBlog(array $data, $rootPath, User $owner)
    {
        $blogDatas = $data['data'];
        $optionsData = $blogDatas['options'];

        $blogOptions = new BlogOptions();
        $blogOptions
            ->setAuthorizeComment($optionsData['authorize_comment'])
            ->setAuthorizeAnonymousComment($optionsData['authorize_anonymous_comment'])
            ->setPostPerPage($optionsData['post_per_page'])
            ->setAutoPublishPost($optionsData['auto_publish_post'])
            ->setAutoPublishComment($optionsData['auto_publish_comment'])
            ->setDisplayTitle($optionsData['display_title'])
            ->setBannerActivate($optionsData['banner_activate'])
            ->setDisplayPostViewCounter($optionsData['display_post_view_counter'])
            ->setBannerBackgroundColor($optionsData['banner_background_color'])
            ->setBannerHeight($optionsData['banner_height'])
            ->setBannerBackgroundImagePosition($optionsData['banner_background_image_position'])
            ->setBannerBackgroundImageRepeat($optionsData['banner_background_image_repeat'])
            ->setTagCloud($optionsData['tag_cloud']);

        if (isset($optionsData['display_full_posts'])) {
            $blogOptions->setDisplayFullPosts($optionsData['display_full_posts']);
        } else {
            $blogOptions->setDisplayFullPosts(false);
        }

        if (isset($optionsData['comment_moderation_mode'])) {
            $blogOptions->setCommentModerationMode($optionsData['comment_moderation_mode']);
        } else {
            $blogOptions->setCommentModerationMode(BlogOptions::COMMENT_MODERATION_ALL);
        }

        $blog = new Blog();
        if (isset($blogDatas['infos_path']) && null !== $blogDatas['infos_path']) {
            $infos = file_get_contents(
                $rootPath.DIRECTORY_SEPARATOR.$blogDatas['infos_path']
            );
            $blog->setInfos($infos);
        }
        $blog->setOptions($blogOptions);
        $this->objectManager->persist($blog);
        //flush, otherwise we dont have the website ID needed for building uploadPath for banner
        //$this->objectManager->forceFlush();

        //Copy banner bg image to web folder, old system, for compatibility
        if (isset($optionsData['banner_background_image']) && null !== $optionsData['banner_background_image'] && !filter_var($optionsData['banner_background_image'], FILTER_VALIDATE_URL)) {
            $bannerPath = $rootPath.DIRECTORY_SEPARATOR.$optionsData['banner_background_image'];
            if (file_exists($bannerPath)) {
                $publicFile = $this->fileUtils->createFile(new File($bannerPath));
                $blog->getResourceNode()->setPoster($publicFile->getUrl());
            }
        }

        $postsDatas = $blogDatas['posts'];
        $posts = new ArrayCollection();

        foreach ($postsDatas as $postsData) {
            $tagsDatas = $postsData['tags'];
            $tags = [];
            foreach ($tagsDatas as $tagsData) {
                $tags[] = $tagsData['name'];
            }
            $post = new Post();
            //insert tags
            $event = new GenericDataEvent([
                'tags' => array_values($tags),
                'data' => [
                    [
                        'class' => 'Icap\BlogBundle\Entity\Post',
                        'id' => $post->getUuid(),
                        'name' => $post->getTitle(),
                    ],
                ],
                'replace' => true,
            ]);
            $this->eventDispatcher->dispatch('claroline_tag_multiple_data', $event);

            $commentsDatas = $postsData['comments'];
            $comments = new ArrayCollection();
            foreach ($commentsDatas as $commentsData) {
                $comment = new Comment();
                $commentMessage = file_get_contents($rootPath.DIRECTORY_SEPARATOR.$commentsData['message']);
                $comment
                    ->setMessage($commentMessage)
                    ->setAuthor($this->retrieveUser($commentsData['author'], $owner))
                    ->setCreationDate(new \DateTime($postsData['creation_date']))
                    ->setUpdateDate(new \DateTime($postsData['modification_date']))
                    ->setPublicationDate(new \DateTime($postsData['publication_date']))
                    ->setStatus($commentsData['status'])
                ;
                if (isset($commentsData['reported'])) {
                    $comment->setReported($commentsData['reported']);
                }

                $this->objectManager->persist($comment);
                $comments->add($comment);
            }

            $postContent = file_get_contents($rootPath.DIRECTORY_SEPARATOR.$postsData['content']);

            $post
                ->setTitle($postsData['title'])
                ->setContent($postContent)
                ->setAuthor($this->retrieveUser($postsData['author'], $owner))
                ->setCreationDate(new \DateTime($postsData['creation_date']))
                ->setModificationDate(new \DateTime($postsData['modification_date']))
                ->setPublicationDate(new \DateTime($postsData['publication_date']))
                ->setComments($comments)
                ->setStatus($postsData['status'])
            ;

            if (isset($postsData['pinned'])) {
                $post->setPinned($postsData['pinned']);
            }

            $posts->add($post);
        }

        $blog->setPosts($posts);

        return $blog;
    }
936824
public function createBlock($ownerId, $type, $parentId, $placeholder, $sort, $data = null)
    {
        $owner = $this->find($ownerId);
        $version = $this->getNewVersion($owner);
        $className = $this->em->getClassMetadata($type)->getName();
        $block = new $className();
        $parent = $this->find($parentId ?: $ownerId);

        $block->setRootVersion($version);
        $block->setPosition($placeholder);
        $block->setSort(0); // < default, gets recalculated later for entire level
        $block->setLevel(0); // < need to be calculated when putting in the tree

        // Set owner
        $block->setOwner($owner);
        $owner->addOwning($block);
        $owner->setRootVersion($version);

        // This should replaced with a more hardened function
        if ($data) {
            foreach ($data as $attribute => $value) {
                $method = "set$attribute";
                $block->$method($value);
            }
        }

        $block->setParent($parent);
        $parent->setRootVersion($version);

        // Save now, rest will be in changeset. All we do is a create a stub entry anyway.
        $this->save($block);

        if (count($sort) > 1) {
            // Replace the zero value in the posted sort array
            // with the newly created id to perform sorting
            $id = $block->getId();
            $sort = array_map(
                function ($v) use ($id) {
                    return $v == "" || $v == "0" ? $id : $v;
                },
                $sort
            );

            $siblings = $this->getSiblings($block, $version);
            $siblings[] = $block;
            if ($siblings) {
                $siblings = $this->sortBlocksByDirective($siblings, $sort);

                foreach ($siblings as $sibling) {
                    $this->save($sibling);
                }
            }
        } else {
        }

        return $block;
    }
1104016
public function getEntityNavigation($rootPage = null, $mode = AbstractQuery::HYDRATE_ARRAY, $cacheKey = null)
    {
        /** @var $repo  PageRepository */
        $this->setCacheKey($cacheKey);
        $repo  = $this->getRepository();
        $query = $this->addHints($repo->getNodesHierarchyQuery($rootPage));
        $query = $this->setCacheFlag($query);

        return $query->execute([], $mode);
    }
118403
public function makeSharedAction(Request $request, $owner, $ownerId)
    {
        /** @var BlockManager $manager */
        $manager = $this->get('opifer.content.block_manager');

        $response = new JsonResponse;
        $id       = (int) $request->request->get('id');

        try {
            /** @var PointerBlock $pointerBlock */
            $pointerBlock = $manager->makeBlockShared($id);

            $response->setStatusCode(200);
            $response->setData(['state' => 'created', 'id' => $pointerBlock->getId()]);
            $response->headers->add(['Location' => $this->generateUrl('opifer_content_api_contenteditor_view_block', ['owner' => $owner, 'ownerId' => $ownerId, 'id' => $pointerBlock->getId()])]);
        } catch (\Exception $e) {
            $response->setStatusCode(500, 'Exception');
            $response->setData(['error' => $e->getMessage()]);
        }

        return $response;
    }
995389
protected function loadMigrationFields(DOMXPath $rootPath)
    {
        $fields = $rootPath->query(
            './value[@type="list" and @key="columns"]/value[@type="object" and @struct-name="db.mysql.Column"]'
        );

        if ($fields && $fields->length) {
            /** @var \DOMNode $field */
            foreach ($fields as $field) {
                $fieldName = $rootPath->query('./value[@key="name"]', $field)->item(0)->nodeValue;

                $this->addField($fieldName)->load($field, $rootPath);
            } // foreach
        } // if

        $this->addIndicesToFields($rootPath);

        return $this->addForeignKeys($rootPath);
    }
1108675
private function getOnePathData($data, string $root, bool $allowFiles, bool $allowDirs): ?string
    {
        if ($data === null) {
            return null;
        }

        if (!\is_array($data)) {
            $data = [$data];
        }

        $result = $this->existingPaths($data, $root, $allowFiles, $allowDirs);

        if ($result === null || \count($result) !== 1) {
            return null;
        }

        return reset($result);
    }
105705
private function parse(array $data, NodePath $nodePath, $parentId = null)
    {
        $parentId = $this->validateParentId($parentId);
        $csvFile = $this->createCsvFile($this->structure->getTypeFromNodePath($nodePath), $nodePath, $parentId);
        $parentCols = array_fill_keys(array_keys($parentId), "string");

        foreach ($data as $row) {
            // in case of non-associative array of strings
            // prepare {"data": $value} objects for each row
            if (is_scalar($row) || is_null($row)) {
                $row = (object) [Structure::DATA_COLUMN => $row];
            } elseif ($this->analyzer->getNestedArrayAsJson() && is_array($row)) {
                $row = (object) [Structure::DATA_COLUMN => json_encode($row)];
            }

            // Add parentId to each row
            if (!empty($parentId)) {
                $row = (object) array_replace((array) $row, $parentId);
            }

            $csvRow = $this->parseRow($row, $nodePath, $parentCols);
            $csvFile->writeRow($csvRow->getRow());
        }
    }
197478
public function renderView($viewPath, array $data = null)
    {
        $this->setView($viewPath);

        !$data or extract($data);
        ob_start();

        if (file_exists(rtrim(
                $this->getViewPath(), $this->getFileExt()
            ) . $this->getFileExt())) {

            /** @noinspection PhpIncludeInspection */
            include rtrim(
                    $this->getViewPath(), $this->getFileExt()
                ) . $this->getFileExt();

        } elseif (file_exists(rtrim(
                $this->getViewFallbackPath(), $this->getFileExt()
            ) . $this->getFileExt())) {

            /** @noinspection PhpIncludeInspection */
            include rtrim(
                    $this->getViewFallbackPath(), $this->getFileExt()
                ) . $this->getFileExt();

        } else {
            throw new ViewNotFoundException('View ' . rtrim(
                    $this->getViewPath(), $this->getFileExt()
                ) . $this->getFileExt() . ' not found');
        }

        $rendered = ob_get_contents();
        ob_end_clean();

        return $rendered;
    }
821662
public function renderTemplate($templatePath = null, $data = [])
    {
        $renderedTemplate = $this->view->renderTemplate($templatePath, $data);
        return $renderedTemplate;
    }
976419
public static function find($owner, $ownerId = null)
    {
        // get class
        if ($owner instanceof Pluf_Model) { // Pluf module
            $ownerClass = $owner->getClass();
            $ownerId = $owner->getId();
        } elseif (! is_null($owner)) { // module
            $ownerClass = $owner;
        }

        // get list
        $receipt = new Bank_Receipt();
        $q = new Pluf_SQL('owner_class=%s AND owner_id=%s', array(
            $ownerClass,
            $ownerId
        ));
        $list = $receipt->getList(array(
            'filter' => $q->gen()
        ));
        return $list;
    }
853848
public function initializeWithUrlAndRootPath($url, $root_path)
    {
        $this->initializeWithUrl($url);
        $this->root_path = $root_path;

        return $this;
    }
121172
private function resolveSchemasFromRoutes(array $data, $basePath)
    {
        $schemas = [];
        $type    = SystemAbstract::TYPE_ROUTES;

        if (isset($data[$type]) && is_array($data[$type])) {
            foreach ($data[$type] as $name => $row) {
                // resolve includes
                $row = IncludeDirective::resolve($row, $basePath, $type);

                if (isset($row['methods']) && is_array($row['methods'])) {
                    foreach ($row['methods'] as $method => $config) {
                        // parameters
                        if (isset($config['parameters']) && !$this->isName($config['parameters'])) {
                            $schema = $this->resolveSchema($config['parameters'], $basePath);
                            $name   = NameGenerator::getSchemaNameFromSource($config['parameters']);

                            $schemas[$name] = $schema;
                        }

                        // request
                        if (isset($config['request']) && !$this->isName($config['request'])) {
                            $schema = $this->resolveSchema($config['request'], $basePath);
                            $name   = NameGenerator::getSchemaNameFromSource($config['request']);

                            $schemas[$name] = $schema;
                        }

                        // responses
                        if (isset($config['response']) && !$this->isName($config['response'])) {
                            $schema = $this->resolveSchema($config['response'], $basePath);
                            $name   = NameGenerator::getSchemaNameFromSource($config['response']);

                            $schemas[$name] = $schema;
                        } elseif (isset($config['responses']) && is_array($config['responses'])) {
                            foreach ($config['responses'] as $code => $response) {
                                if (!$this->isName($response)) {
                                    $schema = $this->resolveSchema($response, $basePath);
                                    $name   = NameGenerator::getSchemaNameFromSource($response);

                                    $schemas[$name] = $schema;
                                }
                            }
                        }
                    }
                }
            }
        }

        return $schemas;
    }
1027013
public function update($owner, $eventId, array $data)
    {
        $data = self::mergeData($data, [
            'owner' => $owner,
            'contactEvent' => [
                'eventId' => $eventId,
            ],
        ]);

        return $this->client->doPost('contact/updateContactExtEvent', $data);
    }
194296
public function build($basepath, $language = null)
    {
        $sitemapElements = [];

        foreach ($this->sitemapElementGenerators as $sitemapElementGenerator) {
            $sitemapElements = array_merge(
                $sitemapElements,
                $sitemapElementGenerator->generateElements($language)
            );
        }

        $data = $this
            ->sitemapRenderer
            ->render($sitemapElements, $basepath);

        return $data;
    }
442990
public function postRequireArray($requestPath, array $postData)
    {
        $responseData = $this->post($requestPath, $postData);

        return self::requireArray($responseData);
    }
971423
public function findDomainRecordsByRootPagesIds(array $rootPageIds = [])
    {
        $resultTmp = $this->getDomainRecordsByRootPageIds($rootPageIds);

        $result = [];
        foreach ($resultTmp as $key => $row) {
            $result[$row['pid']] = $row;
        }
        return $result;
    }
1204096
public function renderView($viewPath = null, $data = [], $layout = null)
    {
        $renderedView = $this->view->renderView($viewPath, $data, $layout);
        return $renderedView;
    }