Query Builder example documentation
Closed this issue · 5 comments
How can I get the actions where I am the subjet or I am a direct Complement?
Also Spy\TimelineBundle\Driver\ORM\QueryBuilder\QueryBuilder::APPLY_FILTER constant does not exists in the documentation https://github.com/stephpy/TimelineBundle/blob/master/Resources/doc/query_builder.markdown
$results = $qb->execute(Spy\TimelineBundle\Driver\ORM\QueryBuilder\QueryBuilder::APPLY_FILTER); // apply filters
$results = $qb->execute(Spy\TimelineBundle\Driver\ORM\QueryBuilder\QueryBuilder::NOT_APPLY_FILTER); // not apply filters
// return a pager of Actions.
Thanks.
Hi,
Yes, documentation is outdated. (I'll fix it)
How can I get the actions where I am the subjet or I am a direct Complement?
$qb = $this->get('spy_timeline.query_builder');
$criterias = $qb->logicalOr(
$qb->logicalAnd(
$qb->field('type')->equals('subject'),
$qb->field('model')->equals('User'),
$qb->field('identifier')->equals('me'),
),
$qb->logicalAnd(
$qb->field('type')->equals('directComplement'),
$qb->field('model')->equals('User'),
$qb->field('identifier')->equals('me'),
)
);
//(actionComponent.type = 'subject' & component.model = 'User' & component.identifer = 'me') OR (actionComponent.type = 'directComplement' & component.model = 'User' & component.identifer = 'me')
// OR
$criterias = $qb->logicalAnd(
$qb->logicalOr(
$qb->field('type')->equals('subject'),
$qb->field('type')->equals('directComplement')
),
$qb->field('model')->equals('User'),
$qb->field('identifier')->equals('me')
);
//(actionComponent.type = 'subject' OR actionComponent.type = 'directComplement') AND component.model = 'User' & component.identifer = 'me'
//I guess second solution is the best.
$qb->setCriterias($criterias);
// to execute:
$results = $qb->execute(array(
'filter' => true,
'paginate' => true,
));
Should be ok. Can you confirm me it's ok ?
One other thing, QueryBuilder is useful to create a "search engine" of actions, but you could use an SqlQuery of Doctrine to fetch actions and filter them easily too.
QueryBuilder could be very very slow, because it does a lot of joins.
I get the following error:
An exception has been thrown during the rendering of a template ("[Semantical Error] line 0, col 701 near 'actionComponent1.type': Error: 'actionComponent1' is not defined.") in /var/www/workspace/myproject/vendor/ping86/social-bundle/ant/SocialBundle/Resources/views/Perfil/index.html.twig at line 59.
The line 59 is the render of this controller:
$u = $this->get('security.context')->getToken()->getUser();
$qb = $this->get('spy_timeline.query_builder');
$criterias = $qb->logicalAnd(
$qb->logicalOr(
$qb->field('type')->equals('subject'),
$qb->field('type')->equals('directComplement')
),
$qb->field('model')->equals('project\UsuarioBundle\Entity\User'),
$qb->field('identifier')->equals($u->getId())
);
$qb->setCriterias($criterias);
$results = $qb->execute(array(
'filter' => true,
'paginate' => true,
));
return array('timeline' => $results, 'usuario'=> $u);
Hi.
OK, i'll look at this ASAP
Le 8 févr. 2013 08:59, "ping86" notifications@github.com a écrit :
I get the following error:
An exception has been thrown during the rendering of a template ("[Semantical Error] line 0, col 701 near 'actionComponent1.type': Error: 'actionComponent1' is not defined.") in /var/www/workspace/myproject/vendor/ping86/social-bundle/ant/SocialBundle/Resources/views/Perfil/index.html.twig at line 59.
The line 59 is the render of this controller:
$u = $this->get('security.context')->getToken()->getUser();
$qb = $this->get('spy_timeline.query_builder');
$criterias = $qb->logicalAnd(
$qb->logicalOr(
$qb->field('type')->equals('subject'),
$qb->field('type')->equals('directComplement')
),
$qb->field('model')->equals('project\UsuarioBundle\Entity\User'),$qb->field('identifier')->equals($u->getId()) ); $qb->setCriterias($criterias); $results = $qb->execute(array( 'filter' => true, 'paginate' => true, )); return array('timeline' => $results, 'usuario'=> $u);
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/88#issuecomment-13280431.