Get average block info

@param string $block - key to identify block

@return mixed - associative array
@throws \Exception
428432
public function getAvg($block)
    {
        if ($this->enabled) {
            if (!array_key_exists($block, $this->avgs)) {
                throw new \Exception('Average block '.$block.' not defined');
            }

            $this->finishAvgBlock($block);

            return $this->avgs[$block];
        }
    }
707743
protected function _patchEntity($block)
    {
        $this->loadModel('Block.Blocks');
        $data = ['region' => []];

        foreach ($this->request->data() as $column => $value) {
            if ($column == 'region') {
                foreach ($value as $theme => $region) {
                    $tmp = ['theme' => $theme, 'region' => $region];
                    foreach ((array)$block->region as $blockRegion) {
                        if ($blockRegion->theme == $theme) {
                            $tmp['id'] = $blockRegion->id;
                            break;
                        }
                    }
                    $data[$column][] = $tmp;
                }
            } else {
                $data[$column] = $value;
            }
        }

        if ($block->isNew()) {
            $data['handler'] = 'Block\Widget\CustomBlockWidget';
            $block->set('handler', 'Block\Widget\CustomBlockWidget');
        }

        $validator = $block->isCustom() ? 'custom' : 'widget';

        return $this->Blocks->patchEntity($block, $data, ['validate' => $validator, 'entity' => $block]);
    }
942542
public function getBlockError($blockName)
    {
        if (array_key_exists($blockName, $this->blockErrors)) {
            return $this->blockErrors[$blockName];
        }

        return null;
    }
1033703
public function get($block = false)
    {
        if ($this->block != $block) {
            $this->pipe->setBlock($block);
            $this->block = $block;
        }
        $len = $this->pipe->read(4);
        if ($len === false) {
            throw new \RuntimeException('read pipe failed');
        }

        if (strlen($len) === 0) {
            return null;
        }
        $len = unpack('N', $len);
        if (empty($len) || !array_key_exists(1, $len) || empty($len[1])) {
            throw new \RuntimeException('data protocol error');
        }
        $len = intval($len[1]);

        $value = '';
        while (true) {
            $temp = $this->pipe->read($len);
            if (strlen($temp) == $len) {
                return $temp;
            }
            $value .= $temp;
            $len -= strlen($temp);
            if ($len == 0) {
                return $value;
            }
        }
    }
592639
protected function getNodes(ReadBlockInterface $block)
    {
        $nodes = null;
        $nodeName = $block->getAttribute('nodeName');
        $siteId = $this->currentSiteManager->getSiteId();

        if (!is_null($nodeName)) {
            $nodes = $this->nodeRepository->getSubMenu($nodeName, $block->getAttribute('nbLevel'), $this->request->getLocale(), $siteId);
            $nodes = $this->getGrantedNodes($nodes);
        }

        return $nodes;
    }
367298
protected function getDailymotionParameters(ReadBlockInterface $block)
    {
        $urlParams = array();

        foreach (array('dailymotionAutoplay', 'dailymotionChromeless') as $key) {
            if ($block->getAttribute($key) === true) {
                $urlParams[strtolower(substr($key, 11))] = 1;
            }
        }
        foreach (array('dailymotionLogo', 'dailymotionInfo', 'dailymotionRelated') as $key) {
            if ($block->getAttribute($key) === false) {
                $urlParams[strtolower(substr($key, 11))] = 0;
            }
        }
        foreach (array('dailymotionBackground', 'dailymotionForeground', 'dailymotionHighlight', 'dailymotionQuality') as $key) {
            if ($block->getAttribute($key) !== '') {
                $urlParams[strtolower(substr($key, 11))] = $block->getAttribute($key);
            }
        }

        $url = "//www.dailymotion.com/embed/video/" . $block->getAttribute('dailymotionVideoId') . "?" . http_build_query($urlParams);

        return array(
            'url' => $url,
            'width' => $block->getAttribute('dailymotionWidth'),
            'height' => $block->getAttribute('dailymotionHeight')
        );
    }
99117
public function getViewParameters(BlockInterface $block)
    {
        $authErrorKey = Security::AUTHENTICATION_ERROR;
        $lastUsernameKey = Security::LAST_USERNAME;

        // get the error if any (works with forward and redirect -- see below)
        if ($this->getRequest()->attributes->has($authErrorKey)) {
            $error = $this->getRequest()->attributes->get($authErrorKey);
        } elseif (null !== $this->session && $this->session->has($authErrorKey)) {
            $error = $this->session->get($authErrorKey);
            $this->session->remove($authErrorKey);
        } else {
            $error = null;
        }

        if (!$error instanceof AuthenticationException) {
            $error = null; // The value does not come from the security component.
        }

        // last username entered by the user
        $lastUsername = (null === $this->session) ? '' : $this->session->get($lastUsernameKey);
        $csrfToken = $this->csrfTokenManager->getToken('authenticate')->getValue();
        $parameters = [
            'block_service' => $this,
            'block' => $block,
            'last_username' => $lastUsername,
            'error' => $error,
            'csrf_token' => $csrfToken
        ];

        return $parameters;
    }
797306
public function getBlock($key)
    {
        if (($find = $this->searchBlock($key)) !== null) {
            return $find;
        }

        throw new \Exception(htmlspecialchars("The block $key does not exist."));
    }
645660
public function getBlock($pBlock, array $pVars = array())
	{
		if (! preg_match('#^([a-z0-9]+)/([a-z0-9_-]+)$#', $pBlock, $blockPathInfos)
			or ! isset($blockPathInfos[1])
			or ! isset($blockPathInfos[2])) {
			throw new Exception("Block identifier '$pBlock' is not correct");
		}

        $this->_blocks[] = array(
        	'group' => $blockPathInfos[1],
        	'block' => $blockPathInfos[2]
        );

        $blockConfig = Agl::app()->getConfig('core-layout/blocks/' . $blockPathInfos[1] . '#' . $blockPathInfos[2]);
        if ($blockConfig === NULL) {
        	$blockConfig = array();
        }

		if (! BlockAbstract::checkAcl($blockPathInfos[1], $blockPathInfos[2])) {
			return '';
		}

		$isCacheEnabled = Agl::app()->isCacheEnabled();

		if ($isCacheEnabled) {
			$cacheInfo = BlockAbstract::getCacheInfo($blockPathInfos, $blockConfig);

			if (! empty($cacheInfo)
				and $cacheInstance = Agl::getCache()
				and $cacheInstance->has($cacheInfo[CacheInterface::CACHE_KEY])) {
				return $cacheInstance->get($cacheInfo[CacheInterface::CACHE_KEY]);
			}
		}

		$blockPath = APP_PATH
					. Agl::APP_PHP_DIR
                    . BlockInterface::APP_PHP_DIR
                    . DS
                    . $blockPathInfos[1]
                    . DS
                    . $blockPathInfos[2]
                    . Agl::PHP_EXT;

        if (file_exists($blockPath)) {
            $className = $blockPathInfos[1] . ucfirst($blockPathInfos[2]) . BlockInterface::APP_SUFFIX;
            $blockModel = Agl::getInstance($className);
        } else {
            $blockModel = new Block();
        }

        ob_start();

        $blockModel
			->setFile($blockPathInfos[1] . DS . $blockPathInfos[2] . Agl::PHP_EXT)
			->setVars($pVars)
			->render();

		$content = ob_get_clean();

		if ($isCacheEnabled and ! empty($cacheInfo)) {
        	$cacheInstance->set($cacheInfo[CacheInterface::CACHE_KEY], $content, $cacheInfo[ConfigInterface::CONFIG_CACHE_TTL_NAME]);
		}

		return $content;
	}
851517
public function startAvg($block)
    {
        if ($this->enabled) {
            if (!isset($this->avgs[$block])) {
                $this->avgs[$block] = array();
                $this->avgs[$block]['count'] = 0;
                $this->avgs[$block]['total'] = 0;
            }

            $this->avgs[$block]['start'] = microtime(true);
            if (!isset($this->avgs[$block]['start-line'])) {
                $this->avgs[$block]['start-line'] = $this->getLineNumber();
            }

            // Initialise max and min time
            if (!isset($this->avgs[$block]['max-time'])) {
                $this->avgs[$block]['max-time'] = 0;
            }
            if (!isset($this->avgs[$block]['min-time'])) {
                $this->avgs[$block]['min-time'] = 9999;
            }
        }
    }
223479
public function transform($block)
    {
        $block = $this->entityToArray(Block::class, $block);
        return [
            'id'          => $this->setNullableValue($block['id']),
            'type'        => $block['type'],
            'region'      => $block['region'],
            'filter'      => $block['filter'],
            'options'     => $block['options'],
            'theme'       => $block['theme'],
            'weight'      => (int) $block['weight'],
            'isActive'    => (bool) $block['is_active'],
            'isCacheable' => (bool) $block['is_cacheable'],
            'createdAt'   => $block['created_at'],
            'updatedAt'   => $block['updated_at']
        ];
    }
1330855
public function getValidBlockItems(Block $block)
    {
        $dbHandler = $this->getConnection();
        $q = $dbHandler->createSelectQuery();
        $q
            ->select('object_id, ezm_pool.node_id, ezm_pool.priority, ts_publication, ts_visible, rotation_until, moved_to')
            ->from($dbHandler->quoteTable('ezm_pool'))
            ->innerJoin(
                $dbHandler->quoteTable('ezcontentobject_tree'),
                $q->expr->eq('ezcontentobject_tree.node_id', 'ezm_pool.node_id')
            )
            ->where(
                $q->expr->eq('block_id', $q->bindValue($block->id)),
                $q->expr->gt('ts_visible', $q->bindValue(0, null, PDO::PARAM_INT)),
                $q->expr->eq('ts_hidden', $q->bindValue(0, null, PDO::PARAM_INT))
            )
            ->orderBy('priority', SelectQuery::DESC);

        $stmt = $q->prepare();
        $stmt->execute();
        $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
        $items = array();
        foreach ($rows as $row) {
            $items[] = $this->buildBlockItem(
                $row + array(
                    'block_id' => $block->id,
                    'ts_hidden' => 0,
                )
            );
        }

        return $items;
    }
642885
public function parse_docblock(string $block){
    $b = [
			'description' => '',
			'tags' => []
		];
    // Remove start pattern
    //$block = trim(substr($block, 3));
		// Remove end pattern
		$block = trim(substr($block, 0, strlen($block) - 2));
		// Tags
    $tags = $this->get_tags($block);
    foreach ( $tags as $i => $tag ){
			if (
				(
					isset($tags[$i+1]) &&
					($t = $this->parse_tag(substr($block, $tag[1], $tags[$i+1][1] - $tag[1])))
        ) ||
				($t = $this->parse_tag(substr($block, $tag[1])))
			){
				$b['tags'][] = $t;
			}
    }
    // Get Description
    $b['description'] = $this->clear_text(isset($tags[0]) ? substr($block, 3, $tags[0][1]-1) : substr($block, 3));
    return $b;
  }
429093
function group( $blockName )
    {
        if ( !isset( $this->BlockValues[$blockName] ) )
        {
            eZDebug::writeError( "Unknown group: '$blockName'", __METHOD__ );
            $ret = null;
            return $ret;
        }
        if ( isset( self::$injectedSettings[$this->FileName][$blockName] ) )
        {
            $ret = array_merge(
                $this->BlockValues[$blockName],
                self::$injectedSettings[$this->FileName][$blockName]
            );
        }
        else
        {
            $ret = $this->BlockValues[$blockName];
        }

        return $ret;
    }
356597
public function getCacheKeys(BlockInterface $block)
    {
        $settings = $block->getSettings();

        $keys = parent::getCacheKeys($block);

        $keys['environment'] = $this->getContainer()->get('kernel')->getEnvironment();

        if (isset($settings['template'])) {
            $keys['template'] = $settings['template'];
        }

        if (isset($settings['id'])) {
            $key = $this->getName() . ':' . $settings['id'];

            if (isset($settings['template'])) {
                $key = $key . ':' . $settings['template'];
            }

            $keys['block_id'] = $key;
        }

        $keys['updated_at'] = '';

        return $keys;
    }
393868
private function extractField($blocks)
    {
        $fieldData = array();

        $pattern = "/([a-zA-Z]+) *(.+)/";

        foreach ($blocks as $block) {
            $match = preg_match($pattern, $block, $matches);

            // A full double string match found
            if (count($matches) == 3) {
                $docLabel = trim(strtolower($matches[1]));
                $docValue = trim($matches[2]);

                if (in_array($docLabel, self::$VALID_EXPRESSIONS)) {
                    $fieldData[self::$VALID_EXPRESSIONS_NAMES[$docLabel]] = $docValue;
                }
            }
        }

        return $fieldData;
    }
917389
public static function parseDocCommentDetail($block)
    {
        $comment = strtr(trim(preg_replace('/^\s*\**( |\t)?/m', '', trim($block, '/'))), "\r", '');
        if (preg_match('/^\s*@\w+/m', $comment, $matches, PREG_OFFSET_CAPTURE)) {
            $comment = trim(substr($comment, 0, $matches[0][1]));
        }

        if (empty($comment)) {
            return '';
        }

        $summary = self::parseDocCommentSummary($block);
        $pos = strpos($comment, $summary);
        if ($pos !== false) {
            $comment = trim(substr_replace($comment, '', $pos, strlen($summary)));
        }

        return $comment;
    }