/** * {@inheritdoc} */ public function initBlock() { $currentUserId = \Magelight\Http\Session::getInstance()->get('user_id', false); if ($currentUserId && ($userData = \Magelight\Auth\Models\User::find($currentUserId)->asArray())) { $this->set('user_id', $currentUserId); $this->set('user_data', $userData); } return parent::initBlock(); }
/** * {@inheritdoc} */ public function initBlock() { $this->sectionAppend('top', Top::forge()); $document = \Magelight\Core\Blocks\Document::getInstance(); $document->addMeta(['http-equiv' => "content-type", 'content' => "text/html; charset=utf-8"]); $document->addMeta(['name' => 'keywords', 'content' => 'welcome app, magelight']); $document->addCss('Magelight/Core/static/css/bootstrap.min.css'); $document->addCss('Magelight/Core/static/css/core.css'); $document->addJs('Magelight/Core/static/js/jquery.js'); $document->addJs('Magelight/Core/static/js/bootstrap.min.js'); return parent::initBlock(); }
/** * {@inheritdoc} */ public function initBlock() { $currentUserId = \Magelight\Http\Session::getInstance()->get('user_id'); if (!empty($currentUserId)) { if ($user = \Magelight\Auth\Models\User::find($currentUserId)) { $userData = $user->asArray(); $this->setGlobal('user_data', $userData); } } $document = \Magelight\Core\Blocks\Document::getInstance(); $document->addMeta(['http-equiv' => "content-type", 'content' => "text/html; charset=utf-8"]); $document->addCss('Magelight/Core/static/css/bootstrap.css'); $document->addCss('Magelight/Core/static/css/hint.css'); $document->addJs('Magelight/Core/static/js/jquery.js'); $document->addJs('Magelight/Core/static/js/bootstrap.min.js'); return parent::initBlock(); }
/** * Render element to html * * @return string */ public function toHtml() { if (!empty($this->template)) { return parent::toHtml(); } $this->beforeToHtml(); $html = '<' . $this->tag . ' ' . $this->renderAttributes(); if ($this->empty) { $html .= ' />'; return $html; } else { $html .= '>'; } foreach ($this->content as $content) { if ($content instanceof \Magelight\Block) { $html .= $content->toHtml(); } elseif (is_string($content)) { $html .= $content; } } $html .= '</' . $this->tag . '>'; $this->afterToHtml(); return $html; }
public function testTruncatePreserveWords() { $text = 'Lorem ipsum dolor sit amet'; $this->assertEquals('Lorem ipsum dolor...', \Magelight\Block::forge()->truncatePreserveWords($text, 13, '...')); }
public function testRenderView() { $blockMock = $this->getMock(\Magelight\Block::class, [], [], '', false); \Magelight\Block::forgeMock($blockMock); $this->controller->setView(\Magelight\Block::class); $this->controller->init(); $blockMock->expects($this->once())->method('toHtml')->will($this->returnValue('HTML OUTPUT')); $this->responseMock->expects($this->once())->method('setContent')->will($this->returnSelf()); $this->responseMock->expects($this->once())->method('send'); $this->assertEquals($this->controller, $this->controller->renderView()); }
/** * Append section * * @param string $name - section name * @param \Magelight\Block|string $block * @return Block */ public function sectionAppend($name, $block) { if ($block instanceof \Magelight\Block) { $block->init(); } if (!isset(self::$sections[$name]) || !is_array(self::$sections[$name])) { return $this->sectionReplace($name, $block); } self::$sections[$name][] = $block; return $this; }
/** * {@inheritdoc} */ public function beforeToHtml() { $this->tableFields = $this->scaffold->getEntityFields($this->entity); return parent::beforeToHtml(); }
/** * @return string * @throws \Magelight\Exception */ public function toHtml() { if (!empty($this->template)) { return parent::toHtml(); } $this->init(); $this->beforeToHtml(); ob_start(); echo '<!DOCTYPE ' . $this->doctype . '>' . $this->getRootElement()->toHtml(); $this->afterToHtml(); $html = ob_get_clean(); return $html; }
/** * Initialize block * * @return \Magelight\Block|void */ protected function initBlock() { $pages = []; $pagesCount = ceil($this->total / $this->perPage); if ($this->showFirstLast) { $pages[] = ['page' => 0, 'caption' => $this->first_caption, 'url' => $this->getPageUrl(0), 'active' => false, 'disabled' => $this->currentPage <= 0]; } if ($this->prev_caption) { $pages[] = ['page' => $this->currentPage, 'caption' => $this->prev_caption, 'url' => $this->getPageUrl($this->currentPage - 1), 'active' => false, 'disabled' => $this->currentPage <= 0]; } $start = $this->currentPage - $this->siblingsCount > 0 ? $this->currentPage - $this->siblingsCount : 0; $finish = $this->currentPage + $this->siblingsCount + 1 < $pagesCount ? $this->currentPage + $this->siblingsCount + 1 : $pagesCount; for ($i = $start; $i < $finish; $i++) { $pages[] = ['page' => $i, 'caption' => $i + 1, 'url' => $this->getPageUrl($i), 'active' => $i == (int) $this->currentPage, 'disabled' => false]; } if ($this->next_caption) { $pages[] = ['page' => $this->currentPage, 'caption' => $this->next_caption, 'url' => $this->getPageUrl($this->currentPage + 1), 'active' => false, 'disabled' => $this->currentPage >= $pagesCount - 1]; } if ($this->showFirstLast) { $pages[] = ['page' => $pagesCount - 1, 'caption' => $this->last_caption, 'url' => $this->getPageUrl($pagesCount - 1), 'active' => false, 'disabled' => $this->currentPage >= $pagesCount - 1]; } $this->set('pages', $pages); unset($pages); return parent::initBlock(); }