From 65056dd12dce34e3f6a45cdd7e3228290819cbda Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 7 Mar 2017 21:13:10 +0100 Subject: [PATCH] Database adjustments for client & item --- Admin/Installer.php | 62 ++++++++++++++--- Models/AccountMapper.php | 120 ++++++++++++++++++++++++++++++++ Models/ContactElement.php | 90 ++++++++++++++++++++++++ Models/ContactElementMapper.php | 111 +++++++++++++++++++++++++++++ 4 files changed, 374 insertions(+), 9 deletions(-) create mode 100644 Models/ContactElement.php create mode 100644 Models/ContactElementMapper.php diff --git a/Admin/Installer.php b/Admin/Installer.php index 36f1326..2b55702 100644 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -49,6 +49,7 @@ class Installer extends InstallerAbstract `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_account` int(11) DEFAULT NULL, PRIMARY KEY (`profile_account_id`), @@ -61,20 +62,63 @@ class Installer extends InstallerAbstract ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'profile_account_ibfk_1` 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 $dbPool->get('core')->con->prepare( - 'CREATE TABLE if NOT EXISTS `' . $dbPool->get('core')->prefix . 'profile_phone` ( - `profile_phone_id` int(11) NOT NULL, - `profile_phone_type` tinyint(2) NOT NULL, - `profile_phone_number` varchar(50) NOT NULL, - `profile_phone_account` int(11) NOT NULL, - PRIMARY KEY (`profile_phone_id`), - KEY `profile_phone_account` (`profile_phone_account`) + 'CREATE TABLE if NOT EXISTS `' . $dbPool->get('core')->prefix . 'profile_contact` ( + `profile_contact_id` int(11) NOT NULL, + `profile_contact_name1` varchar(250) NOT NULL, + `profile_contact_name2` varchar(250) NOT NULL, + `profile_contact_name3` varchar(250) NOT NULL, + `profile_contact_company` varchar(250) NOT NULL, + `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_description` text NOT NULL, + `profile_contact_account` int(11) NOT NULL, + PRIMARY KEY (`profile_contact_id`), + KEY `profile_contact_account` (`profile_contact_account`) )ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' )->execute(); $dbPool->get('core')->con->prepare( - 'ALTER TABLE `' . $dbPool->get('core')->prefix . 'profile_phone` - ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'profile_phone_ibfk_1` FOREIGN KEY (`profile_phone_account`) REFERENCES `' . $dbPool->get('core')->prefix . 'account` (`account_id`);' + 'ALTER TABLE `' . $dbPool->get('core')->prefix . 'profile_contact` + 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(); + + $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_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`) + )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`);' + )->execute(); + + // not a full contact only the element like email, phone etc. for the accounts themselves + $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_type` tinyint(2) NOT NULL, + `profile_contactelement_subtype` tinyint(2) NOT NULL, + `profile_contactelement_content` varchar(50) NOT NULL, + `profile_contactelement_account` int(11) NOT NULL, + PRIMARY KEY (`profile_contactelement_id`), + KEY `profile_contactelement_account` (`profile_contactelement_account`) + )ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' + )->execute(); + + $dbPool->get('core')->con->prepare( + 'ALTER TABLE `' . $dbPool->get('core')->prefix . 'profile_contactelement` + ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'profile_contactelement_ibfk_1` FOREIGN KEY (`profile_contactelement_account`) REFERENCES `' . $dbPool->get('core')->prefix . 'account` (`account_id`);' )->execute(); $dbPool->get('core')->con->prepare( diff --git a/Models/AccountMapper.php b/Models/AccountMapper.php index e69de29..5b42e97 100644 --- a/Models/AccountMapper.php +++ b/Models/AccountMapper.php @@ -0,0 +1,120 @@ + + * @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\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; + +class AccountMapper extends DataMapperAbstract +{ + /** + * Columns. + * + * @var array + * @since 1.0.0 + */ + protected static $columns = [ + 'profile_account_id' => ['name' => 'profile_account_id', 'type' => 'int', 'internal' => 'id'], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + protected static $table = 'profile'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + protected static $primaryField = 'profile_id'; + + /** + * Created at column + * + * @var string + * @since 1.0.0 + */ + protected static $createdAt = 'profile_created_at'; + + /** + * Create object. + * + * @param mixed $obj Object + * @param int $relations Behavior for relations creation + * + * @return mixed + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function create($obj, int $relations = RelationType::ALL) + { + try { + $objId = parent::create($obj, $relations); + $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 + */ + public static function get($primaryKey, int $relations = RelationType::ALL, $fill = null) + { + return parent::get((int) $primaryKey, $relations, $fill); + } +} diff --git a/Models/ContactElement.php b/Models/ContactElement.php new file mode 100644 index 0000000..301012f --- /dev/null +++ b/Models/ContactElement.php @@ -0,0 +1,90 @@ + + * @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; + +/** + * 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 ContactElement +{ + private $id = 0; + + private $type = 0; + + private $subtype = 0; + + private $value = ''; + + private $description = ''; + + public function __construct() + { + } + + public function getId() : int + { + return $this->id; + } + + public function setType(int $type) /* : void */ + { + $this->type = $type; + } + + public function getType() : int + { + return $this->type; + } + + public function setSubtype(int $type) /* : void */ + { + $this->subtype = $type; + } + + public function getSubtype() : int + { + return $this->subtype; + } + + public function getValue() : string + { + return $this->value; + } + + public function setValue(string $value) /* : void */ + { + $this->value = $value; + } + + public function getDescription() : string + { + return $this->description; + } + + public function setDescription(string $description) /* : void */ + { + $this->description = $description; + } +} diff --git a/Models/ContactElementMapper.php b/Models/ContactElementMapper.php new file mode 100644 index 0000000..7d2e2a2 --- /dev/null +++ b/Models/ContactElementMapper.php @@ -0,0 +1,111 @@ + + * @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 phpOMS\DataStorage\Database\DataMapperAbstract; +use phpOMS\DataStorage\Database\Query\Builder; +use phpOMS\DataStorage\Database\Query\Column; +use phpOMS\DataStorage\Database\RelationType; + +class ContactElementMapper extends DataMapperAbstract +{ + /** + * Columns. + * + * @var array + * @since 1.0.0 + */ + protected static $columns = [ + 'profile_contact_id' => ['name' => 'profile_contact_id', 'type' => 'int', 'internal' => 'id'], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + protected static $table = 'profile_contact'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + protected static $primaryField = 'profile_contact_id'; + + /** + * Create object. + * + * @param mixed $obj Object + * @param int $relations Behavior for relations creation + * + * @return mixed + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function create($obj, int $relations = RelationType::ALL) + { + try { + $objId = parent::create($obj, $relations); + $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 + */ + public static function get($primaryKey, int $relations = RelationType::ALL, $fill = null) + { + return parent::get((int) $primaryKey, $relations, $fill); + } +}