Beispiel #1
0
 /**
  * @param  Request $request
  * @return Response
  */
 public function listSetsAction(Request $request)
 {
     $session = $this->get('session');
     $data = [];
     /** @var \Doctrine\ORM\EntityManager $em */
     $em = $this->getDoctrine()->getManager();
     $from = $request->get('from', false);
     $until = $request->get('until', false);
     $qb = $em->createQueryBuilder();
     $qb->select("j")->from("OjsJournalBundle:Journal", 'j');
     if ($from) {
         $_from = new \DateTime();
         $_from->setTimestamp(strtotime($from));
         $qb->where($qb->expr()->gte('j.created', ':from'))->setParameter('from', $_from);
     }
     if ($until) {
         $_until = new \DateTime();
         $_until->setTimestamp(strtotime($until));
         $condition = $qb->expr()->lte('j.created', ':until');
         if ($from) {
             $qb->andWhere($condition);
         } else {
             $qb->where($condition);
         }
         $qb->setParameter('until', $_until);
     }
     $paginator = $this->get('knp_paginator');
     $resumptionToken = $request->get('resumptionToken');
     if ($resumptionToken) {
         $currentPage = (int) $session->get($resumptionToken);
     } else {
         $currentPage = 1;
     }
     $sets = $paginator->paginate($qb->getQuery(), $currentPage, 100);
     $data['records'] = $sets;
     $key = md5(StringHelper::generateKey());
     $session->set($key, $currentPage + 1);
     $data['resumptionToken'] = $key;
     $data['isLast'] = $sets->getTotalItemCount() >= $currentPage * 100 ? true : false;
     $data['currentPage'] = $currentPage;
     $data['metadataPrefix'] = $request->get('metadataPrefix', 'oai_dc');
     return $this->response('OjsOAIBundle:Default:sets.xml.twig', $data);
 }
Beispiel #2
0
 /**
  * Generates an API Key
  */
 public function generateApiKey()
 {
     $this->apiKey = StringHelper::generateKey();
 }