This commit is contained in:
2025-01-19 17:15:58 +03:00
parent 40369fb515
commit b18378bcb1
41 changed files with 1257 additions and 30 deletions

View File

@ -2,7 +2,31 @@
namespace app\modules\photo;
use Illuminate\Database\Eloquent\Model;
use kernel\app_modules\photo\models\Photo;
class PhotoModule extends \kernel\app_modules\photo\PhotoModule
{
public function getItems(string $entity, Model $model): array|string
{
$photos = Photo::where("entity", $entity)->where("entity_id", $model->id)->get();
$photoArr = [];
foreach ($photos as $photo) {
$photoArr[] =$photo->image;
}
return $photoArr;
}
public function getItem(string $entity, string $entity_id): string
{
$photos = Photo::where("entity", $entity)->where("entity_id", $entity_id)->first();
if ($photos){
return $photos->image;
}
return "";
}
}

View File

@ -2,7 +2,9 @@
namespace app\modules\tgbot\controllers;
use kernel\app_modules\tag\service\TagService;
use kernel\Controller;
use kernel\modules\post\models\Post;
class TgMainController extends Controller
{
@ -21,4 +23,18 @@ class TgMainController extends Controller
$this->cgView->render("index.php");
}
public function actionNews(): void
{
$news = TagService::getEntityByTagId(2, Post::class);
$this->cgView->render("news.php", ['news' => $news]);
}
public function actionPromo(): void
{
$news = TagService::getEntityByTagId(1, Post::class);
$this->cgView->render("news.php", ['news' => $news]);
}
}

View File

@ -8,4 +8,6 @@ include KERNEL_APP_MODULES_DIR . "/tgbot/routs/tgbot.php";
App::$collector->group(["prefix" => "miniapp"], function (CGRouteCollector $router) {
App::$collector->get('/', [\app\modules\tgbot\controllers\TgMainController::class, 'actionMain']);
App::$collector->get('/news', [\app\modules\tgbot\controllers\TgMainController::class, 'actionNews']);
App::$collector->get('/promo', [\app\modules\tgbot\controllers\TgMainController::class, 'actionPromo']);
});

View File

@ -41,10 +41,10 @@
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="nav navbar-nav ml-auto">
<li class="nav-item active">
<a class="nav-link" href="/miniapp/card">Карта</a>
<a class="nav-link" href="/miniapp/news">Новости</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/miniapp/sale">Акции</a>
<a class="nav-link" href="/miniapp/promo">Акции</a>
</li>
</ul>
</div>

View File

@ -0,0 +1,20 @@
<?php
/**
* @var \Illuminate\Database\Eloquent\Collection $news
*/
$entityRelation = new \kernel\EntityRelation();
?>
<?php foreach ($news as $new): ?>
<?php
$img = $entityRelation->getAdditionalPropertyByEntityId("post", $new['id'], 'photo');
?>
<div class="card">
<?php if ($img): ?>
<img src="<?= $img ?>" class="card-img-top"/>
<?php endif; ?>
<div class="card-body">
<h5 class="card-title"><?= $new['title'] ?></h5>
<p class="card-text"><?= $new['content'] ?></p>
</div>
</div>
<?php endforeach; ?>