Ejemplo n.º 1
0
 /**
  * Returns HTML code for the GeoAnalysis general tab (can be either a map or a table).
  *
  * @param GeoAnalysis $ga Reference GeoAnalysis 
  * @param array $placesGeneralResults Analysis results at a general level
  * @param (null|array) $flags Array of flags
  * @return string HTML code for the general tab
  */
 protected function htmlPlacesAnalysisGeneralTab(GeoAnalysis $ga, $placesGeneralResults, $flags = null)
 {
     global $WT_TREE;
     if (!empty($placesGeneralResults)) {
         $data = new ViewBag();
         $nb_found = $placesGeneralResults['knownsum'];
         $nb_other = 0;
         if (isset($placesGeneralResults['other'])) {
             $nb_other = $placesGeneralResults['other'];
         }
         $nb_unknown = $placesGeneralResults['unknown'];
         $data->set('stats_gen_nb_found', $nb_found);
         $data->set('stats_gen_nb_other', $nb_other);
         $data->set('stats_gen_nb_unknown', $nb_unknown);
         $data->set('use_flags', $ga->getOptions() && $ga->getOptions()->isUsingFlags());
         if ($ga->hasMap()) {
             $max = $placesGeneralResults['max'];
             $map = $ga->getOptions()->getMap();
             $results_by_subdivs = $map->getSubdivisions();
             $places_mappings = $map->getPlacesMappings();
             foreach ($placesGeneralResults['places'] as $location => $count) {
                 $levelvalues = array_reverse(array_map('trim', explode(',', $location)));
                 $level_map = $ga->getAnalysisLevel() - $ga->getOptions()->getMapLevel();
                 if ($level_map >= 0 && $level_map < count($levelvalues)) {
                     $levelref = $levelvalues[0] . '@' . $levelvalues[$level_map];
                     if (!isset($results_by_subdivs[$levelref])) {
                         $levelref = $levelvalues[0];
                     }
                 } else {
                     $levelref = $levelvalues[0];
                 }
                 if (isset($places_mappings[$levelref])) {
                     $levelref = $places_mappings[$levelref];
                 }
                 if (isset($results_by_subdivs[$levelref])) {
                     $count_subd = isset($results_by_subdivs[$levelref]['count']) ? $results_by_subdivs[$levelref]['count'] : 0;
                     $count_subd += $count;
                     $results_by_subdivs[$levelref]['count'] = $count_subd;
                     $results_by_subdivs[$levelref]['transparency'] = Functions::safeDivision($count_subd, $max);
                     if ($ga->getOptions()->isUsingFlags() && $flags) {
                         $results_by_subdivs[$levelref]['place'] = new Place($location, $WT_TREE);
                         $results_by_subdivs[$levelref]['flag'] = $flags[$location];
                     }
                 }
             }
             $data->set('map', $ga->getOptions()->getMap());
             $data->set('results_by_subdivisions', $results_by_subdivs);
             $html = ViewFactory::make('GeoAnalysisTabGeneralMap', $this, new BaseController(), $data)->getHtmlPartial();
         } else {
             $results = $placesGeneralResults['places'];
             arsort($results);
             $data->set('results', $results);
             $data->set('analysis_level', $ga->getAnalysisLevel());
             $html = ViewFactory::make('GeoAnalysisTabGeneralTable', $this, new BaseController(), $data)->getHtmlPartial();
         }
     } else {
         $html = '<p class="warning">' . I18N::translate('No data is available for the general analysis.') . '</p>';
     }
     return $html;
 }
Ejemplo n.º 2
0
 /**
  * Update a geodispersion analysis in the database, in transactional manner.
  * When successful, returns the updated GeoAnalysis object
  *  
  * @param GeoAnalysis $ga
  * @return GeoAnalysis
  */
 public function updateGeoAnalysis(GeoAnalysis $ga)
 {
     try {
         Database::beginTransaction();
         Database::prepare('UPDATE `##maj_geodispersion`' . ' SET majgd_descr = :description,' . ' majgd_sublevel = :analysis_level,' . ' majgd_map = :map,' . ' majgd_toplevel = :map_top_level,' . ' majgd_useflagsgen = :use_flags,' . ' majgd_detailsgen = :gen_details' . ' WHERE majgd_file = :gedcom_id AND majgd_id = :ga_id')->execute(array('gedcom_id' => $this->tree->getTreeId(), 'ga_id' => $ga->getId(), 'description' => $ga->getTitle(), 'analysis_level' => $ga->getAnalysisLevel(), 'use_flags' => $ga->getOptions() && $ga->getOptions()->isUsingFlags() ? 'yes' : 'no', 'gen_details' => $ga->getOptions() ? $ga->getOptions()->getMaxDetailsInGen() : 0, 'map' => $ga->hasMap() ? $ga->getOptions()->getMap()->getFileName() : null, 'map_top_level' => $ga->hasMap() ? $ga->getOptions()->getMapLevel() : -100));
         $ga = $this->getGeoAnalysis($ga->getId(), false);
         Database::commit();
     } catch (\Exception $ex) {
         Database::rollback();
         Log::addErrorLog('The Geo Analysis ID “' . $ga->getId() . '” failed to be updated. Transaction rollbacked. Exception: ' . $ex->getMessage());
         $ga = null;
     }
     return $ga;
 }