@param Blog     $blog
@param bool     $executeQuery
@param int|null $max

@return array|\Doctrine\ORM\AbstractQuery
354487
public function findByBlog(Blog $blog, $executeQuery = true, $max = null)
    {
        $query = $this->getEntityManager()
            ->createQuery('
                SELECT t, COUNT(t.id) AS frequency, COUNT(p.id) as countPosts
                FROM IcapBlogBundle:Tag t
                JOIN t.posts p
                WHERE p.blog = :blogId
                AND p.status = :postStatus
                AND p.publicationDate IS NOT NULL
                GROUP BY t.id
                ORDER BY frequency DESC
            ')
            ->setParameter('blogId', $blog->getId())
            ->setParameter('postStatus', Statusable::STATUS_PUBLISHED)
        ;

        if (null !== $max) {
            $query->setMaxResults($max);
        }

        return $executeQuery ? $query->getResult() : $query;
    }
456264
public function serialize(Blog $blog, BlogOptions $blogOptions, array $options = [])
    {
        return [
            'authorizeComment' => $blogOptions->getAuthorizeComment(),
            'authorizeAnonymousComment' => $blogOptions->getAuthorizeAnonymousComment(),
            'postPerPage' => $blogOptions->getPostPerPage(),
            'autoPublishPost' => $blogOptions->getAutoPublishPost(),
            'commentModerationMode' => $this->getModerationModeStringValue($blogOptions->getCommentModerationMode()),
            'displayTitle' => $blogOptions->getDisplayTitle(),
            'bannerActivate' => $blogOptions->isBannerActivate(),
            'displayPostViewCounter' => $blogOptions->getDisplayPostViewCounter(),
            'tagCloud' => null !== $blogOptions->getTagCloud() ? $this->getTagModeStringValue($blogOptions->getTagCloud()) : '0',
            'widgetOrder' => $this->serializeWidgetOrder($blogOptions->getListWidgetBlog()),
            'widgetList' => $this->serializeWidgetList($this->blogManager->getPanelInfos()),
            'tagTopMode' => $blogOptions->isTagTopMode(),
            'maxTag' => $blogOptions->getMaxTag(),
            'displayFullPosts' => $blogOptions->getDisplayFullPosts(),
            'infos' => $blog->getInfos(),
        ];
    }
266787
public static function runOnBlog( int $blog_id, callable $callback, ...$args ) {
		switch_to_blog( $blog_id );
		$result = call_user_func_array( $callback, $args );
		switch_to_blog( get_current_blog_id() );

		return $result;
	}
805834
public function getLastLog()
    {
        $log = $this->createQueryBuilder()
                    ->select('l.*')
                    ->from($this->tableName, 'l')
                    ->orderBy('l.id', 'DESC')
                    ->setMaxResults(1)
                    ->execute()
                    ->fetch();
        
        if (false !== $log) {
            return new Log($log);
        }
    }
6797
public function listAction(Request $request, Blog $blog)
    {
        $this->checkPermission('OPEN', $blog->getResourceNode(), [], true);

        $parameters = $request->query->all();

        //if no edit rights, list only published posts
        $posts = $this->postManager->getPosts(
            $blog->getId(),
            $parameters,
            $this->checkPermission('ADMINISTRATE', $blog->getResourceNode())
            || $this->checkPermission('EDIT', $blog->getResourceNode())
            || $this->checkPermission('MODERATE', $blog->getResourceNode())
                ? PostManager::GET_ALL_POSTS
                : PostManager::GET_PUBLISHED_POSTS,
            !$blog->getOptions()->getDisplayFullPosts());

        return new JsonResponse($posts);
    }
275710
public function countAll($executeQuery = true)
    {
        $queryBuilder = $this->createQueryBuilder('p')
            ->select('COUNT(p)');

        return $executeQuery ? $queryBuilder->getQuery()->getSingleScalarResult() : $queryBuilder;
    }
758961
public function serialize(Blog $blog, array $options = [])
    {
        return [
            'id' => $blog->getUuid(),
            'name' => $blog->getResourceNode()->getName(),
            'infos' => $blog->getInfos(),
            'options' => $this->blogOptionsSerializer->serialize($blog, $blog->getOptions()),
        ];
    }
750041
public function getOptionsAction(Request $request, Blog $blog)
    {
        $this->checkPermission('EDIT', $blog->getResourceNode(), [], true);

        return new JsonResponse($this->blogOptionsSerializer->serialize($blog, $blog->getOptions(), $this->blogManager->getPanelInfos()));
    }
1023709
public function findOrderedByRowAndCol(Portfolio $portfolio, $executeQuery = true)
    {
        $queryBuilder = $this->createQueryBuilder('pw')
            ->andWhere('pw.portfolio = :portfolio')
            ->setParameter('portfolio', $portfolio)
            ->orderBy('pw.row', 'ASC')
            ->addOrderBy('pw.col', 'ASC')
        ;

        return $executeQuery ? $queryBuilder->getQuery()->getResult() : $queryBuilder->getQuery();
    }
1164959
public function runDql($dql, $hydrationMode = \Doctrine\ORM\Query::HYDRATE_OBJECT, $firstResult = null, $maxResult = null)
    {
        /** @var \Doctrine\ORM\Query $query */
        $query = $this->entityManager->createQuery($dql);
        if ($firstResult !== null) {
            $query->setFirstResult($firstResult);
        }
        if ($maxResult !== null) {
            $query->setMaxResults($maxResult);
        }

        return $query->execute([], $hydrationMode);
    }
264576
public function getBaseQuery(QueryBuilder $query, EntityDefinition $definition, Context $context): QueryBuilder
    {
        $table = $definition->getEntityName();

        $query->from(self::escape($table));

        $useVersionFallback = (
            // only applies for versioned entities
            $definition->isVersionAware()
            // only add live fallback if the current version isn't the live version
            && $context->getVersionId() !== Defaults::LIVE_VERSION
            // sub entities have no live fallback
            && $definition->getParentDefinition() === null
        );

        if ($useVersionFallback) {
            $this->joinVersion($query, $definition, $definition->getEntityName(), $context);
        } elseif ($definition->isVersionAware()) {
            $versionIdField = array_filter(
                $definition->getPrimaryKeys()->getElements(),
                function ($f) {
                    return $f instanceof VersionField || $f instanceof ReferenceVersionField;
                }
            );

            if (!$versionIdField) {
                throw new \RuntimeException('Missing `VersionField` in `' . $definition->getClass() . '`');
            }

            /** @var FkField|null $versionIdField */
            $versionIdField = array_shift($versionIdField);

            $query->andWhere(self::escape($table) . '.' . self::escape($versionIdField->getStorageName()) . ' = :version');
            $query->setParameter('version', Uuid::fromHexToBytes($context->getVersionId()));
        }

        $this->addRuleCondition($query, $definition, $context);

        return $query;
    }
1176653
public static function ExecuteAll($executeQueries)
	{
		$db = self::connect();
	
		$db->beginTransaction();
		$rowsAffected = 0;
		
		try
		{
			foreach($executeQueries as $executeQuery)
			{
				$query = $db->prepare($executeQuery["statement"]);
			
				foreach($executeQuery["parameters"] as $key => $parameter)
				{
					if(!isset($parameter["type"]))
						$parameter["type"] = PDO::PARAM_STR;
						
					$query->bindParam($key,$parameter["value"],$parameter["type"]);
				}
					
				$query->execute();
				$rowsAffected += $query->rowCount();	
			}
		}
		catch (PDOException $e)
		{
			$db->rollBack();
			$exception = "Sorry, there was a problem with query execution. ({$e->getMessage()})";
		}

		if($exception) throw new \Exception($exception);
		
		$db->commit();
		return $rowsAffected;
	}
1130557
public function findOneByPermalink($permalink, BlogInterface $blog)
    {
        $query = $this->getRepository()->createQueryBuilder('p');

        try {
            $urlParameters = $blog->getPermalinkGenerator()->getParameters($permalink);
        } catch (\InvalidArgumentException $exception) {
            return null;
        }

        $parameters = [];

        if (isset($urlParameters['year'], $urlParameters['month'], $urlParameters['day'])) {
            $dateQueryParts = $this->getPublicationDateQueryParts(
                sprintf('%d-%d-%d', $urlParameters['year'], $urlParameters['month'], $urlParameters['day']),
                'day'
            );

            $parameters = $dateQueryParts['params'];

            $query->andWhere($dateQueryParts['query']);
        }

        if (isset($urlParameters['slug'])) {
            $query->andWhere('p.slug = :slug');
            $parameters['slug'] = $urlParameters['slug'];
        }

        if (isset($urlParameters['collection'])) {
            $collectionQueryParts = $this->getPublicationCollectionQueryParts($urlParameters['collection']);

            $parameters = array_merge($parameters, $collectionQueryParts['params']);

            $query
                ->leftJoin('p.collection', 'c')
                ->andWhere($collectionQueryParts['query']);
        }

        if (0 === \count($parameters)) {
            return null;
        }

        $query->setParameters($parameters);

        return $query->getQuery()->getOneOrNullResult();
    }
935859
public function create(Blog &$blog)
    {
        $data = $blog->exportData();
        $endpoint = '/admin/blogs.json';
        $response = $this->request(
            $endpoint, 'POST', array(
            'blog' => $data
            )
        );
        $blog->setData($response['blog']);
    }
506854
protected function getBlog(Request $request, $blogId)
    {
        /** @var BlogRepository $blogRepo */
        $blogRepo = $this->get('doctrine.orm.entity_manager')->getRepository('VictoireBlogBundle:Blog');

        if ($blogId) {
            $blog = $blogRepo->find($blogId);
        } else {
            $blogs = $blogRepo->joinTranslations($request->getLocale())->run();
            $blog = reset($blogs);
        }

        return $blog;
    }
105144
private function playRollbackQueries($executeQueries = false)
    {
        foreach ($this->migration->getRollbackQueries() as $query) {
            $this->runQuery($query, $executeQueries);
        }
    }
1185582
public function view(UserPolicy $user, Blog $blog)
    {
        if ($user->canDo('blog.blog.view') && $user->isAdmin()) {
            return true;
        }

        return $blog->user_id == user_id() && $blog->user_type == user_type();
    }