/** * Return the filter values (list form) */ public function getFilterValues() { $filters = array(); if ($this->auth->hasPerm('SHOW', 'ALL_DOMAINS')) { $do_id = null; $filters['do_values'] = R3EcoGisHelper::getDomainList(); } else { $do_id = $this->auth->getDomainID(); } $filters['pr_values'] = R3EcoGisHelper::getProvinceList($do_id); $filters['mu_values'] = R3EcoGisHelper::getMunicipalityList($do_id); $filters['bpu_values'] = R3EcoGisHelper::getBuildingPurposeUseList($do_id); $filters['do_id'] = $this->do_id; $filters['pr_id'] = $this->pr_id; $filters['mu_id'] = $this->mu_id; $filters['bpu_id'] = $this->bpu_id; return $filters; }
public function fetch_municipality($request) { $like = isset($request['term']) ? $request['term'] : null; $limit = isset($request['limit']) ? $request['limit'] : null; return R3EcoGisHelper::getMunicipalityList($this->do_id, $like, $limit); }
/** * Create the table header * param string $order The table order */ public function createListTableHeader(&$order) { if ($this->auth->getParam('mu_id') == '' && count(R3EcoGisHelper::getMunicipalityList($this->do_id)) > 1) { if ($this->mu_id == '') { $this->simpleTable->addSimpleField(_('Comuni'), 'mu_name', 'text', null, array('sortable' => true, 'order_fields' => 'mu_name')); } } $this->simpleTable->addSimpleField(_('Fornitore'), 'us_name', 'text', null, array('sortable' => true)); $this->simpleTable->addSimpleField(_('Prodotti'), 'up_name', 'text', null, array('sortable' => true)); $this->simpleTable->addSimpleField(_('Ordinamento'), 'us_order', 'integer', 80, array('sortable' => true)); $this->simpleTable->addSimpleField(_('Azione'), '', 'link', 85); $this->tableHtml = $this->simpleTable->CreateTableHeader($order, 'energy_source_list_table'); }
public function getMunicipalityList($request) { $like = isset($request['term']) ? $request['term'] : null; $limit = isset($request['limit']) ? $request['limit'] : null; return R3EcoGisHelper::getMunicipalityList($_SESSION['do_id'], $like, $limit); }
/** * Return the data for a single customer */ public function getData($id = null) { $lang = R3Locale::getLanguageID(); if ($id === null) { $id = $this->id; } $db = ezcDbInstance::get(); if ($this->act != 'add') { $q = $db->createSelectQuery(); $q->select('*')->from('global_entry_data')->where('ge_id=' . (int) $id); $vlu = $db->query($q)->fetch(PDO::FETCH_ASSOC); $vlu['cus_name'] = $vlu['cus_name_' . $lang]; $vlu['mu_name'] = $vlu['mu_name_' . $lang]; // Autocomplete $vlu['ge_year_as_string'] = $vlu['ge_year']; // Prevent number format $vlu['ge_green_electricity_purchase'] = $vlu['ge_green_electricity_purchase'] / 1000; // Revert to MWh $vlu = array_merge($vlu, R3EcoGisHelper::getChangeLogData('global_entry', $vlu['ge_id'])); } else { $vlu = array(); $vlu['do_id'] = $_SESSION['do_id']; $vlu['cus_name'] = R3EcoGisHelper::getDomainName($_SESSION['do_id']); $mu_values = R3EcoGisHelper::getMunicipalityList($this->do_id); if (count($mu_values) == 1) { $vlu['mu_id'] = key($mu_values); } else { if ($this->auth->getParam('mu_id') > 0) { $vlu['mu_id'] = $this->auth->getParam('mu_id'); } } if ($this->auth->getParam('mu_id') > 0) { $vlu['mu_id'] = $this->auth->getParam('mu_id'); $vlu['mu_name'] = R3EcoGisHelper::getMunicipalityName($this->auth->getParam('mu_id')); } } $this->data = $vlu; // Save the data (prevent multiple sql) return $vlu; }
/** * Set the mu_id for the user from auth, installation, mu_id & mu_name * @param type $request */ public function setMunicipalityForUser(&$request) { if ($this->auth->getParam('mu_id') != '') { $request['mu_id'] = $this->auth->getParam('mu_id'); return true; } $muList = R3EcoGisHelper::getMunicipalityList($this->do_id); if (count($muList) == 1) { $request['mu_id'] = key($muList); return true; } if (isset($request['mu_name'])) { $request['mu_id'] = R3EcoGisHelper::getMunicipalityIdByName($this->do_id, $request['mu_name'], $this->auth->getParam('mu_id')); return true; } // User has more municipality return false; }
/** * Return the data for a single customer */ public function getData($id = null) { $lang = R3Locale::getLanguageID(); $db = ezcDbInstance::get(); if ($this->act != 'add') { $q = $db->createSelectQuery(); $q->select('*')->from('action_catalog_data ac')->where("ac_id={$this->id}"); $vlu = $db->query($q)->fetch(PDO::FETCH_ASSOC); $vlu['mu_name'] = $vlu["mu_name_{$lang}"]; // Autocomplete $vlu['ac_expected_co2_reduction'] = $vlu['ac_expected_co2_reduction_calc'] / 1000; // Get the calculated value - the db value is not used $vlu['ac_expected_energy_saving_mwh'] = $vlu['ac_expected_energy_saving_kwh'] / 1000; $vlu['ac_green_electricity_purchase_mwh'] = R3NumberFormat($vlu['ac_green_electricity_purchase_kwh'] / 1000, 2, true); $vlu['ac_co2_reduction_tco2'] = R3NumberFormat($vlu['ac_co2_reduction'] / 1000, 2, true); $vlu['ac_expected_renewable_energy_production_mwh'] = $vlu['ac_expected_renewable_energy_production_kwh'] / 1000; // Get the calculated value - the db value is not used // get expected energy savings $vlu['ac_expected_energy_savings'] = array(); $sql = "SELECT action_catalog_energy.*, energy_source_udm.*, " . " esu_kwh_factor * ace_expected_energy_saving AS ace_expected_energy_saving_kwh, " . " esu_co2_factor * ace_expected_energy_saving AS ace_expected_co2_reduction_calc " . " FROM action_catalog_energy " . " INNER JOIN energy_source_udm USING(esu_id) " . " WHERE ac_id={$this->id} " . "ORDER BY ace_id"; $r = $db->query($sql); while ($row = $r->fetch()) { $lkp = $this->getLookupDataForEnergySavings($row['ges_id']); $tmp = array('ges_id' => $row['ges_id'], 'es_id' => $row['es_id'], 'udm_id' => $row['udm_id'], 'ac_expected_energy_saving' => R3NumberFormat($row['ace_expected_energy_saving'], 2, true), 'ac_expected_energy_saving_mwh' => R3NumberFormat($row['ace_expected_energy_saving_kwh'] / 1000, 2, true), 'ac_expected_co2_reduction' => R3NumberFormat($row['ace_expected_co2_reduction_calc'] / 1000, 2, true), 'es_id_consumption_values' => $lkp['es_id_consumption_values'], 'udm_id_consumption_values' => $lkp['udm_id_consumption_values']); $vlu['ac_expected_energy_savings'][] = $tmp; } // get related actions $vlu['ac_related_actions'] = array(); $vlu['ac_related_required_actions'] = array(); $vlu['ac_related_excluded_actions'] = array(); $sql = "SELECT action_catalog.ac_id, ac_name_{$lang}, acd_type " . " FROM action_catalog " . " INNER JOIN action_catalog_dependencies on action_catalog.ac_id = action_catalog_dependencies.ac_related_id " . " WHERE action_catalog_dependencies.ac_id={$this->id}"; $r = $db->query($sql); while ($row = $r->fetch()) { if ($row['acd_type'] == 'R') { $index = 'ac_related_required_actions'; } else { if ($row['acd_type'] == 'D') { $index = 'ac_related_actions'; } else { if ($row['acd_type'] == 'E') { $index = 'ac_related_excluded_actions'; } else { throw new exceltion('Invalid value for acd_type'); } } } $tmp = array('ac_id' => $row['ac_id'], 'ac_name' => $row['ac_name_' . $lang]); array_push($vlu[$index], $tmp); } // get benefit year $vlu['ac_benefit_year'] = array(); $sql = "SELECT acby_year, acby_benefit \r\n FROM action_catalog_benefit_year\r\n WHERE ac_id={$this->id}\r\n ORDER BY acby_year"; $vlu['enable_benefit_year'] = 'F'; foreach ($db->query($sql, PDO::FETCH_ASSOC) as $row) { $vlu['ac_benefit_year'][] = $row; $vlu['enable_benefit_year'] = 'T'; } if ($this->bu_id != '') { $vlu['bu_id'] = $this->bu_id; } $vlu = array_merge($vlu, R3EcoGisHelper::getChangeLogData('action_catalog', $vlu['ac_id'])); } else { $vlu = array(); $vlu['ac_id'] = null; $vlu['bu_id'] = $this->bu_id; $mu_values = R3EcoGisHelper::getMunicipalityList($this->do_id); if (count($mu_values) == 1) { $vlu['mu_id'] = key($mu_values); } else { if ($this->auth->getParam('mu_id') > 0) { $vlu['mu_id'] = $this->auth->getParam('mu_id'); } } if (isset($vlu['mu_id']) && $vlu['mu_id'] != '') { $vlu['mu_name'] = R3EcoGisHelper::getMunicipalityName($vlu['mu_id']); } if ($this->bu_id != '') { $vlu['mu_id'] = $db->query('SELECT mu_id FROM building WHERE bu_id=' . (int) $this->bu_id)->fetchColumn(); $emo_id = R3EcoGisHelper::getEnergyMeterObjectIdByCode('BUILDING'); $codePart1 = $db->query('SELECT bu_code FROM building WHERE bu_id=' . (int) $this->bu_id)->fetchColumn(); $codePart2 = $db->query("SELECT LPAD((COUNT(ac_code) + 1)::TEXT, 2, '0') FROM action_catalog WHERE emo_id={$emo_id} AND ac_object_id=" . (int) $this->bu_id)->fetchColumn(); if ($codePart1 == '') { $vlu['ac_code'] = $codePart2; } else { $vlu['ac_code'] = "{$codePart1}-{$codePart2}"; } // Ricavo Macro-settore, Settore, Sub-settore list($gc_id, $gc_id_parent) = R3EcoGisHelper::getGlobalCategoryForActionCatalogBuilding($this->bu_id); if ($gc_id_parent === null || $gc_id === null) { throw new Exception(_("Destinazione d'uso dell'edificio mancante, o categoria PAES non valida")); } $vlu['gc_parent_id'] = $gc_id_parent; $vlu['gc_id'] = $gc_id; } else { if (isset($vlu['mu_id'])) { $vlu['ac_code'] = (int) $db->query('SELECT MAX(ac_code) FROM action_catalog WHERE mu_id=' . (int) $vlu['mu_id'])->fetchColumn() + 1; } } $vlu['ac_benefit_end_date'] = $this->auth->getConfigValue('APPLICATION', 'DEFAULT_ACTION_BENEFIT_END_DATE', '2020-12-31'); } $this->data = $vlu; // Save the data (prevent multiple sql) return $vlu; }
/** * If has municipality collection, return a 2D array with municipality and municipality collection. * if anly municipality present return only the municipality list in 1Dim array. Used for option and optiongroup in html select * * @param type $do_id * @return type */ public static function getMunicipalityAndMunicipalityCollectionList($do_id, $like = null, $limit = null, array $opt = array()) { $result = array(); $result['has_municipality_collection'] = R3EcoGisHelper::hasMunicipalityCollection($do_id); if ($result['has_municipality_collection']) { $munucipalityCollectionList = R3EcoGisHelper::getMunicipalityCollectionList($do_id, $like, $limit, $opt); $munucipalityList = R3EcoGisHelper::getMunicipalityList($do_id, $like, $limit, $opt); if (count($munucipalityCollectionList) > 0) { $result['data'][_('Raggruppamenti')] = $munucipalityCollectionList; $result['tot']['collection'] = count($result['data'][_('Raggruppamenti')]); } else { $result['tot']['collection'] = 0; } if (count($munucipalityList) > 0) { $result['data'][_('Comuni')] = $munucipalityList; $result['tot']['municipality'] = count($result['data'][_('Comuni')]); } else { $result['tot']['municipality'] = 0; } } else { $result['data'] = R3EcoGisHelper::getMunicipalityList($do_id, $like, $limit, $opt); $result['tot']['municipality'] = count($result['data']); } return $result; }
/** * Return the data for a single customer */ public function getLookupData($id = null) { $lang = R3Locale::getLanguageID(); $db = ezcDbInstance::get(); $lkp = array(); if ($this->auth->getParam('mu_id') == '') { $lkp['pr_values'] = R3EcoGisHelper::getProvinceList($this->do_id); $lkp['mu_values'] = R3EcoGisHelper::getMunicipalityList($this->do_id); } else { $lkp['mu_values'] = array($this->auth->getParam('mu_id') => ''); } $mu_id = $this->auth->getParam('mu_id'); if ($this->act == 'add' && count($lkp['mu_values']) == 1) { $mu_id = key($lkp['mu_values']); } else { if ($this->act == 'mod') { $mu_id = $this->data['mu_id']; } } $lkp['es_values'] = R3Opt::getOptList('energy_source_udm_data', 'es_id', 'es_name_' . R3Locale::getLanguageID(), array('constraints' => "do_id={$this->do_id} AND mu_id IS NULL")); // AND esu_is_private IS FALSE")); if ($this->data['es_id'] != '') { $sqlUDM = "SELECT udm_id, udm_name_{$lang} AS udm_name\r\n FROM energy_source_udm_data\r\n WHERE do_id IS NULL AND es_id={$this->data['es_id']}\r\n GROUP BY udm_id, udm_name_{$lang}\r\n ORDER BY udm_name, udm_id"; $lkp['udm_values'] = $db->query($sqlUDM)->fetchAll(PDO::FETCH_COLUMN | PDO::FETCH_UNIQUE); } return $lkp; }
public function getPageVars() { if ($this->act != 'list') { $mu_id = $this->auth->getParam('mu_id'); if ($this->act == 'add') { $mu_values = R3EcoGisHelper::getMunicipalityList($this->do_id); if (count($mu_values) == 1) { $mu_id = key($mu_values); } } else { if ($this->act == 'mod' || $this->act == 'show') { $mu_id = $this->data['mu_id']; } } if ($mu_id > 0) { $autoSelectedActions = $this->select_done == 'T' && $this->data['actions']['ac_id_list'] != ''; return array('catalog_html' => R3EcoGisSimulationHelper::getCatalogDataHTML($this->do_id, $mu_id, array('alternative_data_only' => $this->alternativeSimulation)), 'selected_html' => R3EcoGisSimulationHelper::getSelectedCatalogDataHTML($this->do_id, $mu_id), 'auto_selected_actions' => $autoSelectedActions); } } return array(); }
/** * Return the data for a single customer */ public function getData($id = null) { $lang = R3Locale::getLanguageID(); $db = ezcDbInstance::get(); if ($this->act != 'add') { $q = $db->createSelectQuery(); $q->select('*')->from('global_plain_data')->where("gp_id={$this->id}"); $vlu = $db->query($q)->fetch(PDO::FETCH_ASSOC); $vlu['mu_name'] = $vlu["mu_name_{$lang}"]; // Autocomplete $vlu['gp_url_1'] = $this->adjURL($vlu["gp_url_1"], true); if (isset($vlu["gp_url_2"])) { $vlu['gp_url_2'] = $this->adjURL($vlu["gp_url_2"], true); } $vlu = array_merge($vlu, R3EcoGisHelper::getChangeLogData('global_plain', $vlu['gp_id'])); } else { $vlu = array(); $vlu['do_id'] = $this->do_id; $mu_values = R3EcoGisHelper::getMunicipalityList($this->do_id); if (count($mu_values) == 1) { $vlu['mu_id'] = key($mu_values); } else { if ($this->auth->getParam('mu_id') > 0) { $vlu['mu_id'] = $this->auth->getParam('mu_id'); } } if (isset($vlu['mu_id']) && $vlu['mu_id'] != '') { $vlu['mu_name'] = R3EcoGisHelper::getMunicipalityName($vlu['mu_id']); } $vlu['gp_url_1'] = $this->adjURL('', true); $vlu['gp_url_2'] = $this->adjURL('', true); } $this->data = $vlu; // Save the data (prevent multiple sql) return $vlu; }
/** * Create the table header * param string $order The table order */ public function createListTableHeader(&$order) { if ($this->auth->hasPerm('SHOW', 'ALL_DOMAINS')) { if ($this->do_id == '') { $this->simpleTable->addSimpleField(_('Ente'), 'cus_name', 'text', null, array('sortable' => true, 'order_fields' => 'cus_name, mu_name, sl_id')); } if ($this->mu_id == '') { $this->simpleTable->addSimpleField(_('Comune'), 'mu_name', 'text', null, array('sortable' => true)); } } else { if (count(R3EcoGisHelper::getMunicipalityList($this->auth->getDomainID())) > 1) { if ($this->mu_id == '') { $this->simpleTable->addSimpleField(_('Comune'), 'mu_name', 'text', null, array('sortable' => true)); } } } $this->simpleTable->addSimpleField(_('Tratto'), 'sl_full_name', 'text', null, array('sortable' => true)); $this->simpleTable->addSimpleField(_('Lunghezza'), 'sl_length', 'number', 80, array('sortable' => true, 'align' => 'center')); $this->simpleTable->addSimpleField(_('Da controllare'), 'sl_to_check', 'text', 80, array('sortable' => true, 'align' => 'center')); $this->simpleTable->addSimpleField(_('Azione'), '', 'link', 85); $this->tableHtml = $this->simpleTable->CreateTableHeader($order); }