<commit_before><?php

namespace Application\Bundle\FrontBundle\Controller;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Application\Bundle\FrontBundle\Entity\UserSettings;
use Application\Bundle\FrontBundle\Helper\DefaultFields as DefaultFields;
use Application\Bundle\FrontBundle\Form\UserSettingsType;

/**
 * UserSettings controller.
 *
 * @Route("/fieldsettings")
 */
class UserSettingsController extends Controller {

    /**
     * User settings
     *
     * @Route("/", name="field_settings")
     * @Method("GET")
     * @Template()
     * @return array
     */
    public function indexAction() {
        $em = $this->getDoctrine()->getManager();

        $entities = $em->getRepository('ApplicationFrontBundle:UserSettings')->findOneBy(array('user' => $this->getUser()->getId()));

        if (!$entities) {
            $fObj = new DefaultFields();
            $viewSettings = $fObj->getDefaultOrder();
        } else {
            $viewSettings = $entities->getViewSetting();
        }
        $userViewSettings = json_decode($viewSettings, true);

        return array(
            'entities' => $userViewSettings,
        );
    }

    /**
     * Update user settings
     *
     * @param Request $request
     *
     * @Route("/update", name="field_settings_update")
     * @Method("POST")
     * @Template()
     * @return array
     */
    public function updateAction(Request $request) {
        $success = FALSE;
        $reload = FALSE;
        if ($request->getMethod() == 'POST') {
            $settings = $this->get('request')->request->get('settings');
            $userSetting = json_encode($settings);
            $em = $this->getDoctrine()->getManager();
            $userEntity = $em->getRepository('ApplicationFrontBundle:UserSettings')->findOneBy(array('user' => $this->getUser()->getId()));
            if ($userEntity) {
                $userEntity->setViewSetting($userSetting);
                $userEntity->setUpdatedOnValue(date('Y-m-d h:i:s'));
                $em->persist($userEntity);
                $em->flush();
                $this->get('session')->getFlashBag()->add('success', 'Settings updated succesfully.');
                $success = TRUE;
                $reload = TRUE;
            } else {
                $userEntity = new UserSettings();
                $userEntity->setUser($this->getUser());
                $userEntity->setViewSetting($userSetting);
                $userEntity->setEnableBackup(0);
                $userEntity->setCreatedOnValue(date('Y-m-d h:i:s'));
                $em->persist($userEntity);
                $em->flush();
                $this->get('session')->getFlashBag()->add('success', 'Settings added succesfully.');
                $success = TRUE;
                $reload = TRUE;
            }
        }
        echo json_encode(array('success' => $success, 'reload' => $reload));
        exit;
    }

    /**
     * enable backup
     * 
     * @param \Symfony\Component\HttpFoundation\Request $request
     * 
     * @Route("/backup", name="field_settings_backup")
     * @Template()
     * @return array
     */
    public function backupAction(Request $request) {

        $userEntity = $this->getDoctrine()
                ->getRepository('ApplicationFrontBundle:UserSettings')
                ->findOneBy(array('user' => $this->getUser()->getId()));
        if ($userEntity) {
            $form = $this->createEditForm($userEntity);
            return array(
                'entity' => $userEntity,
                'form' => $form->createView(),
            );
        } else {
            $entity = new UserSettings();
            $form = $this->createNewForm($entity);
            return array(
                'form' => $form->createView(),
            );
        }
    }

    /**
     * create New Form
     * 
     * @param UserSettings $entity
     * 
     * @return type
     */
    public function createNewForm(UserSettings $entity) {
        $form = $this->createForm(new UserSettingsType(), $entity, array(
            'action' => $this->generateUrl('new_backup'),
            'method' => 'POST',
        ));
        $form->add('submit', 'submit', array('label' => 'Save', 'attr' => array('class' => 'button primary')));
        return $form;
    }

    /**
     * create Edit Form
     * 
     * @param UserSettings $userEntity
     * 
     * @return type
     */
    public function createEditForm(UserSettings $userEntity) {
        $form = $this->createForm(new UserSettingsType(), $userEntity, array(
            'action' => $this->generateUrl('edit_backup', array('id' => $userEntity->getId())),
            'method' => 'POST',
        ));
        $form->add('submit', 'submit', array('label' => 'Save', 'attr' => array('class' => 'button primary')));
        return $form;
    }

    /**
     * edit form
     * 
     * @param \Symfony\Component\HttpFoundation\Request $request
     * @Method ("POST")
     * @Route("/backup/{id}", name="edit_backup")
     * @Template()
     * @return array
     */
    public function updateFormAction(Request $request, $id) {
        $em = $this->getDoctrine()->getManager();
        $entity = $em->getRepository('ApplicationFrontBundle:UserSettings')->find($id);
        if (!$entity) {
            throw $this->createNotFoundException('Unable to find UserSettings entity.');
        }

        $editForm = $this->createEditForm($entity);
        $new = $editForm->handleRequest($request);

        if ($editForm->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $new =  $editForm->getData();
            echo $new['enableBackup'];exit;
            $em->persist($entity);
            $em->flush();
        }
        return $this->redirect($this->generateUrl('field_settings_backup'));
    }

    /**
     * edit form
     * 
     * @param \Symfony\Component\HttpFoundation\Request $request
     * 
     * @Route("/new", name="new_backup")
     * @Template()
     * @return array
     */
    public function newFormAction(Request $request) {
        $entity = new UserSettings();
        $form = $this->createNewForm($entity);
        $form->handleRequest($request);
        $em = $this->getDoctrine()->getManager();
        $fObj = new DefaultFields();
        $settings = $fObj->getFieldSettings($this->getUser(), $em);
        if ($form->isValid()) {
            $entity->setUser($this->getUser());
            $entity->setViewSetting(json_encode($settings));
            $em->persist($entity);
            $em->flush();
        }
        return $this->redirect($this->generateUrl('field_settings_backup'));
    }

}
<commit_msg>changes in settings<commit_after><?php

namespace Application\Bundle\FrontBundle\Controller;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Application\Bundle\FrontBundle\Entity\UserSettings;
use Application\Bundle\FrontBundle\Helper\DefaultFields as DefaultFields;
use Application\Bundle\FrontBundle\Form\UserSettingsType;

/**
 * UserSettings controller.
 *
 * @Route("/fieldsettings")
 */
class UserSettingsController extends Controller {

    /**
     * User settings
     *
     * @Route("/", name="field_settings")
     * @Method("GET")
     * @Template()
     * @return array
     */
    public function indexAction() {
        $em = $this->getDoctrine()->getManager();

        $entities = $em->getRepository('ApplicationFrontBundle:UserSettings')->findOneBy(array('user' => $this->getUser()->getId()));

        if (!$entities) {
            $fObj = new DefaultFields();
            $viewSettings = $fObj->getDefaultOrder();
        } else {
            $viewSettings = $entities->getViewSetting();
        }
        $userViewSettings = json_decode($viewSettings, true);

        return array(
            'entities' => $userViewSettings,
        );
    }

    /**
     * Update user settings
     *
     * @param Request $request
     *
     * @Route("/update", name="field_settings_update")
     * @Method("POST")
     * @Template()
     * @return array
     */
    public function updateAction(Request $request) {
        $success = FALSE;
        $reload = FALSE;
        if ($request->getMethod() == 'POST') {
            $settings = $this->get('request')->request->get('settings');
            $userSetting = json_encode($settings);
            $em = $this->getDoctrine()->getManager();
            $userEntity = $em->getRepository('ApplicationFrontBundle:UserSettings')->findOneBy(array('user' => $this->getUser()->getId()));
            if ($userEntity) {
                $userEntity->setViewSetting($userSetting);
                $userEntity->setUpdatedOnValue(date('Y-m-d h:i:s'));
                $em->persist($userEntity);
                $em->flush();
                $this->get('session')->getFlashBag()->add('success', 'Settings updated succesfully.');
                $success = TRUE;
                $reload = TRUE;
            } else {
                $userEntity = new UserSettings();
                $userEntity->setUser($this->getUser());
                $userEntity->setViewSetting($userSetting);
                $userEntity->setEnableBackup(0);
                $userEntity->setCreatedOnValue(date('Y-m-d h:i:s'));
                $em->persist($userEntity);
                $em->flush();
                $this->get('session')->getFlashBag()->add('success', 'Settings added succesfully.');
                $success = TRUE;
                $reload = TRUE;
            }
        }
        echo json_encode(array('success' => $success, 'reload' => $reload));
        exit;
    }

    /**
     * enable backup
     * 
     * @param \Symfony\Component\HttpFoundation\Request $request
     * 
     * @Route("/backup", name="field_settings_backup")
     * @Template()
     * @return array
     */
    public function backupAction(Request $request) {

        $userEntity = $this->getDoctrine()
                ->getRepository('ApplicationFrontBundle:UserSettings')
                ->findOneBy(array('user' => $this->getUser()->getId()));
        if ($userEntity) {
            $form = $this->createEditForm($userEntity);
            return array(
                'entity' => $userEntity,
                'form' => $form->createView(),
            );
        } else {
            $entity = new UserSettings();
            $form = $this->createNewForm($entity);
            return array(
                'form' => $form->createView(),
            );
        }
    }

    /**
     * create New Form
     * 
     * @param UserSettings $entity
     * 
     * @return type
     */
    public function createNewForm(UserSettings $entity) {
        $form = $this->createForm(new UserSettingsType(), $entity, array(
            'action' => $this->generateUrl('new_backup'),
            'method' => 'POST',
        ));
        $form->add('submit', 'submit', array('label' => 'Save', 'attr' => array('class' => 'button primary')));
        return $form;
    }

    /**
     * create Edit Form
     * 
     * @param UserSettings $userEntity
     * 
     * @return type
     */
    public function createEditForm(UserSettings $userEntity) {
        $form = $this->createForm(new UserSettingsType(), $userEntity, array(
            'action' => $this->generateUrl('edit_backup', array('id' => $userEntity->getId())),
            'method' => 'POST',
        ));
        $form->add('submit', 'submit', array('label' => 'Save', 'attr' => array('class' => 'button primary')));
        return $form;
    }

    /**
     * edit form
     * 
     * @param \Symfony\Component\HttpFoundation\Request $request
     * @Method ("POST")
     * @Route("/backup/{id}", name="edit_backup")
     * @Template()
     * @return array
     */
    public function updateFormAction(Request $request, $id) {
        $em = $this->getDoctrine()->getManager();
        $entity = $em->getRepository('ApplicationFrontBundle:UserSettings')->find($id);
        if (!$entity) {
            throw $this->createNotFoundException('Unable to find UserSettings entity.');
        }
		echo '<pre>';
		print_r($this->get('request')->request->get('settings'))
		;exit;
        $editForm = $this->createEditForm($entity);
        $new = $editForm->handleRequest($request);

        if ($editForm->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $new =  $editForm->getData();
            echo $new['enableBackup'];exit;
            $em->persist($entity);
            $em->flush();
        }
        return $this->redirect($this->generateUrl('field_settings_backup'));
    }

    /**
     * edit form
     * 
     * @param \Symfony\Component\HttpFoundation\Request $request
     * 
     * @Route("/new", name="new_backup")
     * @Template()
     * @return array
     */
    public function newFormAction(Request $request) {
        $entity = new UserSettings();
        $form = $this->createNewForm($entity);
        $form->handleRequest($request);
        $em = $this->getDoctrine()->getManager();
        $fObj = new DefaultFields();
        $settings = $fObj->getFieldSettings($this->getUser(), $em);
        if ($form->isValid()) {
            $entity->setUser($this->getUser());
            $entity->setViewSetting(json_encode($settings));
            $em->persist($entity);
            $em->flush();
        }
        return $this->redirect($this->generateUrl('field_settings_backup'));
    }

}

{'fraction_non_alphanumeric': 0.16317658140714442, 'fraction_numerical': 0.00014491703499746396, 'mean_word_length': 2.2791636968401043, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 207, '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': '4941834', 'n_tokens_mistral': 3804, 'n_tokens_neox': 3749, 'n_words': 640}