src/Controller/api/ApiController.php line 175

  1. <?php
  2. namespace App\Controller\api;
  3. use App\Classes\ApiUtility;
  4. use App\Classes\ASUtility;
  5. use App\Classes\CommonUtility;
  6. use App\Entity\AccountCodes;
  7. use App\Entity\Configurations;
  8. use App\Repository\ConfigurationsRepository;
  9. use App\Repository\ActivityAssignmentsRepository;
  10. use App\Repository\ActivityDefineCrewsRepository;
  11. use App\Repository\ActivityDefineCrewPairsRepository;
  12. use App\Repository\AccountCodeActivitiesRepository;
  13. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\HttpFoundation\Response;
  16. use Symfony\Component\Routing\Annotation\Route;
  17. use Psr\Log\LoggerInterface;
  18. use Doctrine\ORM\EntityManagerInterface;
  19. /**
  20.  * @Route("/api")
  21.  */
  22. class ApiController extends AbstractController
  23. {
  24.     private $apiLogger;
  25.     private $apiUtility;
  26.     private $activityAssignmentsRepository;
  27.     private $activityDefineCrewsRepository;
  28.     private $activityDefineCrewPairsRepository;
  29.     private $accountCodeActivitiesRepository;
  30.     private $entityManager;
  31.     public function __construct(
  32.         ApiUtility $apiUtility,
  33.         LoggerInterface $apiLogger,
  34.         EntityManagerInterface $entityManager,
  35.         ConfigurationsRepository $configurationsRepository,
  36.         ActivityAssignmentsRepository $activityAssignmentsRepository,
  37.         ActivityDefineCrewsRepository $activityDefineCrewsRepository,
  38.         ActivityDefineCrewPairsRepository $activityDefineCrewPairsRepository,
  39.         AccountCodeActivitiesRepository $accountCodeActivitiesRepository,
  40.     ) {
  41.         header('Content-type: application/json');
  42.         $this->apiUtility                          $apiUtility;
  43.         $this->activityAssignmentsRepository       $activityAssignmentsRepository;
  44.         $this->activityDefineCrewsRepository       $activityDefineCrewsRepository;
  45.         $this->activityDefineCrewPairsRepository   $activityDefineCrewPairsRepository;
  46.         $this->accountCodeActivitiesRepository     $accountCodeActivitiesRepository;
  47.         $this->apiLogger                           $apiLogger;
  48.         $this->entityManager                       $entityManager;
  49.         $CONF_EW_API_ADMIN_USERNAME $configurationsRepository->findByCode(Configurations::CONF_EW_API_ADMIN_USERNAME);
  50.         $CONF_EW_API_ADMIN_PASSWORD $configurationsRepository->findByCode(Configurations::CONF_EW_API_ADMIN_PASSWORD);
  51.         // dd($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'],
  52.         //$CONF_EW_API_ADMIN_USERNAME, $CONF_EW_API_ADMIN_PASSWORD);
  53.         if (
  54.             (isset($_SERVER['PHP_AUTH_USER']) && ($_SERVER['PHP_AUTH_USER'] === $CONF_EW_API_ADMIN_USERNAME))
  55.             && (isset($_SERVER['PHP_AUTH_PW']) && ($_SERVER['PHP_AUTH_PW'] === $CONF_EW_API_ADMIN_PASSWORD))
  56.         ) {
  57.         } else {
  58.             //Send headers to cause a browser to request
  59.             //username and password from user
  60.             header("WWW-Authenticate: " "Basic realm=\"AS-EW Protected Area\"");
  61.             header("HTTP/1.0 401 Unauthorized");
  62.             //Show failure text, which browsers usually
  63.             //show only after several failed attempts
  64.             print("invalid webservice credentials");
  65.             exit;
  66.         }
  67.     }
  68.     /**
  69.      * @Route("/hworld", name="hello_world", methods={"GET"})
  70.      * @return Response
  71.      */
  72.     public function helloWorld(Request $request)
  73.     {
  74.         $response 'Hello World';
  75.         return $this->json($response);
  76.     }
  77.     /**
  78.      * @Route("/checkActivityAssignWorkers", name="check_activity_assign_workers", methods={"GET"})
  79.      * @param Request $request
  80.      * @return Response
  81.      */
  82.     public function checkActivityAssignWorkers(Request $request)
  83.     {
  84.         $conferenceId $request->query->get('conferenceId');
  85.         $worksheetId $request->query->get('worksheetId');
  86.         $response = array();
  87.         try {
  88.             if ($conferenceId && $worksheetId) {
  89.                 $response $this->activityAssignmentsRepository->findByFilters(array(
  90.                     'assign_workers' => true,
  91.                     'conference_id' => $conferenceId,
  92.                     'worksheet_id' => $worksheetId
  93.                 ));
  94.                 $response = (CommonUtility::countArray($response) > 0) ? true false;
  95.             }
  96.         } catch (\Exception $e) {
  97.             $response = array(
  98.                 "error" => array(
  99.                     "message" => $e->getMessage(),
  100.                     "code" => $e->getCode()
  101.                 )
  102.             );
  103.         }
  104.         return $this->json($response);
  105.     }
  106.     /**
  107.      * @Route("/loadActivityAssignWorkers", name="load_activity_assign_workers", methods={"GET"})
  108.      * @param Request $request
  109.      * @return Response
  110.      */
  111.     public function loadActivityAssignWorkers(Request $request)
  112.     {
  113.         $conferenceId $request->query->get('conferenceId');
  114.         $schoolYear $request->query->get('schoolYear');
  115.         $eventId $request->query->get('eventId');
  116.         $dateId $request->query->get('dateId');
  117.         $aglId $request->query->get('aglId');
  118.         $response = array();
  119.         try {
  120.             if ($conferenceId && $dateId && $eventId) {
  121.                 $response $this->activityAssignmentsRepository->findByFilters(array(
  122.                     'assign_workers' => true,
  123.                     'conference_id' => $conferenceId,
  124.                     'school_year' => $schoolYear,
  125.                     'date_id' => $dateId,
  126.                     'event_id' => $eventId,
  127.                 ));
  128.                 if (CommonUtility::countArray($response) > 0) {
  129.                     $response $response[$aglId];
  130.                 }
  131.             }
  132.         } catch (\Exception $e) {
  133.             $response = array(
  134.                 "error" => array(
  135.                     "message" => $e->getMessage(),
  136.                     "code" => $e->getCode()
  137.                 )
  138.             );
  139.         }
  140.         return $this->json($response);
  141.     }
  142.     /**
  143.      * @Route("/eventSync", name="event_sync", methods={"POST"})
  144.      * @param Request $request
  145.      * @return Response
  146.      */
  147.     public function eventSync(Request $request)
  148.     {
  149.         $parameters json_decode($request->getContent(), true);
  150.         $action = (isset($parameters["action"])) ? $parameters["action"] : '';
  151.         $eventIds = (isset($parameters["eventIds"])) ? $parameters["eventIds"] : array();
  152.         $conferenceId = (isset($parameters["conferenceId"])) ? $parameters["conferenceId"] : 0;
  153.         $details = (isset($parameters["details"])) ? $parameters["details"] : array();
  154.         $this->apiLogger->info(" --- START EVENT SYNCING ---");
  155.         $this->apiLogger->info("parameters: " $request->getContent());
  156.         $response = array();
  157.         $objEntityManager $this->entityManager;
  158.         try {
  159.             if (isset($action)) {
  160.                 if ($action === 'edit') {
  161.                     if (CommonUtility::countArray($eventIds) > 0) {
  162.                         $aActivityAssignments $this->activityAssignmentsRepository->findByFilters(array(
  163.                             'conference_id' => $conferenceId,
  164.                             'event_ids' => $eventIds,
  165.                             'event' => true
  166.                         ));
  167.                         if (CommonUtility::countArray($aActivityAssignments) > 0) {
  168.                             $aActivityAssignmentsEventIdFound = array();
  169.                             foreach ($aActivityAssignments as $assId) {
  170.                                 $objActivityAssignmentsRepository $this->activityAssignmentsRepository
  171.                                 ->find($assId['assignment_id']);
  172.                                 if ($objActivityAssignmentsRepository) {
  173.                                     if ($objActivityAssignmentsRepository->getEventId()) {
  174.                                         $aActivityAssignmentsEventIdFound[] =
  175.                                             $objActivityAssignmentsRepository->getEventId();
  176.                                     }
  177.                                     if (isset($details["date_id"])) {
  178.                                         $objActivityAssignmentsRepository->setDateId($details["date_id"]);
  179.                                     }
  180.                                     if (isset($details["event_id"])) {
  181.                                         $objActivityAssignmentsRepository->setEventId($details["event_id"]);
  182.                                     }
  183.                                     if (isset($details["season_id"])) {
  184.                                         $objActivityAssignmentsRepository->setSeasonId($details["season_id"]);
  185.                                     }
  186.                                     if (isset($details["season_name"])) {
  187.                                         $objActivityAssignmentsRepository->setSeasonName($details["season_name"]);
  188.                                     }
  189.                                     if (isset($details["activity_id"])) {
  190.                                         $objActivityAssignmentsRepository->setActivityId($details["activity_id"]);
  191.                                     }
  192.                                     if (isset($details["activity_name"])) {
  193.                                         $objActivityAssignmentsRepository->setActivityName($details["activity_name"]);
  194.                                     }
  195.                                     if (isset($details["event_date"]) || isset($details["event_updated_details"])) {
  196.                                         $eventDate $details["event_updated_details"]["date"]["new"] !== ""
  197.                                             $details["event_updated_details"]["date"]["new"]
  198.                                             : $details["event_date"];
  199.                                         $eventDate = ($eventDate != '')
  200.                                             ? \DateTime::createFromFormat('Y-m-d'$eventDate) : null;
  201.                                         $objActivityAssignmentsRepository->setEventDate($eventDate);
  202.                                     }
  203.                                     if (isset($details["date_start"]) || isset($details["event_updated_details"])) {
  204.                                         $dateStart $details["event_updated_details"]["date"]["new"] !== ""
  205.                                             $details["event_updated_details"]["date"]["new"]
  206.                                             : $details["date_start"];
  207.                                         ;
  208.                                         $dateStart = ($dateStart != '')
  209.                                             ? \DateTime::createFromFormat('Y-m-d'$dateStart) : null;
  210.                                         $objActivityAssignmentsRepository->setDateStart($dateStart);
  211.                                     }
  212.                                     if (isset($details["date_end"]) || isset($details["event_updated_details"])) {
  213.                                         $dateEnd $details["event_updated_details"]["date"]["new"] !== ""
  214.                                             $details["event_updated_details"]["date"]["new"]
  215.                                             : $details["date_end"];
  216.                                         $dateEnd = ($dateEnd != '')
  217.                                             ? \DateTime::createFromFormat('Y-m-d'$dateEnd) : null;
  218.                                         $objActivityAssignmentsRepository->setDateEnd($dateEnd);
  219.                                     }
  220.                                     if (isset($details["time_start"]) || isset($details["event_updated_details"])) {
  221.                                         $timeStart $details["event_updated_details"]["time"]["new"]["start"]
  222.                                             !== "" $details["event_updated_details"]["time"]["new"]["start"]
  223.                                             : $details["time_start"];
  224.                                         $timeStart = ($timeStart != '')
  225.                                             ? \DateTime::createFromFormat('H:i:s'$timeStart) : null;
  226.                                         $objActivityAssignmentsRepository->setTimeStart($timeStart);
  227.                                     }
  228.                                     if (isset($details["time_end"]) || isset($details["event_updated_details"])) {
  229.                                         $timeEnd $details["event_updated_details"]["time"]["new"]["end"]
  230.                                             !== "" $details["event_updated_details"]["time"]["new"]["end"]
  231.                                             : $details["time_end"];
  232.                                         $timeEnd = ($timeEnd != '')
  233.                                             ? \DateTime::createFromFormat('H:i:s'$timeEnd) : null;
  234.                                         $objActivityAssignmentsRepository->setTimeEnd($timeEnd);
  235.                                     }
  236.                                     if (isset($details["location"]) || isset($details["event_updated_details"])) {
  237.                                         $location $details["event_updated_details"]["location"]["new"] !== ""
  238.                                             $details[
  239.                                                 "event_updated_details"
  240.                                                 ]["location"]["new"] : $details["location"];
  241.                                         $objActivityAssignmentsRepository->setLocation($location);
  242.                                     }
  243.                                     if (isset($details["home"])) {
  244.                                         $objActivityAssignmentsRepository->setHome($details["home"]);
  245.                                     }
  246.                                     if (isset($details["away_infos"])) {
  247.                                         $away "";
  248.                                         $awayInfos = array();
  249.                                         if (CommonUtility::countArray($details["away_infos"]) > 0) {
  250.                                             $awayInfos $details["away_infos"];
  251.                                             $away $awayInfos[0]["name"];
  252.                                         }
  253.                                         $objActivityAssignmentsRepository->setAway($away);
  254.                                         $objActivityAssignmentsRepository->setAwayInfos(json_encode($awayInfos));
  255.                                     }
  256.                                     if (isset($details["is_fs_connected"])) {
  257.                                         $objActivityAssignmentsRepository->setIsFsConnected(
  258.                                             $details["is_fs_connected"]
  259.                                         );
  260.                                     }
  261.                                     if (isset($details["event_status_id"])) {
  262.                                         $objActivityAssignmentsRepository->setEventStatusId(
  263.                                             $details["event_status_id"]
  264.                                         );
  265.                                     }
  266.                                     if (isset($details["event_status_name"])) {
  267.                                         $objActivityAssignmentsRepository->setEventStatusName(
  268.                                             $details["event_status_name"]
  269.                                         );
  270.                                     }
  271.                                     if (isset($details["event_status_active"])) {
  272.                                         $objActivityAssignmentsRepository->setEventStatusActive(
  273.                                             intval($details["event_status_active"])
  274.                                         );
  275.                                     }
  276.                                     if (isset($details["event_updated_details"])) {
  277.                                         $objActivityAssignmentsRepository->setEventUpdatedDetails(
  278.                                             json_encode([$details["event_updated_details"]])
  279.                                         );
  280.                                     }
  281.                                     //updating activity assignment info....
  282.                                     $objEntityManager->persist($objActivityAssignmentsRepository);
  283.                                     $objEntityManager->flush();
  284.                                 }
  285.                             }
  286.                             if (CommonUtility::countArray($aActivityAssignmentsEventIdFound) > 0) {
  287.                                 $response = array(
  288.                                     "success" => array(
  289.                                         "event_ids" => $aActivityAssignmentsEventIdFound,
  290.                                         "message" => "Successfully Updated",
  291.                                         "code" => 200
  292.                                     )
  293.                                 );
  294.                             } else {
  295.                                 $response = array(
  296.                                     "error" => array(
  297.                                         "event_ids" => $eventIds,
  298.                                         "message" => "No Event IDs found",
  299.                                         "code" => 404
  300.                                     )
  301.                                 );
  302.                             }
  303.                         } else {
  304.                             $response = array(
  305.                                 "error" => array(
  306.                                     "event_ids" => $eventIds,
  307.                                     "message" => "No Event IDs found",
  308.                                     "code" => 404
  309.                                 )
  310.                             );
  311.                         }
  312.                     } else {
  313.                         $response = array(
  314.                             "error" => array(
  315.                                 "message" => "DATA NOT FOUND",
  316.                                 "code" => 404
  317.                             )
  318.                         );
  319.                     }
  320.                 } elseif ($action === 'delete') {
  321.                     if (CommonUtility::countArray($eventIds) > 0) {
  322.                         $aActivityAssignments $this->activityAssignmentsRepository->findByFilters(array(
  323.                             'conference_id' => $conferenceId,
  324.                             'event_ids' => $eventIds $eventIds false,
  325.                             'event' => true
  326.                         ));
  327.                         if (CommonUtility::countArray($aActivityAssignments) > 0) {
  328.                             $response = array(
  329.                                 "success" => array(
  330.                                     "data" => $aActivityAssignments,
  331.                                     "code" => 200
  332.                                 )
  333.                             );
  334.                         } else {
  335.                             $response = array(
  336.                                 "success" => array(
  337.                                     "message" => "Event(s) not found!",
  338.                                     "code" => 200
  339.                                 )
  340.                             );
  341.                         }
  342.                     }
  343.                 } else {
  344.                     $response = array(
  345.                         "error" => array(
  346.                             "message" => "Please specify action to be process",
  347.                             "code" => 404
  348.                         )
  349.                     );
  350.                 }
  351.             } else {
  352.                 $response = array(
  353.                     "error" => array(
  354.                         "message" => "Please specify action to be process",
  355.                         "code" => 404
  356.                     )
  357.                 );
  358.             }
  359.         } catch (\Exception $e) {
  360.             $response = array(
  361.                 "error" => array(
  362.                     "message" => $e->getMessage(),
  363.                     "code" => $e->getCode()
  364.                 )
  365.             );
  366.         }
  367.         return $this->json($response);
  368.     }
  369.     /**
  370.      * @Route("/deleteEventSync", name="delete_event_sync", methods={"POST"})
  371.      * @param Request $request
  372.      * @return Response
  373.      */
  374.     public function deleteEventSync(Request $request)
  375.     {
  376.         $conferenceId $request->query->get('conferenceId');
  377.         $workSheetIds $request->query->get('workSheetIds');
  378.         $this->apiLogger->info(" --- START EVENT DELETE SYNCING ---");
  379.         $this->apiLogger->info("conferenceId: " $conferenceId);
  380.         $this->apiLogger->info("workSheetIds: " serialize($workSheetIds));
  381.         $workSheetIds = ($workSheetIds) ? $workSheetIds : array();
  382.         $response false;
  383.         if ($conferenceId && CommonUtility::countArray($workSheetIds) > 0) {
  384.             $aActivityAssignments $this->activityAssignmentsRepository->findByFilters(array(
  385.                 'conference_id' => $conferenceId,
  386.                 'worksheet_ids' => $workSheetIds,
  387.                 'event' => true
  388.             ));
  389.             if (CommonUtility::countArray($aActivityAssignments) > 0) {
  390.                 $this->activityAssignmentsRepository->deleteActivityAssignments(array(
  391.                     'conference_id' => $conferenceId,
  392.                     "worksheet_ids" => $workSheetIds
  393.                 ));
  394.                 $response true;
  395.             }
  396.         }
  397.         return $this->json($response);
  398.     }
  399.     public function eventSOSync(Request $request)
  400.     {
  401.         $parameters json_decode($request->getContent(), true);
  402.         $action = (isset($parameters["action"])) ? $parameters["action"] : '';
  403.         $eventIds = (isset($parameters["eventIds"])) ? $parameters["eventIds"] : array();
  404.         $conferenceId = (isset($parameters["conferenceId"])) ? $parameters["conferenceId"] : 0;
  405.         $details = (isset($parameters["details"])) ? $parameters["details"] : array();
  406.         $this->apiLogger->info(" --- START EVENT SO SYNCING ---");
  407.         $this->apiLogger->info("parameters: " $request->getContent());
  408.         $response = array();
  409.         $objEntityManager $this->entityManager;
  410.         try {
  411.             // if(count($eventIds) > 0){
  412.             //     $aActivityAssignments = $this->activityAssignmentsRepository->findByFilters(array(
  413.             //             'conference_id' => $conferenceId,
  414.             //             'event_ids' => $eventIds,
  415.             //             'event' => true
  416.             //         ));
  417.             //     if(count($aActivityAssignments) > 0){
  418.             //         $aActivityAssignmentsEventIdFound = array();
  419.             //         foreach($aActivityAssignments AS $assId){
  420.             //             $objActivityAssignmentsRepository = $this->activityAssignmentsRepository->find($assId);
  421.             //             if($objActivityAssignmentsRepository){
  422.             //                 if($objActivityAssignmentsRepository->getEventId())
  423.             //                     $aActivityAssignmentsEventIdFound[]
  424.             //          = $objActivityAssignmentsRepository->getEventId();
  425.             //                 if(isset($details["date_id"]))
  426.             //                     $objActivityAssignmentsRepository->setDateId($details["date_id"]);
  427.             //                 if(isset($details["event_id"]))
  428.             //                     $objActivityAssignmentsRepository->setEventId($details["event_id"]);
  429.             //                 if(isset($details["season_id"]))
  430.             //                     $objActivityAssignmentsRepository->setSeasonId($details["season_id"]);
  431.             //                 if(isset($details["season_name"]))
  432.             //                     $objActivityAssignmentsRepository->setSeasonName($details["season_name"]);
  433.             //                 if(isset($details["activity_id"]))
  434.             //                     $objActivityAssignmentsRepository->setActivityId($details["activity_id"]);
  435.             //                 if(isset($details["activity_name"]))
  436.             //                     $objActivityAssignmentsRepository->setActivityName($details["activity_name"]);
  437.             //                 if(isset($details["event_date"])){
  438.             //                     $eventDate = $details["event_date"];
  439.             //                     $eventDate = ($eventDate != '')
  440.             // ? \DateTime::createFromFormat('Y-m-d', $eventDate) : null;
  441.             //                     $objActivityAssignmentsRepository->setEventDate($eventDate);
  442.             //                 }
  443.             //                 if(isset($details["date_start"])){
  444.             //                     $dateStart = $details["date_start"];
  445.             //                     $dateStart = ($dateStart != '')
  446.             // ? \DateTime::createFromFormat('Y-m-d', $dateStart) : null;
  447.             //                     $objActivityAssignmentsRepository->setDateStart($dateStart);
  448.             //                 }
  449.             //                 if(isset($details["date_end"])){
  450.             //                     $dateEnd = $details["date_end"];
  451.             //                     $dateEnd = ($dateEnd != '')? \DateTime::createFromFormat('Y-m-d', $dateEnd) : null;
  452.             //                     $objActivityAssignmentsRepository->setDateEnd($dateEnd);
  453.             //                 }
  454.             //                 if(isset($details["time_start"])){
  455.             //                     $timeStart = $details["time_start"];
  456.             //                     $timeStart = ($timeStart != '')
  457.             //? \DateTime::createFromFormat('H:i:s', $timeStart) : null;
  458.             //                     $objActivityAssignmentsRepository->setTimeStart($timeStart);
  459.             //                 }
  460.             //                 if(isset($details["time_end"])){
  461.             //                     $timeEnd = $details["time_end"];
  462.             //                     $timeEnd = ($timeEnd != '')? \DateTime::createFromFormat('H:i:s', $timeEnd) : null;
  463.             //                     $objActivityAssignmentsRepository->setTimeEnd($timeEnd);
  464.             //                 }
  465.             //                 if(isset($details["location"]))
  466.             //                     $objActivityAssignmentsRepository->setLocation($details["location"]);
  467.             //                 if(isset($details["home"]))
  468.             //                     $objActivityAssignmentsRepository->setHome($details["home"]);
  469.             //                 if(isset($details["away_infos"])){
  470.             //                     $away = "";
  471.             //                     $awayInfos = array();
  472.             //                     if(count($details["away_infos"]) > 0){
  473.             //                         $awayInfos = $details["away_infos"];
  474.             //                         $away = $awayInfos[0]["name"];
  475.             //                     }
  476.             //                     $objActivityAssignmentsRepository->setAway($away);
  477.             //                     $objActivityAssignmentsRepository->setAwayInfos(json_encode($awayInfos));
  478.             //                 }
  479.             //                 if(isset($details["is_fs_connected"]))
  480.             //                     $objActivityAssignmentsRepository->setIsFsConnected($details["is_fs_connected"]);
  481.             //                 //updating activity assignment info....
  482.             //                 $objEntityManager->persist($objActivityAssignmentsRepository);
  483.             //                 $objEntityManager->flush();
  484.             //             }
  485.             //         }
  486.             //         if(count($aActivityAssignmentsEventIdFound) > 0){
  487.             //             $response = array(
  488.             //                 "success" => array(
  489.             //                 "event_ids" => $aActivityAssignmentsEventIdFound,
  490.             //                 "message" => "Successfully Updated",
  491.             //                 "code" => 200
  492.             //                 )
  493.             //             );
  494.             //         }else{
  495.             //             $response = array(
  496.             //                 "error" => array(
  497.             //                     "event_ids" => $eventIds,
  498.             //                     "message" => "No Event IDs found",
  499.             //                     "code" => 404
  500.             //                 )
  501.             //             );
  502.             //         }
  503.             //     } else {
  504.             //         $response = array(
  505.             //             "error" => array(
  506.             //                 "event_ids" => $eventIds,
  507.             //                 "message" => "No Event IDs found",
  508.             //                 "code" => 404
  509.             //             )
  510.             //         );
  511.             //     }
  512.             // }else{
  513.             //     $response = array(
  514.             //         "error" => array(
  515.             //             "message" => "DATA NOT FOUND",
  516.             //             "code" => 404
  517.             //         )
  518.             //     );
  519.             // }
  520.         } catch (\Exception $e) {
  521.             $response = array(
  522.                 "error" => array(
  523.                     "message" => $e->getMessage(),
  524.                     "code" => $e->getCode()
  525.                 )
  526.             );
  527.         }
  528.         return $this->json($response);
  529.     }
  530.     /**
  531.      * @Route("/aglSync", name="agl_sync", methods={"POST"})
  532.      * @param Request $request
  533.      * @return Response
  534.      */
  535.     public function activityGenderLevelSync(Request $request)
  536.     {
  537.         $parameters json_decode($request->getContent(), true);
  538.         $action = (isset($parameters["action"])) ? $parameters["action"] : '';
  539.         $activityId = (isset($parameters["activityId"])) ? $parameters["activityId"] : '';
  540.         $activityName = (isset($parameters["activityName"])) ? $parameters["activityName"] : '';
  541.         $this->apiLogger->info(" --- START AGL SYNCING ---");
  542.         $this->apiLogger->info("action: " $action);
  543.         $this->apiLogger->info("activityId: " $activityId);
  544.         $this->apiLogger->info("activityName: " $activityName);
  545.         $response = array();
  546.         $objEntityManager $this->entityManager;
  547.         try {
  548.             if ($activityId != "" && $activityName != "") {
  549.                 if ($action === "edit") {
  550.                     #activity assignment...
  551.                     $aActivityAssignmentsRepository $this->activityAssignmentsRepository
  552.                         ->findAll(array('activity_id' => $activityId));
  553.                     if (CommonUtility::countArray($aActivityAssignmentsRepository) > 0) {
  554.                         foreach ($aActivityAssignmentsRepository as $objActivityAssignmentsRepository) {
  555.                             $objActivityAssignmentsRepository->setActivityName($activityName);
  556.                             //updating activity assignment info....
  557.                             $objEntityManager->persist($objActivityAssignmentsRepository);
  558.                             $objEntityManager->flush();
  559.                         }
  560.                     }
  561.                     #activity define...
  562.                     $aActivityDefineCrewsRepository $this->activityDefineCrewsRepository
  563.                         ->findAll(array('activity_id' => $activityId));
  564.                     if (CommonUtility::countArray($aActivityDefineCrewsRepository) > 0) {
  565.                         foreach ($aActivityDefineCrewsRepository as $objActivityDefineCrewsRepository) {
  566.                             $objActivityDefineCrewsRepository->setActivityName($activityName);
  567.                             //updating activity define info....
  568.                             $objEntityManager->persist($objActivityDefineCrewsRepository);
  569.                             $objEntityManager->flush();
  570.                         }
  571.                     }
  572.                     #activity define pair...
  573.                     $aActivityDefineCrewPairsRepository $this->activityDefineCrewPairsRepository
  574.                         ->findAll(array('activity_id' => $activityId));
  575.                     if (CommonUtility::countArray($aActivityDefineCrewPairsRepository) > 0) {
  576.                         foreach ($aActivityDefineCrewPairsRepository as $objActivityDefineCrewPairsRepository) {
  577.                             $objActivityDefineCrewPairsRepository->setActivityName($activityName);
  578.                             //updating activity define pair info....
  579.                             $objEntityManager->persist($objActivityDefineCrewPairsRepository);
  580.                             $objEntityManager->flush();
  581.                         }
  582.                     }
  583.                     #account code activities...
  584.                     $aAccountCodeActivitiesRepository $this->accountCodeActivitiesRepository
  585.                         ->findAll(array('activity_id' => $activityId));
  586.                     if (CommonUtility::countArray($aAccountCodeActivitiesRepository) > 0) {
  587.                         foreach ($aAccountCodeActivitiesRepository as $objAccountCodeActivitiesRepository) {
  588.                             $objAccountCodeActivitiesRepository->setActivityName($activityName);
  589.                             //updating account code activities info....
  590.                             $objEntityManager->persist($objAccountCodeActivitiesRepository);
  591.                             $objEntityManager->flush();
  592.                         }
  593.                     }
  594.                     $response = array(
  595.                         "success" => array(
  596.                             "message" => "Successfully Updated"
  597.                         )
  598.                     );
  599.                 } elseif ($action === "delete") {
  600.                 }
  601.             } else {
  602.                 $response = array(
  603.                     "error" => array(
  604.                         "message" => "NOT FOUND",
  605.                         "code" => 404
  606.                     )
  607.                 );
  608.             }
  609.         } catch (\Exception $e) {
  610.             $response = array(
  611.                 "error" => array(
  612.                     "message" => $e->getMessage(),
  613.                     "code" => $e->getCode()
  614.                 )
  615.             );
  616.         }
  617.         return $this->json($response);
  618.     }
  619.     /**
  620.      * @Route("/getSchoolOnlyActivityUsage", name="get_school_only_activity_usage", methods={"GET"})
  621.      * @param Request $request
  622.      * @return Response
  623.      */
  624.     public function getSchoolOnlyActivityUsage(Request $request)
  625.     {
  626.         $conference_id $request->query->get('conference_id');
  627.         $activity_id $request->query->get('activity_id');
  628.         try {
  629.             $data $this->activityDefineCrewsRepository->findByFilters(array(
  630.                 'checkSOActivities' => true,
  631.                 'conference_id' => $conference_id,
  632.                 'activity_id' => $activity_id
  633.             ));
  634.             if (CommonUtility::countArray($data) > 0) {
  635.                 $response $data;
  636.             } else {
  637.                 $response = array(
  638.                     "data" => null,
  639.                     "meta" => null,
  640.                     "links" => null,
  641.                     "code" => 404,
  642.                     "message" => "data not found",
  643.                     "status" => "NOT_FOUND",
  644.                     "result" => null
  645.                 );
  646.             }
  647.         } catch (\Exception $e) {
  648.             $response = array(
  649.                 "error" => array(
  650.                     "message" => $e->getMessage(),
  651.                     "code" => $e->getCode()
  652.                 )
  653.             );
  654.         }
  655.         return $this->json($response);
  656.     }
  657.     /**
  658.      * @Route("/get-worker-info-by-event", name="get_worker_info_by_event", methods={"POST"})
  659.      * @param Request $request
  660.      * @return Response
  661.      */
  662.     public function getWorkerInfoByEvent(Request $request)
  663.     {
  664.         $parameters json_decode($request->getContent(), true);
  665.         $eventIds = (isset($parameters["eventIds"])) ? $parameters["eventIds"] : array();
  666.         $conference_id = (isset($parameters["conference_id"])) ? $parameters["conference_id"] : '';
  667.         if (count($eventIds) > && isset($conference_id)) {
  668.             $workerInfos $this->activityAssignmentsRepository->getWorkerInfoPerEvent(array(
  669.                 'event_ids' => $eventIds,
  670.                 'conference_id' => $conference_id
  671.             ));
  672.             if (count($workerInfos) > 0) {
  673.                 $response = array(
  674.                     "success" => array(
  675.                         "data" => $workerInfos,
  676.                         "message" => "Worker Info Successfully Fetched!",
  677.                         "code" => 200
  678.                     )
  679.                 );
  680.             } else {
  681.                 $response = array(
  682.                     "error" => array(
  683.                         "event_ids" => $eventIds,
  684.                         "message" => "No Event IDs found",
  685.                         "code" => 404
  686.                     )
  687.                 );
  688.             }
  689.         } else {
  690.             $response = array(
  691.                 "error" => array(
  692.                     "message" => "DATA NOT FOUND",
  693.                     "payload_required" => 'eventIds, conference_id',
  694.                     "code" => 404
  695.                 )
  696.             );
  697.         }
  698.         return $this->json($response);
  699.     }
  700. }