@param $siteId
@param $entities

@return array
164946
public function findUsageReferenceInOtherSite($siteId, $entities)
    {
        $usedOtherSite = array();
        $supportedEntities = array(BlockInterface::ENTITY_TYPE, ContentInterface::ENTITY_TYPE);
        /** @var UseTrackableInterface $entity */
        foreach ($entities as $entity) {
            $references = $entity->getUseReferences();
            $entityReferences = array(
                'entity' => $entity,
                'references' => array()
            );
            if (!empty($references)) {
                foreach ($references as $type => $reference) {
                    if (in_array($type, $supportedEntities)) {
                        $referenceIds = array_keys($reference);
                        $repo = $this->getRepositoryByType($type);
                        foreach ($referenceIds as $referenceId) {
                            $referenceEntity = $repo->findById($referenceId);
                            if (
                                $siteId !== $referenceEntity->getSiteId()
                            ) {
                                $entityReferences['references'][$type][$referenceEntity->getId()] = $referenceEntity;
                            }
                        }
                    }
                }
                $usedOtherSite[] = $entityReferences;
            }
        }

        return $usedOtherSite;
    }
750884
public function actionGetAllUrls(array $criteria = [], $siteId = null): Response
    {
        return $this->asJson(RouteMap::$plugin->routes->getAllUrls($criteria, $siteId));
    }
481641
public function getBlockById(int $blockId, int $siteId = null)
    {
        /** @var SuperTableBlock|null $block */
        $block = Craft::$app->getElements()->getElementById($blockId, SuperTableBlockElement::class, $siteId);

        return $block;
    }
1133641
public function getSitePages($siteId)
    {
        $results = array();
        
        // Event parameters prepare
        $arrayParameters = $this->makeArrayFromParameters(__METHOD__, func_get_args());
        
        // Sending service start event
        $arrayParameters = $this->sendEvent('meliscmssite_service_get_site_pages_start', $arrayParameters);
        
        // Service implementation start
        
        $siteTable = $this->getServiceLocator()->get('MelisEngineTableSite');
        
        $site = $siteTable->getEntryById($arrayParameters['siteId'])->current();
        
        if (!empty($site))
        {
            $pages = $siteTable->getSiteSavedPagesById($site->site_id)->toArray();
            
            if (!empty($pages))
            {
                $site->pages = $pages;
            }
            
            $results = $site;
        }
        
        // Service implementation end
         
        // Adding results to parameters for events treatment if needed
        $arrayParameters['results'] = $results;
        // Sending service end event
        $arrayParameters = $this->sendEvent('meliscmssite_service_get_site_pages_start', $arrayParameters);
        
        return $arrayParameters['results'];
        
    }
288463
protected function getSite($siteId)
    {
        try {
            /** @var Site $site */
            $site = $this->getSiteRepo()->findOneBy(['siteId' => $siteId]);
        } catch (\Exception $e) {
            $site = null;
        }

        return $site;
    }
766922
public function findProductsByProductNumbers(int $siteId, array $productNumbers, int $page = 1, int $pageSize = 100) : array
    {
        Assert::that($siteId)->greaterThan(0, 'The $siteId has to be positive');
        Assert::that($productNumbers)->notEmpty();
        Assert::thatAll($productNumbers)->minLength(1, 'All product numbers in $productNumbers must have a length > 0');
        Assert::that($page)->greaterThan(0, 'The $page has to be positive');
        Assert::that($pageSize)->greaterThan(0, 'The $pageSize has to be positive');

        $body = [
            'Identifiers' => $productNumbers,
            'PageIndex' => $page,
            'Pagesize' => $pageSize
        ];

        return (array)$this->master->doRequest(
            'GET',
            sprintf('/admin/WEBAPI/Endpoints/v1_0/ProductService/{KEY}/FindProductsByProductNumbers/%d', $siteId),
            $body
        );
    }
1071518
protected function getSiteForRootPageId(int $pageId): array
    {
        return is_array($this->sites[$pageId]) ? $this->sites[$pageId] : [];
    }
855389
public static function collectIds($entities)
	{
		$ids = array();

		foreach ($entities as $entity) {
			$ids[] = $entity->getId();
		}

		return $ids;
	}
903486
public function getElementUrls($elementType, array $criteria = [], $siteId = null): array
    {
        return RouteMap::$plugin->routes->getElementUrls($elementType, $criteria, $siteId);
    }
532319
public function getEntity($entityId)
    {
        if (isset($this->entities[$entityId])) {
            return $this->entities[$entityId];
        }

        $this->entities[$entityId] = $this->client->getEntity($entityId);

        return $this->entities[$entityId];
    }
583886
public function update($siteId, $data)
    {
        //ACCESS CHECK
        if (!$this->isAllowed(
            ResourceName::RESOURCE_SITES,
            'admin'
        )
        ) {
            $this->getResponse()->setStatusCode(Response::STATUS_CODE_401);

            return $this->getResponse();
        }

        if (!is_array($data)) {
            throw new \Exception('Invalid data format');
        }

        /** @var \Doctrine\ORM\EntityManager $entityManager */
        $entityManager = $this->getEntityManager();

        /** @var \Rcm\Repository\Site $siteRepo */
        $siteRepo = $entityManager->getRepository(\Rcm\Entity\Site::class);

        if (!$siteRepo->isValidSiteId($siteId)) {
            $this->getResponse()->setStatusCode(Response::STATUS_CODE_400);

            return $this->getResponse();
        }

        /** @var \Rcm\Entity\Site $site */
        $site = $siteRepo->findOneBy(['siteId' => $siteId]);

        $newStatus = $site->getStatus();

        if ($data['status'] == 'D') {
            $newStatus = 'D';
        }
        if ($data['status'] == 'A') {
            $newStatus = 'A';
        }

        $site->setStatus($newStatus);

        $site->setModifiedByUserId(
            $this->getCurrentUserId(),
            "Update site status to {$newStatus} in " . get_class($this)
        );

        $entityManager->persist($site);
        $entityManager->flush($site);

        $this->siteVersionRepo->publish(
            new SiteLocator($site->getDomainName()),
            $this->getSiteManager()->siteToImmutableSiteContent($site),
            $this->getCurrentUserTracking()->getId(),
            __CLASS__ . '::' . __FUNCTION__,
            $site->getSiteId()
        );

        return new JsonModel($site);
    }
50372
public function getPerimetersConfiguration($siteId)
    {
        $perimetersConfiguration = array();
        foreach ($this->strategies as $strategy) {
            $perimetersConfiguration = array_merge(
                $perimetersConfiguration,
                array($strategy->getType() => $strategy->getPerimeterConfiguration($siteId))
            );
        }

        return $perimetersConfiguration;
    }
820232
public function workers($serverId, $siteId)
    {
        return $this->transformCollection(
            $this->get("servers/$serverId/sites/$siteId/workers")['workers'],
            Worker::class,
            ['server_id' => $serverId, 'site_id' => $siteId]
        );
    }
560724
protected function getSitePagesResourceId($siteId)
    {
        /** @var ResourceName $resourceName */
        $resourceName = $this->getServiceLocator()->get(
            ResourceName::class
        );

        return $resourceName->get(
            ResourceName::RESOURCE_SITES,
            $siteId,
            ResourceName::RESOURCE_PAGES
        );
    }
1368871
public function generatePerimeters($siteId)
    {
        $perimeters = array();
        foreach ($this->strategies as $strategy) {
            $perimeters = array_merge($perimeters, array($strategy->getType() => $strategy->generatePerimeter($siteId)));
        }

        return $perimeters;
    }
972569
public function getAllPageIdsAndNamesBySiteThenType($siteId, $type)
    {
        $queryBuilder = $this->_em->createQueryBuilder();

        $queryBuilder->select('page.name, page.pageId')
            ->from(\Rcm\Entity\Page::class, 'page')
            ->join('page.site', 'site')
            ->where('page.pageType = :pageType')
            ->andWhere('site.siteId = :siteId')
            ->setParameter('pageType', $type)
            ->setParameter('siteId', $siteId);

        $result = $queryBuilder->getQuery()->getArrayResult();

        if (empty($result)) {
            return null;
        }

        $return = [];

        foreach ($result as &$page) {
            $return[$page['pageId']] = $page['name'];
        }

        return $return;
    }
402633
public function getSiteInfo($siteId)
    {
        /** @var \Doctrine\ORM\QueryBuilder $queryBuilder */
        $queryBuilder = $this->_em->createQueryBuilder();
        $queryBuilder->select(
            'partial site.{
                owner,
                theme,
                status,
                favIcon,
                loginPage,
                notAuthorizedPage,
                siteLayout,
                siteTitle,
                siteId
            },
            language,
            country'
        )->from(\Rcm\Entity\Site::class, 'site')
            ->join('site.country', 'country')
            ->join('site.language', 'language')
            ->where('site.siteId = :siteId')
            ->setParameter('siteId', $siteId);

        try {
            return $queryBuilder->getQuery()->getSingleResult(
                Query::HYDRATE_ARRAY
            );
        } catch (NoResultException $e) {
            return null;
        }
    }