Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Controller;
- use App\Entity\CommonEmployee;
- use App\Service\SuratService;
- use App\Service\UserInfo;
- use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
- use Symfony\Component\Routing\Annotation\Route;
- use Symfony\Component\HttpFoundation\JsonResponse;
- use App\Entity\CommonDivision;
- use App\Repository\CommonDivisionRepository;
- use Symfony\Component\HttpFoundation\Request;
- /**
- * @Route("/addressbook")
- */
- class AddressbookController extends AbstractController
- {
- /**
- * @Route("/node/{parent}", name="addressbook_node", methods={"GET"})
- */
- public function index(CommonDivisionRepository $CDR,Request $req,
- $parent=null)
- {
- $ids=$req->query->get('id');
- if($ids!='#'){
- $parent=$ids;
- }
- if($parent){
- $data = $CDR->findBy(['idParent'=>$parent], ['level' => 'asc', 'id' => 'asc']);
- }else{
- $data = $CDR->findBy(['idParent'=> null], ['level' => 'asc', 'id' => 'asc']);
- }
- return new JsonResponse($data, JsonResponse::HTTP_OK);
- }
- /**
- * @Route("/childnode/{parent}", name="addressbook_childnode", methods={"GET"})
- */
- public function getChilds(Request $req,$parent=null)
- {
- $ids=$req->query->get('id');
- if($ids!='#'){
- $parent=$ids;
- }
- if($parent){
- $data= $this->getNode($parent);
- }else{
- $data= $this->nodeRoot();
- }
- foreach ($data as &$thevalue) {
- if($thevalue['children']=="1"){
- $thevalue['children'] = true;
- }else{
- $thevalue['children'] = false;
- }
- }
- return new JsonResponse($data, JsonResponse::HTTP_OK);
- }
- function nodeRoot(){
- $sql = "
- (
- select
- id,
- names as text,
- false as leaf,
- 'icon-structure' as iconCls,
- true as children,
- names as qtip
- from
- common_division
- where id_parent is null order by code
- )
- union
- (
- select
- os.id,
- concat(concat(names,'/'),e.name) as text,
- true as leaf,
- 'icon-structure' as iconCls,
- false as children,
- concat(concat(names,'/'),e.name) as qtip
- from
- common_organization_structure as os,
- common_job_position as jo,
- common_employee as e,
- common_organization_employee oe
- where
- id_division is null and os.id_job_position=jo.id and
- oe.id_organization_structure=os.id and os.structure_type=1 and
- oe.id_employee=e.id order by os.all_division desc
- )
- ";
- $em = $this->getDoctrine()->getManager();
- $stmt = $em->getConnection()->prepare($sql);
- $stmt->execute();
- return $stmt->fetchAll();
- }
- function getNode($idn){
- $sql = "
- (
- select
- id,
- names as text,
- false as leaf,
- 'icon-structure' as iconCls,
- true as children,
- names as qtip
- from
- common_division
- where id_parent = ? order by code
- )
- union
- (
- select
- os.id,
- concat(concat(names,'/'),e.name) as text,
- true as leaf,
- 'icon-structure' as iconCls,
- false as children,
- concat(concat(names,'/'),e.name) as qtip
- from
- common_organization_structure as os,
- common_job_position as jo,
- common_employee as e,
- common_organization_employee oe
- where
- id_division = ? and os.id_job_position=jo.id and
- oe.id_organization_structure=os.id and os.structure_type=1 and
- oe.id_employee=e.id order by os.all_division desc
- )
- ";
- $em = $this->getDoctrine()->getManager();
- $stmt = $em->getConnection()->prepare($sql);
- $stmt->bindValue(1, $idn);
- $stmt->bindValue(2, $idn);
- $stmt->execute();
- return $stmt->fetchAll();
- }
- /**
- * @Route("/GetData", methods={"GET"})
- */
- public function getData(Request $request, UserInfo $userInfo, SuratService $suratService)
- {
- $data = $request->query->get('data');
- $emp = $suratService->findEmpolyeeByName($data);
- $cont = [];
- $idOrg = [];
- $name = [];
- if($data == ""){
- $cont[0] = "Data Not Found";
- }else{
- if($emp == [])
- {
- $emp = $suratService->findEmployeeByNum($data);
- if($emp == [])
- {
- $cont[0] = 'Data Not Found';
- }else{
- foreach ($emp as $em)
- {
- $jobPos = $userInfo->getJabatan($em->getId())->getIdOrganizationStructure()->getIdJobPosition()->getNames();
- $cont[] = $jobPos."/".$em->getName()."/".$em->getEmployeeNumber();
- $idOrg[] = $userInfo->getJabatan($em->getId())->getIdOrganizationStructure()->getId();
- $name[] = $em->getName();
- }
- }
- }else{
- foreach ($emp as $em)
- {
- $jobPos = $userInfo->getJabatan($em->getId())->getIdOrganizationStructure()->getIdJobPosition()->getNames();
- $cont[] = $jobPos."/".$em->getName()."/".$em->getEmployeeNumber();
- $idOrg[] = $userInfo->getJabatan($em->getId())->getIdOrganizationStructure()->getId();
- $name[] = $em->getName();
- }
- }
- }
- return new JsonResponse(['mess' => $cont, 'idOrg' => $idOrg, 'nameArr' => $name]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement