當前位置: 首頁>>代碼示例>>PHP>>正文


PHP User::getBusinessUnits方法代碼示例

本文整理匯總了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;
 }
開發者ID:ashutosh-srijan,項目名稱:findit_akeneo,代碼行數:37,代碼來源:BusinessUnitRepository.php

示例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());
 }
開發者ID:ashutosh-srijan,項目名稱:findit_akeneo,代碼行數:11,代碼來源:UserTest.php

示例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));
         }
     }
 }
開發者ID:nmallare,項目名稱:platform,代碼行數:30,代碼來源:OwnerFormExtension.php

示例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);
 }
開發者ID:ashutosh-srijan,項目名稱:findit_akeneo,代碼行數:18,代碼來源:OwnerFormExtension.php


注:本文中的Oro\Bundle\UserBundle\Entity\User::getBusinessUnits方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。