Esempio n. 1
0
 public function DoPost()
 {
     /** @var \Doctrine\ORM\EntityManager $em */
     $em = CommonController::$EntityManager;
     $request = $this->request;
     $audioId = $request->getPost("audioId");
     $listeningState = $request->getPost("state");
     $userId = $this->userId;
     $audio = $em->getRepository('audio')->find($audioId);
     if ($audio !== null) {
         $user = $em->getRepository('User')->find($userId);
         if ($user !== null) {
             $listening = new \Listening();
             $listening->setDatetime(new \DateTime("now"));
             $listening->setIdAudio($audio);
             $listening->setIdUser($user);
             $listening->setState($listeningState);
             $em->persist($listening);
             $metadata = $em->getClassMetaData(get_class($listening));
             $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_NONE);
             $em->flush();
             return "true";
         }
     }
     return "false";
 }
Esempio n. 2
0
 public function DoPost()
 {
     $uri = CommonController::GetCurrentUri();
     $explUri = explode("/", $uri);
     $id = $explUri[count($explUri) - 2];
     $repo = CommonController::$EntityManager->getRepository('audio');
     $audio = $repo->find($id);
     if ($audio !== null) {
         $UserRepo = CommonController::$EntityManager->getRepository('User');
         $user = $UserRepo->find('00000000001');
         if ($user !== null) {
             $Listening = new \Listening();
             $Listening->setDatetime(new \DateTime("now"));
             $Listening->setIdAudio($audio);
             $Listening->setIdUser($user);
             $Listening->setState($explUri[count($explUri) - 1]);
             CommonController::$EntityManager->persist($Listening);
             CommonController::$EntityManager->flush();
             return true;
         }
     }
     return false;
 }