Add reputation to users
OriolLlovera opened this issue · 2 comments
OriolLlovera commented
I add a reputation field on my fos_user table and I'm trying to implement this system on posts to vote users. I create a function on PostController that works fine if I check the database but the redirect didn't work.
`public function puntuacioAction(Request $request){
$em = $this->getDoctrine()->getManager();
$idPoster = $request->request->get('id_posterUser');
$positive= $request->request->get('positive');
$negative= $request->request->get('negative');
$user= $em->getRepository(User::class)->findOneById($idPoster);
$topic = $em->getRepository(Topic::class)->findOneByUser($user->getId());
$puntuacio = $usuari->getReputatio();
if ($positive!= null) {
$puntuacio = $puntuacio + 1;
}
if($negative!= null){
$puntuacio = $puntuacio - 1;
}
$usuari->setReputacio($puntuacio);
$em->persist($usuari);
$em->flush();
return $this->forward('DForumBundle:Post:post', array('slug' => $topic->getSlug()));
}`
Can someone tell me how should be my return? I'm not sure how does annotations routes works so I did it on my own way.
OriolLlovera commented
I didn't translate the code sorry now its in english.
Solved if someone need the code :
public function ScoreAction(Request $request){`
$em = $this->getDoctrine()->getManager();
$idTopic = $request->request->get('id_topic');
$idPoster = $request->request->get('id_poster');
$positive= $request->request->get('positive');
$negative= $request->request->get('negatiu');
$user= $em->getRepository(User::class)->findOneById($idPoster);
$topic = $em->getRepository(Topic::class)->findOneById($idTopic);
$score= $user->getReputation();
if ($positive!= null) {
$score= $score+ 1;
}
if($negative!= null){
$score= $score- 1;
}
$user->setReputation($score);
$em->persist($user);
$em->flush();
$redirect = $this->generateUrl('discutea_forum_post', array('slug' => $topic->getSlug()));
return $this->redirect($redirect);
}`
Strategy47 commented
Thank you sorry for the delay.