news
This commit is contained in:
parent
6b61b51d53
commit
d9178c17f7
@ -2,8 +2,10 @@
|
||||
|
||||
namespace app\modules\tgbot\controllers;
|
||||
|
||||
use Cassandra\Decimal;
|
||||
use kernel\app_modules\tag\service\TagService;
|
||||
use kernel\Controller;
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\modules\post\models\Post;
|
||||
|
||||
class TgMainController extends Controller
|
||||
@ -25,14 +27,14 @@ class TgMainController extends Controller
|
||||
|
||||
public function actionNews(): void
|
||||
{
|
||||
$news = TagService::getEntityByTagId(2, Post::class);
|
||||
$news = TagService::getEntityByTagSlug("novosti", Post::class);
|
||||
|
||||
$this->cgView->render("news.php", ['news' => $news]);
|
||||
}
|
||||
|
||||
public function actionPromo(): void
|
||||
{
|
||||
$news = TagService::getEntityByTagId(1, Post::class);
|
||||
$news = TagService::getEntityByTagSlug("akcii", Post::class);
|
||||
|
||||
$this->cgView->render("news.php", ['news' => $news]);
|
||||
}
|
||||
|
@ -57,4 +57,23 @@ class TagService
|
||||
return $queryBuilder->whereIn("id", $entityIdArr)->get();
|
||||
}
|
||||
|
||||
public static function getEntityByTagSlug(string $tagSlug, $model)
|
||||
{
|
||||
$tag = Tag::where("slug", $tagSlug)->first();
|
||||
if ($tag){
|
||||
$tagEntity = TagEntity::where("tag_id", $tag->id)->get();
|
||||
if ($tagEntity){
|
||||
$entityIdArr = [];
|
||||
foreach ($tagEntity as $item){
|
||||
$entityIdArr[] = $item['entity_id'];
|
||||
}
|
||||
}
|
||||
$queryBuilder = $model::query();
|
||||
|
||||
return $queryBuilder->whereIn("id", $entityIdArr)->get();
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user