<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;
use App\Entity\Members;
use App\Entity\MembersProfiles;
use App\Entity\MembersPictures;
use App\Entity\MembersTimelines;
use App\Entity\MembersInfo;
use App\Entity\MembersInfoHistory;
use App\Repository\MembersRepository;
use App\Repository\MembersProfilesRepository;
use App\Repository\MembersPicturesRepository;
use App\Repository\MembersTimelinesRepository;
use App\Repository\MembersInfoRepository;
use App\Repository\MembersInfoHistoryRepository;
use App\Repository\CouplesRepository;
use App\Repository\CouplesActivityRepository;
use Symfony\Contracts\Translation\TranslatorInterface;
use App\Service\MembersService;
#[Route('/members', name: 'members_')]
class MembersController extends AbstractController
{
private $members;
private $membersProfiles;
private $membersPictures;
private $membersTimeline;
private $membersInfo;
private $membersInfoHistory;
private $couples;
private $couplesActivity;
private $translator;
private $memberService;
public function __construct(MembersRepository $members,
MembersProfilesRepository $membersProfiles,
MembersPicturesRepository $membersPictures,
MembersTimelinesRepository $membersTimeline,
MembersInfoRepository $membersInfo,
MembersInfoHistoryRepository $membersInfoHistory,
CouplesRepository $couples,
CouplesActivityRepository $couplesActivity,
TranslatorInterface $translator,
MembersService $memberService)
{
$this->members = $members;
$this->membersProfiles = $membersProfiles;
$this->membersPictures = $membersPictures;
$this->membersTimeline = $membersTimeline;
$this->membersInfo = $membersInfo;
$this->membersInfoHistory = $membersInfoHistory;
$this->couples = $couples;
$this->couplesActivity = $couplesActivity;
$this->translator = $translator;
$this->mService = $memberService;
}
#[Route('/all', name: 'allmembers')]
public function allMembers(): Response
{
return $this->render('members/all.html.twig', [
]);
}
#[Route('/my-follows', name: 'myfollows')]
public function myFollows(): Response
{
return $this->render('members/myfollows.html.twig', [
]);
}
#[Route('/{member}/card/profile', name: 'membercard_profile')]
public function memberCardProfile($member): Response
{
$memberData = $this->members->findOneBy(['userId' => $member]);
$profile = $this->membersProfiles->findOneBy(['userId' => $member]);
$profileImage = $this->membersPictures->findOneBy(['creator' => $member, 'imageType' => 'member_public', 'isMain' => true]);
$profileImages = $this->membersPictures->findBy(['creator' => $member, 'imageType' => 'member_public', 'isRemove' => false, 'isMain' => false]);
$memberInfo = $this->membersInfo->findOneBy(['userId' => $member]);
$memberInfoHistory = $this->membersInfoHistory->findBy(['userId' => $member]);
$lastActivity = [];
$imagesFetch = [];
if(count($profileImages) > 0){
foreach($profileImages as $pImage){
$pathFor = '../pjhnDcTQED/medium/'.$member.'/'.$pImage->getNameMedium();
$typeFor = pathinfo($pathFor, PATHINFO_EXTENSION);
$dataFor = file_get_contents($pathFor);
list($width, $height) = getimagesize($pathFor);
$base64for = 'data:image/' . $typeFor . ';base64,' . base64_encode($dataFor);
$imagesFetch[] = ['base64' => $base64for, 'widthImg' => strval($width), 'heightImg' => strval($height)];
}
}
// Birthday
// Profile image base64
$path = '../pjhnDcTQED/medium/'.$member.'/'.$profileImage->getNameMedium();
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
$memberCard = [
'username' => $profile->getUsername(),
'id' => $member,
'cl' => $profile->getCoupleRole(),
'geo' => $profile->getGeoCity(),
'isViD' => $profile->getIsVerifiedIdentity(),
'isTiD' => $this->getStatusColor($profile->getLastActivity()),
'ag' => $this->dateToAge($memberData->getDateOfBirth()),
'pi' => $base64,
'picCount' => count($profileImages),
'pictures' => $imagesFetch,
'gender' => $profile->getGender(),
'lastActivity' => $lastActivity,
'lastActivityCount' => count($lastActivity),
'memInfo' => $this->mService->organizeInfo($memberInfo),
];
return $this->render('members/member_card_profile.html.twig', [
'member' => $memberCard
]);
}
#[Route('/{member}/card/timeline', name: 'membercard_timeline')]
public function memberCardTimeline($member, MembersRepository $members, MembersProfilesRepository $profiles, MembersPicturesRepository $pictures): Response
{
$memberData = $members->findOneBy(['userId' => $member]);
$profile = $profiles->findOneBy(['userId' => $member]);
$profileImage = $pictures->findOneBy(['creator' => $member, 'imageType' => 'member_public', 'isMain' => true]);
$profileImages = $pictures->findBy(['creator' => $member, 'imageType' => 'member_public', 'isRemove' => false, 'isMain' => false]);
$timelineItems = $this->membersTimeline->findBy(['targetMember' => $member], ['addedAt' => 'DESC']);
$fetchTimeline = [];
if(count($timelineItems) > 0){
foreach($timelineItems as $timelineItem){
$fetchTimeline[] = $this->mService->prepareTimelineItem($timelineItem);
}
}
$imagesFetch = [];
if(count($profileImages) > 0){
foreach($profileImages as $pImage){
$pathFor = '../pjhnDcTQED/medium/'.$member.'/'.$pImage->getNameMedium();
$typeFor = pathinfo($pathFor, PATHINFO_EXTENSION);
$dataFor = file_get_contents($pathFor);
list($width, $height) = getimagesize($pathFor);
$base64for = 'data:image/' . $typeFor . ';base64,' . base64_encode($dataFor);
$imagesFetch[] = ['base64' => $base64for, 'widthImg' => strval($width), 'heightImg' => strval($height)];
}
}
// Birthday
$dateNow = new \DateTime('now');
$dateTarget = $memberData->getDateOfBirth();
$interval = $dateTarget->diff($dateNow);
// Profile image base64
$path = '../pjhnDcTQED/medium/'.$member.'/'.$profileImage->getNameMedium();
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
$memberCard = [
'username' => $profile->getUsername(),
'id' => $member,
'cl' => $profile->getCoupleRole(),
'geo' => $profile->getGeoCity(),
'ag' => $interval->format('%Y'),
'pi' => $base64,
'picCount' => count($profileImages),
'pictures' => $imagesFetch,
'isViD' => $profile->getIsVerifiedIdentity(),
'isTiD' => $this->getStatusColor($profile->getLastActivity()),
'gender' => $profile->getGender(),
'timelineData' => $fetchTimeline
];
return $this->render('members/member_card_timeline.html.twig', [
'member' => $memberCard
]);
}
#[Route('/{member}/card/messenger', name: 'membercard_message')]
public function memberCardMessage($member, MembersRepository $members, MembersProfilesRepository $profiles, MembersPicturesRepository $pictures): Response
{
$memberData = $members->findOneBy(['userId' => $member]);
$profile = $profiles->findOneBy(['userId' => $member]);
$profileImage = $pictures->findOneBy(['creator' => $member, 'imageType' => 'member_public', 'isMain' => true]);
$profileImages = $pictures->findBy(['creator' => $member, 'imageType' => 'member_public', 'isRemove' => false, 'isMain' => false]);
$imagesFetch = [];
if(count($profileImages) > 0){
foreach($profileImages as $pImage){
$pathFor = '../pjhnDcTQED/medium/'.$member.'/'.$pImage->getNameMedium();
$typeFor = pathinfo($pathFor, PATHINFO_EXTENSION);
$dataFor = file_get_contents($pathFor);
list($width, $height) = getimagesize($pathFor);
$base64for = 'data:image/' . $typeFor . ';base64,' . base64_encode($dataFor);
$imagesFetch[] = ['base64' => $base64for, 'widthImg' => strval($width), 'heightImg' => strval($height)];
}
}
// Birthday
$dateNow = new \DateTime('now');
$dateTarget = $memberData->getDateOfBirth();
$interval = $dateTarget->diff($dateNow);
// Profile image base64
$path = '../pjhnDcTQED/medium/'.$member.'/'.$profileImage->getNameMedium();
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
$memberCard = [
'username' => $profile->getUsername(),
'id' => $member,
'cl' => $profile->getCoupleRole(),
'geo' => $profile->getGeoCity(),
'ag' => $interval->format('%Y'),
'pi' => $base64,
'picCount' => count($profileImages),
'pictures' => $imagesFetch,
'isViD' => $profile->getIsVerifiedIdentity(),
'isTiD' => $this->getStatusColor($profile->getLastActivity()),
'gender' => $profile->getGender()
];
return $this->render('members/member_card_messages.html.twig', [
'member' => $memberCard
]);
}
#[Route('/{member}/card/gallery', name: 'membercard_gallery')]
public function memberCardGallery($member, MembersRepository $members, MembersProfilesRepository $profiles, MembersPicturesRepository $pictures): Response
{
$memberData = $members->findOneBy(['userId' => $member]);
$profile = $profiles->findOneBy(['userId' => $member]);
$profileImage = $pictures->findOneBy(['creator' => $member, 'imageType' => 'member_public', 'isMain' => true]);
$profileImages = $pictures->findBy(['creator' => $member, 'imageType' => 'member_public', 'isRemove' => false, 'isMain' => false]);
$imagesFetch = [];
if(count($profileImages) > 0){
foreach($profileImages as $pImage){
$pathFor = '../pjhnDcTQED/medium/'.$member.'/'.$pImage->getNameMedium();
$typeFor = pathinfo($pathFor, PATHINFO_EXTENSION);
$dataFor = file_get_contents($pathFor);
list($width, $height) = getimagesize($pathFor);
$base64for = 'data:image/' . $typeFor . ';base64,' . base64_encode($dataFor);
$imagesFetch[] = ['base64' => $base64for, 'widthImg' => strval($width), 'heightImg' => strval($height)];
}
}
// Birthday
$dateNow = new \DateTime('now');
$dateTarget = $memberData->getDateOfBirth();
$interval = $dateTarget->diff($dateNow);
// Profile image base64
$path = '../pjhnDcTQED/medium/'.$member.'/'.$profileImage->getNameMedium();
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
$memberCard = [
'username' => $profile->getUsername(),
'id' => $member,
'cl' => $profile->getCoupleRole(),
'geo' => $profile->getGeoCity(),
'ag' => $interval->format('%Y'),
'pi' => $base64,
'picCount' => count($profileImages),
'pictures' => $imagesFetch,
'isViD' => $profile->getIsVerifiedIdentity(),
'isTiD' => $this->getStatusColor($profile->getLastActivity()),
'gender' => $profile->getGender()
];
return $this->render('members/member_card_gallery.html.twig', [
'member' => $memberCard
]);
}
#[Route('/{member}/card/tracking', name: 'membercard_tracking')]
public function memberCardTracking($member, MembersRepository $members, MembersProfilesRepository $profiles, MembersPicturesRepository $pictures): Response
{
$memberData = $members->findOneBy(['userId' => $member]);
$profile = $profiles->findOneBy(['userId' => $member]);
$profileImage = $pictures->findOneBy(['creator' => $member, 'imageType' => 'member_public', 'isMain' => true]);
$profileImages = $pictures->findBy(['creator' => $member, 'imageType' => 'member_public', 'isRemove' => false, 'isMain' => false]);
$imagesFetch = [];
if(count($profileImages) > 0){
foreach($profileImages as $pImage){
$pathFor = '../pjhnDcTQED/medium/'.$member.'/'.$pImage->getNameMedium();
$typeFor = pathinfo($pathFor, PATHINFO_EXTENSION);
$dataFor = file_get_contents($pathFor);
list($width, $height) = getimagesize($pathFor);
$base64for = 'data:image/' . $typeFor . ';base64,' . base64_encode($dataFor);
$imagesFetch[] = ['base64' => $base64for, 'widthImg' => strval($width), 'heightImg' => strval($height)];
}
}
$timingResult = [];
$todayResult = date("y-m-d") . ' 00:00:00';
$timingTester = strtotime($todayResult);
for ($i = 0; $i <= 1439; $i++) {
$timingTest = $timingTester + ($i * 60);
$timingResult[date("H:i", $timingTest)] = date("Y-m-d H:i", $timingTest);
}
echo $timingResult["03:32"];
// Birthday
$dateNow = new \DateTime('now');
$dateTarget = $memberData->getDateOfBirth();
$interval = $dateTarget->diff($dateNow);
// Profile image base64
$path = '../pjhnDcTQED/medium/'.$member.'/'.$profileImage->getNameMedium();
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
$memberCard = [
'username' => $profile->getUsername(),
'id' => $member,
'cl' => $profile->getCoupleRole(),
'geo' => $profile->getGeoCity(),
'ag' => $interval->format('%Y'),
'pi' => $base64,
'picCount' => count($profileImages),
'pictures' => $imagesFetch,
'isViD' => $profile->getIsVerifiedIdentity(),
'isTiD' => $this->getStatusColor($profile->getLastActivity()),
'gender' => $profile->getGender(),
'timRes' => $timingResult
];
return $this->render('members/member_card_tracking.html.twig', [
'member' => $memberCard
]);
}
#[Route('/{member}/card/locked', name: 'membercard_locked')]
public function memberCardLocked($member, MembersRepository $members, MembersProfilesRepository $profiles, MembersPicturesRepository $pictures): Response
{
$memberData = $members->findOneBy(['userId' => $member]);
$profile = $profiles->findOneBy(['userId' => $member]);
$profileImage = $pictures->findOneBy(['creator' => $member, 'imageType' => 'member_public', 'isMain' => true]);
$profileImages = $pictures->findBy(['creator' => $member, 'imageType' => 'member_public', 'isRemove' => false, 'isMain' => false]);
$imagesFetch = [];
if(count($profileImages) > 0){
foreach($profileImages as $pImage){
$pathFor = '../pjhnDcTQED/medium/'.$member.'/'.$pImage->getNameMedium();
$typeFor = pathinfo($pathFor, PATHINFO_EXTENSION);
$dataFor = file_get_contents($pathFor);
list($width, $height) = getimagesize($pathFor);
$base64for = 'data:image/' . $typeFor . ';base64,' . base64_encode($dataFor);
$imagesFetch[] = ['base64' => $base64for, 'widthImg' => strval($width), 'heightImg' => strval($height)];
}
}
// Birthday
$dateNow = new \DateTime('now');
$dateTarget = $memberData->getDateOfBirth();
$interval = $dateTarget->diff($dateNow);
// Profile image base64
$path = '../pjhnDcTQED/medium/'.$member.'/'.$profileImage->getNameMedium();
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
$memberCard = [
'username' => $profile->getUsername(),
'id' => $member,
'cl' => $profile->getCoupleRole(),
'geo' => $profile->getGeoCity(),
'ag' => $interval->format('%Y'),
'pi' => $base64,
'picCount' => count($profileImages),
'pictures' => $imagesFetch,
'isViD' => $profile->getIsVerifiedIdentity(),
'isTiD' => $this->getStatusColor($profile->getLastActivity()),
'gender' => $profile->getGender()
];
return $this->render('members/member_card_locked.html.twig', [
'member' => $memberCard
]);
}
#[Route('/fetch', name: 'membersfetch')]
public function membersFetch(MembersRepository $members, MembersProfilesRepository $profiles, MembersPicturesRepository $pictures, TranslatorInterface $translator): Response
{
switch ($_POST['a']) {
case 0:
$limitAgeFrom = new \DateTime('- 99 years');
$limitAgeTo = new \DateTime('now');
break;
case 1:
$limitAgeFrom = new \DateTime('- 22 years');
$limitAgeTo = new \DateTime('now');
break;
case 2:
$limitAgeFrom = new \DateTime('- 30 years');
$limitAgeTo = new \DateTime('- 23 years');
break;
case 3:
$limitAgeFrom = new \DateTime('- 45 years');
$limitAgeTo = new \DateTime('- 31 years');
break;
case 4:
$limitAgeFrom = new \DateTime('- 99 years');
$limitAgeTo = new \DateTime('- 46 years');
break;
}
// switch gender select
switch ($_POST['g']) {
case 0:
$limitGender = "c.gender = 'F' OR c.gender = 'M'";
break;
case 1:
$limitGender = "c.gender = 'M'";
break;
case 2:
$limitGender = "c.gender = 'F'";
break;
}
switch ($_POST['r']) {
case 0:
$limitRole = "c.coupleRole = 'sub' OR c.coupleRole = 'dom' OR c.coupleRole = 'switch'";
break;
case 1:
$limitRole = "c.coupleRole = 'dom'";
break;
case 2:
$limitRole = "c.coupleRole = 'sub'";
break;
case 3:
$limitRole = "c.coupleRole = 'switch'";
break;
}
if ($_POST['v'] == 'on'){
$limitVerify = 'c.isVerifiedIdentity = 1';
}else{
$limitVerify = 'c.isVerifiedIdentity = 1 OR c.isVerifiedIdentity = 0';
}
if ($_POST['nf'] == 'on'){
$limitedTime = new \DateTime("now - 15 minutes");
$limitedTimeFinal = $limitedTime->format('Y.m.d H:i:s');
$limitNotFake = "c.lastActivity > '${limitedTimeFinal}'";
}else{
$limitedTime = new \DateTime("now - 99 years");
$limitedTimeFinal = $limitedTime->format('Y.m.d H:i:s');
$limitNotFake = "c.lastActivity > '${limitedTimeFinal}'";
}
$membersData = $profiles->findMembersByFilter($limitAgeFrom, $limitAgeTo, $limitGender, $limitRole, $limitVerify, $limitNotFake, $_POST['off']);
$membersPageData = [];
foreach($membersData as $member){
$dateNow = new \DateTime('now');
$dateTarget = $member['dateOfBirth'];
$interval = $dateTarget->diff($dateNow);
$profileImage = $pictures->findOneBy(['creator' => $member['userId'], 'isMain' => true, 'imageType' => 'member_public']);
$path = '../pjhnDcTQED/medium/'.$member['userId'].'/'.$profileImage->getNameMedium();
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
$membersPageData[] = [
'member' => base64_encode($member['userId']),
'age' => $this->dateToAge($member['dateOfBirth']),
'un' => $member['username'],
'fn' => $member['firstName'],
'ln' => $member['lastName'],
'g' => $translator->trans($member['gender'], [], 'api'),
'c' => $member['geoCity'],
'cl' => $translator->trans($member['coupleRole'], [], 'api'),
'la' => $this->getStatusColor($member['lastActivity']),
'vi' => $member['isVerifiedIdentity'],
'pi' => $base64
];
}
$final = $membersPageData;
$response = new JsonResponse($final);
return $response;
}
function dateToString($dateObject, $time = false){
$currentYear = new \DateTime('now');
if($dateObject->format('Y') == $currentYear->format('Y')){
if($time == true){
$dateString = $dateObject->format('g:i A d.m');
}else{
$dateString = $dateObject->format('d.m');
}
}else{
if($time == true){
$dateString = $dateObject->format('g:i A d.m.Y');
}else{
$dateString = $dateObject->format('d.m.Y');
}
}
return $dateString;
}
function dateToAge($dateFrom){
$dateTo = new \DateTime('now');
$interval = $dateFrom->diff($dateTo);
return $interval->format('%Y');
}
function dateToAgo($dateObject, $time = false){
$dateStr = $dateObject->format('Y-m-d H:i:s');
$dateToStr = strtotime($dateStr);
$dateDiff = time() - $dateToStr;
if($dateDiff < 60){
$dateString = 'now';
}else if($dateDiff < 3600){
$dateString = $dateDiff / 60 . ' min.';
}else if($dateDiff < 86400){
$dateString = $dateDiff / 3600 . ' hr.';
}else if($dateDiff >= 86400){
$currentYear = new \DateTime('now');
if($dateObject->format('Y') == $currentYear->format('Y')){
$dateString = $dateObject->format('g:i A d.m');
}else{
$dateString = $dateObject->format('g:i A d.m Y');
}
}
return $dateString;
}
function getStatusColor($lastActivity){
$statusColor = "danger";
$dateStr = $lastActivity->format('Y-m-d H:i:s');
$dateToStr = strtotime($dateStr);
$dateDiff = time() - $dateToStr;
if($lastActivity !== null){
if($dateDiff > 900 && $dateDiff < 3600){
$statusColor = "warning";
}else if($dateDiff <= 900){
$statusColor = "success";
}else{
$statusColor = "danger";
}
}else{
$statusColor = "danger";
}
return $statusColor;
}
}