本文整理汇总了PHP中Oro\Bundle\UserBundle\Entity\User::getBusinessUnits方法的典型用法代码示例。如果您正苦于以下问题:PHP User::getBusinessUnits方法的具体用法?PHP User::getBusinessUnits怎么用?PHP User::getBusinessUnits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Oro\Bundle\UserBundle\Entity\User
的用法示例。
在下文中一共展示了User::getBusinessUnits方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getBusinessUnitsTree
/**
* Build business units tree for user page
*
* @param User $user
* @return array
*/
public function getBusinessUnitsTree(User $user = null)
{
$businessUnits = $this->createQueryBuilder('businessUnit')->select(array('businessUnit.id', 'businessUnit.name', 'IDENTITY(businessUnit.owner) parent'));
if ($user && $user->getId()) {
$units = $user->getBusinessUnits()->map(function (BusinessUnit $businessUnit) {
return $businessUnit->getId();
});
$units = $units->toArray();
if ($units) {
$businessUnits->addSelect('CASE WHEN businessUnit.id IN (:userUnits) THEN 1 ELSE 0 END as hasUser');
$businessUnits->setParameter(':userUnits', $units);
}
}
$businessUnits = $businessUnits->getQuery()->getArrayResult();
$children = array();
foreach ($businessUnits as &$businessUnit) {
$parent = $businessUnit['parent'] ?: 0;
$children[$parent][] =& $businessUnit;
}
unset($businessUnit);
foreach ($businessUnits as &$businessUnit) {
if (isset($children[$businessUnit['id']])) {
$businessUnit['children'] = $children[$businessUnit['id']];
}
}
unset($businessUnit);
if (isset($children[0])) {
$children = $children[0];
}
return $children;
}
示例2: testBusinessUnit
public function testBusinessUnit()
{
$user = new User();
$businessUnit = new BusinessUnit();
$user->setBusinessUnits(new ArrayCollection(array($businessUnit)));
$this->assertContains($businessUnit, $user->getBusinessUnits());
$user->removeBusinessUnit($businessUnit);
$this->assertNotContains($businessUnit, $user->getBusinessUnits());
$user->addBusinessUnit($businessUnit);
$this->assertContains($businessUnit, $user->getBusinessUnits());
}
示例3: addBusinessUnitOwnerField
/**
* @param FormBuilderInterface $builder
* @param User $user
* @param string $className
*/
protected function addBusinessUnitOwnerField($builder, User $user, $className)
{
/**
* Owner field is required for all entities except business unit
*/
if (!$this->checkIsBusinessUnitEntity($className)) {
$validation = ['constraints' => [new NotBlank()], 'required' => true];
$emptyValueLabel = 'oro.business_unit.form.choose_business_user';
} else {
$validation = ['required' => false];
$emptyValueLabel = 'oro.business_unit.form.none_business_user';
$this->fieldLabel = 'oro.organization.businessunit.parent.label';
}
if ($this->isAssignGranted) {
/**
* If assign permission is granted, showing all available business units
*/
$builder->add($this->fieldName, 'oro_business_unit_tree_select', array_merge(['empty_value' => $emptyValueLabel, 'mapped' => true, 'label' => $this->fieldLabel, 'business_unit_ids' => $this->getBusinessUnitIds(), 'configs' => ['is_safe' => true], 'translatable_options' => false, 'choices' => $this->businessUnitManager->getTreeOptions($this->businessUnitManager->getBusinessUnitsTree(null, $this->getOrganizationContextId()))], $validation));
} else {
$businessUnits = $user->getBusinessUnits();
if (count($businessUnits)) {
$builder->add($this->fieldName, 'entity', array_merge(['class' => 'OroOrganizationBundle:BusinessUnit', 'property' => 'name', 'choices' => $businessUnits, 'mapped' => true, 'label' => $this->fieldLabel, 'translatable_options' => false], $validation));
}
}
}
示例4: addOrganizationOwnerField
/**
* @param FormBuilderInterface $builder
* @param User $user
*/
protected function addOrganizationOwnerField(FormBuilderInterface $builder, User $user)
{
$fieldOptions = array('class' => 'OroOrganizationBundle:Organization', 'property' => 'name', 'mapped' => true, 'required' => true, 'constraints' => array(new NotBlank()));
if (!$this->isAssignGranted) {
$organizations = array();
$bu = $user->getBusinessUnits();
/** @var $businessUnit BusinessUnit */
foreach ($bu as $businessUnit) {
$organizations[] = $businessUnit->getOrganization();
}
$fieldOptions['choices'] = $organizations;
}
$builder->add($this->fieldName, 'entity', $fieldOptions);
}