From a9aedcac02e104091f2eb808ae47d0636576d9ce Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 8 Mar 2017 22:04:54 +0100 Subject: [PATCH] Profile mapper/test implemented --- Admin/Installer.php | 11 +-- Models/Account.php | 38 ---------- Models/Profile.php | 74 +++++++++++++++++++ .../{AccountMapper.php => ProfileMapper.php} | 30 +++++--- 4 files changed, 101 insertions(+), 52 deletions(-) delete mode 100644 Models/Account.php create mode 100644 Models/Profile.php rename Models/{AccountMapper.php => ProfileMapper.php} (80%) diff --git a/Admin/Installer.php b/Admin/Installer.php index 2b55702..35fd3b6 100644 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -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`), diff --git a/Models/Account.php b/Models/Account.php deleted file mode 100644 index 6dadf89..0000000 --- a/Models/Account.php +++ /dev/null @@ -1,38 +0,0 @@ - - * @author Dennis Eichhorn - * @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 - * @author Dennis Eichhorn - * @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); - } -} diff --git a/Models/Profile.php b/Models/Profile.php new file mode 100644 index 0000000..816fd86 --- /dev/null +++ b/Models/Profile.php @@ -0,0 +1,74 @@ + + * @author Dennis Eichhorn + * @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 + * @author Dennis Eichhorn + * @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; + } +} diff --git a/Models/AccountMapper.php b/Models/ProfileMapper.php similarity index 80% rename from Models/AccountMapper.php rename to Models/ProfileMapper.php index 5b42e97..162d60b 100644 --- a/Models/AccountMapper.php +++ b/Models/ProfileMapper.php @@ -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. *