<commit_before><?php
namespace OpenCFP\Controller\Admin;

use Silex\Application;
use Symfony\Component\HttpFoundation\Request;
use OpenCFP\Model\Talk;
use OpenCFP\Model\Speaker;
use Pagerfanta\View\TwitterBootstrapView;

class TalksController 
{
    public function indexAction(Request $req, Application $app)
    {
        if (!$app['sentry']->check()) {
            return $app->redirect($app['url'] . '/login');
        }

        $user = $app['sentry']->getUser();
        $permissions = $user->hasPermission('admin');
        
        if (!$permissions) {
            return $app->redirect($app['url'] . '/login');
        }

        $talkModel = new Talk($app['db']);
        $rawTalks = $talkModel->getAll();

        // Set up our page stuff
        $adapter = new \Pagerfanta\Adapter\ArrayAdapter($rawTalks);
        $pagerfanta = new \Pagerfanta\Pagerfanta($adapter);
        $pagerfanta->setMaxPerPage(20);
        $pagerfanta->getNbResults();

        if ($req->get('page') !== null) {
            $pagerfanta->setCurrentPage($req->get('page'));
        }

        // Create our default view for the navigation options
        $routeGenerator = function($page) {
            return '/admin/talks/' . $page;
        };
        $view = new TwitterBootstrapView();
        $pagination = $view->render(
            $pagerfanta,
            $routeGenerator,
            array('proximity' => 3)
        );

        $template = $app['twig']->loadTemplate('admin/talks.twig');
        $templateData = array(
            'pagination' => $pagination,
            'talks' => $pagerfanta,
            'page' => $pagerfanta->getCurrentPage()
        );

        return $template->render($templateData);
    }

    public function viewAction(Request $req, Application $app)
    {
        if (!$app['sentry']->check()) {
            return $app->redirect($app['url'] . '/login');
        }

        $user = $app['sentry']->getUser();
        $permissions = $user->getPermissions();

        if (!isset($permissions['admin']) || $permissions['admin'] !== 1) {
            return $app->redirect($app['url'] . '/login');
        }

        // Get info about the talks
        $talkId = $req->get('id');
        $talkModel = new Talk($app['db']);
        $talk = $talkModel->findById($talkId);

        // Get info about our speaker
        $speakerModel = new Speaker($app['db']);
        $speaker = $speakerModel->findByUserId($talk['user_id']);
        <commit_msg>Fixed Admin priviledges (for viewing talks) to use the correct method for retrieving group.<commit_after><?php
namespace OpenCFP\Controller\Admin;

use Silex\Application;
use Symfony\Component\HttpFoundation\Request;
use OpenCFP\Model\Talk;
use OpenCFP\Model\Speaker;
use Pagerfanta\View\TwitterBootstrapView;

class TalksController 
{
    public function indexAction(Request $req, Application $app)
    {
        if (!$app['sentry']->check()) {
            return $app->redirect($app['url'] . '/login');
        }

        $user = $app['sentry']->getUser();
        $permissions = $user->hasPermission('admin');
        
        if (!$permissions) {
            return $app->redirect($app['url'] . '/login');
        }

        $talkModel = new Talk($app['db']);
        $rawTalks = $talkModel->getAll();

        // Set up our page stuff
        $adapter = new \Pagerfanta\Adapter\ArrayAdapter($rawTalks);
        $pagerfanta = new \Pagerfanta\Pagerfanta($adapter);
        $pagerfanta->setMaxPerPage(20);
        $pagerfanta->getNbResults();

        if ($req->get('page') !== null) {
            $pagerfanta->setCurrentPage($req->get('page'));
        }

        // Create our default view for the navigation options
        $routeGenerator = function($page) {
            return '/admin/talks/' . $page;
        };
        $view = new TwitterBootstrapView();
        $pagination = $view->render(
            $pagerfanta,
            $routeGenerator,
            array('proximity' => 3)
        );

        $template = $app['twig']->loadTemplate('admin/talks.twig');
        $templateData = array(
            'pagination' => $pagination,
            'talks' => $pagerfanta,
            'page' => $pagerfanta->getCurrentPage()
        );

        return $template->render($templateData);
    }

    public function viewAction(Request $req, Application $app)
    {
        if (!$app['sentry']->check()) {
            return $app->redirect($app['url'] . '/login');
        }

        $user = $app['sentry']->getUser();
        $permissions['admin'] = $user->hasPermission('admin');

        if (!$permissions['admin']) {
            return $app->redirect($app['url'] . '/login');
        }

        // Get info about the talks
        $talkId = $req->get('id');
        $talkModel = new Talk($app['db']);
        $talk = $talkModel->findById($talkId);

        // Get info about our speaker
        $speakerModel = new Speaker($app['db']);
        $speaker = $speakerModel->findByUserId($talk['user_id']);
        
{'fraction_non_alphanumeric': 0.16696805304400242, 'fraction_numerical': 0.0014064697609001407, 'mean_word_length': 2.298873426110007, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 57, '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': '7482186', 'n_tokens_mistral': 1491, 'n_tokens_neox': 1464, 'n_words': 281}