Example #1
0
    public static function outTop8Links()
    {
        $topTags = TopTag::find()->orderBy(['id' => SORT_DESC])->limit(8)->all();
        for ($i = 0; $i < count($topTags) - 1; $i++) {
            for ($j = $i + 1; $j < count($topTags); $j++) {
                $first = $topTags[$i];
                $second = $topTags[$j];
                if (strcmp($first->tag->name, $second->tag->name) < 0) {
                    $temp = $topTags[$i];
                    $topTags[$i] = $topTags[$j];
                    $topTags[$j] = $temp;
                }
            }
        }
        foreach ($topTags as $tag) {
            $tagName = str_replace(' ', '+', $tag->name);
            ?>
            <a href="<?php 
            echo Url::to(['site/search', 't' => $tagName]);
            ?>
" class="tag"><?php 
            echo $tag->name;
            ?>
</a>
            <?php 
        }
        ?>
 <a href="<?php 
        echo Url::to(['site/tags']);
        ?>
" class="tag">Все теги</a> <?php 
    }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = TopTag::find();
     $topTagTable = TopTag::tableName();
     $tagTable = Tag::tableName();
     $query->joinWith(['tag' => function ($query) use($tagTable) {
         $query->from(['tag' => $tagTable]);
     }]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]);
     // enable sorting for the related columns
     $addSortAttributes = ["tag.name"];
     foreach ($addSortAttributes as $addSortAttribute) {
         $dataProvider->sort->attributes[$addSortAttribute] = ['asc' => [$addSortAttribute => SORT_ASC], 'desc' => [$addSortAttribute => SORT_DESC]];
     }
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'tag_id' => $this->tag_id]);
     $query->andFilterWhere(['like', 'tag.name', $this->getAttribute('tag.name')]);
     return $dataProvider;
 }
 /**
  * Finds the TopTag model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return TopTag the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = TopTag::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #4
0
            </div>

            <div class="top-banners-area">
                <?php 
$bannerBlock = SiteBlock::getBanner(Banner::REGION_TOP);
if ($bannerBlock) {
    echo $this->render($bannerBlock['view'], isset($bannerBlock['data']) ? $bannerBlock['data'] : []);
}
?>
            </div>

            <div class="breadcrumbs">
                <div class="header">Главное</div>
                <div class="arrow"></div>
                <?php 
echo TopTag::outTop8Links();
?>
            </div>

        </div>
    </header>

    <div id="wrapper">
        <?php 
echo $content;
?>
    </div>

    <footer id="colophon" class="site-footer" role="contentinfo">
        <div class="footer-wrapper">