Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.08 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Controller;
  4.  
  5. use App\Entity\CommonEmployee;
  6. use App\Service\SuratService;
  7. use App\Service\UserInfo;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Symfony\Component\HttpFoundation\JsonResponse;
  11. use App\Entity\CommonDivision;
  12. use App\Repository\CommonDivisionRepository;
  13. use Symfony\Component\HttpFoundation\Request;
  14.  
  15. /**
  16. * @Route("/addressbook")
  17. */
  18. class AddressbookController extends AbstractController
  19. {
  20. /**
  21. * @Route("/node/{parent}", name="addressbook_node", methods={"GET"})
  22. */
  23. public function index(CommonDivisionRepository $CDR,Request $req,
  24. $parent=null)
  25. {
  26. $ids=$req->query->get('id');
  27. if($ids!='#'){
  28. $parent=$ids;
  29. }
  30. if($parent){
  31. $data = $CDR->findBy(['idParent'=>$parent], ['level' => 'asc', 'id' => 'asc']);
  32. }else{
  33. $data = $CDR->findBy(['idParent'=> null], ['level' => 'asc', 'id' => 'asc']);
  34. }
  35.  
  36. return new JsonResponse($data, JsonResponse::HTTP_OK);
  37. }
  38.  
  39.  
  40. /**
  41. * @Route("/childnode/{parent}", name="addressbook_childnode", methods={"GET"})
  42. */
  43. public function getChilds(Request $req,$parent=null)
  44. {
  45. $ids=$req->query->get('id');
  46. if($ids!='#'){
  47. $parent=$ids;
  48. }
  49.  
  50. if($parent){
  51. $data= $this->getNode($parent);
  52.  
  53. }else{
  54. $data= $this->nodeRoot();
  55. }
  56. foreach ($data as &$thevalue) {
  57.  
  58. if($thevalue['children']=="1"){
  59. $thevalue['children'] = true;
  60. }else{
  61. $thevalue['children'] = false;
  62. }
  63.  
  64. }
  65. return new JsonResponse($data, JsonResponse::HTTP_OK);
  66. }
  67.  
  68. function nodeRoot(){
  69. $sql = "
  70. (
  71. select
  72. id,
  73. names as text,
  74. false as leaf,
  75. 'icon-structure' as iconCls,
  76. true as children,
  77. names as qtip
  78. from
  79. common_division
  80. where id_parent is null order by code
  81. )
  82. union
  83. (
  84. select
  85. os.id,
  86. concat(concat(names,'/'),e.name) as text,
  87. true as leaf,
  88. 'icon-structure' as iconCls,
  89. false as children,
  90. concat(concat(names,'/'),e.name) as qtip
  91. from
  92. common_organization_structure as os,
  93. common_job_position as jo,
  94. common_employee as e,
  95. common_organization_employee oe
  96. where
  97. id_division is null and os.id_job_position=jo.id and
  98. oe.id_organization_structure=os.id and os.structure_type=1 and
  99. oe.id_employee=e.id order by os.all_division desc
  100. )
  101. ";
  102.  
  103. $em = $this->getDoctrine()->getManager();
  104. $stmt = $em->getConnection()->prepare($sql);
  105. $stmt->execute();
  106.  
  107. return $stmt->fetchAll();
  108. }
  109.  
  110. function getNode($idn){
  111.  
  112. $sql = "
  113. (
  114. select
  115. id,
  116. names as text,
  117. false as leaf,
  118. 'icon-structure' as iconCls,
  119. true as children,
  120. names as qtip
  121. from
  122. common_division
  123. where id_parent = ? order by code
  124. )
  125. union
  126. (
  127. select
  128. os.id,
  129. concat(concat(names,'/'),e.name) as text,
  130. true as leaf,
  131. 'icon-structure' as iconCls,
  132. false as children,
  133. concat(concat(names,'/'),e.name) as qtip
  134. from
  135. common_organization_structure as os,
  136. common_job_position as jo,
  137. common_employee as e,
  138. common_organization_employee oe
  139. where
  140. id_division = ? and os.id_job_position=jo.id and
  141. oe.id_organization_structure=os.id and os.structure_type=1 and
  142. oe.id_employee=e.id order by os.all_division desc
  143. )
  144. ";
  145.  
  146. $em = $this->getDoctrine()->getManager();
  147. $stmt = $em->getConnection()->prepare($sql);
  148. $stmt->bindValue(1, $idn);
  149. $stmt->bindValue(2, $idn);
  150. $stmt->execute();
  151.  
  152.  
  153. return $stmt->fetchAll();
  154.  
  155. }
  156.  
  157. /**
  158. * @Route("/GetData", methods={"GET"})
  159. */
  160. public function getData(Request $request, UserInfo $userInfo, SuratService $suratService)
  161. {
  162. $data = $request->query->get('data');
  163. $emp = $suratService->findEmpolyeeByName($data);
  164. $cont = [];
  165. $idOrg = [];
  166. $name = [];
  167.  
  168. if($data == ""){
  169. $cont[0] = "Data Not Found";
  170.  
  171. }else{
  172. if($emp == [])
  173. {
  174. $emp = $suratService->findEmployeeByNum($data);
  175.  
  176. if($emp == [])
  177. {
  178. $cont[0] = 'Data Not Found';
  179. }else{
  180. foreach ($emp as $em)
  181. {
  182. $jobPos = $userInfo->getJabatan($em->getId())->getIdOrganizationStructure()->getIdJobPosition()->getNames();
  183. $cont[] = $jobPos."/".$em->getName()."/".$em->getEmployeeNumber();
  184. $idOrg[] = $userInfo->getJabatan($em->getId())->getIdOrganizationStructure()->getId();
  185. $name[] = $em->getName();
  186. }
  187. }
  188. }else{
  189. foreach ($emp as $em)
  190. {
  191. $jobPos = $userInfo->getJabatan($em->getId())->getIdOrganizationStructure()->getIdJobPosition()->getNames();
  192. $cont[] = $jobPos."/".$em->getName()."/".$em->getEmployeeNumber();
  193. $idOrg[] = $userInfo->getJabatan($em->getId())->getIdOrganizationStructure()->getId();
  194. $name[] = $em->getName();
  195. }
  196. }
  197. }
  198.  
  199. return new JsonResponse(['mess' => $cont, 'idOrg' => $idOrg, 'nameArr' => $name]);
  200. }
  201.  
  202. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement