src/OceanExpertBundle/Controller/ProfileController.php line 50

Open in your IDE?
  1. <?php
  2. namespace OceanExpertBundle\Controller;
  3. use DateTime;
  4. use Doctrine\ORM\AbstractQuery;
  5. use Doctrine\ORM\Query;
  6. use FOS\UserBundle\Mailer\MailerInterface;
  7. use FOS\UserBundle\Model\UserManagerInterface;
  8. use FOS\UserBundle\Util\TokenGeneratorInterface;
  9. use OceanExpertBundle\Entity\Indiv;
  10. use OceanExpertBundle\Entity\MemberEditsCountry;
  11. use OceanExpertBundle\Entity\MemberEditsInstitution;
  12. use OceanExpertBundle\Entity\MemberGroups;
  13. use OceanExpertBundle\Entity\ProfileImages;
  14. use OceanExpertBundle\Entity\IndivMeta;
  15. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  16. use Symfony\Component\HttpFoundation\RedirectResponse;
  17. use Symfony\Component\HttpFoundation\Request;
  18. use Symfony\Component\HttpFoundation\Response;
  19. use CommerceGuys\Addressing\Model\Address;
  20. use CommerceGuys\Addressing\Formatter\DefaultFormatter;
  21. use CommerceGuys\Addressing\Repository\AddressFormatRepository;
  22. use CommerceGuys\Addressing\Repository\CountryRepository;
  23. use CommerceGuys\Addressing\Repository\SubdivisionRepository;
  24. use Symfony\Component\HttpFoundation\JsonResponse;
  25. class ProfileController extends AbstractController
  26. {
  27.     private UserManagerInterface $fosUserManager;
  28.     private TokenGeneratorInterface $fosTokenGenerator;
  29.     private MailerInterface $fosMailer;
  30.     public function __construct(
  31.         UserManagerInterface $fosUserManager
  32.         TokenGeneratorInterface $fosTokenGenerator
  33.         MailerInterface $fosMailer
  34.     ){
  35.         $this->fosUserManager $fosUserManager;
  36.         $this->fosTokenGenerator $fosTokenGenerator;
  37.         $this->fosMailer $fosMailer;
  38.     }
  39.     /**
  40.      * @param string  $user
  41.      * @param Request $request
  42.      *
  43.      * @return Response
  44.      */
  45.     public function viewProfileAction(Request $requeststring $user ''): Response
  46.     {
  47.         $loggedUser $this->get('security.token_storage')->getToken()->getUser();
  48.         $isLoggedIn $this->get('security.authorization_checker')->isGranted('ROLE_USER');
  49.         if ($isLoggedIn
  50.             && $user == 'me'
  51.         ) {
  52.             //get the user id from the currently logged in user
  53.             $user $loggedUser->getId();
  54.         } elseif (!is_numeric($user)) {
  55.             //try to find the user id
  56.             //try to find the user id by looking at the login credentials
  57.             $searchUser $this->fosUserManager->findUserByUsername($user);
  58.             if ($searchUser) {
  59.                 $user $searchUser->getId();
  60.             } else {
  61.                 //last try to find the user id
  62.                 $searchUser $this->fosUserManager->findUserByUsername($user);
  63.                 if ($searchUser) {
  64.                     $user $searchUser->getId();
  65.                 } else {
  66.                     return new Response("no idea what to do with user '$user', not found in DB");
  67.                 }
  68.             }
  69.         }
  70.         $qb $this->getDoctrine()
  71.             ->getManager()
  72.             ->createQueryBuilder()
  73.             ->add('select''i,ins,p')
  74.             ->add('from''OceanExpertBundle:Indiv i')
  75.             ->leftJoin('OceanExpertBundle:ProfileImages''p''WITH''p.idInd = i.idInd')
  76.             ->leftJoin('OceanExpertBundle:IndivInstitution''idins''WITH''i.idInd = idins.idInd')
  77.             ->leftJoin('OceanExpertBundle:Institutions''ins''WITH''idins.idInst = ins.idInst')
  78.             ->where('i.idInd = :userId')
  79.             ->setParameter('userId'$user);
  80.         if ($this->get('security.authorization_checker')->isGranted('ROLE_GLOBAL_EDITOR')
  81.             || ($isLoggedIn
  82.                 && $user == $loggedUser->getId()
  83.             )
  84.         ) {
  85.             //@todo what should be here? Arno 10/06/2021
  86.         } else {
  87.             $qb->andWhere('i.status = 1');
  88.         }
  89.         $expert $qb->getQuery()
  90.             ->getResult(AbstractQuery::HYDRATE_ARRAY);
  91.         
  92.         $metadata = array();
  93.         $usermeta = array();
  94.         /*
  95.          * collect the data we need for the OIH JSON-LD in this array
  96.          * in the end we will need something like
  97.          * {
  98.             "@context": {
  99.                 "@vocab": "https://schema.org/"
  100.             },
  101.             "@id": "https://example.org/id/x",
  102.             "@type": "Person",
  103.             "name": "Jane Doe",
  104.             "jobTitle": "Professor",
  105.             "telephone": "(425) 123-4567",
  106.             "url": "http://www.janedoe.com",
  107.             "knowsAbout": [
  108.                 {
  109.                     "@type": "Text",
  110.                     "description": "Invasive species in brackish water"
  111.                 },
  112.                 {
  113.                     "@type": "URL",
  114.                     "url": "https://www.wikidata.org/wiki/Q183368"
  115.                 },
  116.                 {
  117.                     "@id": "https://example.org/id/course/x",
  118.                     "@type": "Course",
  119.                     "description": "In this course ...",
  120.                     "url": "URL to the course"
  121.                 }
  122.             ],
  123.             "identifier": {
  124.                 "@id": "https://orcid.org/0000-0002-2257-9127",
  125.                 "@type": "PropertyValue",
  126.                 "propertyID": "https://registry.identifiers.org/registry/orcid",
  127.                 "url": "https://orcid.org/0000-0002-2257-9127",
  128.                 "description": "Optional description of this record..."
  129.             }
  130.           }
  131.          */
  132.         $OIHData = array(
  133.             '@context' => array(
  134.                 '@vocab' => 'https://schema.org/'
  135.             ),
  136.             '@id' => 'https://oceanexpert.org/expert/' $user,
  137.             '@type' => 'Person'
  138.         );
  139.         if ($expert
  140.             && count($expert) > 0
  141.         ) {
  142.             $metadata $this->getMetaData($user);
  143.             $jobtype $this->getJobTypes($user);
  144.             $expert['jobType'] = $jobtype['jobtype'];
  145.             $jobTypes explode('\r'$expert['jobType']);
  146.             foreach ($jobTypes as $jobType) {
  147.                 $OIHData['knowsAbout'][] = array(
  148.                     '@type' => 'Text',
  149.                     'description' => trim($jobType)
  150.                 );
  151.             }
  152.             $expert['groups'] = $this->getUserGroups($user);
  153.             $usermeta $this->getMetaData($user);
  154.         } else {
  155.             $userExists $this->fosUserManager->findUserBy(array('id' => $user));
  156.             if (!null == $userExists
  157.                 && ($this->get('security.authorization_checker')->isGranted('ROLE_GLOBAL_EDITOR'))
  158.                 || ($isLoggedIn
  159.                     && ($user == $loggedUser->getId())
  160.                 )
  161.             ) {
  162.                 $searchUser $this->fosUserManager->findUserBy(array('id'=>$user));
  163.                 $expert[0]['idInd'] = $user;
  164.                 $expert['username'] = $searchUser->getUsername();
  165.                 $expert['error'] = "Incomplete Profile.";
  166.                 return $this->render(
  167.                     'Profile/profile.html.twig',
  168.                     array(
  169.                         'expert' => $expert
  170.                     )
  171.                 );
  172.             } else {
  173.                 $expert['error'] = 'User not found.';
  174.             }
  175.         }
  176.         if (isset($expert)
  177.             && isset($expert[0])
  178.             && is_array($expert[0])
  179.         ) {
  180.             //make the name
  181.             //for the website this is done in the profile.html.twig template
  182.             $userNameParts = array();
  183.             foreach (array('fname','mname','sname') as $namePart) {
  184.                 if (isset($expert[0][$namePart])
  185.                     && $expert[0][$namePart] != ''
  186.                 ) {
  187.                     $userNameParts[] = trim($expert[0][$namePart]);
  188.                 }
  189.             }
  190.             $OIHData['name'] = implode(' '$userNameParts);
  191.             //make the address
  192.             $addressParts = array();
  193.             foreach (array('addr1','addr2') as $addressPart) {
  194.                 if (isset($expert[0][$addressPart])
  195.                     && $expert[0][$addressPart] != ''
  196.                 ) {
  197.                     $addressParts[] = trim($expert[0][$addressPart]);
  198.                 }
  199.             }
  200.             $address implode(', '$addressParts);
  201.             if (isset($expert[0]['postcode'])
  202.                 && $expert[0]['postcode'] != ''
  203.             ) {
  204.                 $address .= ', ' $expert[0]['postcode'];
  205.             }
  206.             if (isset($expert[0]['city'])
  207.                 && $expert[0]['city'] != ''
  208.             ) {
  209.                 $address .= ' ' $expert[0]['city'];
  210.             }
  211.             if (isset($expert[0]['countryCode'])
  212.                 && $expert[0]['countryCode'] != ''
  213.             ) {
  214.                 $address .= ', ' $this->getCountryFromIds(
  215.                     explode(
  216.                         ',',
  217.                         $expert[0]['countryCode']
  218.                     )
  219.                 );
  220.             }
  221.             $OIHData['workLocation'] = array(
  222.                 '@type' => 'Place',
  223.                 'address' => trim($address)
  224.             );
  225.             if (isset($expert[0]['languages'])) {
  226.                 /*
  227.                  * never used, remove
  228.                  * Arno 30/07/2021
  229.                  *
  230.                 $qb1 = $this->getDoctrine()->getManager()->createQueryBuilder();
  231.                 $qb1->add('select', 'l')
  232.                     ->add('from', 'OceanExpertBundle:Locale l')
  233.                     ->where('l.locCode in (:locCode)')
  234.                     ->setParameter('locCode', explode(',', $expert[0]['languages']));
  235.                 $userLangs = $qb1->getQuery()->getResult(Query::HYDRATE_ARRAY);
  236.                 */
  237.                 $knowsLanguages explode(','$expert[0]['languages']);
  238.                 foreach ($knowsLanguages as $knowsLanguage) {
  239.                     $OIHData['knowsLanguage'][] = array(
  240.                         '@type' => 'Text',
  241.                         'name' => trim($knowsLanguage)
  242.                     );
  243.                 }
  244.             }
  245.             if (isset($expert[0]['jobtitle'])) {
  246.                 $expert['jobtitle'] = $this->getJobTypeByCodes(explode(','$expert[0]['jobtitle']));
  247.                 $OIHData['jobTitle'] = trim($expert[0]['jobtitle']);
  248.             }
  249.             if (isset($expert['0']['lastEditBy'])) {
  250.                 $expert['lastEditBy'] = $this->getUpdatedBy($expert['0']['lastEditBy']);
  251.             }
  252.             if (isset($expert['0']['createdBy'])) {
  253.                 $expert['createdBy'] = $this->getUpdatedBy($expert['0']['createdBy']);
  254.             }
  255.             $expert['subjectArea'] = $this->getSubjectAreas($user);
  256.             if ($expert['subjectArea']
  257.                 && $expert['subjectArea'] != ''
  258.             ) {
  259.                 $subjectAreas explode(','$expert['subjectArea']);
  260.                 foreach ($subjectAreas as $subjectArea) {
  261.                     $OIHData['knowsAbout'][] = array(
  262.                         '@type' => 'Text',
  263.                         'description' => trim($subjectArea)
  264.                     );
  265.                 }
  266.             }
  267.             if (isset($expert[0]['idNationality'])) {
  268.                 $expert['nationality'] = $this->getCountryFromIds(
  269.                     explode(
  270.                         ',',
  271.                         $expert[0]['idNationality']
  272.                     )
  273.                 );
  274.                 $expertCountryCode $this->getCountryCodeFromId($expert[0]['idNationality']);
  275.                 if (trim($expert['nationality'] != '')) {
  276.                     $OIHData['nationality'][] = array(
  277.                         '@type' => 'Country',
  278.                         'name' => trim($expert['nationality'])
  279.                     );
  280.                     $OIHData['nationality'][] = array(
  281.                         '@type' => 'DefinedTerm',
  282.                         'url' => 'https://unece.org/trade/cefact/unlocode-code-list-country-and-territory',
  283.                         'inDefinedTermSet' => 'UN/LOCODE Code List by Country and Territory',
  284.                         'name' => trim($expert['nationality']),
  285.                         'termCode' => trim($expertCountryCode)
  286.                     );
  287.                 }
  288.             }
  289.             foreach (array('url1''url2''url3') as $urlId) {
  290.                 if (isset($expert[0][$urlId])
  291.                     && trim($expert[0][$urlId]) != ''
  292.                 ) {
  293.                     $OIHData['url'][] = trim($expert[0][$urlId]);
  294.                 }
  295.             }
  296.             if (isset($expert[0]['studyregion'])) {
  297.                 $expert['studyregion'] = $this->getResearchAreaByCodes(
  298.                     explode(
  299.                         ',',
  300.                         $expert[0]['studyregion']
  301.                     )
  302.                 );
  303.             }
  304.             if (isset($expert[0]['countryCode'])) {
  305.                 $expert['expertCountry'] = $this->getCountryFromId($expert[0]['countryCode']);
  306.                 $expert['exrtCtryCode'] = $this->getCountryCodeFromId($expert[0]['countryCode']);
  307.             }
  308.             if (isset($expert[2]['countryCode'])) {
  309.                 $expert['instituteCountry'] = $this->getCountryFromId($expert[2]['countryCode']);
  310.                 $expert['instCtryCode'] = $this->getCountryCodeFromId($expert[2]['countryCode']);
  311.             }
  312.             if (isset($expert[0]['qualityCheckedBy'])) {
  313.                 $expert['qcby'] = $this->getUpdatedBy($expert[0]['qualityCheckedBy']);
  314.             }
  315.             if (isset($expert[0]['doNoInviteBy'])
  316.                 && isset($expert[0]['doNoInviteBy'])!=0
  317.             ) {
  318.                 $expert['doNoInviteBy'] = $this->getUpdatedBy($expert[0]['doNoInviteBy']);
  319.             }
  320.             if (isset($expert[0]['twitter'])) {
  321.                 $twitterUser $expert[0]['twitter'];
  322.                 /*
  323.                 if (strpos($twitterUser, '@') !== false) {
  324.                     $arrVal = preg_split('@', $twitterUser);
  325.                     $twitterUser = "https://twitter.com/@" . $arrVal[1];
  326.                 }
  327.                 */
  328.                 if (preg_match('/(@.+)/'$twitterUser$matches)) {
  329.                     $twitterUser 'https://twitter.com/' $matches[1];
  330.                 }
  331.                 $expert['twitter'] = $twitterUser;
  332.             }
  333.             if (isset($expert[0]['idInd'])) {
  334.                 $addressFormatRepository = new AddressFormatRepository();
  335.                 $countryRepository = new CountryRepository();
  336.                 $subdivisionRepository = new SubdivisionRepository();
  337.                 $formatter = new DefaultFormatter(
  338.                     $addressFormatRepository,
  339.                     $countryRepository,
  340.                     $subdivisionRepository
  341.                 );
  342.                 $itemId $expert[0]['idInd'];
  343.                 $em $this->getDoctrine()
  344.                     ->getRepository('OceanExpertBundle:MemberGroups');
  345.                 $query $em->createQueryBuilder('m')
  346.                     ->select('m.idGroup')
  347.                     ->where('m.idInd =:idInd')
  348.                     ->setParameter('idInd'$itemId)
  349.                     ->getQuery();
  350.                 $groups $query->getResult();
  351.                 $expert['groupids'] = array_column($groups'idGroup');
  352.                 $em $this->getDoctrine()
  353.                     ->getRepository('OceanExpertBundle:MemberEditsCountry');
  354.                 $query $em->createQueryBuilder('m')
  355.                     ->select('m.idCountry')
  356.                     ->where('m.idInd =:idInd')
  357.                     ->setParameter('idInd'$itemId)
  358.                     ->getQuery();
  359.                 $countries $query->getResult();
  360.                 $expert['countries'] = array_column($countries'idCountry');
  361.                 $em $this->getDoctrine()
  362.                     ->getRepository('OceanExpertBundle:MemberEditsInstitution');
  363.                 $expert['canEditOwnInst'] = 0;
  364.                 if (isset($expert[2]['idInst'])) {
  365.                     $query $em->createQueryBuilder('m')
  366.                         ->select('m')
  367.                         ->where('m.idInd =:idInd')
  368.                         ->andWhere('m.idInst =:idInst')
  369.                         ->setParameters(
  370.                             array(
  371.                                 'idInst' => $expert[2]['idInst'],
  372.                                 'idInd' => $itemId
  373.                             )
  374.                         )
  375.                         ->getQuery();
  376.                     $canEditOwnInst $query->getOneOrNullResult(AbstractQuery::HYDRATE_ARRAY);
  377.                     if (is_array($canEditOwnInst)
  378.                         && count($canEditOwnInst)
  379.                     ) {
  380.                         $expert['canEditOwnInst'] = 1;
  381.                     }
  382.                 }
  383.                 $address = new Address();
  384.                 $address $address
  385.                     ->withCountryCode($expert['exrtCtryCode'])
  386.                     ->withAdministrativeArea($expert[0]['state'])
  387.                     ->withLocality($expert[0]['city'])
  388.                     ->withPostalCode($expert[0]['postcode'])
  389.                     ->withAddressLine2($expert[0]['addr2'])
  390.                     ->withAddressLine1($expert[0]['addr1']);
  391.                 $expert['expertAddress'] = $formatter->format($address);
  392.                 if (array_key_exists('instCtryCode',$expert)) {
  393.                     $address = new Address();
  394.                     $address $address
  395.                         ->withCountryCode($expert['instCtryCode'])
  396.                         ->withAdministrativeArea($expert[2]['state'])
  397.                         ->withLocality($expert[2]['city'])
  398.                         ->withPostalCode($expert[2]['postcode'])
  399.                         ->withAddressLine2($expert[2]['addr2'])
  400.                         ->withAddressLine1($expert[2]['instAddress']);
  401.                     $expert['instAddress'] = $formatter->format($address);
  402.                 }
  403.             }
  404.             $fosUserData $this->fosUserManager
  405.                 ->findUserBy(
  406.                     array(
  407.                         'id'=>$user
  408.                     )
  409.                 );
  410.             if ($fosUserData) {
  411.                 $expert['roles']=$fosUserData->getRoles();
  412.                 $expert['username'] = $fosUserData->getUsername();
  413.                 $expert['email'] = $fosUserData->getEmail();
  414.                 $userLink $this->generateUrl(
  415.                     'view_profile',
  416.                     array(
  417.                         'user' => $fosUserData->getUsername()
  418.                     )
  419.                 );
  420.                 $expert['profileUrl'] = $request->getUriForPath($userLink);
  421.                 $expert['username'] = $fosUserData->getUsername();
  422.             }
  423.             $adminOption['countries'] = $this->getDoctrine()
  424.                 ->getRepository('OceanExpertBundle:Countries')
  425.                 ->findBy(
  426.                     [],
  427.                     ['country' => 'ASC']
  428.                 );
  429.             if (isset($expert[1]['path'])) {
  430.                 $expert['imgPath'] = $request
  431.                     ->getUriForPath('/uploads/profile/' $expert[1]['path']);
  432.             }
  433.             $adminOption['userGroups'] = $this->getDoctrine()
  434.                 ->getManager()
  435.                 ->getRepository('OceanExpertBundle:Groups')
  436.                 ->findBy([], ['groupname' => 'ASC']);
  437.             $eventData '';
  438.             if ($this->container->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
  439.                 $eventData $this->getExpertEventParticipation($user$request);
  440.             }
  441.             $OIHEventData $this->getExpertEventParticipation($user$request);
  442.             /*
  443.              * #552
  444.              *
  445.             foreach ($OIHEventData as $event) {
  446.                 $OIHData['knowsAbout'][] = array(
  447.                     '@type' => 'Event',
  448.                     'identifier' => 'https://www.oceanexpert.org/event/' . $event['idEvent'],
  449.                     'url' => 'https://www.oceanexpert.org/event/' . $event['idEvent'],
  450.                     'description' => $event['title'],
  451.                     'endDate' => $event['endOn'],
  452.                     'startDate' => $event['startOn']
  453.                 );
  454.             }
  455.             */
  456.             if (isset($metadata['orcid'])
  457.                 && $metadata['orcid'] != ''
  458.             ) {
  459.                 $OIHData['identifier'][] = array(
  460.                     '@id' => $metadata['orcid'],
  461.                     '@type' => 'PropertyValue',
  462.                     'propertyID' => 'https://registry.identifiers.org/registry/orcid',
  463.                     'url' => 'https://orcid.org/' $metadata['orcid']
  464.                 );
  465.             }
  466.             if (isset($metadata['researcherid'])
  467.                 && $metadata['researcherid'] != ''
  468.             ) {
  469.                 $OIHData['identifier'][] = array(
  470.                     '@id' => $metadata['researcherid'],
  471.                     '@type' => 'PropertyValue',
  472.                     'propertyID' => 'https://www.researcherid.com',
  473.                     'url' => 'https://www.researcherid.com/' $metadata['researcherid']
  474.                 );
  475.             }
  476.             if (isset($usermeta['researcharea'])
  477.                 && $usermeta['researcharea'] != ''
  478.             ) {
  479.                 $OIHData['knowsAbout'][] = array(
  480.                     '@type' => 'Text',
  481.                     'description' => $usermeta['researcharea']
  482.                 );
  483.             }
  484.             //dump($OIHData);
  485.             //die;
  486.         }
  487.         $OIHData json_encode(
  488.             $OIHData,
  489.             JSON_UNESCAPED_UNICODE JSON_UNESCAPED_SLASHES JSON_NUMERIC_CHECK
  490.         );
  491.         return $this->render(
  492.             'Profile/profile.html.twig',
  493.             array(
  494.                 'OIHData' => $OIHData,
  495.                 'expert' => $expert,
  496.                 'usermeta' => $usermeta,
  497.                 'metadata' => $metadata,
  498.                 'adminOption' => $adminOption,
  499.                 'eventData' => $eventData
  500.             )
  501.         );
  502.     }
  503.     /**
  504.      * @todo fix missing $data
  505.      */
  506.     public function userProfileAction(Request $request): Response
  507.     {
  508.         if (!isset($data['userEmail'])) {
  509.             if ($this->container->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
  510.                 $username $this->get('security.token_storage')->getToken()->getUser()->getUsername();
  511.                 return $this->redirect('expert/' $username);
  512.             }
  513.         }
  514.         if (isset($data['userEmail'])) {
  515.             $data $request->request->all();
  516.             $userId $this->fosUserManager->findUserByEmail($data['userEmail'])->getId();
  517.             unset($data['_wysihtml5_mode']);
  518.             $data array_filter($data);
  519.             if (isset($data['researcharea'])) {
  520.                 $data['research'] = $this->getResearchAreaByCodes($data['researcharea']);
  521.             }
  522.             if (isset($data['studyregion'])) {
  523.                 $data['study'] = $this->getResearchAreaByCodes($data['studyregion']);
  524.             } else {
  525.                 $data['studyregion'] = array();
  526.             }
  527.             if (null !== ($data['country'])) {
  528.                 $data['countryName'] = $this->getCountryByCode($data['country']);
  529.             }
  530.             if (null !== ($data['jobtype'])) {
  531.                 $data['job'] = $this->getJobTypeByCodes($data['jobtype']);
  532.             }
  533.             if ($data['reg-type'] == '1') {
  534.                 $data['type'] = "Organisation";
  535.             } else {
  536.                 $data['type'] = "Personal";
  537.                 $data['country'] = $data['country2'];
  538.                 $data['locality'] = isset($data['city2']) ? $data['city2'] : '';
  539.                 $data['administrative_area_level_1'] = isset($data['state2']) ? $data['state2'] : '';
  540.                 $data['postal_code'] = isset($data['postcode2']) ? $data['postcode2'] : '';
  541.                 $data['box'] = isset($data['box2']) ?: '';
  542.                 $data['route'] = isset($data['address2']) ? $data['address2'] : '';
  543.                 $data['addrline2'] = isset($data['addrline2']) ? $data['addrline2'] : '';
  544.             }
  545.             if (null !== $request->files->get('file')) {
  546.                 $file $request->files->get('file');
  547.                 $filetype $request->files->get('file')->guessClientExtension();
  548.                 $filename "profile_" $userId "." $filetype;
  549.                 $em $this->getDoctrine()->getManager();
  550.                 $item $em->getRepository('OceanExpertBundle:ProfileImages')->findOneBy(array('idInd' => $userId));
  551.                 if ($item) {
  552.                     $item->setFile($file);
  553.                     $item->setName($filename);
  554.                     $item->setPath($filename);
  555.                     $item->upload();
  556.                     $em->persist($item);
  557.                     $em->flush();
  558.                     $data['profileId'] = $item->getId();
  559.                 } else {
  560.                     $profile = new ProfileImages();
  561.                     $profile->setFile($file);
  562.                     $profile->setName($filename);
  563.                     $profile->setPath($filename);
  564.                     $profile->setIdInd($userId);
  565.                     $profile->upload();
  566.                     $em->persist($profile);
  567.                     $em->flush();
  568.                     if ($profile) {
  569.                         $data['profileId'] = $profile->getId();
  570.                     }
  571.                 }
  572.             }
  573.             try {
  574.                 $privateaddress = isset($data['route'])?trim($data['route']) . '<br />':'';
  575.                 $privateaddress .= isset($data['addrline2'])?trim($data['addrline2']) . '<br />':'';
  576.                 $privateaddress .= isset($data['postal_code'])?trim($data['postal_code']).", ":'';
  577.                 $privateaddress .= isset($data['locality'])?trim($data['locality']).", ":'';
  578.                 $privateaddress .= isset($data['administrative_area_level_1'])?trim($data['administrative_area_level_1']) . '<br />':'';
  579.                 $privateaddress .= isset($data['country'])?trim($this->getCountryByCode($data['country'])) . '<br />':'';
  580.                 
  581.                 $indiv = new Indiv();
  582.                 $indiv->setTitle(isset($data['title']) ? $data['title'] : '');
  583.                 $indiv->setFname(isset($data['firstname']) ? $data['firstname'] : '');
  584.                 $indiv->setMname(isset($data['middlename']) ? $data['middlename'] : '');
  585.                 $indiv->setSname(isset($data['lastname']) ? $data['lastname'] : '');
  586.                 $indiv->setRegType(isset($data['reg-type']) ? $data['reg-type'] : '');
  587.                 $indiv->setIdentifier('');
  588.                 $indiv->setUseInstAddr(isset($data['instaddress']) ? $data['instaddress'] : 0);
  589.                 $indiv->setPrivateAddress($privateaddress);
  590.                 $indiv->setCity(isset($data['locality']) ? $data['locality'] : '');
  591.                 $indiv->setAddr1(isset($data['route']) ? $data['route'] : '');
  592.                 $indiv->setAddr2(isset($data['addrline2']) ? $data['addrline2'] : '');
  593.                 $indiv->setState(isset($data['administrative_area_level_1']) ? $data['administrative_area_level_1'] : '');
  594.                 $indiv->setPostcode(isset($data['postal_code']) ? $data['postal_code'] : '');
  595.                 $indiv->setCountryCode(isset($data['country']) ? $data['country'] : '');
  596.                 $indiv->setIDNationality(isset($data['id_nationality']) ? $data['id_nationality'] : 0);
  597.                 $indiv->setGender(isset($data['gender']) ? $data['gender'] : '');
  598.                 $indiv->setTel(isset($data['phone']) ? $data['phone'] : '');
  599.                 //we are already in a condition where we are sure the $data['userEmail'] exists
  600.                 $indiv->setEmail1($data['userEmail']);
  601.                 $indiv->setEmail2(isset($data['alternateEmail']) ? $data['alternateEmail'] : '');
  602.                 $indiv->setUrl1(isset($data['website-personal']) ? $data['website-personal'] : '');
  603.                 $indiv->setUrl2(isset($data['website-institution']) ? $data['website-institution'] : '');
  604.                 $indiv->setLinkedin(isset($data['linkedin']) ? $data['linkedin'] : '');
  605.                 $indiv->setFacebook(isset($data['facebook']) ? $data['facebook'] : '');
  606.                 $indiv->setTwitter(isset($data['twitter']) ? $data['twitter'] : '');
  607.                 $indiv->setOther(isset($data['other']) ? $data['other'] : '');
  608.                 $indiv->setDegree(isset($data['degree']) ? $data['degree'] : '');
  609.                 $indiv->setJobtitle(isset($data['job']) ? $data['job'] : '');
  610.                 $indiv->setDept(isset($data['department']) ? $data['department'] : '');
  611.                 $indiv->setStudyregion(isset($data['study']) ? $data['study'] : '');
  612.                 $indiv->setLanguages(implode(','$data['languages']));
  613.                 $indiv->setComments(isset($data['comments']) ? $data['comments'] : '');
  614.                 $indiv->setSkills(isset($data['skills']) ? $data['skills'] : '');
  615.                 $indiv->setIdImagefile(isset($data['profileId']) ? $data['profileId'] : null);
  616.                 $indiv->setFDateEnt(new DateTime('now'));
  617.                 $indiv->setLDateUpd(new DateTime('now'));
  618.                 $indiv->setCreatedBy(isset($data['']) ? $data[''] : 0);
  619.                 $indiv->setLastEditBy(isset($data['']) ? $data[''] : 0);
  620.                 $indiv->setFax(isset($data['']) ? $data[''] : '');
  621.                 $indiv->setEmail2(isset($data['']) ? $data[''] : '');
  622.                 $indiv->setEmail3(isset($data['']) ? $data[''] : '');
  623.                 $indiv->setUrl3(isset($data['']) ? $data[''] : '');
  624.                 $indiv->setUrlsChecked(new DateTime('now'));
  625.                 $indiv->setFlickr(isset($data['']) ? $data[''] : '');
  626.                 $indiv->setActiveng(isset($data['']) ? $data[''] : '');
  627.                 $indiv->setActivother(isset($data['']) ? $data[''] : '');
  628.                 $indiv->setDoNotInvite(isset($data['']) ? $data[''] : 0);
  629.                 $indiv->setAdminComments(isset($data['']) ? $data[''] : '');
  630.                 $indiv->setIsGlobal(isset($data['']) ? $data[''] : 0);
  631.                 $indiv->setStatus(isset($data['']) ? $data[''] : 0);
  632.                 $indiv->setStatusLastChanged(new DateTime());
  633.                 $indiv->setDeceased(isset($data['']) ? $data[''] : 0);
  634.                 $indiv->setRetired(isset($data['']) ? $data[''] : 0);
  635.                 $em $this->getDoctrine()->getManager();
  636.                 $em->persist($indiv); //marks object to be saved in the next transaction.
  637.                 $em->flush(); //performs all saves and transactions.
  638.                 if (!isset($data['orcid'])) {
  639.                     $data['orcid'] = '';
  640.                 }
  641.                 if (!isset($data['researcherid'])) {
  642.                     $data['researcherid'] = '';
  643.                 }
  644.                 if (!isset($data['google-scholar'])) {
  645.                     $data['google-scholar'] = '';
  646.                 }
  647.                 if (!isset($data['researchgate'])) {
  648.                     $data['researchgate'] = '';
  649.                 }
  650.                 if (!isset($data['others'])) {
  651.                     $data['others'] = '';
  652.                 }
  653.                 if (!isset($data['researcharea'])) {
  654.                     $data['researcharea'] = array();
  655.                 }
  656.                 if ($indiv->getIdInd()) {
  657.                     $usermeta = array(
  658.                         'orcid' => $data['orcid'],
  659.                         'researcherid' => $data['researcherid'],
  660.                         'researcharea' => implode(', '$data['researcharea']),
  661.                         'google-scholar' => $data['google-scholar'],
  662.                         'researchgate' => $data['researchgate'],
  663.                         'others' => $data['others']
  664.                     );
  665.                     $usermeta array_filter($usermeta);
  666.                     foreach ($usermeta as $key => $value) {
  667.                         $chkmeta $em->getRepository('OceanExpertBundle:IndivMeta')
  668.                             ->findOneBy(
  669.                                 array(
  670.                                     'indivId' => $indiv->getIdInd(),
  671.                                     'metaOption' => $key
  672.                                 )
  673.                             );
  674.                         if ($chkmeta) {
  675.                             $chkmeta->setMetaValue($value);
  676.                             $em->persist($chkmeta);
  677.                             $em->flush();
  678.                         } else {
  679.                             $meta = new IndivMeta();
  680.                             $meta->setIndivId($indiv->getIdInd());
  681.                             $meta->setMetaOption($key);
  682.                             $meta->setMetaValue($value);
  683.                             $em $this->getDoctrine()->getManager();
  684.                             $em->persist($meta);
  685.                             $em->flush();
  686.                         }
  687.                     }
  688.                 }
  689.             } catch (Exception $e) {
  690.                 //@todo what happens here Arno 10/06/2021
  691.             }
  692.         }
  693.         return $this->redirect($this->generateUrl('profile_status'));
  694.     }
  695.     /**
  696.      * edit an existing user profile
  697.      *
  698.      * @param int|null $userId the id of the profile to edit
  699.      *
  700.      * @return Response
  701.      *
  702.      * @throws \Psr\Container\ContainerExceptionInterface
  703.      * @throws \Psr\Container\NotFoundExceptionInterface
  704.      */
  705.     public function editAction(int $userId null): Response
  706.     {
  707.         //only logged-in users can get the right to edit
  708.         //this is only a first check (see #493)
  709.         if (!$this->get('security.authorization_checker')->isGranted('ROLE_USER')) {
  710.             $url $this->container->get('router')->generate('frontend_homepage');
  711.             return new RedirectResponse($url);
  712.         }
  713.         //we will alway need to know the current user to be sure that not everybody can change another account
  714.         $user $this->get('security.token_storage')->getToken()->getUser();
  715.         if ($userId == '') {
  716.             //this is the simplest case
  717.             //no userid is given so edit the profile from the person that is logged in
  718.             $userId $user->getId();
  719.         }
  720.         //we want to edit an existing user, so this user must have an entry in the fos_user db
  721.         $fosUserData $this->fosUserManager
  722.             ->findUserBy(
  723.                 array(
  724.                     'id'=>$userId
  725.                 )
  726.             );
  727.         if (!$fosUserData) {
  728.             //no such user, strange...
  729.             $message "There is no user with this id ($userId).";
  730.             return $this->render(
  731.                 'Default/error.html.twig',
  732.                 array(
  733.                     'message' => $message
  734.                 )
  735.             );
  736.         }
  737.         //here it gets tricky
  738.         //who can edit, what profile??
  739.         if ($userId == $user->getId() //no problem, everybody can adapt his/here own profile
  740.             || $this->get('security.authorization_checker')->isGranted('ROLE_ADMIN')) //no problem, admin users can change the profiles of others
  741.         {
  742.             $em $this->getDoctrine()->getManager();
  743.             $indiv =  $this->getDoctrine()
  744.                 ->getRepository('OceanExpertBundle:Indiv')
  745.                 ->findOneByIdInd($userId);
  746.             if(!$indiv) {
  747.                 //create a new profile as it does not exist yet
  748.                 //this happens when people subscribe and want to complete their profile
  749.                 $indiv = new Indiv();
  750.                 $indiv->setTitle('');
  751.                 $indiv->setFname('');
  752.                 $indiv->setMname('');
  753.                 $indiv->setSname('');
  754.                 $indiv->setIdentifier('');
  755.                 $indiv->setRegType('');
  756.                 $indiv->setUseInstAddr(0);
  757.                 $indiv->setPrivateAddress('');
  758.                 $indiv->setAddr1('');
  759.                 $indiv->setAddr2('');
  760.                 $indiv->setCity('');
  761.                 $indiv->setState('');
  762.                 $indiv->setPostcode('');
  763.                 $indiv->setIdNationality('');
  764.                 $indiv->setTel('');
  765.                 $indiv->setFax('');
  766.                 $indiv->setEmail2('');
  767.                 $indiv->setEmail3('');
  768.                 $indiv->setUrl1('');
  769.                 $indiv->setUrl2('');
  770.                 $indiv->setUrl3('');
  771.                 $indiv->setGender('');
  772.                 $indiv->setLinkedin('');
  773.                 $indiv->setFacebook('');
  774.                 $indiv->setFlickr('');
  775.                 $indiv->setTwitter('');
  776.                 $indiv->setOther('');
  777.                 $indiv->setDegree('');
  778.                 $indiv->setActiveng('');
  779.                 $indiv->setActivother('');
  780.                 $indiv->setJobtitle('');
  781.                 $indiv->setDept('');
  782.                 $indiv->setStudyregion('');
  783.                 $indiv->setLanguages('');
  784.                 $indiv->setSkills('');
  785.                 $indiv->setComments('');
  786.                 $indiv->setDoNotInvite('');
  787.                 $indiv->setAdminComments('');
  788.                 $indiv->setIsGlobal(1);
  789.                 $indiv->setStatus(0);
  790.                 $indiv->setDeceased(0);
  791.                 $indiv->setRetired(0);
  792.                 $indiv->setIdInd($userId);
  793.                 $indiv->setCountryCode(21);
  794.                 $indiv->setEmail1($fosUserData->getEmail());
  795.                 $em->persist($indiv);
  796.                 $em->flush();
  797.             }
  798.         } else {
  799.             //this is not correct #491
  800.             $message 'You do not have the correct rights (your are not this person and you are not an admin user) to edit this profile.';
  801.             return $this->render(
  802.                 'Default/error.html.twig',
  803.                 array(
  804.                     'message' => $message
  805.                 )
  806.             );
  807.         }
  808.         $qb $this->getDoctrine()
  809.             ->getManager()
  810.             ->createQueryBuilder();
  811.         $qb->add('select''i, ins, p, c')
  812.             ->add('from''OceanExpertBundle:Indiv i')
  813.             ->leftJoin('OceanExpertBundle:ProfileImages''p''WITH''p.idInd = i.idInd')
  814.             ->leftJoin('OceanExpertBundle:IndivInstitution''idins''WITH''i.idInd = idins.idInd')
  815.             ->leftJoin('OceanExpertBundle:Institutions''ins''WITH''idins.idInst = ins.idInst')
  816.             ->leftJoin('OceanExpertBundle:Countries''c''WITH''c.idCountry = i.countryCode')
  817.             ->where('i.idInd = :userId')
  818.             ->setParameter('userId'$userId);
  819.         //get the expert data as far as we can find it
  820.         $expert $qb->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY);
  821.         $metadata $this->getMetaData($userId);
  822.         $jobType $this->getJobTypes($userId);
  823.         $expert['jobType'] = $jobType['jobId'];
  824.         $expert['userId'] = $userId;
  825.         $expert['subjectArea'] = $this->getSubjectAreas($userId);
  826.         $expert['roles'] = $fosUserData->getRoles();
  827.         $expert['username'] = $fosUserData->getUsername();
  828.         $expert['email'] = $fosUserData->getEmail();
  829.         //get some data for the rest of the form
  830.         $countries $this->getDoctrine()
  831.             ->getRepository('OceanExpertBundle:Countries')
  832.             ->findBy(
  833.                 [],
  834.                 ['country' => 'ASC']
  835.             );
  836.         $locales $this->getDoctrine()
  837.             ->getRepository('OceanExpertBundle:Locale')
  838.             ->findBy(
  839.                 [],
  840.                 ['locale' => 'ASC']
  841.             );
  842.         $studyregions $this->getDoctrine()
  843.             ->getRepository('OceanExpertBundle:Regions')
  844.             ->findBy(
  845.                 [],
  846.                 ['name' => 'ASC']
  847.             );
  848.         $instituteSeaRegion $this->getDoctrine()
  849.             ->getRepository('OceanExpertBundle:Regions')
  850.             ->seaRegions();
  851.         $allSubjects $this->getDoctrine()
  852.             ->getRepository('OceanExpertBundle:Subjects')
  853.             ->findBy(
  854.                 [],
  855.                 ['subname' => 'ASC']
  856.             );
  857.         return $this->render('Profile/editProfile.html.twig', array(
  858.             'expert' => $expert,
  859.             'countries' => $countries,
  860.             'locales' => $locales,
  861.             'nationalities' => $countries
  862.             'metadata' => $metadata
  863.             'studyregions' => $studyregions,
  864.             'availableSeaRegions' => $instituteSeaRegion,
  865.             'allSubjects' => $allSubjects
  866.         ));
  867.     }
  868.     public function updateProfileTimeAction(Request $request): Response
  869.     {
  870.         $security_context $this->get('security.authorization_checker');
  871.         if ($security_context->isGranted('ROLE_USER')) {
  872.             $userId $request->request->get('userId');
  873.             if ($userId) {
  874.                 $indiv $this->getDoctrine()->getRepository('OceanExpertBundle:Indiv')->findOneByIdInd($userId);
  875.                 if ($indiv) {
  876.                     $indiv->setLDateUpd(new DateTime('now'));
  877.                     $indiv->setLastEditBy($security_context->getToken()->getUser()->getId());
  878.                     $em $this->getDoctrine()->getManager();
  879.                     $em->persist($indiv); //marks object to be saved in the next transaction.
  880.                     $em->flush(); //performs all saves and transactions.
  881.                 }
  882.                 return new Response("updated successfully");
  883.             } else {
  884.                 return new Response("cannot update");
  885.             }
  886.         }
  887.         return new Response("cannot update");
  888.     }
  889.     public function activateUserAction($userId): Response
  890.     {
  891.         $security_context $this->get('security.authorization_checker');
  892.         if ($security_context->isGranted('ROLE_GLOBAL_EDITOR')) {
  893.             if ($userId) {
  894.                 $indiv $this->getDoctrine()
  895.                     ->getRepository('OceanExpertBundle:Indiv')
  896.                     ->findOneByIdInd($userId);
  897.                 if ($indiv) {
  898.                     $indiv->setStatus(1);
  899.                     $indiv->setStatusLastChanged(new DateTime('now'));
  900.                     $em $this->getDoctrine()->getManager();
  901.                     $em->persist($indiv); //marks object to be saved in the next transaction.
  902.                     $em->flush(); //performs all saves and transactions.
  903.                 }
  904.                 return new JsonResponse(
  905.                     array(
  906.                         'status' => true,
  907.                         'msg' => "updated successfully"
  908.                     )
  909.                 );
  910.             } else {
  911.                 return new Response("cannot update");
  912.             }
  913.         }
  914.         return new Response($userId);
  915.     }
  916.     public function deactivateUserAction($userId): Response
  917.     {
  918.         $security_context $this->get('security.authorization_checker');
  919.         $message = array();
  920.         if ($security_context->isGranted('ROLE_GLOBAL_EDITOR')) {
  921.             if ($userId) {
  922.                 $em $this->getDoctrine()->getManager();
  923.                 //disable the login
  924.                 $FOSUser $em
  925.                     ->getRepository('OceanExpertBundle:FosUser')
  926.                     ->findOneById($userId);
  927.                 if ($FOSUser) {
  928.                     $FOSUser->setEnabled(0);
  929.                     $FOSUser->setUpdatedAt(new DateTime('now'));
  930.                     $em->persist($FOSUser);
  931.                     $em->flush();
  932.                 } else {
  933.                     $message[] = array(
  934.                         'id' => $userId,
  935.                         'status' => 0,
  936.                         'message' => "no user found in fos_user table with id $userId"
  937.                     );
  938.                 }
  939.                 //deactivate the expert
  940.                 $indiv $em
  941.                     ->getRepository('OceanExpertBundle:Indiv')
  942.                     ->findOneByIdInd($userId);
  943.                 if ($indiv) {
  944.                     $indiv->setStatus(3);
  945.                     $indiv->setStatusLastChanged(new DateTime('now'));
  946.                     $em->persist($indiv); //marks object to be saved in the next transaction.
  947.                     $em->flush(); //performs all saves and transactions.
  948.                 } else {
  949.                     $message[] = array(
  950.                         'id' => $userId,
  951.                         'status' => 0,
  952.                         'message' => "no user found in indiv table with idInd $userId"
  953.                     );
  954.                 }
  955.                 if (!count($message)) {
  956.                     //no error messages yet so all should be fine
  957.                     $message[] = array(
  958.                         'id' => $userId,
  959.                         'status' => true,
  960.                         'message' => "user with idInd $userId deactivated"
  961.                     );
  962.                 }
  963.             } else {
  964.                 $message[] = array(
  965.                     'id' => $userId,
  966.                     'status' => 0,
  967.                     'message' => 'incorrect or no user id given'
  968.                 );
  969.             }
  970.         } else {
  971.             $message[] = array(
  972.                 'id' => $userId,
  973.                 'status' => 0,
  974.                 'message' => 'you do not have enough rights to do this'
  975.             );
  976.         }
  977.         return new JsonResponse($message);
  978.     }
  979.     public function getNationalityFromId($id)
  980.     {
  981.         $em $this->getDoctrine()->getRepository('OceanExpertBundle:Nationality')->findOneById($id);
  982.         if ($em == null) {
  983.             return false;
  984.         } else {
  985.             return $em->getNationality();
  986.         }
  987.     }
  988.     public function getCountryFromId($id)
  989.     {
  990.         $em $this->getDoctrine()->getRepository('OceanExpertBundle:Countries')->findOneByIdCountry($id);
  991.         if ($em == null) {
  992.             return false;
  993.         } else {
  994.             return $em->getCountry();
  995.         }
  996.     }
  997.     public function getCountryCodeFromId($id)
  998.     {
  999.         $em $this->getDoctrine()
  1000.             ->getRepository('OceanExpertBundle:Countries')
  1001.             ->findOneByIdCountry($id);
  1002.         if ($em == null) {
  1003.             return false;
  1004.         } else {
  1005.             return $em->getCountryCode();
  1006.         }
  1007.     }
  1008.     public function getCountryFromIds($countryArr)
  1009.     {
  1010.         $em $this->getDoctrine()
  1011.             ->getRepository('OceanExpertBundle:Countries');
  1012.         $query $em->createQueryBuilder('c')
  1013.             ->select('c.country')
  1014.             ->where('c.idCountry in (:idCountry)')
  1015.             ->setParameter('idCountry'$countryArr)
  1016.             ->getQuery();
  1017.         $countries $query->getResult();
  1018.         $countryList array_column($countries'country');
  1019.         return implode(', '$countryList);
  1020.     }
  1021.     public function csvComma($value '')
  1022.     {
  1023.         return "'" implode("','"explode(","$value)) . "'";
  1024.     }
  1025.     public function getJobTypeByCodes($jobArr)
  1026.     {
  1027.         $em $this->getDoctrine()
  1028.             ->getRepository('OceanExpertBundle:Jobtypes');
  1029.         $query $em->createQueryBuilder('a')
  1030.             ->select('a.jobname')
  1031.             ->where('a.idJob in (:jobArr)')
  1032.             ->setParameter('jobArr'$jobArr)
  1033.             ->getQuery();
  1034.         $jobs $query->getResult();
  1035.         $jobList array_column($jobs'jobname');
  1036.         return implode(', '$jobList);
  1037.     }
  1038.     public function getResearchAreaByCodes($codeArr)
  1039.     {
  1040.         $em $this->getDoctrine()
  1041.             ->getRepository('OceanExpertBundle:Regions');
  1042.         $query $em->createQueryBuilder('a')
  1043.             ->select('a.name')
  1044.             ->where('a.idRegion in (:codeArr)')
  1045.             ->setParameter('codeArr'$codeArr)
  1046.             ->getQuery();
  1047.         $regions $query->getResult();
  1048.         $regionsList array_column($regions'name');
  1049.         return implode(', '$regionsList);
  1050.     }
  1051.     /**
  1052.      * get all the meta data for a given userId
  1053.      * this data comes as a key-value pair
  1054.      *
  1055.      * @param int $userId the userId of the expert
  1056.      *
  1057.      * @return array
  1058.      */
  1059.     public function getMetaData(int $userId): array
  1060.     {
  1061.         $qb $this->getDoctrine()->getManager()->createQueryBuilder();
  1062.         $qb->add('select''m.metaOption,m.metaValue')
  1063.             ->add('from''OceanExpertBundle:IndivMeta m')
  1064.             ->where('m.indivId = :userId')
  1065.             ->setParameter('userId'$userId);
  1066.         $meta $qb->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY);
  1067.         $metadata = array();
  1068.         foreach ($meta as $value) {
  1069.             $metadata[$value['metaOption']] = $value['metaValue'];
  1070.         }
  1071.         return $metadata;
  1072.     }
  1073.     /**
  1074.      * get all the different job types for a given userId
  1075.      *
  1076.      * @param int $userId the userId of the expert
  1077.      *
  1078.      * @return array
  1079.      */
  1080.     public function getJobTypes(int $userId): array
  1081.     {
  1082.         $qb $this->getDoctrine()->getManager()->createQueryBuilder();
  1083.         $qb->add('select''jt.jobname,jt.idJob')
  1084.             ->add('from''OceanExpertBundle:IndivJobtype j')
  1085.             ->leftJoin('OceanExpertBundle:Jobtypes''jt''WITH''jt.idJob = j.idJob')
  1086.             ->where('j.idInd = :userId')
  1087.             ->setParameter('userId'$userId);
  1088.         $meta $qb->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY);
  1089.         $jobTypes implode(
  1090.             '\r',
  1091.             array_column(
  1092.                 $meta,
  1093.                 'jobname'
  1094.             )
  1095.         );
  1096.         $jobId implode(
  1097.             ',',
  1098.             array_column(
  1099.                 $meta,
  1100.                 'idJob'
  1101.             )
  1102.         );
  1103.         return array(
  1104.             'jobtype' => $jobTypes,
  1105.             'jobId' => $jobId
  1106.         );
  1107.     }
  1108.     public function getUserGroups($userId) {
  1109.         $qb $this->getDoctrine()->getManager()->createQueryBuilder();
  1110.         $qb->add('select''g.groupname, g.idGroup')
  1111.             ->add('from''OceanExpertBundle:MemberGroups mg')
  1112.             ->leftJoin('OceanExpertBundle:Groups''g''WITH''mg.idGroup = g.idGroup')
  1113.             ->where('mg.idInd = :userId')
  1114.             ->setParameter('userId'$userId)
  1115.             ->orderBy('g.groupname','ASC');
  1116.         return $qb->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY);
  1117.     }
  1118.     /**
  1119.      * get all the subject areas for a given userId
  1120.      *
  1121.      * @param int $userId the userId of the expert
  1122.      *
  1123.      * @return string
  1124.      */
  1125.     public function getSubjectAreas(int $userId): string
  1126.     {
  1127.         $qb $this->getDoctrine()->getManager()->createQueryBuilder();
  1128.         $qb->add('select''s.subname,s.idSub')
  1129.             ->add('from''OceanExpertBundle:IndivSubjects ivs')
  1130.             ->leftJoin('OceanExpertBundle:Subjects''s''WITH''s.idSub = ivs.idSub')
  1131.             ->where('ivs.idInd = :userId')
  1132.             ->setParameter('userId'$userId);
  1133.         $meta $qb->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY);
  1134.         return implode(
  1135.             ',',
  1136.             array_column(
  1137.                 $meta,
  1138.                 'subname'
  1139.             )
  1140.         );
  1141.     }
  1142.     public function getUpdatedBy($id '')
  1143.     {
  1144.         $updatedBy $this->getDoctrine()->getRepository('OceanExpertBundle:Indiv')->findOneByIdInd($id);
  1145.         if ($updatedBy) {
  1146.             $name $updatedBy->getfname() . " " strtoupper($updatedBy->getsname());
  1147.         } else {
  1148.             $name false;
  1149.         }
  1150.         return $name;
  1151.     }
  1152.     public function qccontrolAction(Request $request): Response
  1153.     {
  1154.         $id $request->request->get('userId');
  1155.         $action $request->request->get('action');
  1156.         $return '';
  1157.         $security_context $this->get('security.authorization_checker');
  1158.         if ($security_context->isGranted('ROLE_GLOBAL_EDITOR')) {
  1159.             $author $this->get('security.token_storage')->getToken()->getUser()->getId();
  1160.             $updatedBy $this->getDoctrine()->getRepository('OceanExpertBundle:Indiv')->findOneByIdInd($id);
  1161.             if ($action == 1) {
  1162.                 $updatedBy->setQualityCheckedBy($author);
  1163.                 $updatedBy->setQualityCheckedDate(new DateTime('now'));
  1164.                 $updatedBy->setQualityChecked(1);
  1165.                 $return "This record has been marked as quality controlled on <strong>" date('F j, Y') . "</strong> by <strong>" $this->getUpdatedBy($author)."</strong>";
  1166.             } else {
  1167.                 $updatedBy->setQualityCheckedBy(null);
  1168.                 $updatedBy->setQualityCheckedDate(null);
  1169.                 $updatedBy->setQualityChecked(0);
  1170.                 $return "This record has not been quality controlled";
  1171.             }
  1172.             $updatedBy->setLDateUpd(new DateTime('now'));
  1173.             $updatedBy->setLastEditBy($author);
  1174.             $em $this->getDoctrine()->getManager();
  1175.             $em->persist($updatedBy); //marks object to be saved in the next transaction.
  1176.             $em->flush(); //performs all saves and transactions.
  1177.         }
  1178.         return new Response($return);
  1179.     }
  1180.     public function setRetiredAction(Request $request): Response
  1181.     {
  1182.         $id $request->request->get('userId');
  1183.         $date $request->request->get('retiredDate');
  1184.         $retiredStatus $request->request->get('retiredStatus');
  1185.         $security_context $this->get('security.authorization_checker');
  1186.         if ($security_context->isGranted('ROLE_USER')) {
  1187.             $author $this->get('security.token_storage')->getToken()->getUser()->getId();
  1188.             $updateRecord $this->getDoctrine()->getRepository('OceanExpertBundle:Indiv')->findOneByIdInd($id);
  1189.             if ($updateRecord) {
  1190.                 if ($retiredStatus == 1) {
  1191.                     $updateRecord->setRetired(1);
  1192.                     if (trim($date) == '') {
  1193.                         $updateRecord->setRetiredDate(null);
  1194.                     } else {
  1195.                         $updateRecord->setRetiredDate(DateTime::createFromFormat('Y-m-d'$date));
  1196.                     }
  1197.                 } else {
  1198.                     $updateRecord->setRetired(0);
  1199.                     $updateRecord->setRetiredDate(null);
  1200.                 }
  1201.             }
  1202.             $updateRecord->setLDateUpd(new DateTime('now'));
  1203.             $updateRecord->setLastEditBy($author);
  1204.             $em $this->getDoctrine()->getManager();
  1205.             $em->persist($updateRecord); //marks object to be saved in the next transaction.
  1206.             $em->flush(); //performs all saves and transactions.
  1207.         }
  1208.         return new Response($date);
  1209.     }
  1210.     public function setDeceasedAction(Request $request): Response
  1211.     {
  1212.         $id $request->request->get('userId');
  1213.         $date $request->request->get('deceasedDate');
  1214.         $deceasedStatus $request->request->get('deceasedStatus');
  1215.         $return '';
  1216.         $security_context $this->get('security.authorization_checker');
  1217.         if ($security_context->isGranted('ROLE_GLOBAL_EDITOR')) {
  1218.             $author $this->get('security.token_storage')->getToken()->getUser()->getId();
  1219.             $updateRecord $this->getDoctrine()
  1220.                 ->getRepository('OceanExpertBundle:Indiv')
  1221.                 ->findOneByIdInd($id);
  1222.             if ($updateRecord) {
  1223.                 if ($deceasedStatus == 1) {
  1224.                     $updateRecord->setDeceased(1);
  1225.                     if (trim($date) == '') {
  1226.                         $updateRecord->setDeceasedDate(null);
  1227.                     } else {
  1228.                         $updateRecord->setDeceasedDate(DateTime::createFromFormat('Y-m-d'$date));
  1229.                     }
  1230.                 } else {
  1231.                     $updateRecord->setDeceased(0);
  1232.                     $updateRecord->setDeceasedDate(null);
  1233.                 }
  1234.             }
  1235.             $updateRecord->setLDateUpd(new DateTime('now'));
  1236.             $updateRecord->setLastEditBy($author);
  1237.             $em $this->getDoctrine()->getManager();
  1238.             $em->persist($updateRecord); //marks object to be saved in the next transaction.
  1239.             $em->flush(); //performs all saves and transactions.
  1240.         }
  1241.         return new Response($return);
  1242.     }
  1243.     public function setDoNotInviteAction(Request $request): Response
  1244.     {
  1245.         $id $request->request->get('userId');
  1246.         $status $request->request->get('status');
  1247.         $return '';
  1248.         $security_context $this->get('security.authorization_checker');
  1249.         if ($security_context->isGranted('ROLE_USER')) {
  1250.             $author $this->get('security.token_storage')->getToken()->getUser()->getId();
  1251.             $updateRecord $this->getDoctrine()
  1252.                 ->getRepository('OceanExpertBundle:Indiv')
  1253.                 ->findOneByIdInd($id);
  1254.             if ($updateRecord) {
  1255.                 if ($status == 1) {
  1256.                     $updateRecord->setDoNotInvite(1);
  1257.                     $updateRecord->setDoNoInviteBy($author);
  1258.                     $updateRecord->setDoNoInviteOn(new DateTime('now'));
  1259.                     $return 'This record has been set as do not invite on <strong>' date('F j, Y') . '</strong>';
  1260.                     $return .= 'by <strong>' $this->getUpdatedBy($author) . '</strong>';
  1261.                 } else {
  1262.                     $updateRecord->setDoNotInvite(0);
  1263.                     $updateRecord->setDoNoInviteBy(0);
  1264.                     $updateRecord->setDoNoInviteOn(NULL);
  1265.                     $return 'Please select "Yes" to add this member to the do not invite list.';
  1266.                 }
  1267.             }
  1268.             $updateRecord->setLDateUpd(new DateTime('now'));
  1269.             $updateRecord->setLastEditBy($author);
  1270.             $em $this->getDoctrine()->getManager();
  1271.             $em->persist($updateRecord); //marks object to be saved in the next transaction.
  1272.             $em->flush(); //performs all saves and transactions.
  1273.         }
  1274.         return new Response($return);
  1275.     }
  1276.     public function setAdmincommentsAction(Request $request): Response
  1277.     {
  1278.         $id $request->request->get('userId');
  1279.         $comments $request->request->get('comments');
  1280.         $return '';
  1281.         if (trim($comments) != '') {
  1282.             $security_context $this->get('security.authorization_checker');
  1283.             if ($security_context->isGranted('ROLE_GLOBAL_EDITOR')) {
  1284.                 $author $this->get('security.token_storage')->getToken()->getUser()->getId();
  1285.                 $updateRecord $this->getDoctrine()
  1286.                     ->getRepository('OceanExpertBundle:Indiv')
  1287.                     ->findOneByIdInd($id);
  1288.                 $comments .= '<br />';
  1289.                 $comments .= '(Added by ' $this->getUpdatedBy($author);
  1290.                 $comments .= ' on ' date('d-m-y');
  1291.                 $comments .= ')<br /><br />';
  1292.                 $comments .= $updateRecord->getAdminComments();
  1293.                 if ($updateRecord) {
  1294.                     $updateRecord->setAdminComments($comments);
  1295.                 }
  1296.                 $updateRecord->setLDateUpd(new DateTime('now'));
  1297.                 $updateRecord->setLastEditBy($author);
  1298.                 $em $this->getDoctrine()->getManager();
  1299.                 $em->persist($updateRecord); //marks object to be saved in the next transaction.
  1300.                 $em->flush(); //performs all saves and transactions.
  1301.                 $return $comments;
  1302.             }
  1303.         }
  1304.         return new Response($return);
  1305.     }
  1306.     public function setGroupsAction(Request $request): Response
  1307.     {
  1308.         $id $request->request->get('userId');
  1309.         $groups $request->request->get('groups');
  1310.         $return '';
  1311.         $security_context $this->get('security.authorization_checker');
  1312.         if ($security_context->isGranted('ROLE_GLOBAL_EDITOR')) {
  1313.             $author $this->get('security.token_storage')
  1314.                 ->getToken()
  1315.                 ->getUser()
  1316.                 ->getId();
  1317.             $updateRecord $this->getDoctrine()
  1318.                 ->getRepository('OceanExpertBundle:Indiv')
  1319.                 ->findOneByIdInd($id);
  1320.             if ($updateRecord) {
  1321.                 $updateRecord->setLDateUpd(new DateTime('now'));
  1322.                 $updateRecord->setLastEditBy($author);
  1323.                 $em $this->getDoctrine()->getManager();
  1324.                 $em->persist($updateRecord); //marks object to be saved in the next transaction.
  1325.                 $em->flush(); //performs all saves and transactions.
  1326.             }
  1327.             if (is_array($groups)) {
  1328.                 $em $this->getDoctrine()->getManager();
  1329.                 $results $em->createQueryBuilder()
  1330.                     ->add('select''m')
  1331.                     ->add('from''OceanExpertBundle:MemberGroups m')
  1332.                     ->where('m.idGroup not in (:groups)')
  1333.                     ->andWhere('m.idInd =:idInd')
  1334.                     ->setParameters(array('groups' => $groups'idInd' => $id))
  1335.                     ->getQuery()->getResult();
  1336.                 foreach ($results as $result) {
  1337.                     $em->remove($result);
  1338.                 }
  1339.                 $em->flush();
  1340.                 foreach ($groups as $value) {
  1341.                     $updateGroup $this->getDoctrine()
  1342.                         ->getRepository('OceanExpertBundle:MemberGroups')
  1343.                         ->find(
  1344.                             array(
  1345.                                 'idInd' => $id
  1346.                                 'idGroup' => $value
  1347.                             )
  1348.                         );
  1349.                     if (!$updateGroup) {
  1350.                         $addGroups = new MemberGroups();
  1351.                         $addGroups->setIdInd($id);
  1352.                         $addGroups->setIdGroup($value);
  1353.                         $addGroups->setRole('');
  1354.                         $addGroups->setMemberOrder(NULL);
  1355.                         $addGroups->setIsLeader(0);
  1356.                         $em $this->getDoctrine()->getManager();
  1357.                         $em->persist($addGroups); //marks object to be saved in the next transaction.
  1358.                         $em->flush(); //performs all saves and transactions.
  1359.                     }
  1360.                 }
  1361.             } else {
  1362.                 $updateGroup $this->getDoctrine()
  1363.                     ->getRepository('OceanExpertBundle:MemberGroups')
  1364.                     ->findBy(array('idInd' => $id));
  1365.                 $em $this->getDoctrine()->getEntityManager();
  1366.                 foreach ($updateGroup as $groups) {
  1367.                     $em->remove($groups);
  1368.                 }
  1369.                 $em->flush();
  1370.             }
  1371.         }
  1372.         return new Response($return);
  1373.     }
  1374.     public function setPrivilegesAction(Request $request): Response
  1375.     {
  1376.         //get all the values from the request
  1377.         //these values are send from profile.html.twig $("#addPrivileges").click(function () {....
  1378.         $id $request->request->get('userId');
  1379.         $countries $request->request->get('countries');
  1380.         $ownInstitute $request->request->get('ownInstitute');
  1381.         $countryList $request->request->get('countryList');
  1382.         $editor $request->request->get('editor');
  1383.         $security_context $this->get('security.authorization_checker');
  1384.         if ($security_context->isGranted('ROLE_GLOBAL_EDITOR')) {
  1385.             $return = array(
  1386.                 'status' => 0,
  1387.                 'message' => array()
  1388.             );
  1389.             //who is doing this update
  1390.             $author $this->get('security.token_storage')
  1391.                 ->getToken()
  1392.                 ->getUser()
  1393.                 ->getId();
  1394.             //what record needs to be updated
  1395.             $updateRecord $this->getDoctrine()
  1396.                 ->getRepository('OceanExpertBundle:Indiv')
  1397.                 ->findOneByIdInd($id);
  1398.             if ($updateRecord) {
  1399.                 $updateRecord->setLDateUpd(new DateTime('now'));
  1400.                 $updateRecord->setLastEditBy($author);
  1401.                 $em $this->getDoctrine()->getManager();
  1402.                 $em->persist($updateRecord); //marks object to be saved in the next transaction.
  1403.                 $em->flush(); //performs all saves and transactions.
  1404.             }
  1405.             if ($ownInstitute == 1) {
  1406.                 $updateInstEdit $this->getDoctrine()
  1407.                     ->getRepository('OceanExpertBundle:MemberEditsInstitution')
  1408.                     ->findOneBy(array(
  1409.                             'idInd' => $id,
  1410.                             'idInst' => $this->getIndivInstitute($id)
  1411.                         )
  1412.                     );
  1413.                 if (!$updateInstEdit) {
  1414.                     $updateInstEdit = new MemberEditsInstitution();
  1415.                     $updateInstEdit->setIdInd($id);
  1416.                     $updateInstEdit->setIdInst($this->getIndivInstitute($id));
  1417.                 } else {
  1418.                     $updateInstEdit->setIdInst($this->getIndivInstitute($id));
  1419.                 }
  1420.                 $em->persist($updateInstEdit); //marks object to be saved in the next transaction.
  1421.                 $em->flush(); //performs all saves and transactions.
  1422.                 $return['message'][] = 'update own institute activated';
  1423.             } else {
  1424.                 $qb $em->createQueryBuilder();
  1425.                 $query $qb->delete('OceanExpertBundle:MemberEditsInstitution''m')
  1426.                     ->where('m.idInd = :id')
  1427.                     ->andWhere('m.idInst = :idInst')
  1428.                     ->setParameters(
  1429.                         array(
  1430.                             'id' => $id,
  1431.                             'idInst' => $this->getIndivInstitute($id)
  1432.                         )
  1433.                     )
  1434.                     ->getQuery();
  1435.                 $query->execute();
  1436.                 $em->flush();
  1437.                 $return['message'][] = 'update own institute removed';
  1438.             }
  1439.             if (is_array($countries)
  1440.                 && $countryList == 1
  1441.             ) {
  1442.                 $em $this->getDoctrine()->getManager();
  1443.                 $results $em->createQueryBuilder()
  1444.                     ->add('select''m')
  1445.                     ->add('from''OceanExpertBundle:MemberEditsCountry m')
  1446.                     ->where('m.idCountry not in (:countries)')
  1447.                     ->andWhere('m.idInd =:idInd')
  1448.                     ->setParameters(
  1449.                         array(
  1450.                             'countries' => $countries
  1451.                             'idInd' => $id
  1452.                         )
  1453.                     )
  1454.                     ->getQuery()->getResult();
  1455.                 foreach ($results as $result) {
  1456.                     $em->remove($result);
  1457.                 }
  1458.                 $em->flush();
  1459.                 foreach ($countries as $value) {
  1460.                     $updateCountries $this->getDoctrine()
  1461.                         ->getRepository('OceanExpertBundle:MemberEditsCountry')
  1462.                         ->find(array(
  1463.                             'idInd' => $id,
  1464.                                 'idCountry' => $value
  1465.                             )
  1466.                     );
  1467.                     if (!$updateCountries) {
  1468.                         $addCountry = new MemberEditsCountry();
  1469.                         $addCountry->setIdInd($id);
  1470.                         $addCountry->setIdCountry($value);
  1471.                         $em $this->getDoctrine()->getManager();
  1472.                         $em->persist($addCountry); //marks object to be saved in the next transaction.
  1473.                         $em->flush(); //performs all saves and transactions.
  1474.                     }
  1475.                 }
  1476.                 $return['message'][] = 'countries added';
  1477.             } else {
  1478.                 $updateGroup $this->getDoctrine()
  1479.                     ->getRepository('OceanExpertBundle:MemberEditsCountry')
  1480.                     ->findBy(array('idInd' => $id));
  1481.                 $em $this->getDoctrine()->getEntityManager();
  1482.                 foreach ($updateGroup as $groups) {
  1483.                     $em->remove($groups);
  1484.                 }
  1485.                 $em->flush();
  1486.                 $return['message'][] = 'countries removed';
  1487.             }
  1488.             $user$em->getRepository('OceanExpertBundle:User')
  1489.                 ->findOneBy(
  1490.                     array(
  1491.                         'id' => $id
  1492.                     )
  1493.                 );
  1494.             if($editor == 1) {
  1495.                 $user->addRole("ROLE_GLOBAL_EDITOR");
  1496.                 $return['message'][] = 'global editor activated';
  1497.             } elseif ($editor == 0) {
  1498.                 $user->removeRole('ROLE_GLOBAL_EDITOR');
  1499.                 $return['message'][] = 'global editor removed';
  1500.             }
  1501.             $em->persist($user);
  1502.             $em->flush();
  1503.         } else {
  1504.             $return = array(
  1505.                 'status' => 1,
  1506.                 'error' => 'you have no rights to do this'
  1507.             );
  1508.         }
  1509.         return new Response(json_encode($return));
  1510.     }
  1511.     public function resetPasswordLinkAction(Request $request): Response
  1512.     {
  1513.         if ($request->query->get('username')) {
  1514.             $username $request->query->get('username');
  1515.         } else {
  1516.             $username $request->request->get('username');
  1517.         }
  1518.         $user $this->fosUserManager->findUserByUsernameOrEmail($username);
  1519.         if (null === $user) {
  1520.             $return "Error in sending email. User not found.";
  1521.             return new Response($return);
  1522.         }
  1523.         if (null === $user->getConfirmationToken()) {
  1524.             $user->setConfirmationToken($this->fosTokenGenerator->generateToken());
  1525.         }
  1526.         $this->fosMailer->sendResettingEmailMessage($user);
  1527.         $user->setPasswordRequestedAt(new DateTime());
  1528.         $this->fosUserManager->updateUser($user);
  1529.         $return "Password reset link send successfully.";
  1530.         if ($request->query->get('username')) {
  1531.             $email $user->getEmail();
  1532.             if (false !== $pos strpos($email'@')) {
  1533.                 $email '...' substr($email$pos);
  1534.             }
  1535.             return new RedirectResponse(
  1536.                 $this->generateUrl(
  1537.                     'fos_user_resetting_check_email',
  1538.                     array('email' => $email)
  1539.                 )
  1540.             );
  1541.         }
  1542.        
  1543.         return new Response($return);
  1544.     }
  1545.     public function getIndivInstitute($idInd)
  1546.     {
  1547.         $getInstId $this->getDoctrine()
  1548.             ->getRepository('OceanExpertBundle:IndivInstitution')
  1549.             ->findOneByIdInd($idInd);
  1550.         if ($getInstId) {
  1551.             return $getInstId->getIdInst();
  1552.         } else {
  1553.             return 0;
  1554.         }
  1555.     }
  1556.     /**
  1557.      * @return Response
  1558.      */
  1559.     public function assignRolesAction(Request $request): Response
  1560.     {
  1561.         $username =  $request->request->get('username');
  1562.         $em $this->getDoctrine()->getManager();
  1563.         $user$em->getRepository("OceanExpertBundle:User")
  1564.             ->findOneBy(array('username' => $username));
  1565.         if ($request->request->get('superadmin')==1) {
  1566.             $user->addRole('ROLE_SUPERADMIN');
  1567.         } else {
  1568.             $user->removeRole('ROLE_SUPERADMIN');
  1569.         }
  1570.         if ($request->request->get('administrator')==1) {
  1571.             $user->addRole('ROLE_ADMIN');
  1572.         } else {
  1573.             $user->removeRole('ROLE_ADMIN');
  1574.         }
  1575.         if ($request->request->get('manager')==1) {
  1576.             $user->addRole('ROLE_MANAGER');
  1577.         } else {
  1578.             $user->removeRole('ROLE_MANAGER');
  1579.         }
  1580.         if ($request->request->get('lme')==1) {
  1581.             $user->addRole('ROLE_LME');
  1582.         } else {
  1583.             $user->removeRole('ROLE_LME');
  1584.         }
  1585.         $em->persist($user);
  1586.         $em->flush();
  1587.         return new JsonResponse(
  1588.             array(
  1589.                 'status' => ,
  1590.                 'message' => 'Role assigned successfully',
  1591.                 'roles' => $username,
  1592.                 'user' => $user
  1593.             )
  1594.         );
  1595.     }
  1596.     /**
  1597.      * @return JsonResponse
  1598.      */
  1599.     public function getExpertsAjaxAction(Request $request): Response
  1600.     {
  1601.         if (!null == $request->query->get('q')) {
  1602.             $query $request->query->get('q');
  1603.             $em $this->getDoctrine()->getManager();
  1604.             $connection $em->getConnection();
  1605.             $statement $connection->prepare("SELECT 
  1606.                 i.id_ind AS id, 
  1607.                 i.fname, 
  1608.                 i.sname, 
  1609.                 i.jobtitle,
  1610.                 inst.inst_name,
  1611.                 c.country 
  1612.             FROM indiv i
  1613.             LEFT JOIN countries c ON c.id_country =  i.country_code
  1614.             LEFT JOIN indiv_institution ii ON ii.id_ind = i.id_ind
  1615.             LEFT JOIN institutions inst ON inst.id_inst = ii.id_inst
  1616.             LEFT JOIN countries ic ON ic.id_country =  inst.country_code
  1617.             WHERE ( MATCH (fname,sname) AGAINST (:searchterm IN BOOLEAN MODE) 
  1618.                 OR fname like '%$query%' 
  1619.                 OR fname like '%$query%' 
  1620.                 OR sname like '%$query%' 
  1621.                 OR sname like '%$query%') 
  1622.                 AND status = 1;
  1623.             ");
  1624.             $statement->bindValue('searchterm'$query);
  1625.             $statement->execute();
  1626.             $query $statement->fetchAll();
  1627.                 
  1628.             $data = array();
  1629.             if($query) {
  1630.                 $data = array(
  1631.                     'incomplete_results' => false,
  1632.                     'items' => $query,
  1633.                     'total_count' => count($query),
  1634.                 );
  1635.             }
  1636.             return new JsonResponse($data);
  1637.         }
  1638.         return new JsonResponse(array());
  1639.     }
  1640.     
  1641.     function getExpertEventParticipation($idInd$request) {
  1642.         $em $this->getDoctrine()->getManager();
  1643.         $participation $em->createQueryBuilder()
  1644.             ->add('select''ep.idEvent')
  1645.             ->add('from''OceanExpertBundle:EventParticipants ep')
  1646.             ->where('ep.idInd =:idInd')
  1647.             ->setParameters(array('idInd' => $idInd ))
  1648.             ->getQuery()->getResult();
  1649.         $participation array_column($participation"idEvent");
  1650.         $contacts $em->createQueryBuilder()
  1651.             ->add('select''ec.idEvent')
  1652.             ->add('from''OceanExpertBundle:EventContacts ec')
  1653.             ->where('ec.idInd =:idInd')
  1654.             ->setParameters(array('idInd' => $idInd ))
  1655.             ->getQuery()->getResult();
  1656.         $contacts array_column($contacts"idEvent");
  1657.         $staff $em->createQueryBuilder()
  1658.             ->add('select''es.idEvent')
  1659.             ->add('from''OceanExpertBundle:EventStaff es')
  1660.             ->where('es.idInd =:idInd')
  1661.             ->setParameters(array('idInd' => $idInd ))
  1662.             ->getQuery()->getResult();
  1663.         $staff array_column($staff"idEvent");
  1664.         $results array_merge($participation,$contacts,$staff);
  1665.         $results array_unique($results);
  1666.         $qb $this->getDoctrine()->getManager()->createQueryBuilder();
  1667.         $qb->add('select''e.idEvent,e.title, e.startOn, e.endOn, e.address, e.city, e.state, e.postcode, c.country')
  1668.             ->add('from''OceanExpertBundle:Events e')
  1669.             ->leftJoin('OceanExpertBundle:Countries''c''WITH''e.idCountry = c.idCountry')
  1670.             ->where('e.idEvent in (:idEvent)')
  1671.             ->andWhere('e.status = 1')
  1672.             ->orderBy('e.startOn''DESC')
  1673.             ->setParameter('idEvent'$results );
  1674.         $resultData $qb->getQuery()->getResult();
  1675.         $paginator $this->get('knp_paginator');
  1676.         $members $paginator->paginate(
  1677.             $resultData,
  1678.             $request->query->getInt('page'1),
  1679.             5,
  1680.             array(
  1681.                 'pageParameterName' => 'page',
  1682.                 'sortDirectionParameterName' => 'dir'
  1683.             )
  1684.         );
  1685.         //@todo some code goes here (i.e. your symfony request dispatching)
  1686.         return $members;
  1687.     }
  1688. }