Ejemplo n.º 1
0
 /**
  * Returns HTML code for the GeoAnalysis generations tab.
  *
  * @param GeoAnalysis $ga Reference GeoAnalysis 
  * @param array $placesGenerationsResults Analysis results at a generations level
  * @param (null|array) $flags Array of flags
  * @return string HTML code for the generations tab
  */
 protected function htmlPlacesAnalysisGenerationsTab(GeoAnalysis $ga, $placesGenerationsResults, $flags = null)
 {
     global $WT_TREE;
     if (!empty($placesGenerationsResults) && $ga->getOptions()) {
         $data = new ViewBag();
         ksort($placesGenerationsResults);
         $detailslevel = $ga->getOptions()->getMaxDetailsInGen();
         $data->set('max_details_gen', $detailslevel);
         $data->set('use_flags', $ga->getOptions()->isUsingFlags());
         $data->set('analysis_level', $ga->getAnalysisLevel());
         $display_all_places = !is_null($detailslevel) && $detailslevel == 0;
         $data->set('display_all_places', $display_all_places);
         $results_by_gen = array();
         foreach ($placesGenerationsResults as $gen => $genData) {
             $sum = 0;
             $other = 0;
             $unknown = 0;
             if (isset($genData['sum'])) {
                 $sum = $genData['sum'];
             }
             if (isset($genData['other'])) {
                 $other = $genData['other'];
             }
             if (isset($genData['unknown'])) {
                 $unknown = $genData['unknown'];
             }
             if ($sum > 0) {
                 $results_by_gen[$gen]['sum'] = $sum;
                 $results_by_gen[$gen]['other'] = $other;
                 $results_by_gen[$gen]['unknown'] = $unknown;
                 $results_by_gen[$gen]['places'] = array();
                 arsort($genData['places']);
                 if ($display_all_places) {
                     foreach ($genData['places'] as $placename => $count) {
                         $results_by_gen[$gen]['places'][$placename]['count'] = $count;
                         if ($ga->getOptions() && $ga->getOptions()->isUsingFlags() && ($flag = $flags[$placename]) != '') {
                             $results_by_gen[$gen]['places'][$placename]['place'] = new Place($placename, $WT_TREE);
                             $results_by_gen[$gen]['places'][$placename]['flag'] = $flag;
                         }
                     }
                 } else {
                     $tmp = $genData['places'];
                     if ($other > 0) {
                         $tmp = array_slice($tmp, 0, 5, true);
                         $tmp['other'] = $other;
                         arsort($tmp);
                     }
                     $results_by_gen[$gen]['places'] = array_slice($tmp, 0, 5, true);
                 }
             }
         }
         $data->set('results_by_generations', $results_by_gen);
         $html = ViewFactory::make('GeoAnalysisTabGenerations', $this, new BaseController(), $data)->getHtmlPartial();
     } else {
         $html = '<p class="warning">' . I18N::translate('No data is available for the generations 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;
 }