From 68d67893ba55ac88709bf297021cba9c5ec806ce Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 10 May 2017 21:17:44 +0200 Subject: [PATCH] Adjust location --- Admin/Installer.php | 10 ++-- Models/AddressMapper.php | 124 +++++++++++++++++++++++++++++++++++++++ Models/Profile.php | 12 ++++ Models/ProfileMapper.php | 15 +++++ 4 files changed, 156 insertions(+), 5 deletions(-) create mode 100644 Models/AddressMapper.php diff --git a/Admin/Installer.php b/Admin/Installer.php index 0d3c5e6..20b32f1 100644 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -126,11 +126,11 @@ class Installer extends InstallerAbstract 'CREATE TABLE if NOT EXISTS `' . $dbPool->get('core')->prefix . 'profile_address` ( `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, - `profile_address_city` varchar(50) NOT NULL, - `profile_address_zip` varchar(50) NOT NULL, - `profile_address_country` varchar(50) NOT NULL, + `profile_address_address` varchar(255) NOT NULL, + `profile_address_street` varchar(255) NOT NULL, + `profile_address_city` varchar(255) NOT NULL, + `profile_address_zip` varchar(255) NOT NULL, + `profile_address_country` varchar(255) NOT NULL, `profile_address_account` int(11) DEFAULT NULL, PRIMARY KEY (`profile_address_id`), KEY `profile_address_account` (`profile_address_account`) diff --git a/Models/AddressMapper.php b/Models/AddressMapper.php new file mode 100644 index 0000000..a4f98d6 --- /dev/null +++ b/Models/AddressMapper.php @@ -0,0 +1,124 @@ + + * @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; +use phpOMS\Datatypes\Location; + +class ProfileMapper extends DataMapperAbstract +{ + /** + * Columns. + * + * @var array + * @since 1.0.0 + */ + protected static $columns = [ + 'profile_address_id' => ['name' => 'profile_address_id', 'type' => 'int', 'internal' => 'id'], + 'profile_address_type' => ['name' => 'profile_address_type', 'type' => 'int', 'internal' => 'type'], + 'profile_address_address' => ['name' => 'profile_address_address', 'type' => 'string', 'internal' => 'address'], + 'profile_address_street' => ['name' => 'profile_address_street', 'type' => 'string', 'internal' => 'street'], + 'profile_address_city' => ['name' => 'profile_address_city', 'type' => 'string', 'internal' => 'city'], + 'profile_address_zip' => ['name' => 'profile_address_zip', 'type' => 'string', 'internal' => 'postal'], + 'profile_address_country' => ['name' => 'profile_address_country', 'type' => 'string', 'internal' => 'country'], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + protected static $table = 'profile_address'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + protected static $primaryField = 'profile_address_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); + + if($objId === null || !is_scalar($objId)) { + return $objId; + } + + $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/Profile.php b/Models/Profile.php index 3dbd7b4..c6235ba 100644 --- a/Models/Profile.php +++ b/Models/Profile.php @@ -41,6 +41,8 @@ class Profile private $account = null; + private $location = []; + public function __construct() { $this->image = new NullMedia(); @@ -53,6 +55,16 @@ class Profile return $this->id; } + public function getLocation() : array + { + return $this->location; + } + + public function addLocation(Location $location) + { + $this->location[] = $location; + } + public function getImage() : Media { return $this->image; diff --git a/Models/ProfileMapper.php b/Models/ProfileMapper.php index 4d041e9..03e8c9e 100644 --- a/Models/ProfileMapper.php +++ b/Models/ProfileMapper.php @@ -56,6 +56,21 @@ class ProfileMapper extends DataMapperAbstract ], ]; + /** + * Has many relation. + * + * @var array + * @since 1.0.0 + */ + protected static $hasMany = [ + 'location' => [ + 'mapper' => AddressMapper::class, + 'table' => 'profile_address', + 'dst' => 'profile_address_account', + 'src' => null, + ], + ]; + /** * Primary table. *