Profile mapper/test implemented

This commit is contained in:
Dennis Eichhorn 2017-03-08 22:04:54 +01:00
parent 65056dd12d
commit a9aedcac02
4 changed files with 101 additions and 52 deletions

View File

@ -48,18 +48,19 @@ class Installer extends InstallerAbstract
'CREATE TABLE if NOT EXISTS `' . $dbPool->get('core')->prefix . 'profile_account` (
`profile_account_id` int(11) NOT NULL,
`profile_account_begin` datetime NOT NULL,
`profile_account_image` varchar(255) NOT NULL,
`profile_account_birthday` varchar(255) NOT NULL,
`profile_account_cv` text NOT NULL,
`profile_account_image` int(11) NOT NULL,
`profile_account_birthday` datetime NOT NULL,
`profile_account_account` int(11) DEFAULT NULL,
PRIMARY KEY (`profile_account_id`),
KEY `profile_account_image` (`profile_account_image`),
KEY `profile_account_account` (`profile_account_account`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;'
)->execute();
$dbPool->get('core')->con->prepare(
'ALTER TABLE `' . $dbPool->get('core')->prefix . 'profile_account`
ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'profile_account_ibfk_1` FOREIGN KEY (`profile_account_account`) REFERENCES `' . $dbPool->get('core')->prefix . 'account` (`account_id`);'
ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'profile_account_ibfk_1` FOREIGN KEY (`profile_account_image`) REFERENCES `' . $dbPool->get('core')->prefix . 'media` (`media_id`),
ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'profile_account_ibfk_2` FOREIGN KEY (`profile_account_account`) REFERENCES `' . $dbPool->get('core')->prefix . 'account` (`account_id`);'
)->execute();
// real contacts that you also save in your email contact list. this is to store other accounts
@ -73,7 +74,7 @@ class Installer extends InstallerAbstract
`profile_contact_company_job` varchar(250) NOT NULL,
`profile_contact_address` varchar(250) NOT NULL,
`profile_contact_website` varchar(250) NOT NULL,
`profile_contact_birthday` varchar(11) NOT NULL,
`profile_contact_birthday` datetime NOT NULL,
`profile_contact_description` text NOT NULL,
`profile_contact_account` int(11) NOT NULL,
PRIMARY KEY (`profile_contact_id`),

View File

@ -1,38 +0,0 @@
<?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\Admin\Models\Account as AdminAccount;
/**
* Account class.
*
* @category Modules
* @package Modules\Admin
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class Account extends AdminAccount
{
public function __construct(int $id = 0)
{
parent::__construct($id);
}
}

74
Models/Profile.php Normal file
View File

@ -0,0 +1,74 @@
<?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\Admin\Models\Account;
use Modules\Media\Models\NullMedia;
/**
* Account class.
*
* @category Modules
* @package Modules\Admin
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class Profile
{
private $id = 0;
private $image = null;
private $birthday = null;
private $account = null;
public function __construct()
{
$this->image = new NullMedia();
$this->birthday = new \DateTime();
$this->account = new Account();
}
public function getId() : int
{
return $this->id;
}
public function getImage() : Media
{
return $this->image;
}
public function setImage(Media $image) /* : void */
{
$this->image = $image;
}
public function setAccount(Account $account) /* : void */
{
$this->account = $account;
}
public function getAccount() : Account
{
return $this->account;
}
}

View File

@ -21,8 +21,9 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
use phpOMS\DataStorage\Database\Query\Builder;
use phpOMS\DataStorage\Database\Query\Column;
use phpOMS\DataStorage\Database\RelationType;
use Modules\Admin\Account;
class AccountMapper extends DataMapperAbstract
class ProfileMapper extends DataMapperAbstract
{
/**
* Columns.
@ -32,6 +33,25 @@ class AccountMapper extends DataMapperAbstract
*/
protected static $columns = [
'profile_account_id' => ['name' => 'profile_account_id', 'type' => 'int', 'internal' => 'id'],
'profile_account_image' => ['name' => 'profile_account_image', 'type' => 'int', 'internal' => 'image'],
'profile_account_birthday' => ['name' => 'profile_account_birthday', 'type' => '\DateTime', 'internal' => 'birthday'],
];
/**
* Has one relation.
*
* @var array
* @since 1.0.0
*/
protected static $ownsOne = [
'profile' => [
'mapper' => AccountMapper::class,
'src' => 'profile_account_account',
],
'image' => [
'mapper' => MediaMapper::class,
'src' => 'profile_account_image',
],
];
/**
@ -50,14 +70,6 @@ class AccountMapper extends DataMapperAbstract
*/
protected static $primaryField = 'profile_id';
/**
* Created at column
*
* @var string
* @since 1.0.0
*/
protected static $createdAt = 'profile_created_at';
/**
* Create object.
*