minor fix Push Notification

This commit is contained in:
Grégoire
2019-11-05 11:24:34 +01:00
parent 2a9e728354
commit 823a781d3a
6 changed files with 92 additions and 12 deletions
@@ -10,7 +10,7 @@ use Symfony\Component\Console\Input\InputOption;
class SendPushCommand extends ContainerAwareCommand
{
private const defaultEmail = 'thomas.berrod@e-declic.com';
private const defaultEmail = 'lognone.gregoire@hotmail.fr';
protected function configure()
@@ -0,0 +1,80 @@
<?php
namespace AppBundle\Controller\Api;
use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\Controller\Annotations\Post;
use FOS\RestBundle\Controller\Annotations\View;
use FOS\RestBundle\Controller\FOSRestController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use AppBundle\Exception\ResourceValidationException;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
class TalentController extends FOSRestController
{
private static function sortByBeginYearCareer($x, $y) {
return strcasecmp($y['beginYearCareer'], $x['beginYearCareer']);
}
private static function sortByBeginYearFormation($x, $y) {
return strcasecmp($y['beginYearFormation'], $x['beginYearFormation']);
}
private static function sortByLanguageName($x, $y) {
return strcasecmp($y['nameLanguage'], $x['nameLanguage']);
}
/**
* @Rest\post(path="/api/update_user", name="api_update_user")
* @Rest\View
*/
public function updateCareer(Request $request)
{
$em = $this->getDoctrine()->getManager();
$usr = $this->getUser();
if ($usr !== null){
$company = htmlspecialchars($request->get('company'));
$jobCareer = htmlspecialchars($request->get('jobCareer'));
$beginCareer = htmlspecialchars($request->get('beginCareer'));
$endCareer = htmlspecialchars($request->get('endCareer'));
$descriptionCareer = htmlspecialchars($request->get('descriptionCareer'));
$idExperience = htmlspecialchars($request->get('idExperience'));
$beginYearCareer = substr($beginCareer, 0, 4);
$beginMonthCareer = substr($beginCareer, 6, 7);
if($endCareer){
$endYearCareer = substr($endCareer, 0, 4);
$endMonthCareer = substr($endCareer, 6, 7);
} else {
$endYearCareer = null;
$endMonthCareer = null;
}
$newCareer = array (
$idExperience => array(
'company' => $company,
'jobCareer' => $jobCareer,
'descriptionCareer' => $descriptionCareer,
'beginYearCareer' => $beginYearCareer,
'beginMonthCareer' => $beginMonthCareer,
'endYearCareer' => $endYearCareer,
'endMonthCareer' => $endMonthCareer,
)
);
$careers = $usr->getCareer();
array_replace($careers[$idExperience], $newCareer[$idExperience]);
usort($careers, "static::sortByBeginYearCareer");
$usr->setCareer($careers);
$em->persist($usr);
$em->flush();
}
}
}
@@ -67,18 +67,18 @@ class UserSubscriptionRepository extends \Doctrine\ORM\EntityRepository
) AS decimal) / 15) * 100 ) >= :percent')
->setParameters(array('percent' => $completenessPercentage));
dump($qb->getQuery()->getSql());
//dump($qb->getQuery()->getSql());
$result = $qb->getQuery()->getResult();
dump($result);
//dump($result);
return $result;
}
public function findByTagMatching($tags)
{
dump($tags);
//dump($tags);
$config = $this->_em->getConfiguration();
$config->addCustomNumericFunction('CAST', 'AppBundle\Repository\Query\CastAs');
@@ -96,11 +96,11 @@ class UserSubscriptionRepository extends \Doctrine\ORM\EntityRepository
}
}
dump($qb->getQuery()->getSql());
//dump($qb->getQuery()->getSql());
$result = $qb->getQuery()->getResult();
dump($result);
//dump($result);
return $result;
}
@@ -105,9 +105,9 @@ class NotificationSender implements ContainerAwareInterface
$user = $this->userManager->findUserBy(array('email' => $email));
$output->writeln('$user : ' . $user->getFirstname());
$users = $this->subscriptionManager->getAll();
$subscriptions = $this->subscriptionManager->findByEmails(array($email));
foreach ($users as $subscription) {
foreach ($subscriptions as $subscription) {
$this->sendNotification($output, $subscription);
}
@@ -142,6 +142,8 @@ class NotificationSender implements ContainerAwareInterface
private function sendNotification(OutputInterface $output, $subscription)
{
$output->writeln(' ====== subscription ======');
$output->writeln($subscription->getEndpoint());
!$output->isVerbose()?:$output->writeln('send to user ---> ' . $subscription->getEndpoint());
$this->sender->sendNotification(
@@ -1,9 +1,7 @@
{
"parameters": {
"pushType": "tags",
"keywords": "surf;voile",
"profilCompletenessPercentage": "10",
"users": "thomas.berrod@e-declic.com;thomas.berrod@e-declic.com;thomas.berrod@e-declic.com"
"keywords": "trytodev"
},
"notification": {
"title": "Coriolis composites",
@@ -1,7 +1,7 @@
{
"parameters": {
"pushType": "tags",
"keywords": "surf;voile"
"keywords": "trytodev"
},
"notification": {
"title": "D'après vous",