1
0
mirror of https://framagit.org/tykayn/date-poll-api synced 2023-08-25 08:23:11 +02:00

send mail with owner polls

This commit is contained in:
Tykayn 2021-05-21 09:34:01 +02:00 committed by tykayn
parent f8554d5f7a
commit 64fd83caa2
2 changed files with 53 additions and 6 deletions

View File

@ -121,6 +121,36 @@ class PollController extends EmailsController {
404 );
}
/**
* get a poll config by its custom URL, we do not want polls to be reachable by their numeric id
* @Get(
* path = "/owner/{owner_email}/",
* name = "get_owner_poll",
* )
*
* @return JsonResponse|Response
*/
function getOwnerPolls( $owner_email ) {
$repository = $this->getDoctrine()->getRepository( Owner::class );
$owner = $repository->findOneByEmail( $owner_email );
if ( ! $owner ) {
return $this->json( [ 'message' => "Owner $owner_email non trouvé" ], 404 );
} else {
$polls = $owner->getPolls();
$pollsDisplay = [];
foreach ( $polls as $p ) {
$pollsDisplay[] = $p->displayForAdmin();
}
$mail_sent = $this->sendOwnerPollsAction( $owner );
return $this->json( [ 'mail_sent' => $mail_sent ], $mail_sent ? 200 : 404 );
// return $this->json(['owner' => $owner->displayForAdmin(), 'polls' => $pollsDisplay], 200);
}
}
/**
* get a poll config by its custom URL, we do not want polls to be reachable by their numeric id
* @Get(

View File

@ -35,15 +35,15 @@ class PollRepository extends ServiceEntityRepository {
return $this->findExpirationPollOfDay( - 30 );
}
public function findExpirationPollOfDay( $count_of_days){
public function findExpirationPollOfDay( $count_of_days ) {
$today = new \DateTime();
$today = new \DateTime();
if($count_of_days > -1){
if ( $count_of_days > - 1 ) {
$date_soon = $today->add( new \DateInterval( 'P' . $count_of_days . 'D' ) );
}else{
$date_soon = $today->sub( new \DateInterval( 'P' . abs($count_of_days) . 'D' ) );
$date_soon = $today->add( new \DateInterval( 'P' . $count_of_days . 'D' ) );
} else {
$date_soon = $today->sub( new \DateInterval( 'P' . abs( $count_of_days ) . 'D' ) );
}
@ -55,4 +55,21 @@ class PollRepository extends ServiceEntityRepository {
->getResult();
}
/**
* find all the polls of an owner
*
* @param $email
*
* @return int|mixed|string
*/
public function findAllByOwnerEmail( $email ) {
return $this->createQueryBuilder( 'p' )
->andWhere( 'p.owner.email = :email' )
->setParameter( 'email', $email )
->orderBy( 'p.id', 'DESC' )
->getQuery()
->getResult();
}
}