<commit_before><?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace SIWOZ\EguardianBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
//use Symfony\Component\Serializer\Serializer;
//use JMS\SerializerBundle\Serializer;
use JMS\Serializer;
use JMS\Serializer\SerializationContext;

/**
 * Description of UserController
 *
 * @author Marcin
 */
class UserController extends Controller {

    private $serializer;

    function __construct() {
        $this->serializer = Serializer\SerializerBuilder::create()->build();
        // $this->serializer =  $this->getConfigurationPool()->getContainer()->get('jms_serializer');
    }

    public function placeAction($id) {
        $place = $this->getDoctrine()->getRepository('EguardianBundle:Place')->find($id);
        $jsonContent = $this->serializer->serialize($place, 'json');
        return new Response($jsonContent);
    }

    public function putPlaceAction() {
        $json = $this->getRequest()->getContent();
        $em = $this->getDoctrine()->getManager();
        $place = $this->serializer->deserialize($json, 'SIWOZ\EguardianBundle\Entity\Place', 'json');
        $em->persist($place);
        $em->flush();
        return new Response($this->serializer->serialize($place, 'json'));
    }

    public function putSeniorUserAction() {
        /* $place=new Place();
          $place->setApartmentNo("1");
          $place->setCity("Zaniemyl");
          $place->setPostCode("32444");
          $place->setStreet("Libelrer");
          $place->setStreetNo("2");
          $place->setTelephoneNumber("64545666");
          $user=new SeniorUser();
          $user->setLogin("testLogin");
          $user->setPassword("<PASSWORD>");
          $user->setPlace($place);
          return new Response($this->serializer->serialize($user, 'json')); */


        $json = $this->getRequest()->getContent();
        $em = $this->getDoctrine()->getManager();
        $seniorUser = $this->serializer->deserialize($json, 'SIWOZ\EguardianBundle\Entity\SeniorUser', 'json');
        $this->getDoctrine()->getRepository('EguardianBundle:User')->addUser($seniorUser);
        $em->persist($seniorUser);
        $em->flush();
        return new Response($this->serializer->serialize($seniorUser, 'json', SerializationContext::create()->enableMaxDepthChecks()->setGroups(array('Default'))));
    }

    public function putGuardianUserAction() {
        $json = $this->getRequest()->getContent();
        $guardianUser = $this->serializer->deserialize($json, 'SIWOZ\EguardianBundle\Entity\GuardianUser', 'json');
        $this->getDoctrine()->getRepository('EguardianBundle:User')->addUser($guardianUser);
        return new Response($this->serializer->serialize($guardianUser, 'json', SerializationContext::create()->enableMaxDepthChecks()->setGroups(array('Default'))));
    }

    public function addGuardianToSeniorAction($guardianLogin, $seniorLogin) {
        //$json = $this->getRequest()->getContent();
        //$seniorUser = $this->serializer->deserialize($json, 'SIWOZ\EguardianBundle\Entity\GuardianUser', 'json');
        $guardianUser = $this->getDoctrine()->getRepository('EguardianBundle:User')->addGuardianToSenior($guardianLogin, $seniorLogin);
        return new Response($this->serializer->serialize($guardianUser, 'json'), SerializationContext::create()->enableMaxDepthChecks()->setGroups(array('All')));
    }

    public function removeGuardianToSeniorAction($guardianLogin, $seniorLogin) {<commit_msg>poprawione dodawanie seniora do guardian;<commit_after><?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace SIWOZ\EguardianBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
//use Symfony\Component\Serializer\Serializer;
//use JMS\SerializerBundle\Serializer;
use JMS\Serializer;
use JMS\Serializer\SerializationContext;

/**
 * Description of UserController
 *
 * @author Marcin
 */
class UserController extends Controller {

    private $serializer;

    function __construct() {
        $this->serializer = Serializer\SerializerBuilder::create()->build();
        // $this->serializer =  $this->getConfigurationPool()->getContainer()->get('jms_serializer');
    }

    public function placeAction($id) {
        $place = $this->getDoctrine()->getRepository('EguardianBundle:Place')->find($id);
        $jsonContent = $this->serializer->serialize($place, 'json');
        return new Response($jsonContent);
    }

    public function putPlaceAction() {
        $json = $this->getRequest()->getContent();
        $em = $this->getDoctrine()->getManager();
        $place = $this->serializer->deserialize($json, 'SIWOZ\EguardianBundle\Entity\Place', 'json');
        $em->persist($place);
        $em->flush();
        return new Response($this->serializer->serialize($place, 'json'));
    }

    public function putSeniorUserAction() {
        /* $place=new Place();
          $place->setApartmentNo("1");
          $place->setCity("Zaniemyl");
          $place->setPostCode("32444");
          $place->setStreet("Libelrer");
          $place->setStreetNo("2");
          $place->setTelephoneNumber("64545666");
          $user=new SeniorUser();
          $user->setLogin("testLogin");
          $user->setPassword("<PASSWORD>");
          $user->setPlace($place);
          return new Response($this->serializer->serialize($user, 'json')); */


        $json = $this->getRequest()->getContent();
        $em = $this->getDoctrine()->getManager();
        $seniorUser = $this->serializer->deserialize($json, 'SIWOZ\EguardianBundle\Entity\SeniorUser', 'json');
        $this->getDoctrine()->getRepository('EguardianBundle:User')->addUser($seniorUser);
        $em->persist($seniorUser);
        $em->flush();
        return new Response($this->serializer->serialize($seniorUser, 'json', SerializationContext::create()->enableMaxDepthChecks()->setGroups(array('Default'))));
    }

    public function putGuardianUserAction() {
        $json = $this->getRequest()->getContent();
        $guardianUser = $this->serializer->deserialize($json, 'SIWOZ\EguardianBundle\Entity\GuardianUser', 'json');
        $this->getDoctrine()->getRepository('EguardianBundle:User')->addUser($guardianUser);
        return new Response($this->serializer->serialize($guardianUser, 'json', SerializationContext::create()->enableMaxDepthChecks()->setGroups(array('Default'))));
    }

    public function addGuardianToSeniorAction($guardianLogin, $seniorLogin) {
        //$json = $this->getRequest()->getContent();
        //$seniorUser = $this->serializer->deserialize($json, 'SIWOZ\EguardianBundle\Entity\GuardianUser', 'json');
        $guardianUser = $this->getDoctrine()->getRepository('EguardianBundle:User')->addGuardianToSenior($guardianLogin, $seniorLogin);
        return new Response($this->serializer->serialize($guardianUser, 'json', SerializationContext::create()->enableMaxDepthChecks()->setGroups(array('All'))));
    }

    public function removeGuardianToSeniorAction($guardianLogin, $seniorLogin) {
{'fraction_non_alphanumeric': 0.16572123176661263, 'fraction_numerical': 0.004051863857374392, 'mean_word_length': 4.1033769813921435, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 143, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7146952', 'n_tokens_mistral': 2098, 'n_tokens_neox': 2051, 'n_words': 322}