Ejemplo n.º 1
0
 public function enablePublicUser($request)
 {
     require_once R3_LIB_DIR . 'eco_pub_auth.php';
     require_once R3_LIB_DIR . 'eco_stat_utils.php';
     if ($this->auth->hasPerm('MOD', 'PUBLIC_USER')) {
         $db = ezcDbInstance::get();
         $id = (int) $request['id'];
         $data = $db->query("SELECT * FROM ecogis.public_users WHERE us_id={$id}")->fetch(PDO::FETCH_ASSOC);
         $data['login_url'] = R3EcoGisStatHelper::getLoginURL($this->do_id, $data['us_login'], true);
         EcoPublicUser::register($this->do_id, $data, true, $id);
         // set password and change user status
         return array('status' => R3_AJAX_NO_ERROR);
     }
 }
Ejemplo n.º 2
0
 public function generateStatisticClass($request)
 {
     $id = (int) $request['id'];
     if ($request['kind'] == 'absolute') {
         $field = 'sdt_absolute_value';
         $prec = 'st_value_1_prec';
     } else {
         if ($request['kind'] == 'relative') {
             $field = 'sdt_relative_value';
             $prec = 'st_value_2_prec';
         } else {
             throw new Exception("Invalid kind \"{$request['kind']}\"");
         }
     }
     require_once R3_LIB_DIR . 'eco_stat_utils.php';
     require_once R3_LIB_DIR . 'stats_quantile_round.php';
     $statData = R3EcoGisStatHelper::getStatTypeData($this->do_id, R3EcoGisStatHelper::getStatTypeCodeById($id));
     $db = ezcDbInstance::get();
     $sql = "SELECT {$field} \n                FROM ecogis.stat_data_table sdt\n                INNER JOIN ecogis.stat_data sd ON sd.sd_id=sdt.sd_id\n                INNER JOIN ecogis.stat_type st ON sd.st_id=st.st_id\n                INNER JOIN  ecogis.stat_context sc ON sdt.sc_id=sc.sc_id\n                WHERE st.do_id={$this->do_id} AND sd.st_id={$id} AND sc_code='MUNICIPALITY' AND gc_id IS NULL AND ges_id IS NULL AND sbpu_id IS NULL AND bby_id IS NULL";
     $data = $db->query($sql)->fetchAll(PDO::FETCH_COLUMN);
     $capabilities = $this->getStatisticCapabilitiesByCode($statData['st_code']);
     if ($capabilities['is_value_stat']) {
         $limits = $capabilities['default_class_no'];
         $limits = getQuantileRoundLimits($data, $limits, $statData[$prec]);
         $result = array();
         $i = 0;
         $oldValue = null;
         list($r, $g, $b) = $this->decodeRGB($capabilities['class_start_color']);
         list($rEnd, $gEnd, $bEnd) = $this->decodeRGB($capabilities['class_end_color']);
         $deltaR = ($rEnd - $r) / (count($limits) + 1);
         $deltaG = ($gEnd - $g) / (count($limits) + 1);
         $deltaB = ($bEnd - $b) / (count($limits) + 1);
         foreach ($limits as $limit) {
             $expr = $i == 0 ? "[{$field}]<{$limit}" : "[{$field}]>={$oldValue} AND [{$field}]<{$limit}";
             $text1 = $i == 0 ? sprintf('fino a %s', R3NumberFormat($limit, $statData[$prec], true)) : sprintf('tra %s e %s', R3NumberFormat($oldValue, $statData[$prec], true), R3NumberFormat($limit, $statData[$prec], true));
             $text2 = $i == 0 ? sprintf('bis %s', R3NumberFormat($limit, $statData[$prec], true)) : sprintf('von %s und %s', R3NumberFormat($oldValue, $statData[$prec], true), R3NumberFormat($limit, $statData[$prec], true));
             $result[] = array('stc_color' => '#' . sprintf('%02X%02X%02X', $r, $g, $b), 'stc_outline_color' => '#000000', 'stc_text_1' => $text1, 'stc_text_2' => $text2, 'stc_value' => $limit, 'stc_order' => 10 + $i * 10, 'stc_expression' => $expr);
             $i++;
             $oldValue = $limit;
             $r += $deltaR;
             $g += $deltaG;
             $b += $deltaB;
         }
         $expr = "[{$field}]>={$oldValue}";
         $result[] = array('stc_color' => '#' . sprintf('%02X%02X%02X', $r, $g, $b), 'stc_outline_color' => '#000000', 'stc_text_1' => sprintf('oltre %s', R3NumberFormat($oldValue, $statData[$prec], true)), 'stc_text_2' => sprintf('mehr als %s', R3NumberFormat($oldValue, $statData[$prec], true)), 'stc_value' => $oldValue, 'stc_order' => 10 + $i * 10, 'stc_expression' => $expr);
     } else {
         $classData = $this->generateClasses($statData['st_code']);
         if ($classData == null) {
             throw new Exception("Impossibile calcolare automaticamente le classi");
         }
         $i = 0;
         foreach ($classData as $data) {
             $r = rand(0, 255);
             $g = rand(0, 255);
             $b = rand(0, 255);
             $expr = "[{$field}]={$data['id']}";
             $result[] = array('stc_color' => '#' . sprintf('%02X%02X%02X', $r, $g, $b), 'stc_outline_color' => '#000000', 'stc_text_1' => $data['text_1'], 'stc_text_2' => $data['text_1'], 'stc_value' => $data['id'], 'stc_order' => 10 + $i * 10, 'stc_expression' => $expr);
             $i++;
         }
     }
     return array('status' => R3_AJAX_NO_ERROR, 'data' => $result);
 }