Fetches block from database by given $blockID

@param string $blockID
@param bool $asObject
@return eZPageBlock
545233
static public function fetch( $blockID, $asObject = true )
    {
        $db = eZDB::instance();
        $row = $db->arrayQuery(
            "SELECT zone_id, name, node_id, overflow_id, last_update, block_type as type, fetch_params, rotation_type, rotation_interval " .
            "FROM ezm_block WHERE id='" . $db->escapeString( $blockID ) . "'"
        );

        $xmlDocs = $db->arrayQuery(
            "SELECT oa.data_text " .
            "FROM ezcontentobject_tree AS t " .
            "INNER JOIN ezcontentobject AS o ON t.contentobject_id = o.id " .
            "INNER JOIN ezcontentobject_attribute AS oa ON o.id = oa.contentobject_id AND o.current_version = oa.version " .
            "WHERE t.node_id = " . $row[0]["node_id"] . " AND data_type_string = '" . eZPageType::DATA_TYPE_STRING . "'"
        );

        $pageBlock = null;

        foreach ( $xmlDocs as $xmlDoc )
        {
            $doc = new DOMDocument;
            $doc->loadXML( $xmlDoc["data_text"] );

            $xpath = new DOMXPath( $doc );
            foreach ( $xpath->evaluate( '//block[@id="id_' . $blockID . '"]' ) as $result )
            {
                $pageBlock = self::createFromXML( $result );

                // We are only interested by the first match (which is unique)
                break;
            }
        }

        if ( $pageBlock !== null )
        {
            if ( $asObject )
            {
                return $pageBlock;
            }

            $row[0] += array( "id" => $blockID, "view" => $pageBlock->attribute( "view" ) );
        }

        return $asObject ? new eZPageBlock( null, $row[0] ) : $row[0];
    }
196673
public function loadSubBlockIds($blockId, ?int $status = null): array
    {
        $query = $this->connection->createQueryBuilder();
        $query->select('DISTINCT id')
            ->from('ngbm_block')
            ->where(
                $query->expr()->like('path', ':path')
            )
            ->setParameter('path', '%/' . (int) $blockId . '/%', Type::STRING);

        if ($status !== null) {
            $this->applyStatusCondition($query, $status);
        }

        $result = $query->execute()->fetchAll(PDO::FETCH_ASSOC);

        return array_column($result, 'id');
    }
1007345
public function getUuid(bool $asObject = false)
    {
        if (true === $asObject) {
            return UuidIdentifier::fromString($this->uuid);
        }

        return $this->uuid;
    }
797902
public static function fetchBySourceURL( $url, $asObject = true )
    {
        return eZPersistentObject::fetchObject( self::definition(),
                                                null,
                                                array( "source_url" => $url ),
                                                $asObject );
    }
482777
public static function preloadPageBlock($pageId, $blockId, $version = 0, $preloadBy = 'page_id')
    {
        ($preloadBy == 'page_id') ? static::_preloadDataByPage($pageId, $version) : static::_preloadDataByBlock($blockId, $version);
        return static::_preloadGet('byVersionPage', [$version, $pageId, $blockId]) ?: [];
    }
1133458
@SuppressWarnings("unchecked")
    @Override
    public V get(Block<?, ?> block) {
        return (V) storage[block.getId()];
    }
493108
static function fetchList( $asObject = true )
    {
        return eZPersistentObject::fetchObjectList( eZRSSExport::definition(),
                                                    null, array( 'status' => self::STATUS_VALID ), null, null,
                                                    $asObject );
    }
1009407
static function fetchByName( $access_url, $asObject = true )
    {
        return eZPersistentObject::fetchObject( eZRSSExport::definition(),
                                                null,
                                                array( 'access_url' => $access_url,
                                                       'active' => 1,
                                                       'status' => self::STATUS_VALID ),
                                                $asObject );
    }
592462
public function blockAction(Request $request, $pageId, $blockName)
    {
        $em = $this->getDoctrine()->getManager();

        /* get current locale */
        $locale = $request->getLocale();
        
        $entity = $em->getRepository('AmulenPageBundle:Block')->findOneBy(array('page' => $pageId, 'name' => $blockName, "lang" => $locale));
        $content = "";
        if ($entity) {
            $content = $entity->getContent();
        }
        return array(
            'content' => $content
        );
    }
457667
public function injectEsi($eventObject) {
        $blockObject = $eventObject->getBlock();
        $dataHelper = Mage::helper('turpentine/data');
        $esiHelper = Mage::helper('turpentine/esi');
        $debugHelper = Mage::helper('turpentine/debug');
        if ($esiHelper->getEsiBlockLogEnabled()) {
            $debugHelper->logInfo(
                'Checking ESI block candidate: %s',
                $blockObject->getNameInLayout() ? $blockObject->getNameInLayout() : $blockObject->getModuleName() );

            $debugHelper->logInfo("-- block testing: shouldResponseUseEsi = ".$esiHelper->shouldResponseUseEsi());
            $debugHelper->logInfo("-- block testing: instanceof Mage_Core_Block_Template = ".$blockObject instanceof Mage_Core_Block_Template);
            $debugHelper->logInfo("-- block testing: Esi Options = ".print_r($blockObject->getEsiOptions(), true));
        }        
        if ($esiHelper->shouldResponseUseEsi() &&
                $blockObject instanceof Mage_Core_Block_Template &&
                $esiOptions = $blockObject->getEsiOptions()) {

            if ((isset($esiOptions['disableEsiInjection'])) && ($esiOptions['disableEsiInjection'] == 1)) { 
                if ($esiHelper->getEsiBlockLogEnabled()) {
                    $debugHelper->logInfo("-- ESI Injection disabled");
                }
                return;
            }

            if (Mage::app()->getStore()->getCode() == 'admin') {
                // admin blocks are not allowed to be cached for now
                $debugHelper->logWarn(
                    'Ignoring attempt to inject adminhtml block: %s',
                    $blockObject->getNameInLayout() ? $blockObject->getNameInLayout() : $blockObject->getModuleName() );
                return;
            } elseif ($esiHelper->getEsiBlockLogEnabled()) {
                $debugHelper->logInfo('Block check passed, injecting block: %s',
                    $blockObject->getNameInLayout() ? $blockObject->getNameInLayout() : $blockObject->getModuleName());
            }
            Varien_Profiler::start('turpentine::observer::esi::injectEsi');
            $ttlParam = $esiHelper->getEsiTtlParam();
            $cacheTypeParam = $esiHelper->getEsiCacheTypeParam();
            $dataParam = $esiHelper->getEsiDataParam();
            $methodParam = $esiHelper->getEsiMethodParam();
            $hmacParam = $esiHelper->getEsiHmacParam();
            $scopeParam = $esiHelper->getEsiScopeParam();
            $referrerParam = $esiHelper->getEsiReferrerParam();

            $esiOptions = $this->_getDefaultEsiOptions($esiOptions);

            // change the block's template to the stripped down ESI template
            switch ($esiOptions[$methodParam]) {
                case 'ajax':
                    $blockObject->setTemplate('turpentine/ajax.phtml');
                    break;

                case 'esi':
                default:
                    $blockObject->setTemplate('turpentine/esi.phtml');
                    // flag request for ESI processing
                    Mage::register('turpentine_esi_flag', true, true);
            }

            // esi data is the data needed to regenerate the ESI'd block
            $esiData = $this->_getEsiData($blockObject, $esiOptions)->toArray();
            ksort($esiData);
            $frozenData = $dataHelper->freeze($esiData);
            $urlOptions = array(
                $methodParam    => $esiOptions[$methodParam],
                $cacheTypeParam => $esiOptions[$cacheTypeParam],
                $ttlParam       => $esiOptions[$ttlParam],
                $hmacParam      => $dataHelper->getHmac($frozenData),
                $dataParam      => $frozenData,
            );
            if ($esiOptions[$methodParam] == 'ajax') {
                $urlOptions['_secure'] = Mage::app()->getStore()
                    ->isCurrentlySecure();
            }
            if ($esiOptions[$scopeParam] == 'page') {
                $urlOptions[$referrerParam] = Mage::helper('core')->urlEncode(
                    Mage::getUrl('*/*/*', array('_use_rewrite' => true, '_current' => true))
                );
            }

            /**
             * Keep params from original url
             */
            $urlOptions['_query'] = Mage::app()->getRequest()->getParams();
            
            $esiUrl = Mage::getUrl('turpentine/esi/getBlock', $urlOptions);
            if ($esiOptions[$methodParam] == 'esi') {
                // setting [web/unsecure/base_url] can be https://... but ESI can never be HTTPS
                $esiUrl = preg_replace('|^https://|i', 'http://', $esiUrl);
            }
            $blockObject->setEsiUrl($esiUrl);
            // avoid caching the ESI template output to prevent the double-esi-
            // include/"ESI processing not enabled" bug
            foreach (array('lifetime', 'tags', 'key') as $dataKey) {
                $blockObject->unsetData('cache_'.$dataKey);
            }
            if (strlen($esiUrl) > 2047) {
                Mage::helper('turpentine/debug')->logWarn(
                    'ESI url is probably too long (%d > 2047 characters): %s',
                    strlen($esiUrl), $esiUrl );
            }
            Varien_Profiler::stop('turpentine::observer::esi::injectEsi');
        } // else handle the block like normal and cache it inline with the page
    }
240816
function itemList( $asObject = true )
    {
        return eZPersistentObject::fetchObjectList( eZProductCollectionItem::definition(),
                                                    null, array( "productcollection_id" => $this->ID ),
                                                    null,
                                                    null,
                                                    $asObject );
    }
844674
private function setSubject($blockId): BaseBlock
    {
        /** @var BaseBlock $block */
        $block = $this->admin->getObject($blockId);
        if (!$block) {
            throw $this->createNotFoundException(sprintf('Unable to find block with id %d', $blockId));
        }
        $this->admin->setSubject($block);

        return $block;
    }
364020
private function getBlockModule(Tree $tree, int $block_id): ModuleBlockInterface
    {
        $active_blocks = $this->module_service->findByComponent(ModuleBlockInterface::class, $tree, Auth::user());

        $module_name = DB::table('block')
            ->where('block_id', '=', $block_id)
            ->value('module_name');

        $block = $active_blocks->first(static function (ModuleInterface $module) use ($module_name): bool {
            return $module->name() === $module_name;
        });

        if ($block === null) {
            throw new NotFoundHttpException('Block not found');
        }

        return $block;
    }
1352045
static function fetchFilteredList( $cond, $asObject = true, $status = eZRSSExport::STATUS_VALID )
    {
        return eZPersistentObject::fetchObjectList( eZRSSExportItem::definition(),
                                                    null, $cond, array( 'id' => 'asc',
                                                                        'status' => $status ), null,
                                                    $asObject );
    }
274701
protected function getBlockPageURL($blockName, $blockAction = '', $isBlockActionInstanceSpecific = false)
    {
        if (!isset($this->blockPageURLs[$blockName])) {
            $page = null;
            if ($blockName) {
                $block = Block::getByName($blockName);
                if ($block && $block->getBlockID()) {
                    $page = $block->getOriginalCollection();
                }
            }
            $this->blockPageURLs[$blockName] = [
                'foundBlockID' => ($page === null) ? null : $block->getBlockID(),
                'url' => (string) ($page ? URL::to($page) : URL::to('/')),
            ];
        }

        $url = $this->blockPageURLs[$blockName]['url'];
        if ($blockAction !== '' && $this->blockPageURLs[$blockName]['foundBlockID'] !== null) {
            $url = rtrim($url, '/') . '/' . trim($blockAction, '/');
            if ($isBlockActionInstanceSpecific) {
                $url .= '/' . $this->blockPageURLs[$blockName]['foundBlockID'];
            }
        }

        return $url;
    }
707494
static function validNodes( $blockID, $asObject = true )
    {
        if ( isset( $GLOBALS['eZFlowPool'] ) === false )
            $GLOBALS['eZFlowPool'] = array();

        if ( isset( $GLOBALS['eZFlowPool'][$blockID] ) )
            return $GLOBALS['eZFlowPool'][$blockID];

        $visibilitySQL = "";

        if ( eZINI::instance( 'site.ini' )->variable( 'SiteAccessSettings', 'ShowHiddenNodes' ) !== 'true' )
        {
            $visibilitySQL = "AND ezcontentobject_tree.is_invisible = 0 ";
        }

        $db = eZDB::instance();
        $validNodes = $db->arrayQuery( "SELECT ezm_pool.node_id
                                        FROM ezm_pool, ezcontentobject_tree, ezcontentobject
                                        WHERE ezm_pool.block_id='$blockID'
                                          AND ezm_pool.ts_visible>0
                                          AND ezm_pool.ts_hidden=0
                                          AND ezcontentobject_tree.node_id = ezm_pool.node_id
                                          AND ezcontentobject.id = ezm_pool.object_id
                                          AND " . eZContentLanguage::languagesSQLFilter( 'ezcontentobject' ) . "
                                          $visibilitySQL
                                        ORDER BY ezm_pool.priority DESC" );

        if ( $asObject && !empty( $validNodes ) )
        {
            $validNodesObjects = array();

            foreach( $validNodes as $node )
            {
                $validNodeObject = eZContentObjectTreeNode::fetch( $node['node_id'] );
                if ( $validNodeObject instanceof eZContentObjectTreeNode && $validNodeObject->canRead() )
                    $validNodesObjects[] = $validNodeObject;
            }

            $GLOBALS['eZFlowPool'][$blockID] = $validNodesObjects;

            return $validNodesObjects;
        }
        else
        {
            return $validNodes;
        }
    }
670910
function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
    {
        $page = $contentObjectAttribute->content();
        $blockINI = eZINI::instance( 'block.ini' );

        if ( $http->hasPostVariable( $base . '_ezpage_block_fetch_param_' . $contentObjectAttribute->attribute( 'id' ) ) )
        {
            $blockFetchParams = $http->postVariable( $base . '_ezpage_block_fetch_param_' . $contentObjectAttribute->attribute( 'id' ) );

            foreach ( $blockFetchParams as $zoneID => $blocks )
            {
                $zone = $page->getZone( $zoneID );

                foreach ( $blocks as $blockID => $params )
                {
                    $block = $zone->getBlock( $blockID );
                    $fetchParams = array();

                    $fetchParams = unserialize( $block->attribute( 'fetch_params' ) );
                    $tmpFetchParams = $fetchParams;

                    foreach ( $params as $param => $value )
                    {
                        $fetchParams[$param] = $value;
                    }

                    $block->setAttribute( 'fetch_params', serialize( $fetchParams ) );

                    if ( $fetchParams !== $tmpFetchParams )
                    {
                        $persBlockObject = eZFlowBlock::fetch( $block->attribute( 'id' ) );

                        if ( $persBlockObject instanceof eZFlowBlock )
                        {
                            $persBlockObject->setAttribute( 'last_update', 0 );
                            $persBlockObject->store();
                        }
                    }
                }
            }
        }

        if ( $http->hasPostVariable( $base . '_ezpage_block_custom_attribute_' . $contentObjectAttribute->attribute( 'id' ) ) )
        {
            $blockCustomAttributes = $http->postVariable( $base . '_ezpage_block_custom_attribute_' . $contentObjectAttribute->attribute( 'id' ) );

            foreach ( $blockCustomAttributes as $zoneID => $blocks )
            {
                $zone = $page->getZone( $zoneID );

                foreach ( $blocks as $blockID => $params )
                {
                    $block = $zone->getBlock( $blockID );

                    $customAttributes = $block->attribute( 'custom_attributes' );

                    foreach ( $params as $param => $value )
                    {
                        $customAttributes[$param] = $value;
                    }

                    $block->setAttribute( 'custom_attributes', $customAttributes );
                }
            }
        }

        if ( $http->hasPostVariable( $base . '_ezpage_block_view_' . $contentObjectAttribute->attribute( 'id' ) ) )
        {

            $blockViewArray = $http->postVariable( $base . '_ezpage_block_view_' . $contentObjectAttribute->attribute( 'id' ) );

            foreach ( $blockViewArray as $zoneID => $blocks )
            {
                $zone = $page->getZone( $zoneID );

                foreach ( $blocks as $blockID => $view )
                {
                    $block = $zone->getBlock( $blockID );
                    $block->setAttribute( 'view', $view );

                }
            }
        }

        if ( $http->hasPostVariable( $base . '_ezpage_block_overflow_' . $contentObjectAttribute->attribute( 'id' ) ) )
        {
            $blockOverflowArray = $http->postVariable( $base . '_ezpage_block_overflow_' . $contentObjectAttribute->attribute( 'id' ) );

            foreach ( $blockOverflowArray as $zoneID => $blocks )
            {
                $zone = $page->getZone( $zoneID );

                foreach ( $blocks as $blockID => $overflowBlockID )
                {
                    $block = $zone->getBlock( $blockID );
                    $block->setAttribute( 'overflow_id', $overflowBlockID );
                }
            }

        }

        if ( $http->hasPostVariable( $base . '_ezpage_block_name_array_' . $contentObjectAttribute->attribute( 'id' ) ) )
        {
            $blockNameArray = $http->postVariable( $base . '_ezpage_block_name_array_' . $contentObjectAttribute->attribute( 'id' ) );

            foreach ( $blockNameArray as $zoneID => $blocks )
            {
                $zone = $page->getZone( $zoneID );

                foreach ( $blocks as $blockID => $blockName )
                {
                    $block = $zone->getBlock( $blockID );
                    $block->setAttribute( 'name', $blockName );
                }
            }

        }

        if ( $http->hasPostVariable( $base . '_ezpage_item_ts_published_value_' . $contentObjectAttribute->attribute( 'id' ) ) )
        {
            $itemTSPublishedValueArray = $http->postVariable( $base . '_ezpage_item_ts_published_value_' . $contentObjectAttribute->attribute( 'id' ) );

            foreach ( $itemTSPublishedValueArray as $zoneID => $blocks )
            {
                $zone = $page->getZone( $zoneID );

                foreach ( $blocks as $blockID => $itemTSPublishedValueIDs )
                {
                    $block = $zone->getBlock( $blockID );

                    if ( $block->getItemCount() > 0 )
                    {
                        $items = $block->attribute( 'items' );

                        foreach ( $items as $index => $item )
                        {
                            foreach ( $itemTSPublishedValueIDs as $objectID => $value )
                            {
                                if ( $value != '' )
                                {
                                    if ( $item->attribute( 'object_id' ) == $objectID )
                                    {
                                        $item->setAttribute( 'ts_publication', $value );
                                        unset( $itemTSPublishedValueIDs[$objectID] );
                                    }
                                }
                            }
                        }
                    }

                    foreach ( $itemTSPublishedValueIDs as $objectID => $value )
                    {
                        if ( $value != '' )
                        {
                            $item = $block->addItem( new eZPageBlockItem() );
                            $item->setAttribute( 'action', 'modify' );
                            $item->setAttribute( 'object_id', $objectID );
                            $item->setAttribute( 'ts_publication', $value );
                        }
                    }
                }

            }
        }

        $contentObjectAttribute->setContent( $page );

        return true;
    }