/**
  * Lists all Test entities.
  *
  * @Route("/", name="test")
  * @Template()
  */
 public function indexAction()
 {
     $request = $this->getRequest();
     $em = $this->getDoctrine()->getEntityManager();
     $page = $request->query->get('page');
     if (!$page) {
         $page = 1;
     }
     $query = $em->createQueryBuilder();
     $query->add('select', 't')->add('from', 'ApplicationTestBundle:Test t')->add('orderBy', 't.featured DESC, t.position ASC, t.id DESC');
     $adapter = new DoctrineORMAdapter($query);
     $pagerfanta = new Pagerfanta($adapter);
     $pagerfanta->setMaxPerPage(10);
     // 10 by default
     $maxPerPage = $pagerfanta->getMaxPerPage();
     $pagerfanta->setCurrentPage($page);
     // 1 by default
     $entities = $pagerfanta->getCurrentPageResults();
     $routeGenerator = function ($page) {
         $url = '?page=' . $page;
         return $url;
     };
     $view = new DefaultView();
     $html = $view->render($pagerfanta, $routeGenerator);
     //$twig = $this->container->get('twig');
     //$twig->addExtension(new \Twig_Extensions_Extension_Text);
     return array('pager' => $html, 'entities' => $entities);
 }
 public function testRender()
 {
     $pagerfanta = $this->getMockBuilder('Pagerfanta\\Pagerfanta')->disableOriginalConstructor()->getMock();
     $pagerfanta->expects($this->any())->method('getCurrentPage')->will($this->returnValue(10));
     $pagerfanta->expects($this->any())->method('getNbPages')->will($this->returnValue(100));
     $view = new DefaultView();
     $this->assertTrue(is_string($ups = $view->render($pagerfanta, function ($page) {
         return $page;
     })));
 }
 /**
  * Lists all Project entities.
  *
  * @Route("/", name="project")
  * @Template()
  */
 public function indexAction()
 {
     $request = $this->getRequest();
     $page = $request->query->get('page', 1);
     // type?
     $type = $request->query->get('t', 0);
     if (!in_array($type, array(0, 1, 2))) {
         return $this->redirect($this->generateUrl('project'));
     }
     // category_id?
     $category_id = $request->query->get('c', 0);
     $q = $this->getDoctrine()->getEntityManager()->getRepository('ApplicationProjectBundle:Project')->getProjectsDQL($type, $category_id);
     $adapter = new DoctrineORMAdapter($q);
     $pagerfanta = new Pagerfanta($adapter);
     $pagerfanta->setMaxPerPage(10);
     // 10 by default
     $maxPerPage = $pagerfanta->getMaxPerPage();
     $pagerfanta->setCurrentPage($page);
     // 1 by default
     $entities = $pagerfanta->getCurrentPageResults();
     $routeGenerator = function ($page, $category_id, $type) {
         $url = '?page=' . $page;
         if ($category_id) {
             $url .= '&c=' . $category_id;
         }
         if ($type) {
             $url .= '&t=' . $type;
         }
         return $url;
     };
     $view = new DefaultView();
     $html = $view->render($pagerfanta, $routeGenerator, array('category_id' => (int) $category_id, 'type' => (int) $type));
     //$twig = $this->container->get('twig');
     //$twig->addExtension(new \Twig_Extensions_Extension_Text);
     switch ($type) {
         case 0:
             $page_title = 'Ideas';
             break;
         case 1:
             $page_title = 'Beta';
             break;
         case 2:
             $page_title = 'Startup';
             break;
         default:
             throw $this->createNotFoundException('Unable to find Category entity.');
             break;
     }
     return array('pager' => $html, 'entities' => $entities, 'type' => $type, 'page_title' => $page_title, 'category_id' => $category_id);
 }
 /**
  * Finds and displays a Forum entity.
  *
  * @Route("/f{id}/", name="forum_show")
  * @Template()
  */
 public function showAction($id)
 {
     $request = $this->getRequest();
     $em = $this->getDoctrine()->getEntityManager();
     $entity = $em->getRepository('ApplicationForumBundle:Forum')->find($id);
     if (!$entity) {
         throw $this->createNotFoundException('Unable to find Forum entity.');
     }
     $page = $request->query->get('page');
     if (!$page) {
         $page = 1;
     }
     $query = $em->createQueryBuilder();
     $query->add('select', 't')->add('from', 'ApplicationForumBundle:Thread t')->add('where', 't.forum_id = :forum_id')->setParameter('forum_id', $id)->add('orderBy', 't.featured DESC, t.date_update DESC');
     $adapter = new DoctrineORMAdapter($query);
     $pagerfanta = new Pagerfanta($adapter);
     $pagerfanta->setMaxPerPage(10);
     // 10 by default
     $maxPerPage = $pagerfanta->getMaxPerPage();
     $pagerfanta->setCurrentPage($page);
     // 1 by default
     $threads = $pagerfanta->getCurrentPageResults();
     $routeGenerator = function ($page, $id) {
         $url = '?page=' . $page;
         if ($id) {
             $url .= '&c=' . $id;
         }
         return $url;
     };
     $view = new DefaultView();
     $html = $view->render($pagerfanta, $routeGenerator, array('category_id' => $id));
     return array('entity' => $entity, 'threads' => $threads, 'pager' => $html);
 }
 /**
  * Admin Thread entities.
  *
  * @Route("/admin", name="thread_admin")
  * @Template()
  */
 public function adminAction()
 {
     $session = $this->getRequest()->getSession();
     if (!$session->get('admin')) {
         return $this->redirect('/');
     }
     $request = $this->getRequest();
     $page = $request->query->get('page');
     if (!$page) {
         $page = 1;
     }
     $em = $this->getDoctrine()->getEntityManager();
     $query = $em->createQueryBuilder();
     $query->add('select', 't')->add('from', 'ApplicationForumBundle:Thread t')->add('orderBy', 't.featured DESC, t.id DESC');
     // categoria?
     $category_id = $request->query->get('c');
     if ($category_id) {
         $query->add('where', 't.forum_id = :forum_id')->setParameter('forum_id', $category_id);
     }
     $adapter = new DoctrineORMAdapter($query);
     $pagerfanta = new Pagerfanta($adapter);
     $pagerfanta->setMaxPerPage(20);
     // 10 by default
     $maxPerPage = $pagerfanta->getMaxPerPage();
     $pagerfanta->setCurrentPage($page);
     // 1 by default
     $entities = $pagerfanta->getCurrentPageResults();
     $routeGenerator = function ($page, $category_id) {
         $url = '?page=' . $page;
         if ($category_id) {
             $url .= '&c=' . $category_id;
         }
         return $url;
     };
     $view = new DefaultView();
     $html = $view->render($pagerfanta, $routeGenerator, array('category_id' => (int) $category_id));
     // estadisticas de anuncios
     $query = "SELECT COUNT(t.id) AS total, t.forum_id, f.title FROM Thread t, Forum f WHERE t.forum_id = f.id GROUP BY f.title ORDER BY total DESC";
     $db = $this->get('database_connection');
     $categories = $db->fetchAll($query);
     return array('categories_aux' => $categories, 'pager' => $html, 'entities' => $entities);
 }
 /**
  * Admin Place entities.
  *
  * @Route("/admin", name="place_admin")
  * @Template()
  */
 public function adminAction()
 {
     $session = $this->getRequest()->getSession();
     if (!$session->get('admin')) {
         return $this->redirect('/');
     }
     $request = $this->getRequest();
     $page = $request->query->get('page');
     if (!$page) {
         $page = 1;
     }
     $em = $this->getDoctrine()->getEntityManager();
     $query = $em->createQueryBuilder();
     $query->add('select', 'p')->add('from', 'ApplicationPlaceBundle:Place p')->add('orderBy', 'p.featured DESC, p.id DESC');
     $adapter = new DoctrineORMAdapter($query);
     $pagerfanta = new Pagerfanta($adapter);
     $pagerfanta->setMaxPerPage(10);
     // 10 by default
     $maxPerPage = $pagerfanta->getMaxPerPage();
     $pagerfanta->setCurrentPage($page);
     // 1 by default
     $entities = $pagerfanta->getCurrentPageResults();
     $routeGenerator = function ($page) {
         //, $category_id
         $url = '?page=' . $page;
         return $url;
     };
     $view = new DefaultView();
     $html = $view->render($pagerfanta, $routeGenerator);
     //, array('category_id' => (int)$category_id)
     return array('pager' => $html, 'entities' => $entities);
 }
 /**
  * Admin Event entities.
  *
  * @Route("/admin", name="event_admin")
  * @Template()
  */
 public function adminAction()
 {
     $session = $this->getRequest()->getSession();
     if (!$session->get('admin')) {
         return $this->redirect('/');
     }
     $request = $this->getRequest();
     $page = $request->query->get('page');
     if (!$page) {
         $page = 1;
     }
     $em = $this->getDoctrine()->getEntityManager();
     $query = $em->createQueryBuilder();
     $query->add('select', 'e')->add('from', 'ApplicationEventBundle:Event e')->add('orderBy', 'e.featured DESC, e.id DESC');
     $adapter = new DoctrineORMAdapter($query);
     $pagerfanta = new Pagerfanta($adapter);
     $pagerfanta->setMaxPerPage(10);
     // 10 by default
     $maxPerPage = $pagerfanta->getMaxPerPage();
     $pagerfanta->setCurrentPage($page);
     // 1 by default
     $entities = $pagerfanta->getCurrentPageResults();
     $routeGenerator = function ($page) {
         //, $category_id
         $url = '?page=' . $page;
         //if( $category_id ) $url .= '&c=' . $category_id;
         return $url;
     };
     $view = new DefaultView();
     $html = $view->render($pagerfanta, $routeGenerator);
     //, array('category_id' => (int)$category_id)
     //$em = $this->getDoctrine()->getEntityManager();
     //$entities = $em->getRepository('ApplicationEventBundle:Event')->findAll();
     //$twig = $this->container->get('twig');
     //$twig->addExtension(new \Twig_Extensions_Extension_Text);
     return array('pager' => $html, 'entities' => $entities);
 }
Exemple #8
0
use Symfony\Component\HttpFoundation\Response;
use Pagerfanta\Pagerfanta;
use Pagerfanta\View\DefaultView;
$app->get('/search/{query}', function (Request $request, $query) use($app) {
    $q = $app->escape($query);
    $seo = Reg::get('seo');
    $seo['title'] = "Слушать {$q} онлайн.";
    Reg::set('seo', $seo);
    $p = $request->get('p', 1);
    $ipp = $app['conf']->getOption('app', 'itemsPerPage', 10);
    $pagerfanta = new Pagerfanta(new Art\OpenPlayerPagerfantaAdapter($app['openplayer'], $q, $p, $ipp));
    $pagerfanta->setCurrentPage($p);
    $pagerfanta->setMaxPerPage($ipp);
    $view = new DefaultView();
    $pagination = $view->render($pagerfanta, function ($page) use($q) {
        return "./search/{$q}?p={$page}";
    }, array('proximity' => 5, 'next_message' => 'Вперед', 'previous_message' => 'Назад'));
    $similar = array();
    if (!strpos($q, " ")) {
        $lastfmdata = Art\LastFM::request($app['conf'], "artist.getSimilar", array("limit" => 10, "artist" => $q));
        if (isset($lastfmdata->similarartists)) {
            $similar = $lastfmdata->similarartists->artist;
        }
    }
    Reg::set('q', $q);
    return $app['view']->render('layout.phtml', 'search/list.phtml', array('res' => $pagerfanta, 'pagination' => $pagination, 'q' => $q, 'similar' => $similar));
});
$app->get('/track/{vkid}', function (Request $request, $vkid) use($app) {
    $vtrack = $app['openplayer']->audioGetById($vkid)->audio;
    $seo = Reg::get('seo');
    $seo['title'] = "Слушать {$vtrack->artist} - {$vtrack->title} онлайн.";