Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.93 KB | None | 0 0
  1. public function destination_vaccinations ( $attrs = [], $content = null, $tag = '' ) {
  2.         $attrs = array_change_key_case((array) $attrs, CASE_LOWER);
  3.  
  4.         $shortcode_attrs = shortcode_atts(array(
  5.             'api_id'    => ( $this->_isset($_REQUEST, 'api_id') ) ? $_REQUEST['api_id'] : null,
  6.             'country_name'  => ( $this->_isset($_REQUEST, 'country_name') ) ? $_REQUEST['country_name'] : null,
  7.         ), $attrs, $tag);
  8.  
  9.         $api = $this->_get_api($shortcode_attrs['api_id']);
  10.  
  11.         if ( is_bool($api) ) {
  12.             return '';
  13.         }
  14.  
  15.         $countriesArray = $api->get_countries();
  16.         $searchedValue = $shortcode_attrs['country_name'];
  17.         $neededCountryObject = current(array_filter(
  18.             $countriesArray,
  19.             function ($e) use (&$searchedValue) {
  20.                 return strpos($e->Name, $searchedValue) !== false;
  21.                 // return $e->Name == $searchedValue;
  22.             }
  23.         ));
  24.         // var_dump($countriesArray);
  25.  
  26.         if($neededCountryObject) {
  27.             $vaccinationRecommendations = current($api->find_vaccination_recommendations( $neededCountryObject->Id ));
  28.             $diseasesRaw = $vaccinationRecommendations->Diseases;
  29.             $recommendationsRaw = $vaccinationRecommendations->Categories[1]->Recommendations;
  30.             $diseases = $mandatory = $recommended = $consider = array();
  31.  
  32.             foreach($diseasesRaw as $disease)
  33.                 $diseases[ $disease->DiseaseId ] = $disease->Title;
  34.  
  35.             foreach($recommendationsRaw as $recommendation) {
  36.                 switch($recommendation->Level) {
  37.                     case 'Mandatory':
  38.                         $mandatory[ $recommendation->DiseaseId ] = $diseases[ $recommendation->DiseaseId ];
  39.                         break;
  40.                     case 'Recommended':
  41.                         $recommended[ $recommendation->DiseaseId ] = $diseases[ $recommendation->DiseaseId ];
  42.                         break;
  43.                     case 'Consider':
  44.                         $consider[ $recommendation->DiseaseId ] = $diseases[ $recommendation->DiseaseId ];
  45.                         break;
  46.                 }
  47.             }
  48.  
  49.             $associationArray = array(
  50.                 13 => 199, // Hepatitis A
  51.                 2 => 151, // Typhoid
  52.                 9 => 172, // Japanese encephalitis
  53.                 24 => 163, // Rabies
  54.                 27 => 160, // Diphtheria
  55.                 16 => 160, // Tetanus,
  56.                 23 => 160, // Polio,
  57.                 6 => 200, // Cholera
  58.                 14 => 174, // Hepatitis B
  59.                 10 => 145, // Yellow Fever
  60.                 21 => 169, // Meningitis ACWY
  61.                 // 28 => // Tuberculosis -> missing on LTC
  62.             );
  63.             $compiledRecommended = array();
  64.             $compiledConsider = array();
  65.            
  66.             $resultRecommended = array();
  67.             $resultConsider = array();
  68.  
  69.             if($mandatory)
  70.                 foreach($mandatory as $xmedicusId => $disease)
  71.                     $compiledRecommended[] = $xmedicusId;
  72.             if($recommended)
  73.                 foreach($recommended as $xmedicusId => $disease)
  74.                     $compiledRecommended[] = $xmedicusId;
  75.             if($consider)
  76.                 foreach($consider as $xmedicusId => $disease)
  77.                     $compiledConsider[] = $xmedicusId;
  78.             if($compiledRecommended) {
  79.                 foreach($compiledRecommended as $xmedicusId) {
  80.                     if($associationArray[ $xmedicusId ])
  81.                         $resultRecommended[] = $associationArray[ $xmedicusId ];
  82.                 }
  83.             }
  84.             if($compiledConsider) {
  85.                 foreach($compiledConsider as $xmedicusId) {
  86.                     if($associationArray[ $xmedicusId ])
  87.                         $resultConsider[] = $associationArray[ $xmedicusId ];
  88.                 }
  89.             }
  90.  
  91.             $resultRecommended = array_unique($resultRecommended);
  92.             $resultsConsider = array_unique($resultConsider);
  93.            
  94.             // echo '<pre>';
  95.             // var_dump($resultRecommended);
  96.             // echo '</pre>';
  97.  
  98.             // echo '<pre>';
  99.             // var_dump($resultConsider);
  100.             // echo '</pre>';
  101.  
  102.             $mkey = 'vaccines_all_visitors';
  103.             include(dirname( __FILE__ ) . '/templates/destination/listing-destination.php');
  104.  
  105.             $mkey = 'vaccines_some_visitors';
  106.             include(dirname( __FILE__ ) . '/templates/destination/listing-destination.php');
  107.  
  108.             // foreach($recommended as $vaccine_name) {
  109.             //  $args = array(
  110.             //      'xm_search_post_title' => $vaccine_name, // search post title only
  111.             //      'post_status' => 'publish',
  112.             //      'post_type' => 'disease'
  113.             //  );
  114.             //  add_filter( 'posts_where', array( $this, 'post_title_filter' ), 10, 2 );
  115.             //  $query = new \WP_Query( $args );
  116.             //  remove_filter( 'posts_where', array( $this, 'post_title_filter' ), 10, 2 );
  117.  
  118.             //  if($query->have_posts()) {
  119.             //      while($query->have_posts()) {
  120.             //          $query->the_post();
  121.  
  122.             //          echo get_permalink() . '<br>';
  123.             //      }
  124.             //      wp_reset_query();
  125.             //  }
  126.             // }
  127.  
  128.             // // delete_transient('xm_popup_booking');
  129.             // if(get_transient('xm_popup_booking') === false) {
  130.             //  $data = array();
  131.             //  $units = $api->organization_units(null, null, 40);
  132.  
  133.             //  foreach($units as $unit) {
  134.             //      $resources = $api->get_resources($unit->Id);
  135.  
  136.             //      foreach($resources as $resource) {
  137.             //          $resource_treatments = $api->get_treatments($resource->Id, $people);
  138.  
  139.             //          $data[ $unit->Name ] = $resource_treatments;
  140.             //          // var_dump($unit->Name);
  141.             //          // var_dump($resource_treatments);
  142.             //      }
  143.             //  }
  144.  
  145.             //  // Store data in transient, expire after 1 week
  146.             //  set_transient('xm_popup_booking', $data, 7 * 24 * HOUR_IN_SECONDS);
  147.             // }
  148.         }
  149.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement