A set of plugins to help on managing geographic information

This commit is contained in:
ahwelp
2023-01-24 20:41:37 +00:00
parent 616a97f16c
commit a60cfcec3a
61 changed files with 7895 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
<?php
use App\Core\Template\Output as Output;
use Routes\RouteCollection as RouteCollection;
//Menu itens
RouteCollection::get('*', function() {
//Output::addMenu('/state', 'state', "<i class='fa fa-fa-cubes'></i>", ['class' => 'nav-link']);
Output::addOnSubmenu('geo', '/state', 'Estados', "", ['class' => 'nav-link']);
}, -10)->doIgnore();
RouteCollection::group("/state", function(){
RouteCollection::get ("/", "\App\Geo\State\StateController@index");
RouteCollection::get ("/form", "\App\Geo\State\StateController@create");
RouteCollection::get ("/select", "\App\Geo\State\StateController@loadSelect");
RouteCollection::post ("/", "\App\Geo\State\StateController@store");
RouteCollection::get ("/search", "\App\Geo\State\StateController@search");
RouteCollection::post ("/search", "\App\Geo\State\StateController@search");
RouteCollection::get ("/[i:id]", "\App\Geo\State\StateController@show");
RouteCollection::get ("/[i:id]/edit", "\App\Geo\State\StateController@edit");
RouteCollection::put ("/[i:id]/edit", "\App\Geo\State\StateController@update");
RouteCollection::delete("/[i:id]", "\App\Geo\State\StateController@destroy");
});
+139
View File
@@ -0,0 +1,139 @@
<?php
namespace App\Geo\State;
use \App\Core\Template\Output as Output;
use \App\Geo\State\Classes\State as State;
class StateController
{
/**
* Index
* Show the main State list
*/
function index()
{
$list = array();
for ($i = 0; $i <= 10; $i++) {
$obj = array();
$obj['id'] = $i;
$obj['value'] = md5($i);
$obj['description'] = sha1($i);
$list[] = $obj;
}
Output::render('list', $list);
}
/**
* Create
*
* Render the main State formulary
*/
function create()
{
Output::setView('form', ['id' => 0]);
Output::render();
}
/**
* Store
*
* Store the param on the database
* @param State $state
*/
function store(State $state)
{
}
/**
* Search
*
* Store the param on the database
* @param State $state
*/
function search()
{
$states = State::findAll(['id', 'shortname']);
$return = "<option value='0'>Selecione</option>";
foreach ($states as $state) {
if ($state->id == $_GET['value']) {
$return .= "<option value='$state->id' selected>$state->shortname</option>";
} else {
$return .= "<option value='$state->id'>$state->shortname</option>";
}
}
echo $return;
}
/**
* Show
*
* Render one register
*
* @param State $state
*/
function show(State $state)
{
\RR\Response::json($state)->send();
}
/**
* Edit
*
* Render the formular for a database State
*
* @param State $state
*/
function edit(State $state)
{
Output::setView('form', $state);
Output::render();
}
/**
* Update
* Store the changes of the param on the database
*
* @param State $state
*/
function update(State $state)
{
}
/**
* Destroy
* If the object has soft delete.
*
* @param State $state
*/
function destroy(State $state)
{
}
/**
* Purge
* Remove object even with soft delete.
*
* @param State $state
*/
function purge(State $state)
{
}
function loadSelect()
{
//ddd(State::findMany(['country_id' => ['=', '25']])->get());
Output::render(
'select',
[
'states' => State::findMany(['country_id' => ['=', '25']])->get(),
//'selected' => $_GET['value']
]
);
}
}
+25
View File
@@ -0,0 +1,25 @@
<?php
namespace App\Geo\State\Classes;
use ORM\Entity as Entity;
use App\Geo\Country\Classes\Country as Country;
class State extends Entity {
const _tableName = "geo_states";
//const _timestamps = true;
//const _softdelete = true;
//const _connectionName = "";
function country(){
return $this->belongsTo(Country::class, 'country_id');
}
}
@@ -0,0 +1,27 @@
insert into {geo_states} (name, code, shortname, country_id) VALUES('Are' ,12 ,'AC', (SELECT id FROM {geo_countries} WHERE iso3 = 'BRA'));
insert into {geo_states} (name, code, shortname, country_id) VALUES('Alagoas' ,27 ,'AL', (SELECT id FROM {geo_countries} WHERE iso3 = 'BRA'));
insert into {geo_states} (name, code, shortname, country_id) VALUES('Amapá' ,16 ,'AP', (SELECT id FROM {geo_countries} WHERE iso3 = 'BRA'));
insert into {geo_states} (name, code, shortname, country_id) VALUES('Amazonas' ,13 ,'AM', (SELECT id FROM {geo_countries} WHERE iso3 = 'BRA'));
insert into {geo_states} (name, code, shortname, country_id) VALUES('Bahia' ,29 ,'BA', (SELECT id FROM {geo_countries} WHERE iso3 = 'BRA'));
insert into {geo_states} (name, code, shortname, country_id) VALUES('Ceará' ,23 ,'CE', (SELECT id FROM {geo_countries} WHERE iso3 = 'BRA'));
insert into {geo_states} (name, code, shortname, country_id) VALUES('Distrito Federal' ,53 ,'DF', (SELECT id FROM {geo_countries} WHERE iso3 = 'BRA'));
insert into {geo_states} (name, code, shortname, country_id) VALUES('Espírito Santo' ,32 ,'ES', (SELECT id FROM {geo_countries} WHERE iso3 = 'BRA'));
insert into {geo_states} (name, code, shortname, country_id) VALUES('Goiás' ,52 ,'GO', (SELECT id FROM {geo_countries} WHERE iso3 = 'BRA'));
insert into {geo_states} (name, code, shortname, country_id) VALUES('Maranhão' ,21 ,'MA', (SELECT id FROM {geo_countries} WHERE iso3 = 'BRA'));
insert into {geo_states} (name, code, shortname, country_id) VALUES('Mato Grosso' ,51 ,'MT', (SELECT id FROM {geo_countries} WHERE iso3 = 'BRA'));
insert into {geo_states} (name, code, shortname, country_id) VALUES('Mato Grosso do Sul' ,50 ,'MS', (SELECT id FROM {geo_countries} WHERE iso3 = 'BRA'));
insert into {geo_states} (name, code, shortname, country_id) VALUES('Minas Gerais' ,31 ,'MG', (SELECT id FROM {geo_countries} WHERE iso3 = 'BRA'));
insert into {geo_states} (name, code, shortname, country_id) VALUES('Pará' ,15 ,'PA', (SELECT id FROM {geo_countries} WHERE iso3 = 'BRA'));
insert into {geo_states} (name, code, shortname, country_id) VALUES('Paraíba' ,25 ,'PB', (SELECT id FROM {geo_countries} WHERE iso3 = 'BRA'));
insert into {geo_states} (name, code, shortname, country_id) VALUES('Paraná' ,41 ,'PR', (SELECT id FROM {geo_countries} WHERE iso3 = 'BRA'));
insert into {geo_states} (name, code, shortname, country_id) VALUES('Pernambuco' ,26 ,'PE', (SELECT id FROM {geo_countries} WHERE iso3 = 'BRA'));
insert into {geo_states} (name, code, shortname, country_id) VALUES('Piauí' ,22 ,'PI', (SELECT id FROM {geo_countries} WHERE iso3 = 'BRA'));
insert into {geo_states} (name, code, shortname, country_id) VALUES('Rio Grande do Norte' ,24 ,'RN', (SELECT id FROM {geo_countries} WHERE iso3 = 'BRA'));
insert into {geo_states} (name, code, shortname, country_id) VALUES('Rio Grande do Sul' ,43 ,'RS', (SELECT id FROM {geo_countries} WHERE iso3 = 'BRA'));
insert into {geo_states} (name, code, shortname, country_id) VALUES('Rio de Janeiro' ,33 ,'RJ', (SELECT id FROM {geo_countries} WHERE iso3 = 'BRA'));
insert into {geo_states} (name, code, shortname, country_id) VALUES('Rondônia' ,11 ,'RO', (SELECT id FROM {geo_countries} WHERE iso3 = 'BRA'));
insert into {geo_states} (name, code, shortname, country_id) VALUES('Roraima' ,14 ,'RR', (SELECT id FROM {geo_countries} WHERE iso3 = 'BRA'));
insert into {geo_states} (name, code, shortname, country_id) VALUES('Santa Catarina' ,42 ,'SC', (SELECT id FROM {geo_countries} WHERE iso3 = 'BRA'));
insert into {geo_states} (name, code, shortname, country_id) VALUES('São Paulo' ,35 ,'SP', (SELECT id FROM {geo_countries} WHERE iso3 = 'BRA'));
insert into {geo_states} (name, code, shortname, country_id) VALUES('Sergipe' ,28 ,'SE', (SELECT id FROM {geo_countries} WHERE iso3 = 'BRA'));
insert into {geo_states} (name, code, shortname, country_id) VALUES('Tocantins' ,17 ,'TO', (SELECT id FROM {geo_countries} WHERE iso3 = 'BRA'));
+36
View File
@@ -0,0 +1,36 @@
<?php
use Schema\Wrapper as Wrapper;
use App\Core\Sanity\MigratorController as Migrator;
function geo_state_upgrade($pluginversion) {
if ($pluginversion < "0.0.1") {
$table = Wrapper::get_table("geo_states");
$table->addColumn("country_id", "integer", Array("null" => false));
$table->addColumn("name", "string", Array("null" => false));
$table->addColumn("code", "integer", Array("null" => true));
$table->addColumn("shortname", "string", Array("null" => false, 'limit' => 5));
$table->addColumn("description", "string", Array("null" => true));
$table->addForeignKey('country_id', Wrapper::get_table('geo_countries'));
$table->create();
Wrapper::exec(file_get_contents(__DIR__.'/001_brazil_states_seeding.sql') );
Migrator::getInstance()->update_plugin_version("geo_state", "1.0.0");
return;
}
//if ($pluginversion < "0.0.2") {
//$table = Wrapper::get_table("geo_state");
//Migrator::getInstance()->update_plugin_version("geo_states", "1.0.1");
//return;
//}
}
function geo_state_rollback($pluginversion) {
if($pluginversion > "0.0.1"){
$table = Wrapper::get_table("geo_states");
$table->drop();
return;
}
}
+2
View File
@@ -0,0 +1,2 @@
<?php
$lang["state"]["module_name"] = "State";
+2
View File
@@ -0,0 +1,2 @@
<?php
$lang["state"]["module_name"] = "State";
+9
View File
@@ -0,0 +1,9 @@
<?php
$plugin->name = "geo_state";
$plugin->version = "1.0.0";
$plugin->require = Array(
Array("name" => "geo_params", "version" => "1.0.0"),
Array("name" => "geo_country", "version" => "1.0.0")
);
+10
View File
@@ -0,0 +1,10 @@
{{@ if( {{id}} ): @}}
<form method="POST" action="/state/{{id}}/edit">
<input type="hidden" name="id" value="{{id}}" />
<input type="hidden" name="_method" value="put" />
{{@ else: @}}
<form method="POST" action="/state">
<input type="hidden" name="id" value="" />
{{@ endif; @}}
</form>
+4
View File
@@ -0,0 +1,4 @@
<a href='/state/form' >Adicionar </a>
<div class="table-responsive">
</div>
+4
View File
@@ -0,0 +1,4 @@
<option id='0'>Selecione</option>
{{#states}}
<option id='{{id}}' value="{{id}}">{{shortname}}</option>
{{/states}}