Database adjustments for client & item

This commit is contained in:
Dennis Eichhorn 2017-03-07 21:13:10 +01:00
parent 886c3d01b2
commit 65056dd12d
4 changed files with 374 additions and 9 deletions

View File

@ -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(

View File

@ -0,0 +1,120 @@
<?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\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 <d.eichhorn@oms.com>
*/
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 <d.eichhorn@oms.com>
*/
public static function get($primaryKey, int $relations = RelationType::ALL, $fill = null)
{
return parent::get((int) $primaryKey, $relations, $fill);
}
}

90
Models/ContactElement.php Normal file
View File

@ -0,0 +1,90 @@
<?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;
/**
* 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 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;
}
}

View File

@ -0,0 +1,111 @@
<?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 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 <d.eichhorn@oms.com>
*/
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 <d.eichhorn@oms.com>
*/
public static function get($primaryKey, int $relations = RelationType::ALL, $fill = null)
{
return parent::get((int) $primaryKey, $relations, $fill);
}
}