Adjust location

This commit is contained in:
Dennis Eichhorn 2017-05-10 21:17:44 +02:00
parent 3178cba734
commit 68d67893ba
4 changed files with 156 additions and 5 deletions

View File

@ -126,11 +126,11 @@ class Installer extends InstallerAbstract
'CREATE TABLE if NOT EXISTS `' . $dbPool->get('core')->prefix . 'profile_address` (
`profile_address_id` int(11) NOT NULL AUTO_INCREMENT,
`profile_address_type` tinyint(2) NOT NULL,
`profile_address_address` varchar(50) NOT NULL,
`profile_address_street` varchar(50) NOT NULL,
`profile_address_city` varchar(50) NOT NULL,
`profile_address_zip` varchar(50) NOT NULL,
`profile_address_country` varchar(50) NOT NULL,
`profile_address_address` varchar(255) NOT NULL,
`profile_address_street` varchar(255) NOT NULL,
`profile_address_city` varchar(255) NOT NULL,
`profile_address_zip` varchar(255) NOT NULL,
`profile_address_country` varchar(255) NOT NULL,
`profile_address_account` int(11) DEFAULT NULL,
PRIMARY KEY (`profile_address_id`),
KEY `profile_address_account` (`profile_address_account`)

124
Models/AddressMapper.php Normal file
View File

@ -0,0 +1,124 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
namespace Modules\Profile\Models;
use Modules\Media\Models\MediaMapper;
use phpOMS\DataStorage\Database\DataMapperAbstract;
use phpOMS\DataStorage\Database\Query\Builder;
use phpOMS\DataStorage\Database\Query\Column;
use phpOMS\DataStorage\Database\RelationType;
use phpOMS\Datatypes\Location;
class ProfileMapper extends DataMapperAbstract
{
/**
* Columns.
*
* @var array
* @since 1.0.0
*/
protected static $columns = [
'profile_address_id' => ['name' => 'profile_address_id', 'type' => 'int', 'internal' => 'id'],
'profile_address_type' => ['name' => 'profile_address_type', 'type' => 'int', 'internal' => 'type'],
'profile_address_address' => ['name' => 'profile_address_address', 'type' => 'string', 'internal' => 'address'],
'profile_address_street' => ['name' => 'profile_address_street', 'type' => 'string', 'internal' => 'street'],
'profile_address_city' => ['name' => 'profile_address_city', 'type' => 'string', 'internal' => 'city'],
'profile_address_zip' => ['name' => 'profile_address_zip', 'type' => 'string', 'internal' => 'postal'],
'profile_address_country' => ['name' => 'profile_address_country', 'type' => 'string', 'internal' => 'country'],
];
/**
* Primary table.
*
* @var string
* @since 1.0.0
*/
protected static $table = 'profile_address';
/**
* Primary field name.
*
* @var string
* @since 1.0.0
*/
protected static $primaryField = 'profile_address_id';
/**
* Create object.
*
* @param mixed $obj Object
* @param int $relations Behavior for relations creation
*
* @return mixed
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function create($obj, int $relations = RelationType::ALL)
{
try {
$objId = parent::create($obj, $relations);
if($objId === null || !is_scalar($objId)) {
return $objId;
}
$query = new Builder(self::$db);
$query->prefix(self::$db->getPrefix())
->insert(
'account_permission_account',
'account_permission_from',
'account_permission_for',
'account_permission_id1',
'account_permission_id2',
'account_permission_r',
'account_permission_w',
'account_permission_m',
'account_permission_d',
'account_permission_p'
)
->into('account_permission')
->values(1, 'account', 'account', 1, $objId, 1, 1, 1, 1, 1);
self::$db->con->prepare($query->toSql())->execute();
} catch (\Exception $e) {
var_dump($e->getMessage());
return false;
}
return $objId;
}
/**
* Get object.
*
* @param mixed $primaryKey Key
* @param int $relations Load relations
* @param mixed $fill Object to fill
*
* @return Account
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function get($primaryKey, int $relations = RelationType::ALL, $fill = null)
{
return parent::get((int) $primaryKey, $relations, $fill);
}
}

View File

@ -41,6 +41,8 @@ class Profile
private $account = null;
private $location = [];
public function __construct()
{
$this->image = new NullMedia();
@ -53,6 +55,16 @@ class Profile
return $this->id;
}
public function getLocation() : array
{
return $this->location;
}
public function addLocation(Location $location)
{
$this->location[] = $location;
}
public function getImage() : Media
{
return $this->image;

View File

@ -56,6 +56,21 @@ class ProfileMapper extends DataMapperAbstract
],
];
/**
* Has many relation.
*
* @var array
* @since 1.0.0
*/
protected static $hasMany = [
'location' => [
'mapper' => AddressMapper::class,
'table' => 'profile_address',
'dst' => 'profile_address_account',
'src' => null,
],
];
/**
* Primary table.
*