Following my previous question Ive got a new problem. I have 2 entities - authors and books, 1 author may have many books, but 1 book has only 1 author. Now the book also has date of creation. I can show how many books each author has like this,
Author Books
Author1 5
Author2 7 etc...
but along with this in the same table I need to show separately how many books of every author were added in the last month, like this:
Author Books Added in last month
Author1 5 2
Author2 7 3 etc..
In my DB I get all author entities which is mapped with books and this is getting all books for the author, like this:
<td>{{ author.books|length}}</td>
So I think there should be some kind of Twig datetime filter that would show only books, added in the last month. Ive seen this question and some more here on SO but they are mainly related to formatting the date rather than dealing with intervals. Any ideas would be welcome, Thank You.
EDIT 1 Controller code
<?php
namespace AB\ProjectBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Doctrine\Common\Collections\Criteria;
use Symfony\Component\HttpFoundation\Response;
use AB\ProjectBundle\Entity\Book;
class AuthorController extends Controller
{
public function indexAction()
{
$em = $this->getDoctrine()->getManager();
$userid = $this->container->get('security.context')->getToken()->getUser()->getId();
$entity = $em->getRepository('ABProjectBundle:Authors')->findBy(array('userid'=>$userid));
$books = $entity[0]->getBooks();
$criteria = Criteria::create()
->where(Criteria::expr()->gte("datecreation", "2016-03-15"))
->orderBy(array("datecreation" => Criteria::ASC))
->setFirstResult(0)
->setMaxResults(20)
;
$filtered = $books->matching($criteria);
$twig = 'ABProjectBundle::index.html.twig';
$paramTwig = array(
'authors' => $entity,
'filtered' => $filtered,
);
return $this->render($twig, $paramTwig);
}