diff --git a/Admin/Installer.php b/Admin/Installer.php index 35fd3b6..e92cb11 100644 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -46,11 +46,10 @@ class Installer extends InstallerAbstract case DatabaseType::MYSQL: $dbPool->get('core')->con->prepare( '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` int(11) NOT NULL, - `profile_account_birthday` datetime NOT NULL, - `profile_account_account` int(11) DEFAULT NULL, + `profile_account_id` int(11) NOT NULL AUTO_INCREMENT, + `profile_account_image` int(11) DEFAULT NULL, + `profile_account_birthday` datetime DEFAULT NULL, + `profile_account_account` int(11) NOT NULL, PRIMARY KEY (`profile_account_id`), KEY `profile_account_image` (`profile_account_image`), KEY `profile_account_account` (`profile_account_account`) @@ -66,7 +65,7 @@ class Installer extends InstallerAbstract // real contacts that you also save in your email contact list. this is to store other accounts $dbPool->get('core')->con->prepare( 'CREATE TABLE if NOT EXISTS `' . $dbPool->get('core')->prefix . 'profile_contact` ( - `profile_contact_id` int(11) NOT NULL, + `profile_contact_id` int(11) NOT NULL AUTO_INCREMENT, `profile_contact_name1` varchar(250) NOT NULL, `profile_contact_name2` varchar(250) NOT NULL, `profile_contact_name3` varchar(250) NOT NULL, @@ -87,27 +86,28 @@ class Installer extends InstallerAbstract ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'profile_contact_ibfk_1` FOREIGN KEY (`profile_contact_account`) REFERENCES `' . $dbPool->get('core')->prefix . 'profile_account` (`profile_account_id`);' )->execute(); + // email, phone etc for profile_contact $dbPool->get('core')->con->prepare( 'CREATE TABLE if NOT EXISTS `' . $dbPool->get('core')->prefix . 'profile_contact_element` ( - `profile_contact_element_id` int(11) NOT NULL, + `profile_contact_element_id` int(11) NOT NULL AUTO_INCREMENT, `profile_contact_element_type` tinyint(2) NOT NULL, `profile_contact_element_subtype` tinyint(2) NOT NULL, `profile_contact_element_content` varchar(50) NOT NULL, `profile_contact_element_contact` int(11) NOT NULL, PRIMARY KEY (`profile_contact_element_id`), - KEY `profile_contact_element_account` (`profile_contact_element_account`) + KEY `profile_contact_element_contact` (`profile_contact_element_contact`) )ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' )->execute(); $dbPool->get('core')->con->prepare( 'ALTER TABLE `' . $dbPool->get('core')->prefix . 'profile_contact_element` - ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'profile_contact_element_ibfk_1` FOREIGN KEY (`profile_contact_element_account`) REFERENCES `' . $dbPool->get('core')->prefix . 'profile_contact` (`profile_contact_id`);' + ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'profile_contact_element_ibfk_1` FOREIGN KEY (`profile_contact_element_contact`) REFERENCES `' . $dbPool->get('core')->prefix . 'profile_contact` (`profile_contact_id`);' )->execute(); - // not a full contact only the element like email, phone etc. for the accounts themselves + // not a full contact only the element like email, phone etc. for the accounts themselves (not profile_account) $dbPool->get('core')->con->prepare( 'CREATE TABLE if NOT EXISTS `' . $dbPool->get('core')->prefix . 'profile_contactelement` ( - `profile_contactelement_id` int(11) NOT NULL, + `profile_contactelement_id` int(11) NOT NULL AUTO_INCREMENT, `profile_contactelement_type` tinyint(2) NOT NULL, `profile_contactelement_subtype` tinyint(2) NOT NULL, `profile_contactelement_content` varchar(50) NOT NULL, @@ -124,7 +124,7 @@ class Installer extends InstallerAbstract $dbPool->get('core')->con->prepare( 'CREATE TABLE if NOT EXISTS `' . $dbPool->get('core')->prefix . 'profile_address` ( - `profile_address_id` int(11) NOT NULL, + `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, @@ -139,12 +139,12 @@ class Installer extends InstallerAbstract $dbPool->get('core')->con->prepare( 'ALTER TABLE `' . $dbPool->get('core')->prefix . 'profile_address` - ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'profile_address_ibfk_1` FOREIGN KEY (`profile_address_account`) REFERENCES `' . $dbPool->get('core')->prefix . 'account` (`account_id`);' + ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'profile_address_ibfk_1` FOREIGN KEY (`profile_address_account`) REFERENCES `' . $dbPool->get('core')->prefix . 'profile_account` (`profile_account_id`);' )->execute(); $dbPool->get('core')->con->prepare( 'CREATE TABLE if NOT EXISTS `' . $dbPool->get('core')->prefix . 'profile_account_relation` ( - `profile_account_relation_id` int(11) NOT NULL, + `profile_account_relation_id` int(11) NOT NULL AUTO_INCREMENT, `profile_account_relation_type` tinyint(2) NOT NULL, `profile_account_relation_relation` int(11) DEFAULT NULL, `profile_account_relation_account` int(11) DEFAULT NULL, @@ -160,7 +160,7 @@ class Installer extends InstallerAbstract $dbPool->get('core')->con->prepare( 'CREATE TABLE if NOT EXISTS `' . $dbPool->get('core')->prefix . 'profile_account_setting` ( - `profile_account_setting_id` int(11) NOT NULL, + `profile_account_setting_id` int(11) NOT NULL AUTO_INCREMENT, `profile_account_setting_module` int(11) NOT NULL, `profile_account_setting_type` varchar(20) NOT NULL, `profile_account_setting_value` varchar(32) DEFAULT NULL, diff --git a/Models/ContactElementMapper.php b/Models/ContactElementMapper.php index 7d2e2a2..3d19411 100644 --- a/Models/ContactElementMapper.php +++ b/Models/ContactElementMapper.php @@ -64,6 +64,11 @@ class ContactElementMapper extends DataMapperAbstract { try { $objId = parent::create($obj, $relations); + + if($objId === null || !is_scalar($objId)) { + return $objId; + } + $query = new Builder(self::$db); $query->prefix(self::$db->getPrefix()) diff --git a/Models/Profile.php b/Models/Profile.php index 816fd86..3dbd7b4 100644 --- a/Models/Profile.php +++ b/Models/Profile.php @@ -17,6 +17,7 @@ declare(strict_types=1); namespace Modules\Profile\Models; use Modules\Admin\Models\Account; +use Modules\Media\Models\Media; use Modules\Media\Models\NullMedia; /** @@ -43,7 +44,7 @@ class Profile public function __construct() { $this->image = new NullMedia(); - $this->birthday = new \DateTime(); + $this->birthday = new \DateTime('now'); $this->account = new Account(); } @@ -71,4 +72,14 @@ class Profile { return $this->account; } + + public function setBirthday(\DateTime $birthday) /* : void */ + { + $this->birthday = $birthday; + } + + public function getBirthday() : \DateTime + { + return $this->birthday; + } } diff --git a/Models/ProfileMapper.php b/Models/ProfileMapper.php index 162d60b..4d041e9 100644 --- a/Models/ProfileMapper.php +++ b/Models/ProfileMapper.php @@ -21,7 +21,8 @@ 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; +use Modules\Admin\Models\Account; +use Modules\Admin\Models\AccountMapper; class ProfileMapper extends DataMapperAbstract { @@ -34,7 +35,8 @@ class ProfileMapper 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'], + 'profile_account_birthday' => ['name' => 'profile_account_birthday', 'type' => 'DateTime', 'internal' => 'birthday'], + 'profile_account_account' => ['name' => 'profile_account_account', 'type' => 'int', 'internal' => 'account'], ]; /** @@ -44,7 +46,7 @@ class ProfileMapper extends DataMapperAbstract * @since 1.0.0 */ protected static $ownsOne = [ - 'profile' => [ + 'account' => [ 'mapper' => AccountMapper::class, 'src' => 'profile_account_account', ], @@ -60,7 +62,7 @@ class ProfileMapper extends DataMapperAbstract * @var string * @since 1.0.0 */ - protected static $table = 'profile'; + protected static $table = 'profile_account'; /** * Primary field name. @@ -68,7 +70,7 @@ class ProfileMapper extends DataMapperAbstract * @var string * @since 1.0.0 */ - protected static $primaryField = 'profile_id'; + protected static $primaryField = 'profile_account_id'; /** * Create object. @@ -85,6 +87,11 @@ class ProfileMapper extends DataMapperAbstract { try { $objId = parent::create($obj, $relations); + + if($objId === null || !is_scalar($objId)) { + return $objId; + } + $query = new Builder(self::$db); $query->prefix(self::$db->getPrefix()) diff --git a/info.json b/info.json index a750235..41347e0 100644 --- a/info.json +++ b/info.json @@ -17,7 +17,8 @@ "description": "The profile module.", "directory": "Profile", "dependencies": { - "Admin" : "1.0.0" + "Admin" : "1.0.0", + "Media" : "1.0.0" }, "providing": { "Navigation": "*"