/** * Renders the summary text. */ public function renderSummary() { $count = $this->dataProvider->getCount(); if ($count <= 0) { return ''; } $summaryOptions = $this->summaryOptions; $tag = ArrayHelper::remove($summaryOptions, 'tag', 'div'); if (($pagination = $this->dataProvider->getPagination()) !== false) { $totalCount = $this->dataProvider->getTotalCount(); $begin = $pagination->getPage() * $pagination->pageSize + 1; $end = $begin + $count - 1; if ($begin > $end) { $begin = $end; } $page = $pagination->getPage() + 1; $pageCount = $pagination->pageCount; if (($summaryContent = $this->summary) === null) { return Html::tag($tag, Leaps::t('leaps', 'Showing <b>{begin, number}-{end, number}</b> of <b>{totalCount, number}</b> {totalCount, plural, one{item} other{items}}.', ['begin' => $begin, 'end' => $end, 'count' => $count, 'totalCount' => $totalCount, 'page' => $page, 'pageCount' => $pageCount]), $summaryOptions); } } else { $begin = $page = $pageCount = 1; $end = $totalCount = $count; if (($summaryContent = $this->summary) === null) { return Html::tag($tag, Leaps::t('leaps', 'Total <b>{count, number}</b> {count, plural, one{item} other{items}}.', ['begin' => $begin, 'end' => $end, 'count' => $count, 'totalCount' => $totalCount, 'page' => $page, 'pageCount' => $pageCount]), $summaryOptions); } } return Leaps::$app->getI18n()->format($summaryContent, ['begin' => $begin, 'end' => $end, 'count' => $count, 'totalCount' => $totalCount, 'page' => $page, 'pageCount' => $pageCount], Leaps::$app->language); }
/** * Recursively renders the menu items (without the container tag). * @param array $items the menu items to be rendered recursively * @return string the rendering result */ protected function renderItems($items) { $n = count($items); $lines = []; foreach ($items as $i => $item) { $options = array_merge($this->itemOptions, ArrayHelper::getValue($item, 'options', [])); $tag = ArrayHelper::remove($options, 'tag', 'li'); $class = []; if ($item['active']) { $class[] = $this->activeCssClass; } if ($i === 0 && $this->firstItemCssClass !== null) { $class[] = $this->firstItemCssClass; } if ($i === $n - 1 && $this->lastItemCssClass !== null) { $class[] = $this->lastItemCssClass; } if (!empty($class)) { if (empty($options['class'])) { $options['class'] = implode(' ', $class); } else { $options['class'] .= ' ' . implode(' ', $class); } } $menu = $this->renderItem($item); if (!empty($item['items'])) { $submenuTemplate = ArrayHelper::getValue($item, 'submenuTemplate', $this->submenuTemplate); $menu .= strtr($submenuTemplate, ['{items}' => $this->renderItems($item['items'])]); } if ($tag === false) { $lines[] = $menu; } else { $lines[] = Html::tag($tag, $menu, $options); } } return implode("\n", $lines); }
/** * Renders the detail view. * This is the main entry of the whole detail view rendering. */ public function run() { $rows = []; $i = 0; foreach ($this->attributes as $attribute) { $rows[] = $this->renderAttribute($attribute, $i++); } $options = $this->options; $tag = ArrayHelper::remove($options, 'tag', 'table'); echo Html::tag($tag, implode("\n", $rows), $options); }
/** * @inheritdoc */ public function init() { if (!isset($this->options['id'])) { $this->options['id'] = $this->getId(); } if ($this->requiresPjax()) { ob_start(); ob_implicit_flush(false); $view = $this->getView(); $view->clear(); $view->beginPage(); $view->head(); $view->beginBody(); if ($view->title !== null) { echo Html::tag('title', Html::encode($view->title)); } } else { echo Html::beginTag('div', $this->options); } }
/** * Renders a single data model. * @param mixed $model the data model to be rendered * @param mixed $key the key value associated with the data model * @param integer $index the zero-based index of the data model in the model array returned by [[dataProvider]]. * @return string the rendering result */ public function renderItem($model, $key, $index) { if ($this->itemView === null) { $content = $key; } elseif (is_string($this->itemView)) { $content = $this->getView()->render($this->itemView, array_merge(['model' => $model, 'key' => $key, 'index' => $index, 'widget' => $this], $this->viewParams)); } else { $content = call_user_func($this->itemView, $model, $key, $index, $this); } $options = $this->itemOptions; $tag = ArrayHelper::remove($options, 'tag', 'div'); if ($tag !== false) { $options['data-key'] = is_array($key) ? json_encode($key, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) : (string) $key; return Html::tag($tag, $content, $options); } else { return $content; } }
/** * Registers a link tag. * * For example, a link tag for a custom [favicon](http://www.w3.org/2005/10/howto-favicon) * can be added like the following: * * ```php * $view->registerLinkTag(['rel' => 'icon', 'type' => 'image/png', 'href' => '/myicon.png']); * ``` * * which will result in the following HTML: `<link rel="icon" type="image/png" href="/myicon.png">`. * * **Note:** To register link tags for CSS stylesheets, use [[registerCssFile()]] instead, which * has more options for this kind of link tag. * * @param array $options the HTML attributes for the link tag. * @param string $key the key that identifies the link tag. If two link tags are registered * with the same key, the latter will overwrite the former. If this is null, the new link tag * will be appended to the existing ones. */ public function registerLinkTag($options, $key = null) { if ($key === null) { $this->linkTags[] = Html::tag('link', '', $options); } else { $this->linkTags[$key] = Html::tag('link', '', $options); } }
/** * Renders a page button. * You may override this method to customize the generation of page buttons. * @param string $label the text label for the button * @param integer $page the page number * @param string $class the CSS class for the page button. * @param boolean $disabled whether this page button is disabled * @param boolean $active whether this page button is active * @return string the rendering result */ protected function renderPageButton($label, $page, $class, $disabled, $active) { $options = ['class' => $class === '' ? null : $class]; if ($active) { Html::addCssClass($options, $this->activePageCssClass); } if ($disabled) { Html::addCssClass($options, $this->disabledPageCssClass); return Html::tag('li', Html::tag('span', $label), $options); } $linkOptions = $this->linkOptions; $linkOptions['data-page'] = $page; return Html::tag('li', Html::a($label, $this->pagination->createUrl($page), $linkOptions), $options); }
/** * Renders a table row with the given data model and key. * @param mixed $model the data model to be rendered * @param mixed $key the key associated with the data model * @param integer $index the zero-based index of the data model among the model array returned by [[dataProvider]]. * @return string the rendering result */ public function renderTableRow($model, $key, $index) { $cells = []; /* @var $column Column */ foreach ($this->columns as $column) { $cells[] = $column->renderDataCell($model, $key, $index); } if ($this->rowOptions instanceof Closure) { $options = call_user_func($this->rowOptions, $model, $key, $index, $this); } else { $options = $this->rowOptions; } $options['data-key'] = is_array($key) ? json_encode($key) : (string) $key; return Html::tag('tr', implode('', $cells), $options); }
/** * Renders the filter cell. */ public function renderFilterCell() { return Html::tag('td', $this->renderFilterCellContent(), $this->filterOptions); }
/** * Renders the widget. */ public function run() { if (empty($this->links)) { return; } $links = []; if ($this->homeLink === null) { $links[] = $this->renderItem(['label' => Leaps::t('leaps', 'Home'), 'url' => Leaps::$app->homeUrl], $this->itemTemplate); } elseif ($this->homeLink !== false) { $links[] = $this->renderItem($this->homeLink, $this->itemTemplate); } foreach ($this->links as $link) { if (!is_array($link)) { $link = ['label' => $link]; } $links[] = $this->renderItem($link, isset($link['url']) ? $this->itemTemplate : $this->activeItemTemplate); } echo Html::tag($this->tag, implode('', $links), $this->options); }