<commit_before><?php

namespace MVNerds\NewsBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpFoundation\Response;

/**
 * @Route("/news")
 */
class NewsController extends Controller
{

	/**
	 * @Route("/", name="news_index")
	 */
	public function indexAction()
	{
		$newsManager = $this->get('mvnerds.news_manager');
		if ($this->get('security.context')->isGranted('ROLE_NEWSER')){
			$news = $newsManager->findAllNotPrivate();
		} else {
			$news = $newsManager->findAllPublic();
		}
		
		return $this->render('MVNerdsNewsBundle:News:list_index.html.twig', array(
			'news'	=> $news,
			'news_categories' => $newsManager->findAllNewsCategories()
		));
	}
	
	/**
	 * Action appelée par datatables pour charger le tableau de news en ajax
	 * @Route("/list-ajax", name="news_list_ajax", options={"expose"=true})
	 */
	public function listAjaxAction()
	{
		$request = $this->getRequest();
		if (!$request->isXmlHttpRequest()) {
			throw new HttpException(500, 'Request must be AJAX');
		}
		
		$aColumns = array(
			'',
			'',
			'',
			'user.USERNAME',
			'Create_Time',
			'Update_Time',
			'news_i18n.Title',
			'View',
			'news_category.UNIQUE_NAME',
			'Comment_Count'
		);
		
		$limitStart = 0;
		$limitLength = -1;
		//Pagination
		if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' ) {
			$limitStart = $_GET['iDisplayStart'];
			$limitLength = $_GET['iDisplayLength'];
		}
		//Tri
		$orderArr = array();
		if ( isset( $_GET['iSortCol_0'] ) ) {
			for ( $i=0 ; $i<intval( $_GET['iSortingCols'] ) ; $i++ ) {
				if ( $_GET[ 'bSortable_'.intval($_GET['iSortCol_'.$i]) ] == "true" ) {
					$orderArr[$aColumns[intval($_GET['iSortCol_'.$i])]] = ($_GET['sSortDir_'.$i]);
				}
			}
		}
		if (count($orderArr) <= 0) {
			$orderArr = array('Create_Time' => 'desc');
		}
		//Recherche par colonne
		$whereArr = array();
		for ( $i=0 ; $i<count($aColumns) ; $i++ )
		{
			if ( isset($_GET['bSearchable_'.$i]) && $_GET['bSearchable_'.$i] == "true" && $_GET['sSearch_'.$i] != '' )
			{
				if ($aColumns[$i] == 'user.USERNAME' || $aColumns[$i] == 'Title' || $aColumns[$i] == 'news_category.UNIQUE_NAME')
				{
					$whereArr[$aColumns[$i]] = ($_GET['sSearch_'.$i]);
				}
			}
		}
		
		$translator = $this->get('translator');
		$newsManager = $this->get('mvnerds.news_manager');
		
		$onlyPublic = true;
		if ($this->get('security.context')->isGranted('ROLE_NEWSER')){
			$onlyPublic = false;
		}
		
		$news = $newsManager->findAllAjax($onlyPublic, $limitStart, $limitLength, $orderArr, $whereArr);
		
		$jsonNews = array(
			"tab" => $news->count(),<commit_msg>Fix bug filtrage par titre des news<commit_after><?php

namespace MVNerds\NewsBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpFoundation\Response;

/**
 * @Route("/news")
 */
class NewsController extends Controller
{

	/**
	 * @Route("/", name="news_index")
	 */
	public function indexAction()
	{
		$newsManager = $this->get('mvnerds.news_manager');
		if ($this->get('security.context')->isGranted('ROLE_NEWSER')){
			$news = $newsManager->findAllNotPrivate();
		} else {
			$news = $newsManager->findAllPublic();
		}
		
		return $this->render('MVNerdsNewsBundle:News:list_index.html.twig', array(
			'news'	=> $news,
			'news_categories' => $newsManager->findAllNewsCategories()
		));
	}
	
	/**
	 * Action appelée par datatables pour charger le tableau de news en ajax
	 * @Route("/list-ajax", name="news_list_ajax", options={"expose"=true})
	 */
	public function listAjaxAction()
	{
		$request = $this->getRequest();
		if (!$request->isXmlHttpRequest()) {
			throw new HttpException(500, 'Request must be AJAX');
		}
		
		$aColumns = array(
			'',
			'',
			'',
			'user.USERNAME',
			'Create_Time',
			'Update_Time',
			'news_i18n.Title',
			'View',
			'news_category.UNIQUE_NAME',
			'Comment_Count'
		);
		
		$limitStart = 0;
		$limitLength = -1;
		//Pagination
		if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' ) {
			$limitStart = $_GET['iDisplayStart'];
			$limitLength = $_GET['iDisplayLength'];
		}
		//Tri
		$orderArr = array();
		if ( isset( $_GET['iSortCol_0'] ) ) {
			for ( $i=0 ; $i<intval( $_GET['iSortingCols'] ) ; $i++ ) {
				if ( $_GET[ 'bSortable_'.intval($_GET['iSortCol_'.$i]) ] == "true" ) {
					$orderArr[$aColumns[intval($_GET['iSortCol_'.$i])]] = ($_GET['sSortDir_'.$i]);
				}
			}
		}
		if (count($orderArr) <= 0) {
			$orderArr = array('Create_Time' => 'desc');
		}
		//Recherche par colonne
		$whereArr = array();
		for ( $i=0 ; $i<count($aColumns) ; $i++ )
		{
			if ( isset($_GET['bSearchable_'.$i]) && $_GET['bSearchable_'.$i] == "true" && $_GET['sSearch_'.$i] != '' )
			{
				if ($aColumns[$i] == 'user.USERNAME' || $aColumns[$i] == 'news_i18n.Title' || $aColumns[$i] == 'news_category.UNIQUE_NAME')
				{
					$whereArr[$aColumns[$i]] = ($_GET['sSearch_'.$i]);
				}
			}
		}
		
		$translator = $this->get('translator');
		$newsManager = $this->get('mvnerds.news_manager');
		
		$onlyPublic = true;
		if ($this->get('security.context')->isGranted('ROLE_NEWSER')){
			$onlyPublic = false;
		}
		
		$news = $newsManager->findAllAjax($onlyPublic, $limitStart, $limitLength, $orderArr, $whereArr);
		
		$jsonNews = array(
			"tab" => $news->count(),
{'fraction_non_alphanumeric': 0.20625451916124368, 'fraction_numerical': 0.004699927693420101, 'mean_word_length': 4.076146788990826, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 41, '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': '2647067', 'n_tokens_mistral': 2300, 'n_tokens_neox': 2029, 'n_words': 315}