本文整理汇总了PHP中Doctrine\Bundle\DoctrineBundle\Registry::getContainer方法的典型用法代码示例。如果您正苦于以下问题:PHP Registry::getContainer方法的具体用法?PHP Registry::getContainer怎么用?PHP Registry::getContainer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Bundle\DoctrineBundle\Registry
的用法示例。
在下文中一共展示了Registry::getContainer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onPreSetData
/**
* onPreSetData
*
* @param FormEvent $event
*/
public function onPreSetData(FormEvent $event)
{
$data = $event->getData();
$form = $event->getForm();
if (null === $data || null === $data->getId()) {
return;
}
$rootNode = $this->nodeProvider->getRootNode();
$repository = $this->registry->getRepository('Erichard\\DmsBundle\\Entity\\DocumentNode');
$allTree = $this->registry->getRepository('Erichard\\DmsBundle\\Entity\\DocumentNodeClosure')->createQueryBuilder('c')->select('d.id')->innerJoin('c.descendant', 'd')->where('c.ancestor = :id')->setParameter('id', $rootNode->getId())->getQuery()->getResult();
$treeArray = array();
foreach ($allTree as $tree) {
$treeArray[] = $tree['id'];
}
$descendants = $this->registry->getRepository('Erichard\\DmsBundle\\Entity\\DocumentNodeClosure')->createQueryBuilder('c')->select('d.id')->innerJoin('c.descendant', 'd')->where('c.ancestor = :id')->setParameter('id', $data->getId())->getQuery()->getArrayResult();
$descendants = array_map(function ($descendant) {
return $descendant['id'];
}, $descendants);
$tree = $repository->getNodesHierarchyQueryBuilder(null, false, array('childSort' => array('field' => 'name', 'dir' => 'asc')), true);
if (count($descendants) > 0) {
$tree->andWhere('node.id NOT IN (:node_id)')->setParameter('node_id', $descendants);
}
$realTreeArray = array();
foreach ($tree->getQuery()->getArrayResult() as $node) {
if (in_array($node[0]['descendant']['id'], $treeArray)) {
$realTreeArray[] = $node;
}
}
$tree = $repository->buildTree($realTreeArray);
// On met en place notre itérator en vue de retirer la profondeur de nos éléments
$iterator = new \RecursiveIteratorIterator(new GedmoTreeIterator($tree), \RecursiveIteratorIterator::SELF_FIRST);
$choices = array();
foreach ($iterator as $node) {
$nodeName = $node['name'];
if ($node['id'] == $rootNode->getId()) {
$nodeName = $this->registry->getContainer()->get('translator')->trans('home', array(), 'ErichardDmsBundle');
}
$depth = $iterator->getDepth();
$choices[$node['id']] = str_repeat(" ", $depth) . $nodeName;
}
$form->add($this->factory->createNamedBuilder('parent', 'choice', $data->getParent(), array('label' => 'move_node', 'required' => true, 'choices' => $choices, 'auto_initialize' => false))->addModelTransformer(new NodeToIdTransformer($this->registry))->getForm());
}