public function actionContent($links_id, $id = null) { $link = Links::findOne($links_id); if (Yii::$app->request->get('action')) { switch (Yii::$app->request->get('action')) { case "add": $content = new Contents(); $content->links_id = $link->id; $content->seq = $content->findLastSequence($link->id, $id) + 1; $content->save(); break; case "del": Contents::deleteAll(['id' => $id]); (new Contents())->reSort($link->id); break; } return $this->redirect(Url::current(['action' => null, 'id' => null])); } $contents = Contents::find()->where(['links_id' => $links_id])->orderBy(['seq' => SORT_ASC])->all(); if (Yii::$app->request->post()) { foreach ($contents as $index => $content) { if (Yii::$app->request->post('content-' . $index)) { $contents[$index]->load(Yii::$app->request->post()); $contents[$index]->text = Yii::$app->request->post('content-' . $index); $contents[$index]->save(); } } } return $this->render('content', ['link' => $link, 'contents' => $contents]); }
public function actionCatchDef($url = null) { ///////////////////////// $links = Links::find()->where(['categories_id' => 3])->all(); $ads = TorAds::find()->all(); ///////////////////////// $link = Links::findOne(['url' => '/' . $url]); if (!$link) { return $this->render('/site/develop', ['links' => $links, 'ads' => $ads]); } $link = Links::findOne(['url' => '/' . $url]); if (!$link) { return $this->render('/site/develop'); } $this->layout = $link->layout->name; Yii::$app->view->registerMetaTag(['description' => $link->description]); Yii::$app->view->registerMetaTag(['keywords' => $link->keywords]); $parent = Links::findOne($link->parent); if (isset($link->id)) { $content = false; for ($c = 0; $c < count($link->contents); $c++) { $reg = '/\\{\\{(.*)\\}\\}/'; $content = preg_replace_callback('/(\\{{)(\\S+)(}})/', "self::getModule", $link->contents[0]->content); $content = preg_replace_callback('/(\\[\\[)(\\S+)(]])/', "self::getWidget", $content); } } return $this->render($link->view->name, ['link' => $link, 'content' => $content]); }
public function actionNewsDel($links_id) { $link = Links::findOne($links_id); if ($link) { Yii::$app->getSession()->setFlash('success', 'Новость удалена'); $link->delete(); } return $this->redirect(['/news/list']); }
public function getAnchorPath($links_id) { $link = Links::findOne($links_id); if ($link->parent !== null) { $anchor_path = $this->getAnchorPath($link->parent) . ' / ' . $link->anchor; } else { $anchor_path = '/ ' . $link->anchor; } return $anchor_path; }
public function topMenu() { $items = array(); $links = Links::find()->where(['categories_id' => $this->categories_id, 'level' => 1])->orderBy(['seq' => SORT_ASC])->all(); $url = '/' . Yii::$app->request->get('url'); foreach ($links as $link) { $items[] = ['label' => $link->anchor, 'url' => $link->url, 'active' => $link->url == $url ? true : false]; } return $items; }
public function run() { $link = Links::findOne(['url' => '/' . $this->url]); $this->links_id[] = $link->id; if ($link->child_exist == 1) { $this->getLinksId($link->id); } $ads = TorAds::find()->where(['links_id' => $this->links_id])->orderBy(['created_at' => SORT_ASC, 'price' => SORT_ASC])->limit(20)->all(); $ads_promo = TorAds::find()->where(['links_id' => $this->links_id])->limit(5)->orderBy(['created_at' => rand()])->all(); if ($ads) { echo $this->render('preview', ['ads' => $ads, 'ads_promo' => $ads_promo]); } else { echo Html::tag('div', '<em>Для заданных параметров товар не найден</em>', ['class' => 'text-center text-muted']); } $view = $this->view; TorAdsAsset::register($view); }
public function torMenu($parent = null, $level = 1) { $links = Links::find()->where(['categories_id' => $this->categories_id, 'parent' => $parent])->orderBy(['seq' => SORT_ASC])->all(); $items = Html::beginTag('ul', ['class' => 'tor-nav-' . $level . ' ' . ($level > 2 ? 'list-unstyled' : 'list-inline')]); /** @var $link Links */ foreach ($links as $link) { $items .= '<li>' . Html::a($link->anchor, $link->url); if ($link->child_exist == 1) { if ($link->level == 1) { $items .= '<span class="caret"></span>' . Html::tag('div', $this->torMenu($link->id, $link->level + 1), ['class' => 'tor-sub-nav']); } else { $items .= $this->torMenu($link->id, $link->level + 1); } } $items .= '</li>'; } $items .= Html::endTag('ul'); return $items; }
public function getLinks($parent) { $links = \common\models\main\Links::find()->innerJoinWith('category')->where(['categories_id' => $this->categories_id])->andWhere(['categories.visible' => 1])->andWhere(['parent' => $parent])->orderBy(['seq' => SORT_ASC])->all(); if (!$links) { return '<em class="text-muted">Ссылки не добавлены</em>'; } $html = Html::beginTag('ul', ['class' => 'list-unstyled']); /** * @var $i * @var $link \common\models\main\Links */ foreach ($links as $i => $link) { $html .= Html::tag('li', Html::beginTag('div', ['class' => 'row']) . Html::tag('div', Html::a($link->anchor, ['/map/content', 'links_id' => $link->id], ['style' => ($link->state == 0 ? 'text-decoration: line-through; color: #aaa;' : '') . (Yii::$app->request->get('links_id') == $link->id || Yii::$app->request->get('parent_links_id') == $link->id ? 'font-weight: bold;' : '')]), ['class' => 'col-sm-9']) . Html::tag('div', ButtonDropdown::widget(['label' => '<i class="fa fa-cog"></i>', 'dropdown' => ['items' => [['label' => 'Параметры', 'url' => ['/map/links', 'categories_id' => Yii::$app->request->get('categories_id'), 'action' => 'ch', 'id' => $link->id]], ['label' => 'Ретактор контента', 'url' => ['/map/content', 'links_id' => $link->id]], ['label' => 'Добавить дочернюю ссылку', 'url' => ['/map/links', 'categories_id' => Yii::$app->request->get('categories_id'), 'parent' => $link->id, 'action' => 'add']]]], 'encodeLabel' => false, 'options' => ['class' => 'btn-default btn-xs']]), ['class' => 'col-sm-3 action text-right']) . Html::endTag('div')); if ($link->child_exist == '1') { $childs = \common\models\main\Links::find()->innerJoinWith('category')->where(['categories_id' => $this->categories_id])->andWhere(['categories.visible' => 1])->andWhere(['parent' => $link->id])->count(); if ($childs > 0) { $html .= $this->getLinks($link->id); } } } $html .= Html::endTag('ul'); return $html; }
private function addImage($links_id, $item) { $link_imgs_id = Links::findOne($links_id)->gl_imgs_id; $gl_groups = array(); foreach ($item as $image_sxe) { $basename_src = basename(strval($image_sxe->{'ПутьКИзображению'})); if (!$basename_src) { continue; } preg_match('/_(.+)\\s\\[(.+)\\]/', $basename_src, $matches); if ($matches) { $type = $matches[1]; $title = $matches[2]; } else { $type = Yii::$app->params['defaultShGlType']; $title = ''; } if (!GlImgs::findOne(['basename_src' => $basename_src])) { $gl_type = GlTypes::findOne(['type' => $type]); if (!isset($gl_groups[$type])) { $gl_groups[$type] = GlGroups::findOne(['links_id' => $links_id, 'types_id' => $gl_type->id]); if (!$gl_groups[$type]) { $gl_group = new GlGroups(); $gl_group->types_id = GlTypes::findOne(['type' => $type])->id; $gl_group->links_id = $links_id; $gl_group->save(); $gl_groups[$type] = $gl_group; } } $src_image = pathinfo($this->import_file)['dirname'] . '/' . strval($image_sxe->{'ПутьКИзображению'}); $dst_path = Yii::getAlias('@frontend') . '/web' . $gl_type->dir_dst; $images = (new GlImgs())->convertImg($gl_type->id, addslashes($src_image), $dst_path); $gl_img = new GlImgs(); $gl_img->groups_id = $gl_groups[$type]->id; $gl_img->img_small = $gl_type->dir_dst . '/' . $images['img_small']; $gl_img->img_large = $gl_type->dir_dst . '/' . $images['img_large']; $gl_img->basename_src = $basename_src; $gl_img->title = $title; $gl_img->seq = GlImgs::findLastSequence($gl_groups[$type]->id) + 1; $gl_img->save(); if (!$link_imgs_id) { $link = Links::findOne($links_id); $link->gl_imgs_id = $gl_img->id; $link->save(); $link_imgs_id = $gl_img->id; $gl_groups[$type]->imgs_id = $gl_img->id; $gl_groups[$type]->save(); } if ($image_sxe->{'ОсновноеИзображение'} == 1 && $link_imgs_id != $gl_img->id) { $link = Links::findOne($links_id); $link->gl_imgs_id = $gl_img->id; $link->save(); $link_imgs_id = $gl_img->id; $gl_groups[$type]->imgs_id = $gl_img->id; $gl_groups[$type]->save(); } } } }
/** * @return \yii\db\ActiveQuery */ public function getLink() { return $this->hasOne(Links::className(), ['id' => 'links_id']); }
public function getPrefixUrl($pattern, $linkLevel, $parent = null) { $patternSplit = preg_split('/\\//', preg_replace('/\\/$/', '', $pattern)); $prefixUrl = ''; if ($patternSplit) { foreach ($patternSplit as $item) { if (preg_match('/{(level)-(\\d+)}/', $item, $match)) { if (isset($match[2]) && $linkLevel > $match[2]) { $level = $linkLevel - 1; $parentLink = self::findOne($parent); while ($level > $match[2]) { $level = $level - 1; $parentLink = Links::findOne($parentLink->parent); } $prefixUrl .= $parentLink->name . '/'; } } else { $prefixUrl .= $item . '/'; } } } return preg_replace('/\\/$/', '', $prefixUrl); }
public function actionCategories() { if (Yii::$app->request->isAjax) { Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; $categories_id = Yii::$app->request->post('categories_id'); $links = Links::find()->where(['categories_id' => $categories_id])->orderBy(['seq' => SORT_ASC])->all(); return ['success' => true, 'links' => $links, 'level' => $links[0]->level]; } }
private function addImage($item, $src_gallery_types_id, $links_id, $shop_goods_id = null) { $gallery_groups = array(); foreach ($item as $image_sxe) { $basename_src = basename(strval($image_sxe->{'ПутьКИзображению'})); if (!$basename_src) { continue; } $src_image = pathinfo($this->import_file)['dirname'] . '/' . strval($image_sxe->{'ПутьКИзображению'}); if (!is_file($src_image)) { continue; } $gallery_types_id = false; $alt = ''; foreach (Yii::$app->params['shop']['gallery'] as $name => $id) { if (!$gallery_types_id && strripos($basename_src, '_' . $name) !== false) { $gallery_types_id = $id; preg_match('/\\[(.+)\\]/', $basename_src, $matches); $alt = isset($matches[1]) ? $matches[1] : ''; } } if (!$gallery_types_id) { $gallery_types_id = $src_gallery_types_id; } if (GalleryTypes::findOne($gallery_types_id)) { $gallery_groups[$gallery_types_id][] = ['name' => $basename_src, 'src_image' => $src_image, 'alt' => $alt, 'default' => $image_sxe->{'ОсновноеИзображение'} == 1 ? 1 : 0]; } } if (!$gallery_groups) { return false; } $link = Links::findOne($links_id); foreach ($gallery_groups as $gallery_types_id => $images) { $gallery_group = false; if ($shop_goods_id) { $good_gallery = ShopGoodGallery::findOne(['shop_goods_id' => $shop_goods_id, 'gallery_types_id' => $gallery_types_id]); if (!$good_gallery) { $gallery_group = new GalleryGroups(); $gallery_group->gallery_types_id = $gallery_types_id; $gallery_group->save(); $good_gallery = new ShopGoodGallery(); $good_gallery->shop_goods_id = $shop_goods_id; $good_gallery->gallery_types_id = $gallery_types_id; $good_gallery->gallery_groups_id = $gallery_group->id; $good_gallery->save(); } else { $gallery_group = GalleryGroups::findOne($good_gallery->gallery_groups_id); } } elseif (in_array($gallery_types_id, Yii::$app->params['shop']['galleryLink'])) { if (!$link->gallery_images_id) { $gallery_group = new GalleryGroups(); $gallery_group->gallery_types_id = $gallery_types_id; $gallery_group->save(); } else { $gallery_group = GalleryGroups::findOne($link->galleryImage->gallery_groups_id); } } if ($gallery_group) { foreach ($images as $index => $image) { $gallery_image = GalleryImages::findOne(['gallery_groups_id' => $gallery_group->id, 'name' => $image['name']]); if (!$gallery_image) { $new_image = $this->saveImage($image['src_image'], $gallery_types_id, $gallery_group->id); if (isset($new_image['small']) && isset($new_image['large'])) { $gallery_image = new GalleryImages(); $gallery_image->gallery_groups_id = $gallery_group->id; $gallery_image->small = $new_image['small']; $gallery_image->large = $new_image['large']; $gallery_image->name = $image['name']; $gallery_image->alt = $image['alt']; $gallery_image->seq = $new_image['seq']; $gallery_image->save(); } } else { if ($gallery_image->alt != $image['alt']) { $gallery_image->alt = $image['alt']; $gallery_image->update(); } } if ($image['default'] == 1) { if ($gallery_group->gallery_images_id != $gallery_image->id) { $gallery_group->gallery_images_id = $gallery_image->id; $gallery_group->update(); } if ($gallery_image->id && $link->gallery_images_id != $gallery_image->id) { $link->gallery_images_id = $gallery_image->id; $link->update(); } } } $gallery_images = GalleryImages::find()->where(['gallery_groups_id' => $gallery_group->id])->orderBy(['seq' => SORT_ASC])->all(); $resort_images = false; foreach ($gallery_images as $gallery_image) { $delete_image = true; foreach ($images as $index => $image) { if ($image['name'] == $gallery_image->name) { $delete_image = false; } } if ($delete_image) { $resort_images = true; GalleryImages::findOne($gallery_image->id)->delete(); unlink(Yii::getAlias('@frontend/web') . $gallery_image->small); unlink(Yii::getAlias('@frontend/web') . $gallery_image->large); } } if ($resort_images) { $gallery = new Gallery(); $gallery->resortImages($gallery_group->id); } } } }
/** * @return \yii\db\ActiveQuery */ public function getLinks() { return $this->hasMany(Links::className(), ['layouts_id' => 'id']); }
<?php use common\models\main\Links; use frontend\widgets\tor_ads\Homepage; /** @var $this yii\web\View */ /** @var $link common\models\main\Links */ /** @var $contents \common\models\main\Contents */ $this->title = $link->title; if ($link->parent) { $parents[] = Links::findOne($link->parent); while ($parents[count($parents) - 1]->parent) { $parents[] = Links::findOne($parents[count($parents) - 1]->parent); } for ($i = count($parents) - 1; $i >= 0; $i--) { $this->params['breadcrumbs'][] = ['label' => $parents[$i]->anchor, 'url' => $parents[$i]->url]; } } if ($link->start != 1) { $this->params['breadcrumbs'][] = $link->anchor; } ?> <div class="promo text-center">BANNER</div> <div class="container"> <div class="content"> <?php echo Homepage::widget(); ?> <?php echo $contents[0]->text;
/** * @return \yii\db\ActiveQuery */ public function getLinks() { return $this->hasMany(Links::className(), ['categories_id' => 'id']); }
public function getLink() { return $this->hasOne(Links::className(), ['id' => 'links_id'])->via('realtyGroup'); }