<?php
namespace App\Network\Controller;
use App\Network\Service\NetworkProfileService;
use App\Profile\Model\Profile;
use App\Profile\Service\ProfileService;
use Carbon\Carbon;
use Doctrine\DBAL\Query\QueryBuilder;
use Pimcore\Controller\FrontendController;
use Pimcore\Model\DataObject\Auction;
use Pimcore\Model\DataObject\Raceday;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
#[Route([
'name' => 'profile_tab_navigation_',
'localizedPaths' => [
'en' => '/{_locale}/tabnav',
'de' => '/{_locale}/tabnav',
'fr' => '/{_locale}/tabnav',
],
])]
class NetworkTabNavigationController extends FrontendController
{
#[Route('/{id}/timeline', name: 'timeline')]
public function timeline(Request $request, $id, NetworkProfileService $networkProfileService, ProfileService $profileService): Response
{
$profile = Profile::getById($id);
$subprofileKeys = $profileService->getActiveSubProfileIdentifiers($profile);
$horses = $networkProfileService->getAssociatedHorsesByProfile($subprofileKeys, $profile);
$auctionEvents = $networkProfileService->getFutureAuctionsByProfile($profile);
$raceEvents = $networkProfileService->getFutureRacedaysByProfile($profile);
$marketplacePosts = $networkProfileService->getLatestMarketplacePostsByProfile($profile);
// dd();
$request->setRequestFormat('text/html');
return $this->renderForm('network/profile/sections/profile_section_timeline.html.twig', [
'user' => $this->getUser(),
'profile' => Profile::getById($id),
'highlightedPost' => $request->get('highlightedPost'),
'horses' => $horses,
'raceEvents' => $raceEvents,
'auctionEvents' => $auctionEvents,
'marketplacePosts' => $marketplacePosts,
// 'horseEvents' => ['auctions' => $horseAuctions, 'racedays' => $horseRacedays],
]);
}
#[Route('/{id}/achievements', name: 'achievements')]
public function achievements(Request $request, $id, NetworkProfileService $networkProfileService, ProfileService $profileService): Response
{
$profile = Profile::getById($id);
$achievementCategories = $networkProfileService->getAchievementCategoriesByProfile($profile);
// dd();
$request->setRequestFormat('text/html');
return $this->renderForm('network/profile/sections/profile_section_achievements.html.twig', [
'user' => $this->getUser(),
'profile' => $profile,
'categories' => $achievementCategories,
// 'horseEvents' => ['auctions' => $horseAuctions, 'racedays' => $horseRacedays],
]);
}
#[Route('/{id}/news', name: 'news')]
public function news(Request $request, $id): Response
{
$request->setRequestFormat('text/html');
return $this->renderForm('network/profile/sections/profile_section_news.html.twig', [
'user' => $this->getUser(),
'profile' => Profile::getById($id),
// 'horseEvents' => ['auctions' => $horseAuctions, 'racedays' => $horseRacedays],
]);
}
#[Route('/{id}/network', name: 'network')]
public function network(Request $request, $id): Response
{
return $this->renderForm('network/profile/sections/profile_section_network.html.twig', [
'user' => $this->getUser(),
'profile' => Profile::getById($id),
]);
}
#[Route('/{id}/references', name: 'references')]
public function references(Request $request, $id): Response
{
return $this->renderForm('network/profile/sections/profile_section_references.html.twig', [
'user' => $this->getUser(),
'profile' => Profile::getById($id),
]);
}
#[Route('/{id}/team', name: 'team')]
public function team(Request $request, $id): Response
{
return $this->renderForm('network/profile/sections/profile_section_team.html.twig', [
'user' => $this->getUser(),
'profile' => Profile::getById($id),
]);
}
#[Route('/{id}/horse-lists', name: 'horse_lists')]
public function horses(Request $request, $id, NetworkProfileService $networkProfileService, ProfileService $profileService): Response
{
$profile = Profile::getById($id);
$subprofileKeys = $profileService->getActiveSubProfileIdentifiers($profile);
$horses = $networkProfileService->getAssociatedHorsesByProfile($subprofileKeys, $profile);
$profile = Profile::getById($id);
$horseRacedays = Raceday::getList();
$horseRacedays->onCreateQueryBuilder(function (QueryBuilder $queryBuilder) use ($profile) {
$queryBuilder->join('object_raceday', 'object_horse', 'horse', 'horses LIKE CONCAT("%", `horse`.`oo_id` , "%")');
$queryBuilder->where('object_raceday.date >= "'.Carbon::now()->format('Y-m-d').'" AND object_raceday.horses IS NOT NULL AND (horse.racingmanager__id ='.$profile->getId().' OR horse.jockey__id ='.$profile->getId().' OR horse.owner__id ='.$profile->getId().' OR horse.breeder__id ='.$profile->getId().' OR horse.trainer__id ='.$profile->getId().')');
$queryBuilder->orderBy('object_raceday.date', 'ASC');
$queryBuilder->distinct();
$queryBuilder->setMaxResults(3);
});
$horseAuctions = Auction::getList();
$horseAuctions->onCreateQueryBuilder(function (QueryBuilder $queryBuilder) use ($profile) {
$queryBuilder->innerJoin('object_auction', 'object_horse', 'horse', 'horses LIKE CONCAT("%", `horse`.`oo_id` , "%")');
$queryBuilder->where('end >="'.Carbon::now()->format('Y-m-d').'" AND horses IS NOT NULL AND (horse.racingmanager__id ='.$profile->getId().' OR horse.jockey__id ='.$profile->getId().' OR horse.owner__id ='.$profile->getId().' OR horse.breeder__id ='.$profile->getId().' OR horse.trainer__id ='.$profile->getId().')');
$queryBuilder->distinct();
$queryBuilder->setMaxResults(3);
});
return $this->renderForm('network/profile/sections/profile_section_horses.html.twig', [
'user' => $this->getUser(),
'profile' => $profile,
'managedHorses' => $horses['managedHorses'],
'trainedHorses' => $horses['trainedHorses'],
'ownedHorses' => $horses['ownedHorses'],
'bredHorses' => $horses['bredHorses'],
'auctionEvents' => $horseAuctions,
'racedayEvents' => $horseRacedays,
]);
}
// #[Route('/{id}/horse-events', name: 'horse_events')]
// public function horseEvents(Request $request, $id, NetworkProfileService $networkProfileService, ProfileService $profileService): Response
// {
// $profile = Profile::getById($id);
// $horseRacedays = Raceday::getList();
// $horseRacedays->onCreateQueryBuilder(function (QueryBuilder $queryBuilder) use ($profile) {
// $queryBuilder->join('object_raceday', 'object_horse', 'horse', 'horses LIKE CONCAT("%", `horse`.`oo_id` , "%")');
// $queryBuilder->where('object_raceday.date >= "'.Carbon::now()->format('Y-m-d').'" AND object_raceday.horses IS NOT NULL AND (horse.racingmanager__id ='.$profile->getId().' OR horse.jockey__id ='.$profile->getId().' OR horse.owner__id ='.$profile->getId().' OR horse.breeder__id ='.$profile->getId().' OR horse.trainer__id ='.$profile->getId().')');
// $queryBuilder->orderBy('object_raceday.date', 'ASC');
// $queryBuilder->distinct();
// $queryBuilder->setMaxResults(3);
// });
// $horseAuctions = Auction::getList();
// $horseAuctions->onCreateQueryBuilder(function (QueryBuilder $queryBuilder) use ($profile) {
// $queryBuilder->innerJoin('object_auction', 'object_horse', 'horse', 'horses LIKE CONCAT("%", `horse`.`oo_id` , "%")');
// $queryBuilder->where('end >="'.Carbon::now()->format('Y-m-d').'" AND horses IS NOT NULL AND (horse.racingmanager__id ='.$profile->getId().' OR horse.jockey__id ='.$profile->getId().' OR horse.owner__id ='.$profile->getId().' OR horse.breeder__id ='.$profile->getId().' OR horse.trainer__id ='.$profile->getId().')');
// $queryBuilder->distinct();
// $queryBuilder->setMaxResults(3);
// });
// return $this->renderForm('network/profile/sections/profile_section_horse_events.html.twig', [
// 'user' => $this->getUser(),
// 'profile' => $profile,
// 'auctionEvents' => $horseAuctions,
// 'racedayEvents' => $horseRacedays,
// ]);
// }
#[Route('/{id}/auctions', name: 'auctions')]
public function auctions(Request $request, $id): Response
{
$profile = Profile::getById($id);
return $this->renderForm('network/profile/sections/profile_section_auctions.html.twig', [
'user' => $this->getUser(),
'profile' => $profile,
]);
}
#[Route('/{id}/racedays', name: 'raceday_list')]
public function racedays(Request $request, $id): Response
{
$profile = Profile::getById($id);
return $this->renderForm('network/profile/sections/profile_section_racedays.html.twig', [
'user' => $this->getUser(),
'profile' => $profile,
]);
}
// {% do tab_navigation_add({ name: 'network', action: 'network' }) %}
// {% do tab_navigation_add({ name: 'references', action: 'references_list' }) %}
// {% do tab_navigation_add({ name: 'team', action: 'team' }) %}
}