From: Vincent Vanwaelscappel Date: Mon, 15 Jun 2020 16:46:46 +0000 (+0200) Subject: wip #3707 @0.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=468c525948e4db3edacd1ac6048d0b98c7949136;p=cubedesigners_userdatabase.git wip #3707 @0.5 --- 468c525948e4db3edacd1ac6048d0b98c7949136 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8925195 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea +vendor +composer.lock \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..31a2514 --- /dev/null +++ b/composer.json @@ -0,0 +1,31 @@ +{ + "name": "cubedesigners/userdatabase", + "description": "Cubedesigners common users database", + "type": "library", + "license": "proprietary", + "minimum-stability": "dev", + "prefer-stable": true, + "repositories": [ + { + "type": "composer", + "url": "https://composer.cubedesigners.com/" + } + ], + "autoload": { + "psr-0": { + "Cubedesigners\\Userdatabase\\": "src" + }, + "files": [ + "src/app/helpers.php" + ] + }, + "authors": [ + { + "name": "Vincent Vanwaelscappel", + "email": "vincent@cubedesigners.com" + } + ], + "require": { + "cubist/cms-back": "dev-master" + } +} diff --git a/src/Address.php b/src/Address.php new file mode 100644 index 0000000..37e0ea6 --- /dev/null +++ b/src/Address.php @@ -0,0 +1,29 @@ +addField(['name' => 'address', + 'label' => 'Address', + 'type' => 'Textarea']); + + $this->addField(['name' => 'postcode', + 'label' => 'Postcode', + 'type' => 'Postcode']); + + $this->addField(['name' => 'city', + 'label' => 'City', + 'type' => 'Text']); + + $this->addField(['name' => 'country', + 'label' => 'Country', + 'type' => 'Country']); + } +} diff --git a/src/Company.php b/src/Company.php new file mode 100644 index 0000000..c44c6bd --- /dev/null +++ b/src/Company.php @@ -0,0 +1,70 @@ + 'company', + 'singular' => 'company', + 'plural' => 'companies']; + + public function setFields() + { + parent::setFields(); + + $this->addField(['name' => 'name', + 'label' => 'Company name', + 'type' => 'Text', + 'column' => true, + 'tab' => 'Details']); + + $this->addField(['name' => 'address', + 'type' => 'BunchOfFields', + 'bunch' => Address::class, + 'label' => 'Address', + 'tab' => 'Addresses']); + + $this->addField(['name' => 'billing_address', + 'type' => 'BunchOfFields', + 'bunch' => Address::class, + 'label' => 'Billing address', + 'tab' => 'Addresses']); + + $this->addField(['name' => 'vat_number', + 'type' => 'VATNumber', + 'label' => 'VAT number', + 'tab' => 'Details']); + + $this->addField(['name' => 'type', + 'type' => 'SelectFromArray', + 'label' => 'Type', + 'options' => [ + 0 => 'Undefined', + 1 => 'Very small company', + 2 => 'Startup', + 3 => 'Small / medium company', + 4 => 'Agency', + 5 => 'Big company', + 6 => 'Government / Public institution' + ], + 'tab' => 'Details' + ] + ); + + $this->addField(['name' => 'admin', + 'type' => 'SelectFromModel', + 'optionsmodel' => User::class, + 'attribute' => 'nameWithCompany', + 'label' => 'Administrator', + 'tab' => 'Details']); + + $this->addField(['name' => 'website', + 'type' => 'URL', + 'label' => 'Website', + 'tab' => 'Details']); + } +} diff --git a/src/User.php b/src/User.php new file mode 100644 index 0000000..dd22cab --- /dev/null +++ b/src/User.php @@ -0,0 +1,86 @@ + 'users', + 'singular' => 'user', + 'plural' => 'users']; + + protected static $_companyNames = null; + + public function setFields() + { + parent::setFields(); + + $this->addField(['name' => 'firstname', + 'label' => 'Firstname', + 'type' => 'Text', + 'column' => true, + 'tab' => 'Contact']); + + $this->addField(['name' => 'lastname', + 'label' => 'Lastname', + 'type' => 'Text', + 'column' => true, + 'tab' => 'Contact']); + + $this->addField(['name' => 'company', + 'label' => 'Company', + 'type' => 'SelectFromModel', + 'optionsmodel' => Company::class, + 'tab' => 'Contact' + ]); + + $this->addField(['name' => 'address', + 'type' => 'BunchOfFields', + 'bunch' => Address::class, + 'label' => 'Address', + 'tab' => 'Contact']); + + $this->addField(['name' => 'phone', + 'label' => 'Phone', + 'type' => 'Phone', + 'tab' => 'Contact']); + + $this->addField(['name' => 'mobile', + 'label' => 'Mobile', + 'type' => 'Phone', + 'tab' => 'Contact']); + + $this->addField(['name' => 'locale', + 'label' => 'Locale', + 'type' => 'Locale', + 'tab' => 'Settings']); + } + + public function getNameWithCompanyAttribute() + { + $name = trim($this->firstname . ' ' . $this->lastname); + if ($name === '') { + return $this->companyName; + } + return $name . ' (' . $this->companyName . ')'; + } + + public function getCompanyNameAttribute() + { + return self::_getCompanyNames($this->company); + } + + protected static function _getCompanyNames($id = null) + { + if (null === self::$_companyNames) { + self::$_companyNames = Company::all()->pluck('name', 'id')->toArray(); + } + if (null === $id) { + return self::$_companyNames; + } + return self::$_companyNames[$id]; + } +}