<commit_before><?php
namespace AppBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Chme\RestBundle\Controller\RestController;
use AppBundle\Entity\Video;

class Video2ApiController extends RestController {
	/**
	 * @Route("/videoapi/{id}", name="Api", requirements={"id": "\d+"} )
	 */
	public function defaultAction($id=0) {
		
		return parent::indexAction($id);
	}
	
	/**
	 * @Route("/videoapi/", name="ApiNoid" )
	 */
	public function defaultNoIdAction() {
		return parent::indexAction();
	}
	
	protected function GET_PAG(Request $request,$Id=null) {		
		$t['Id']=$Id;
		$video = $this->getDoctrine()->getRepository('AppBundle:Video')->find($Id);
		if (!$video) {
			$t['exception']='No video found for id '.$Id;
			return JsonResponse::create($t,RESPONSE::HTTP_NOT_FOUND);
		}
		$t['data']=$video;
		return $this->json($t);
	}
	
	protected function LIST_PAG(Request $request) {		
		$videos=$this->getDoctrine()->getRepository("AppBundle:Video")->listVideoswithLanguageTranscript() ; //listVideoswithLanguage();
		$resp['data']=$videos;
		$serializer = $this->get('serializer');
		//$json =$serializer->serialize($resp);
		return $this->json($resp);
	}
	
	protected function POST_PAG(Request $request,$Id=null) {		
		$video=$this->setVideo($this->getContentJson($request));
		if (!(strlen($video->getFilename()) > 0 && is_numeric($video->getVideoid()))) {
			$t['exception']='No videoid and/or filename set ';
			return JsonResponse::create($t,RESPONSE::HTTP_UNPROCESSABLE_ENTITY);
		}
		$em = $this->getDoctrine()->getManager();
		$em->persist($video);
		$em->flush();
		return $this->json($video);
	}
	
	
	protected function PUT_PAG(Request $request,$Id=null) {		
		$video=$this->setVideo($this->getContentJson($request));
		if (!(strlen($video->getFilename()) > 0 && is_numeric($video->getVideoid()))) {
			$t['exception']='No videoid and/or filename set ';
			return JsonResponse::create($t,RESPONSE::HTTP_BAD_REQUEST);
		}
		$em = $this->getDoctrine()->getManager();
		$em->flush();		
		return $this->json($video);
	}
	
	protected function setVideo($video_data): Video {
		$video=new Video();
		if (is_array($video_data)) {
			if (array_key_exists('id', $video_data) && $video_data['id']>0) {
				$id=$video_data['id'];
				$video = $this->getDoctrine()->getRepository('AppBundle:Video')->find($id);
				if (!$video) {
					return null;				
				}
			}	
			if (array_key_exists('filename', $video_data))
				$video->setFilename($video_data['filename']);
			if (array_key_exists('subjectname', $video_data))
				$video->setSubjectname($video_data['subjectname']);
			if (array_key_exists('videoid', $video_data))
				$video->setVideoid($video_data['videoid']);
			if (array_key_exists('patientact', $video_data))
				$video->setPatientact(($video_data['patientact']));
				
			if (array_key_exists('language', $video_data) && is_array($video_data['language']) && array_key_exists('id',$video_data['language'] )) {
				 $lid=$video_data['language']['id'];
				 $lang=$this->getDoctrine()->getRepository("AppBundle:Language")->find($lid);
				 if ($lang)
				 	$video->setLanguage($lang);
			}
			foreach ($video->getTranscripts() as $oldtrans) {
				$video->removeTranscript($oldtrans);
			}
			if (array_key_exists('transcripts', $video_data) && is_array($video_data['transcripts']) && count($video_data['transcripts'])>0)  {			
				foreach ($video_data['transcripts'] as $transcript) {
					if (array_key_exists('id',$transcript)) {
						$lid=$transcript['id'];
						$lang=$this->getDoctrine()->getRepository("AppBundle:Language")->find($lid);
						if ($lang) 
							$video->addTranscript($lang);
					}
				}
			}			
		}
		return $video;
	}
	
	protected function getContentJson(Request $request) {
		$content=utf8_encode($request->getContent());
		$jsonvars=null;
		if (!empty($content)) {
			$jsonvars = json_decode($content,true); // 2nd param to get as array
		}
		return $jsonvars;
	}
	
	protected function DELETE_PAG(Request $request,$Id=null) {
		$t['method']= "DELETE  in API!!!";
		$t['contenttype']=$request->headers->get('content_type');
		$t['Id']=$Id;
		//return $this->json($t);
		//$resp=new Response('',RESPONSE::HTTP_OK);
		return JsonResponse::create($t);
	}
	
}<commit_msg>delete video in api<commit_after><?php
namespace AppBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Chme\RestBundle\Controller\RestController;
use AppBundle\Entity\Video;

class Video2ApiController extends RestController {
	/**
	 * @Route("/videoapi/{id}", name="Api", requirements={"id": "\d+"} )
	 */
	public function defaultAction($id=0) {
		
		return parent::indexAction($id);
	}
	
	/**
	 * @Route("/videoapi/", name="ApiNoid" )
	 */
	public function defaultNoIdAction() {
		return parent::indexAction();
	}
	
	protected function GET_PAG(Request $request,$Id=null) {		
		$t['Id']=$Id;
		$video = $this->getDoctrine()->getRepository('AppBundle:Video')->find($Id);
		if (!$video) {
			$t['exception']='No video found for id '.$Id;
			return JsonResponse::create($t,RESPONSE::HTTP_NOT_FOUND);
		}
		$t['data']=$video;
		return $this->json($t);
	}
	
	protected function LIST_PAG(Request $request) {		
		$videos=$this->getDoctrine()->getRepository("AppBundle:Video")->listVideoswithLanguageTranscript() ; //listVideoswithLanguage();
		$resp['data']=$videos;
		$serializer = $this->get('serializer');
		//$json =$serializer->serialize($resp);
		return $this->json($resp);
	}
	
	protected function POST_PAG(Request $request,$Id=null) {		
		$video=$this->setVideo($this->getContentJson($request));
		if (!(strlen($video->getFilename()) > 0 && is_numeric($video->getVideoid()))) {
			$t['exception']='No videoid and/or filename set ';
			return JsonResponse::create($t,RESPONSE::HTTP_UNPROCESSABLE_ENTITY);
		}
		$em = $this->getDoctrine()->getManager();
		$em->persist($video);
		$em->flush();
		return $this->json($video);
	}
	
	
	protected function PUT_PAG(Request $request,$Id=null) {		
		$video=$this->setVideo($this->getContentJson($request));
		if (!(strlen($video->getFilename()) > 0 && is_numeric($video->getVideoid()))) {
			$t['exception']='No videoid and/or filename set ';
			return JsonResponse::create($t,RESPONSE::HTTP_BAD_REQUEST);
		}
		$em = $this->getDoctrine()->getManager();
		$em->flush();		
		return $this->json($video);
	}
	
	protected function setVideo($video_data): Video {
		$video=new Video();
		if (is_array($video_data)) {
			if (array_key_exists('id', $video_data) && $video_data['id']>0) {
				$id=$video_data['id'];
				$video = $this->getDoctrine()->getRepository('AppBundle:Video')->find($id);
				if (!$video) {
					return null;				
				}
			}	
			if (array_key_exists('filename', $video_data))
				$video->setFilename($video_data['filename']);
			if (array_key_exists('subjectname', $video_data))
				$video->setSubjectname($video_data['subjectname']);
			if (array_key_exists('videoid', $video_data))
				$video->setVideoid($video_data['videoid']);
			if (array_key_exists('patientact', $video_data))
				$video->setPatientact(($video_data['patientact']));
				
			if (array_key_exists('language', $video_data) && is_array($video_data['language']) && array_key_exists('id',$video_data['language'] )) {
				 $lid=$video_data['language']['id'];
				 $lang=$this->getDoctrine()->getRepository("AppBundle:Language")->find($lid);
				 if ($lang)
				 	$video->setLanguage($lang);
			}
			foreach ($video->getTranscripts() as $oldtrans) {
				$video->removeTranscript($oldtrans);
			}
			if (array_key_exists('transcripts', $video_data) && is_array($video_data['transcripts']) && count($video_data['transcripts'])>0)  {			
				foreach ($video_data['transcripts'] as $transcript) {
					if (array_key_exists('id',$transcript)) {
						$lid=$transcript['id'];
						$lang=$this->getDoctrine()->getRepository("AppBundle:Language")->find($lid);
						if ($lang) 
							$video->addTranscript($lang);
					}
				}
			}			
		}
		return $video;
	}
	
	protected function getContentJson(Request $request) {
		$content=utf8_encode($request->getContent());
		$jsonvars=null;
		if (!empty($content)) {
			$jsonvars = json_decode($content,true); // 2nd param to get as array
		}
		return $jsonvars;
	}
	
	protected function DELETE_PAG(Request $request,$Id=null) {
		$em = $this->getDoctrine()->getManager();		
		$video = $this->getDoctrine()->getRepository('AppBundle:Video')->find($Id);		
		if (!$video) {
			$t['exception']='No video found for id '.$Id;
			return JsonResponse::create($t,RESPONSE::HTTP_NOT_FOUND);
		}
		$em->remove($video);
		$em->flush();		
		//return $this->json($t);
		//$resp=new Response('',RESPONSE::HTTP_OK);
		return $this->json($video);
	}
	
}
{'fraction_non_alphanumeric': 0.19611736157070372, 'fraction_numerical': 0.0017648356496801235, 'mean_word_length': 5.244490358126722, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 113, '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': '5519532', 'n_tokens_mistral': 3463, 'n_tokens_neox': 3025, 'n_words': 443}