Add municipality (province / municipality / city) data and CAPI call #540
This commit is contained in:
parent
5d98216d21
commit
69fbfe196f
4 changed files with 143 additions and 0 deletions
|
|
@ -57,3 +57,8 @@ access_keys:
|
|||
acls:
|
||||
- id: customer.register
|
||||
label: Register Customer
|
||||
- id: municipality
|
||||
label: Municipality
|
||||
acls:
|
||||
- id: municipality.list
|
||||
label: List
|
||||
|
|
|
|||
|
|
@ -166,3 +166,9 @@ capi_cwarr_register:
|
|||
controller: App\Controller\CAPI\CustomerWarrantyController::register
|
||||
methods: [POST]
|
||||
|
||||
|
||||
# municipality
|
||||
capi_municipality_list:
|
||||
path: /capi/municipality
|
||||
controller: App\Controller\CAPI\MunicipalityController::getAll
|
||||
methods: [GET]
|
||||
|
|
|
|||
63
src/Controller/CAPI/MunicipalityController.php
Normal file
63
src/Controller/CAPI/MunicipalityController.php
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller\CAPI;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Catalyst\APIBundle\Controller\APIController;
|
||||
use Catalyst\APIBundle\Response\APIResponse;
|
||||
|
||||
use App\Entity\Municipality;
|
||||
|
||||
use Catalyst\APIBundle\Access\Generator as ACLGenerator;
|
||||
|
||||
class MunicipalityController extends APIController
|
||||
{
|
||||
protected $acl_gen;
|
||||
|
||||
public function __construct(ACLGenerator $acl_gen)
|
||||
{
|
||||
$this->acl_gen = $acl_gen;
|
||||
}
|
||||
|
||||
public function getAll(EntityManagerInterface $em)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('municipality.list', null, 'No access.');
|
||||
|
||||
$muns = $em->getRepository(Municipality::class)->findBy([], ['province_name' => 'ASC', 'name' => 'ASC']);
|
||||
|
||||
$result = [];
|
||||
$provinces = [];
|
||||
foreach ($muns as $m)
|
||||
{
|
||||
$pid = $m->getProvinceID();
|
||||
$pname = $m->getProvinceName();
|
||||
$mid = $m->getID();
|
||||
$mname = $m->getName();
|
||||
|
||||
if (!isset($provinces[$pid]))
|
||||
{
|
||||
$provinces[$pid] = [
|
||||
'id' => $pid,
|
||||
'name' => $pname,
|
||||
'municipalities' => [],
|
||||
];
|
||||
}
|
||||
|
||||
// error_log("$pid - $pname - $mid - $mname");
|
||||
|
||||
$provinces[$pid]['municipalities'][$mid] = [
|
||||
'id' => $mid,
|
||||
'name' => $mname,
|
||||
];
|
||||
}
|
||||
|
||||
$data = [
|
||||
'provinces' => $provinces,
|
||||
];
|
||||
|
||||
return new APIResponse(true, 'Municipalities loaded.', $data);
|
||||
}
|
||||
}
|
||||
69
src/Entity/Municipality.php
Normal file
69
src/Entity/Municipality.php
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="municipality")
|
||||
*/
|
||||
class Municipality
|
||||
{
|
||||
// unique id
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="string", length=11)
|
||||
*/
|
||||
protected $code;
|
||||
|
||||
// name
|
||||
/**
|
||||
* @ORM\Column(type="string", length=100)
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
// province id
|
||||
/**
|
||||
* @ORM\Column(type="string", length=11)
|
||||
*/
|
||||
protected $province_id;
|
||||
|
||||
// province name
|
||||
/**
|
||||
* @ORM\Column(type="string", length=100)
|
||||
*/
|
||||
protected $province_name;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function getID()
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getProvinceID()
|
||||
{
|
||||
return $this->province_id;
|
||||
}
|
||||
|
||||
public function getProvinceName()
|
||||
{
|
||||
return $this->province_name;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue