src/CorporateTrainingBundle/Controller/OrgController.php line 100

Open in your IDE?
  1. <?php
  2. namespace CorporateTrainingBundle\Controller;
  3. use AppBundle\Controller\BaseController;
  4. use CorporateTrainingBundle\Biz\Org\Service\OrgService;
  5. use CorporateTrainingBundle\Common\OrgToolkit;
  6. use Symfony\Component\HttpFoundation\Request;
  7. class OrgController extends BaseController
  8. {
  9.     public const MAX_ORG_COUNT 1000;
  10.     public function orgSelectAction(Request $request$domId 'select-orgCode'$orgCode ''$disabled false)
  11.     {
  12.         return $this->render(
  13.             '@CorporateTraining/org-select/hinclude.html.twig',
  14.             ['domId' => $domId'orgCode' => $orgCode'disabled' => $disabled]
  15.         );
  16.     }
  17.     public function oneSelfOrgSelectAction(Request $request)
  18.     {
  19.         $orgIds = [];
  20.         $content json_decode($request->getContent(), true);
  21.         if (!empty($content['orgIds'])) {
  22.             $orgIds $content['orgIds'];
  23.         }
  24.         return $this->render(
  25.             '@CorporateTraining/org-select/one-slef-hinclude.html.twig',
  26.             [
  27.                 'domId' => $request->query->get('domId''select-orgIds'),
  28.                 'hasModalOrg' => $request->query->get('hasModalOrg'0),
  29.                 'orgIds' => $orgIds,
  30.                 'hasManageType' => $content['hasManageType'] ?? 0,
  31.             ]
  32.         );
  33.     }
  34.     public function orgVisibleSelectAction(Request $request$resourceType$resourceId$domId$treeName 'publishOrg'$disableUpdate false)
  35.     {
  36.         return $this->render(
  37.             '@CorporateTraining/select/org-visible/hinclude.html.twig',
  38.             [
  39.                 'resourceType' => $resourceType,
  40.                 'resourceId' => $resourceId,
  41.                 'domId' => $domId,
  42.                 'treeName' => $treeName,
  43.                 'disableUpdate' => $disableUpdate,
  44.             ]
  45.         );
  46.     }
  47.     public function buildOrgTreeAction(Request $request)
  48.     {
  49.         $orgCodes $request->request->get('orgCodes''');
  50.         if (empty($orgCodes)) {
  51.             return $this->createJsonResponse();
  52.         }
  53.         $full false;
  54.         $orgCount $this->getOrgService()->countOrgs([]);
  55.         if ($orgCount <= self::MAX_ORG_COUNT) {
  56.             $tree $this->getOrgService()->buildVisibleOrgTreeByOrgCodes($orgCodes);
  57.             $full true;
  58.             return $this->createJsonResponse(
  59.                 [
  60.                     'tree' => $tree,
  61.                     'full' => $full,
  62.                     'more' => false,
  63.                 ]
  64.             );
  65.         }
  66.         $parentId $request->request->get('parentId'1);
  67.         $limit $request->request->get('limit'self::MAX_ORG_COUNT);
  68.         $offset $request->request->get('offset'0);
  69.         $childrenCount $this->getOrgService()->countOrgs(['parentId' => $parentId]);
  70.         $tree = [];
  71.         if (!empty($childrenCount)) {
  72.             $tree $this->getOrgService()->buildOrgTreeByParentId(
  73.                 $parentId,
  74.                 $offset,
  75.                 $limit,
  76.                 true
  77.             );
  78.         }
  79.         return $this->createJsonResponse(
  80.             [
  81.                 'tree' => $tree,
  82.                 'full' => $full,
  83.                 'more' => $childrenCount > (!empty($offset) ? $offset $limit),
  84.             ]
  85.         );
  86.     }
  87.     public function buildCanManageOrgTreeAction(Request $request)
  88.     {
  89.         $fields $request->request->all();
  90.         $parentId $fields['parentId'] ?? 1;
  91.         $limit $fields['limit'] ?? self::MAX_ORG_COUNT;
  92.         $offset $fields['offset'] ?? 0;
  93.         $fields['orgIds'] = empty($fields['orgIds']) ? $fields['orgIds'];
  94.         $settingOrgIds = !empty($fields['orgIds']) ? explode(','$fields['orgIds']) : [];
  95.         $orgCodes array_column($this->getOrgService()->findOrgsByIds($settingOrgIds), 'orgCode');
  96.         $childrenCount $this->getOrgService()->countOrgs(['parentId' => $parentId]);
  97.         if (!empty($childrenCount)) {
  98.             $tree $this->getOrgService()->buildCanManageOrgTreeByParentId(
  99.                 $parentId,
  100.                 $settingOrgIds,
  101.                 $offset,
  102.                 $limit,
  103.                 true
  104.             );
  105.         } else {
  106.             $tree $this->getOrgService()->findOrgsByOrgCodes($orgCodes);
  107.             $tree = empty($tree) ? $tree $tree[0];
  108.         }
  109.         return $this->createJsonResponse(
  110.             [
  111.                 'tree' => $this->buildManageTypeTree($request$tree),
  112.                 'full' => false,
  113.                 'more' => $childrenCount $offset $limit,
  114.             ]
  115.         );
  116.     }
  117.     public function orgMatchAction(Request $request)
  118.     {
  119.         $orgCondition = [
  120.             'name' => $request->query->get('name'''),
  121.         ];
  122.         $orgs $this->getOrgService()->searchOrgs($orgCondition, ['id' => 'ASC'], 020);
  123.         $orgPaths OrgToolkit::buildOrgPathName(array_column($orgs'id'), 'short');
  124.         foreach ($orgs as &$org) {
  125.             $org['name'] = $orgPaths[$org['id']]['name'];
  126.         }
  127.         return $this->createJsonResponse($orgs);
  128.     }
  129.     protected function buildManageTypeTree(Request $request$tree)
  130.     {
  131.         $hasManageType $request->query->get('hasManageType'0);
  132.         if (== $hasManageType && isset($tree['id']) && == $tree['id']) {
  133.             $all = [
  134.                 'id' => '',
  135.                 'name' => $this->trans('group.detail.all_btn'),
  136.                 'parentId' => 0,
  137.                 'depth' => 1,
  138.                 'seq' => 0,
  139.                 'code' => '',
  140.                 'orgCode' => '0.',
  141.                 'selectable' => false,
  142.                 'disableCheckbox' => true,
  143.             ];
  144.             $all['nodes'][0] = [
  145.                 'id' => 0,
  146.                 'name' => $this->getCurrentUser()->isSuperAdmin() ? '指定管理员' '仅自己',
  147.                 'parentId' => 0,
  148.                 'depth' => 1,
  149.                 'seq' => 0,
  150.                 'code' => '',
  151.                 'orgCode' => '0.',
  152.                 'selectable' => true,
  153.                 'disableCheckbox' => false,
  154.             ];
  155.             $all['nodes'][1] = $tree;
  156.             $tree $all;
  157.         }
  158.         return $tree;
  159.     }
  160.     protected function getStrategyContext()
  161.     {
  162.         return $this->getBiz()['resource_scope_strategy_context'];
  163.     }
  164.     /**
  165.      * @return OrgService
  166.      */
  167.     protected function getOrgService()
  168.     {
  169.         return $this->createService('CorporateTrainingBundle:Org:OrgService');
  170.     }
  171. }