Showing one action by id.
Closed this issue · 5 comments
Sorry, this might be a very basic question. I have succeeded in creating timelines and pulling them for display. Now I would like to be able to pull and display an action by id.
If I just load the action entity by its id and pass it to twig's {{ timeline_render(action) }} I get errors.
I am wondering what is the correct way to do that.
Thanks so much in advance
sergio
Hi,
Can you paste me errors ?
If your $action
is an instanceof Acme\Bundle\Entity\Action
it should be rendered by timeline_render
.
May be your components have not __toString
method implemented ? See this https://github.com/stephpy/timeline-bundle/blob/master/Resources/doc/renderer.markdown#timeline-action-component-rendering
Hi, thank you for your reply.
I am sorry, I prolly didn't explain myself clearly.
I don't have any errors, I am asking what is the best way to retrieve an action by its id.
This is what I do now, but I wonder if there is a more obvious way:
class TimelineManager extends BaseTimeLineManager
{
public function getActionById($id, $subject)
{
$qb = $this->objectManager
->getRepository($this->timelineClass)
->createQueryBuilder('t')
->select('t, a, ac, c')
->innerJoin('t.action', 'a')
->leftJoin('a.actionComponents', 'ac')
->leftJoin('ac.component', 'c')
->where('a.id = :id')
->andWhere('t.subject = :subject')
->setParameter('subject', $subject)
->setParameter('id', $id);
$results = $this->resultBuilder->fetchResults(
$qb,
1,
1,
true
);
return (sizeof($results))?$results[0]->getAction():null;
}
}
4 ways to do that:
- If you do not need to request on
subject
as you do on your method:
$action = $this->objectManager->getRepository('%%%ACTION_CLASS%%%%')->find($id);
- And needs to apply filters !
$action = $this->objectManager->getRepository('%%%ACTION_CLASS%%%%')->find($id);
$action = current($this->get('spy_timeline.filter.manager')->filter(array($action));
- If you have to request on
subject
and applying filters:
$qb = $this->objectManager
->getRepository($this->timelineClass)
->createQueryBuilder('t')
->select('t, a, ac, c')
->innerJoin('t.action', 'a')
->leftJoin('a.actionComponents', 'ac')
->leftJoin('ac.component', 'c')
->where('a.id = :id')
->andWhere('t.subject = :subject')
->setParameter('subject', $subject)
->setParameter('id', $id);
$results = $this->resultBuilder->fetchResults(
$qb,
1,
1,
true
);
- Not applying filters
....
$results = $this->resultBuilder->fetchResults($qb);
You can apply filter manually easily by calling
// it expects a collection and return a collection.
$this->get('spy_timeline.filter.manager')->filter(array(xxx));
Thank you very much, exactly what I was looking for. Great work on this bundle!
Thanks :)