add and implement contact(element)

This commit is contained in:
Dennis Eichhorn 2020-10-18 20:56:04 +02:00
parent ba7a4001ae
commit dbd083c9af
8 changed files with 402 additions and 91 deletions

View File

@ -89,26 +89,13 @@
}
},
"profile_contact_company_job": {
"name": "profile_contact_company_job",
"name": "profile_contact_job",
"type": "VARCHAR(255)",
"null": false,
"annotations": {
"gdpr": true
}
},
"profile_contact_address": {
"name": "profile_contact_address",
"type": "VARCHAR(255)",
"null": false,
"annotations": {
"gdpr": true
}
},
"profile_contact_website": {
"name": "profile_contact_website",
"type": "VARCHAR(255)",
"null": false
},
"profile_contact_birthday": {
"name": "profile_contact_birthday",
"type": "DATETIME",
@ -164,44 +151,89 @@
"type": "TINYINT",
"null": false
},
"profile_contact_element_order": {
"name": "profile_contact_element_order",
"type": "INT",
"null": false
},
"profile_contact_element_content": {
"name": "profile_contact_element_content",
"type": "VARCHAR(255)",
"null": false
},
"profile_contact_element_contact": {
"name": "profile_contact_element_contact",
"type": "INT",
"null": false,
"foreignTable": "profile_contact",
"foreignKey": "profile_contact_id"
}
}
},
"profile_contact_address": {
"name": "profile_contact_address",
"profile_contact_elementrel": {
"name": "profile_contact_elementrel",
"fields": {
"profile_contact_address_id": {
"name": "profile_contact_address_id",
"profile_contact_elementrel_id": {
"name": "profile_contact_elementrel_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
},
"profile_contact_address_type": {
"name": "profile_contact_address_type",
"type": "TINYINT",
"null": false
},
"profile_contact_address_contact": {
"name": "profile_contact_address_contact",
"profile_contact_elementrel_contact": {
"name": "profile_contact_elementrel_contact",
"type": "INT",
"null": false,
"foreignTable": "profile_contact",
"foreignKey": "profile_contact_id"
},
"profile_contact_address_address": {
"name": "profile_contact_address_address",
"profile_contact_elementrel_element": {
"name": "profile_contact_elementrel_element",
"type": "INT",
"null": false,
"foreignTable": "profile_contact_element",
"foreignKey": "profile_contact_element_id"
}
}
},
"profile_contactelementrel": {
"name": "profile_contactelementrel",
"fields": {
"profile_contactelementrel_id": {
"name": "profile_contactelementrel_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
},
"profile_contactelementrel_profile": {
"name": "profile_contactelementrel_profile",
"type": "INT",
"null": false,
"foreignTable": "profile_account",
"foreignKey": "profile_account_id"
},
"profile_contactelementrel_element": {
"name": "profile_contactelementrel_element",
"type": "INT",
"null": false,
"foreignTable": "profile_contact_element",
"foreignKey": "profile_contact_element_id"
}
}
},
"profile_contact_addressrel": {
"name": "profile_contact_addressrel",
"fields": {
"profile_contact_addressrel_id": {
"name": "profile_contact_addressrel_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
},
"profile_contact_addressrel_contact": {
"name": "profile_contact_addressrel_contact",
"type": "INT",
"null": false,
"foreignTable": "profile_contact",
"foreignKey": "profile_contact_id"
},
"profile_contact_addressrel_address": {
"name": "profile_contact_addressrel_address",
"type": "INT",
"null": false,
"foreignTable": "address",
@ -209,65 +241,25 @@
}
}
},
"profile_contactelement": {
"name": "profile_contactelement",
"comment": "email, phone etc for profiles",
"profile_addressrel": {
"name": "profile_addressrel",
"fields": {
"profile_contactelement_id": {
"name": "profile_contactelement_id",
"profile_addressrel_id": {
"name": "profile_addressrel_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
},
"profile_contactelement_type": {
"name": "profile_contactelement_type",
"type": "TINYINT",
"null": false
},
"profile_contactelement_subtype": {
"name": "profile_contactelement_subtype",
"type": "TINYINT",
"null": false
},
"profile_contactelement_content": {
"name": "profile_contactelement_content",
"type": "VARCHAR(255)",
"null": false
},
"profile_contactelement_contact": {
"name": "profile_contactelement_contact",
"type": "INT",
"null": false,
"foreignTable": "profile_account",
"foreignKey": "profile_account_id"
}
}
},
"profile_address": {
"name": "profile_address",
"fields": {
"profile_address_id": {
"name": "profile_address_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
},
"profile_address_type": {
"name": "profile_address_type",
"type": "TINYINT",
"null": false
},
"profile_address_profile": {
"name": "profile_address_profile",
"profile_addressrel_profile": {
"name": "profile_addressrel_profile",
"type": "INT",
"null": false,
"foreignTable": "profile_account",
"foreignKey": "profile_account_id"
},
"profile_address_address": {
"name": "profile_address_address",
"profile_addressrel_address": {
"name": "profile_addressrel_address",
"type": "INT",
"null": false,
"foreignTable": "address",

109
Models/Contact.php Normal file
View File

@ -0,0 +1,109 @@
<?php
/**
* Orange Management
*
* PHP Version 7.4
*
* @package Modules\Profile\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Profile\Models;
use Modules\Media\Models\Media;
use Modules\Media\Models\NullMedia;
/**
* Contact element class.
*
* @package Modules\Profile\Models
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
class Contact
{
protected int $id = 0;
protected string $name1 = '';
protected string $name2 = '';
protected string $name3 = '';
protected string $description = '';
protected string $company = '';
protected string $job = '';
protected ?\DateTime $birthday = null;
protected Media $image;
private int $profile = 0;
public function __construct()
{
$this->image = new NullMedia();
}
public function getId() : int
{
return $this->id;
}
public function getName1() : string
{
return $this->name1;
}
public function setName1(string $name) : void
{
$this->name1 = $name;
}
public function getName2() : string
{
return $this->name2;
}
public function setName2(string $name) : void
{
$this->name2 = $name;
}
public function getName3() : string
{
return $this->name3;
}
public function setName3(string $name) : void
{
$this->name3 = $name;
}
public function getDescription() : string
{
return $this->description;
}
public function setDescription(string $description) : void
{
$this->description = $description;
}
public function setImage(Media $image) : void
{
$this->image = $image;
}
public function getImage() : Media
{
return $this->image;
}
}

View File

@ -40,6 +40,14 @@ class ContactElement
*/
private int $type = 0;
/**
* Contact element subtype.
*
* @var int
* @since 1.0.0
*/
private int $subtype = 0;
/**
* Content.
*
@ -48,6 +56,14 @@ class ContactElement
*/
private string $content = '';
/**
* Order.
*
* @var string
* @since 1.0.0
*/
private int $order = 0;
/**
* Get id.
*
@ -86,6 +102,58 @@ class ContactElement
return $this->type;
}
/**
* Set order
*
* @param int $order Type
*
* @return void
*
* @since 1.0.0
*/
public function setOrder(int $order) : void
{
$this->order = $order;
}
/**
* Get order
*
* @return int
*
* @since 1.0.0
*/
public function getOrder() : int
{
return $this->order;
}
/**
* Set subtype
*
* @param int $subtype Subtype
*
* @return void
*
* @since 1.0.0
*/
public function setSubtype(int $subtype) : void
{
$this->subtype = $subtype;
}
/**
* Get subtype
*
* @return int
*
* @since 1.0.0
*/
public function getSubtype() : int
{
return $this->subtype;
}
/**
* Get content
*

View File

@ -33,7 +33,11 @@ final class ContactElementMapper extends DataMapperAbstract
* @since 1.0.0
*/
protected static array $columns = [
'profile_contactelement_id' => ['name' => 'profile_contactelement_id', 'type' => 'int', 'internal' => 'id'],
'profile_contact_element_id' => ['name' => 'profile_contact_element_id', 'type' => 'int', 'internal' => 'id'],
'profile_contact_element_type' => ['name' => 'profile_contact_element_type', 'type' => 'int', 'internal' => 'type'],
'profile_contact_element_subtype' => ['name' => 'profile_contact_element_subtype', 'type' => 'int', 'internal' => 'subtype'],
'profile_contact_element_order' => ['name' => 'profile_contact_element_order', 'type' => 'int', 'internal' => 'order'],
'profile_contact_element_content' => ['name' => 'profile_contact_element_content', 'type' => 'string', 'internal' => 'content'],
];
/**
@ -42,7 +46,7 @@ final class ContactElementMapper extends DataMapperAbstract
* @var string
* @since 1.0.0
*/
protected static string $table = 'profile_contactelement';
protected static string $table = 'profile_contact_element';
/**
* Primary field name.
@ -50,5 +54,5 @@ final class ContactElementMapper extends DataMapperAbstract
* @var string
* @since 1.0.0
*/
protected static string $primaryField = 'profile_contactelement_id';
protected static string $primaryField = 'profile_contact_element_id';
}

75
Models/ContactMapper.php Normal file
View File

@ -0,0 +1,75 @@
<?php
/**
* Orange Management
*
* PHP Version 7.4
*
* @package Modules\Profile\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Profile\Models;
use phpOMS\DataStorage\Database\DataMapperAbstract;
/**
* Contact mapper class.
*
* @package Modules\Profile\Models
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
final class ContactElementMapper extends DataMapperAbstract
{
/**
* Columns.
*
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
* @since 1.0.0
*/
protected static array $columns = [
'profile_contact_id' => ['name' => 'profile_contact_id', 'type' => 'int', 'internal' => 'id'],
'profile_contact_name1' => ['name' => 'profile_contact_name1', 'type' => 'string', 'internal' => 'name1'],
'profile_contact_name2' => ['name' => 'profile_contact_name2', 'type' => 'string', 'internal' => 'name2'],
'profile_contact_name3' => ['name' => 'profile_contact_name3', 'type' => 'string', 'internal' => 'name3'],
'profile_contact_description' => ['name' => 'profile_contact_description', 'type' => 'string', 'internal' => 'description'],
'profile_contact_company' => ['name' => 'profile_contact_company', 'type' => 'string', 'internal' => 'company'],
'profile_contact_job' => ['name' => 'profile_contact_job', 'type' => 'string', 'internal' => 'job'],
'profile_contact_birthday' => ['name' => 'profile_contact_birthday', 'type' => 'DateTime', 'internal' => 'birthday'],
'profile_contact_profile' => ['name' => 'profile_contact_profile', 'type' => 'int', 'internal' => 'profile'],
];
/**
* Has one relation.
*
* @var array<string, array{mapper:string, self:string, by?:string, column?:string}>
* @since 1.0.0
*/
protected static array $ownsOne = [
'image' => [
'mapper' => MediaMapper::class,
'self' => 'profile_contact_image',
],
];
/**
* Primary table.
*
* @var string
* @since 1.0.0
*/
protected static string $table = 'profile_contact';
/**
* Primary field name.
*
* @var string
* @since 1.0.0
*/
protected static string $primaryField = 'profile_contact_id';
}

36
Models/ContactType.php Normal file
View File

@ -0,0 +1,36 @@
<?php
/**
* Orange Management
*
* PHP Version 7.4
*
* @package Modules\Profile\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Profile\Models;
use phpOMS\Stdlib\Base\Enum;
/**
* Contact type enum.
*
* @package Modules\Profile\Models
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
abstract class ContactType extends Enum
{
public const PHONE = 1;
public const FAX = 2;
public const WEBSITE = 3;
public const EMAIL = 4;
}

27
Models/NullContact.php Normal file
View File

@ -0,0 +1,27 @@
<?php
/**
* Orange Management
*
* PHP Version 7.4
*
* @package Modules\Profile\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Profile\Models;
/**
* Contact element class.
*
* @package Modules\Profile\Models
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
final class NullContact extends Contact
{
}

View File

@ -70,15 +70,15 @@ final class ProfileMapper extends DataMapperAbstract
protected static array $hasMany = [
'location' => [
'mapper' => AddressMapper::class,
'table' => 'profile_address',
'external' => 'profile_address_address',
'self' => 'profile_address_profile',
'table' => 'profile_addressrel',
'external' => 'profile_addressrel_address',
'self' => 'profile_addressrel_profile',
],
'contactElements' => [
'mapper' => ContactElementMapper::class,
'table' => 'profile_contactelement',
'self' => null,
'external' => 'profile_contactelement_contact',
'table' => 'profile_contactelementrel',
'self' => 'profile_contactelementrel_element',
'external' => 'profile_contactelementrel_profile',
],
];