--- /dev/null
+.idea
+vendor
+composer.lock
\ No newline at end of file
--- /dev/null
+{
+ "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"
+ }
+}
--- /dev/null
+<?php
+
+
+namespace Cubedesigners\Userdatabase;
+
+use Cubist\Backpack\app\Magic\SubForm;
+
+class Address extends SubForm
+{
+ public function init()
+ {
+ parent::init();
+ $this->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']);
+ }
+}
--- /dev/null
+<?php
+
+namespace Cubedesigners\Userdatabase;
+
+use Cubist\Backpack\app\Magic\Models\CubistMagicAbstractModel;
+
+class Company extends CubistMagicAbstractModel
+{
+
+ protected $table = 'extranet_users.company';
+ protected $_options = ['name' => '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']);
+ }
+}
--- /dev/null
+<?php
+
+namespace Cubedesigners\Userdatabase;
+
+use Cubist\Backpack\app\Magic\Models\CubistMagicAuthenticatable;
+
+class User extends CubistMagicAuthenticatable
+{
+ protected $_permissionsDatabase = 'extranet_users';
+ protected $table = 'extranet_users.user';
+ protected $_options = ['name' => '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];
+ }
+}