作者:novate
项目:SonataMediaBundl
/**
* {@inheritdoc}
*/
public function execute(BlockInterface $block, Response $response = null)
{
// merge settings
$settings = array_merge($this->getDefaultSettings(), $block->getSettings());
$media = $settings['mediaId'];
return $this->renderResponse('SonataMediaBundle:Block:block_feature_media.html.twig', array('media' => $media, 'block' => $block, 'settings' => $settings), $response);
}
作者:serialke
项目:BugTracke
/**
* {@inheritdoc}
*/
public function buildEditForm(FormMapper $formMapper, BlockInterface $block)
{
$contextChoices = $this->getContextChoices();
$formatChoices = $this->getFormatChoices($block->getSetting('mediaId'));
$translator = $this->container->get('translator');
$formMapper->add('settings', 'sonata_type_immutable_array', array('keys' => array(array('title', 'text', array('required' => false)), array('content', 'textarea', array('required' => false)), array('orientation', 'choice', array('choices' => array('left' => $translator->trans('feature_left_choice', array(), 'SonataMediaBundle'), 'right' => $translator->trans('feature_right_choice', array(), 'SonataMediaBundle')))), array('context', 'choice', array('required' => true, 'choices' => $contextChoices)), array('format', 'choice', array('required' => count($formatChoices) > 0, 'choices' => $formatChoices)), array($this->getMediaBuilder($formMapper), null, array()))));
}
作者:r1pp3rj4c
项目:SonataBlockBundl
/**
* {@inheritdoc}
*/
public function render(BlockInterface $block, Response $response = null)
{
if ($this->logger) {
$this->logger->info(sprintf('[cms::renderBlock] block.id=%d, block.type=%s ', $block->getId(), $block->getType()));
}
try {
$service = $this->blockServiceManager->get($block);
$service->load($block);
// load the block
$response = $service->execute($block, $response);
if (!$response instanceof Response) {
throw new \RuntimeException('A block service must return a Response object');
}
} catch (\Exception $e) {
if ($this->logger) {
$this->logger->crit(sprintf('[cms::renderBlock] block.id=%d - error while rendering block - %s', $block->getId(), $e->getMessage()));
}
if ($this->debug) {
throw $e;
}
$response = new Response();
$response->setPrivate();
}
return $response;
}
作者:bruer
项目:platfor
/**
* {@inheritdoc}
*/
public function load(BlockInterface $block)
{
$userManager = $this->container->get('fos_user.user_manager');
$settings = $block->getSettings();
$userRegistrations = $userManager->fetchRegistrationCount(isset($settings['fetchCountRecord']) ? $settings['fetchCountRecord'] : 5);
$block->setSetting('userRegistrations', $userRegistrations);
}
作者:karous
项目:SonataBlockBundl
/**
* {@inheritdoc}
*/
public function validateBlock(ErrorElement $errorElement, BlockInterface $block)
{
if (($name = $block->getSetting('menu_name')) && $name !== '' && !$this->menuProvider->has($name)) {
// If we specified a menu_name, check that it exists
$errorElement->with('menu_name')->addViolation('sonata.block.menu.not_existing', array('name' => $name))->end();
}
}
作者:sonata-projec
项目:SonataDashboardBundl
/**
* {@inheritdoc}
*/
public function addChildren(BlockInterface $child)
{
$this->children[] = $child;
$child->setParent($this);
if ($child instanceof DashboardBlockInterface) {
$child->setDashboard($this->getDashboard());
}
}
作者:r1pp3rj4c
项目:SonataDoctrineORMAdminBundl
/**
* {@inheritdoc}
*/
public function execute(BlockInterface $block, Response $response = null)
{
$settings = array_merge($this->getDefaultSettings(), $block->getSettings());
$revisions = array();
foreach ($this->auditReader->findRevisionHistory($settings['limit'], 0) as $revision) {
$revisions[] = array('revision' => $revision, 'entities' => $this->auditReader->findEntitesChangedAtRevision($revision->getRev()));
}
return $this->renderResponse('SonataDoctrineORMAdminBundle:Block:block_audit.html.twig', array('block' => $block, 'settings' => $settings, 'revisions' => $revisions), $response);
}
作者:selfclos
项目:dos-cernel-bundl
/**
* {@inheritdoc}
*/
public function addChild(BlockInterface $child, $key = null)
{
$child->setParent($this);
if ($key != null) {
$this->children->set($key, $child);
return true;
}
return $this->children->add($child);
}
作者:khasinsk
项目:Iph
/**
* {@inheritdoc}
*/
public function execute(BlockInterface $block, Response $response = null)
{
$settings = array_merge($this->getDefaultSettings(), $block->getSettings());
$response = $this->renderResponse('IphpCoreBundle:Block:block_container.html.twig', array('container' => $block, 'settings' => $settings), $response);
//$response->setContent('Контент контейнера'
/*Mustache::replace($settings['layout'], array(
'CONTENT' => $response->getContent()
))*/
//);
return $response;
}
作者:natxe
项目:SonataAdminBundl
/**
* {@inheritdoc}
*/
public function execute(BlockInterface $block, Response $response = null)
{
$settings = array_merge($this->getDefaultSettings(), $block->getSettings());
$dashboardGroups = $this->pool->getDashboardGroups();
$visibleGroups = array();
foreach ($dashboardGroups as $name => $dashboardGroup) {
if (!$settings['groups'] || in_array($name, $settings['groups'])) {
$visibleGroups[] = $dashboardGroup;
}
}
return $this->renderResponse($this->pool->getTemplate('list_block'), array('block' => $block, 'settings' => $settings, 'admin_pool' => $this->pool, 'groups' => $visibleGroups), $response);
}
作者:r1pp3rj4c
项目:SonataBlockBundl
/**
* {@inheritdoc}
*/
public function execute(BlockInterface $block, Response $response = null)
{
$parameters = (array) json_decode($block->getSetting('parameters'), true);
$parameters = array_merge($parameters, array('_block' => $block));
$settings = array_merge($this->getDefaultSettings(), (array) $block->getSettings());
try {
$actionContent = $this->kernel->render($settings['action'], $parameters);
} catch (\Exception $e) {
throw $e;
}
$content = self::mustache($block->getSetting('layout'), array('CONTENT' => $actionContent));
return $this->renderResponse('SonataBlockBundle:Block:block_core_action.html.twig', array('content' => $content, 'block' => $block), $response);
}
作者:bruer
项目:platfor
/**
* {@inheritdoc}
*/
public function buildEditForm(FormMapper $formMapper, BlockInterface $block)
{
if (!$block->getSetting('mediaId') instanceof MediaInterface) {
$this->load($block);
}
$formatChoices = $this->getFormatChoices($block->getSetting('mediaId'));
$keys[] = array('title', 'text', array('required' => false));
$keys[] = array($this->getMediaBuilder($formMapper), null, array());
$keys[] = array('format', 'choice', array('required' => count($formatChoices) > 0, 'choices' => $formatChoices));
if ($this->getTemplates()) {
$keys[] = array('template', 'choice', array('choices' => $this->getTemplates()));
}
$formMapper->add('settings', 'sonata_type_immutable_array', array('keys' => $keys, 'attr' => array('class' => 'bruery-immutable-container')));
}
作者:bruer
项目:platfor
/**
* {@inheritdoc}
*/
public function load(BlockInterface $block)
{
$gender = $this->manager->fetchGenderCount();
$genderChart = [];
$genderList = [];
foreach ($gender as $data) {
switch ($data['gender']) {
case 'u':
$genderList[] = ['gender' => $this->translator->trans('gender_unknown', [], 'SonataUserBundle'), 'total' => $data['total']];
$genderChart[$this->translator->trans('gender_unknown', [], 'SonataUserBundle')] = array($data['total']);
break;
case 'm':
$genderList[] = ['gender' => $this->translator->trans('gender_male', [], 'SonataUserBundle'), 'total' => $data['total']];
$genderChart[$this->translator->trans('gender_male', [], 'SonataUserBundle')] = array($data['total']);
break;
case 'f':
$genderList[] = ['gender' => $this->translator->trans('gender_female', [], 'SonataUserBundle'), 'total' => $data['total']];
$genderChart[$this->translator->trans('gender_female', [], 'SonataUserBundle')] = array($data['total']);
break;
}
}
$totalGender = $this->manager->fetchGenderCountTotal();
$block->setSetting('genderList', $genderList);
$block->setSetting('genderChart', json_encode($genderChart));
$block->setSetting('genderTotal', $totalGender);
}
作者:bruer
项目:platfor
/**
* {@inheritdoc}
*/
public function load(BlockInterface $block)
{
$ageBrackets = $this->collectionManager->findByContext($this->context);
$ageBracket = $this->manager->fetchAgeBracketCount();
$dataAgeBracketList = [];
$dataAgeBracketChart = [];
$dataAgeBracketBar = [];
//PieChart Data & List Data
foreach ($ageBrackets as $idx => $bracket) {
$dataAgeBracketChart[$bracket->getName()] = array(0);
$dataAgeBracketList[$idx] = ['age' => $bracket->getName(), 'total' => 0];
foreach ($ageBracket as $age) {
if ($bracket->getName() == $age['name']) {
$dataAgeBracketChart[$bracket->getName()] = array($age['ageBracketCount']);
$dataAgeBracketList[$idx] = ['age' => $bracket->getName(), 'total' => $age['ageBracketCount']];
}
}
}
$ageByGender = $this->manager->fetchAgeBracketCountByGender();
//LineGraph Data
$ageX = [];
$ageU = [];
$ageF = [];
$ageM = [];
foreach ($ageBrackets as $idx => $bracket) {
$ageX[$idx] = $bracket->getName();
$ageU[$idx] = "0";
$ageM[$idx] = "0";
$ageF[$idx] = "0";
foreach ($ageByGender as $age) {
if ($bracket->getName() == $age['name']) {
switch ($age['gender']) {
case 'u':
$ageU[$idx] = $age['ageBracketCount'];
break;
case 'm':
$ageM[$idx] = $age['ageBracketCount'];
break;
case 'f':
$ageF[$idx] = $age['ageBracketCount'];
break;
}
}
}
}
$dataAgeBracketBar['x'] = $ageX;
$dataAgeBracketBar['dataU'] = $ageU;
$dataAgeBracketBar['dataM'] = $ageM;
$dataAgeBracketBar['dataF'] = $ageF;
$ageBracketTotal = $this->manager->fetchAgeBracketCountTotal();
$block->setSetting('ageBracketList', $dataAgeBracketList);
$block->setSetting('ageBracketBar', json_encode($dataAgeBracketBar));
$block->setSetting('ageBracketChart', json_encode($dataAgeBracketChart));
$block->setSetting('ageBracketTotal', $ageBracketTotal);
}
作者:Neodor
项目:SonataPageBundl
/**
* @param BlockInterface $block
* @param OutputInterface $output
* @param bool $extended
* @param int $space
*/
public function renderBlock(BlockInterface $block, OutputInterface $output, $extended, $space = 0)
{
$output->writeln(sprintf('%s <comment>> Id: %d - type: %s - name: %s</comment>', str_repeat(' ', $space), $block->getId(), $block->getType(), $block->getName()));
if ($extended) {
$output->writeln(sprintf('%s page class: <comment>%s</comment>', str_repeat(' ', $space + 1), get_class($block->getPage())));
foreach ($block->getSettings() as $name => $value) {
$output->writeln(sprintf('%s %s: %s', str_repeat(' ', $space + 1), $name, var_export($value, 1)));
}
}
foreach ($block->getChildren() as $block) {
$this->renderBlock($block, $output, $extended, $space + 1);
}
}
作者:r1pp3rj4c
项目:SonataBlockBundl
/**
* {@inheritdoc}
*/
public function execute(BlockInterface $block, Response $response = null)
{
// merge settings
$settings = array_merge($this->getDefaultSettings(), $block->getSettings());
$feeds = false;
if ($settings['url']) {
$options = array('http' => array('user_agent' => 'Sonata/RSS Reader', 'timeout' => 2));
// retrieve contents with a specific stream context to avoid php errors
$content = @file_get_contents($settings['url'], false, stream_context_create($options));
if ($content) {
// generate a simple xml element
try {
$feeds = new \SimpleXMLElement($content);
$feeds = $feeds->channel->item;
} catch (\Exception $e) {
// silently fail error
}
}
}
return $this->renderResponse('SonataBlockBundle:Block:block_core_rss.html.twig', array('feeds' => $feeds, 'block' => $block, 'settings' => $settings), $response);
}
作者:nvbooste
项目:StarterBundl
/**
* @param BlockInterface $block
* @param array $attributes
* @param string $prefix
*
* @return string
*/
public function renderAttributes(BlockInterface $block = null, $attributes = array(), $prefix = 'attr')
{
if ($attributes && is_string($attributes)) {
$prefix = $attributes;
$attributes = array();
}
if ($block) {
foreach ($block->getSettings() as $key => $value) {
$key = trim(mb_strtolower($key, 'utf8'));
$match = null;
if (preg_match('@^' . preg_quote($prefix) . '-([a-z][-a-z0-9]*)$@', $key, $match)) {
$attributes[$match[1]] = $value;
}
}
}
$attributesString = '';
foreach ($attributes as $key => $value) {
$key = trim(mb_strtolower($key, 'utf8'));
if (preg_match('@^[a-z][-a-z0-9]*$@', $key)) {
$attributesString .= $key . '="' . addslashes($value) . '" ';
}
}
return trim($attributesString);
}
作者:rederri
项目:SonataBlockBundl
/**
* @param BlockInterface $block
* @param array $stats
*/
protected function stopTracing(BlockInterface $block, array $stats)
{
$e = $this->traces[$block->getId()]->stop();
$this->traces[$block->getId()] = array_merge($stats, array('duration' => $e->getDuration(), 'memory_end' => memory_get_usage(true), 'memory_peak' => memory_get_peak_usage(true)));
$this->traces[$block->getId()]['cache']['lifetime'] = $this->traces[$block->getId()]['cache']['age'] + $this->traces[$block->getId()]['cache']['ttl'];
}
作者:r1pp3rj4c
项目:SonataBlockBundl
/**
* @param \Sonata\BlockBundle\Model\BlockInterface $block
* @return \Sonata\CacheBundle\Cache\CacheInterface;
*/
protected function getCacheService(BlockInterface $block)
{
$type = isset($this->cacheBlocks[$block->getType()]) ? $this->cacheBlocks[$block->getType()] : false;
if (!$type) {
return false;
}
return $this->cacheManager->getCacheService($type);
}
作者:saberyouni
项目:Sonata-Projec
/**
* {@inheritdoc}
*/
public function preUpdate(BlockInterface $block)
{
$block->setSetting('galleryId', is_object($block->getSetting('galleryId')) ? $block->getSetting('galleryId')->getId() : null);
}