Last active
August 30, 2018 09:58
-
-
Save taiebb/ad5ad6986b255a14f087a7c784693e5b to your computer and use it in GitHub Desktop.
comment enlever la duplication de la fonction readNotificationAction (elle est utilisée dans d'autres controleur)?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace AppBundle\Controller; | |
use AppBundle\Service\VisionCriticalApi; | |
use DateTime; | |
use EasyWordpressBundle\Annotation\TemplateName; | |
use EasyWordpressBundle\Controller\WordpressController; | |
use Symfony\Component\HttpFoundation\Request; | |
use Symfony\Component\HttpFoundation\Response; | |
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | |
use AppBundle\Service; | |
/** | |
* Class HomeController. | |
* | |
* @author Thomas Talbot <thomas.talbot@zephyr-web.fr> | |
*/ | |
class HomeController extends WordpressController | |
{ | |
/** | |
* Mark a notification as read | |
* | |
* @Route("/read-notification", | |
* options={"expose"=true}, | |
* name="read_notification", | |
* ) | |
* | |
* @param Request $request The current user request | |
* @return Response | |
*/ | |
public function readNotificationAction(Request $request) | |
{ | |
if ($request->isXmlHttpRequest()) { | |
$response = new Response(); | |
$data = []; | |
if ($request->isMethod('post')) { | |
if (!empty($request->request->get('notifId'))) { | |
$notificationId = $request->request->get('notifId'); | |
$wpUser = wp_get_current_user(); | |
// Update notification status | |
$soNotif = new \SoNotifications(); | |
$unreadNotifs = $soNotif->updateNotifStatus($notificationId, $wpUser->ID); | |
$data = ['status' => 'success', 'unreadNotifs' => $unreadNotifs]; | |
} | |
} else { | |
$data = ['status' => 'failed', 'message' => 'Action non autorisée !']; | |
} | |
$data = json_encode($data); | |
$response->headers->set('Content-Type', 'application/json'); | |
$response->setContent($data); | |
return $response; | |
} else { | |
return new Response(['status' => 'failed', 'message' => 'demande non autorisée !']); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment