]> _ Git - cubedesigners_userdatabase.git/commitdiff
wip #3707 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 15 Jun 2020 16:46:46 +0000 (18:46 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 15 Jun 2020 16:46:46 +0000 (18:46 +0200)
.gitignore [new file with mode: 0644]
composer.json [new file with mode: 0644]
src/Address.php [new file with mode: 0644]
src/Company.php [new file with mode: 0644]
src/User.php [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..8925195
--- /dev/null
@@ -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 (file)
index 0000000..31a2514
--- /dev/null
@@ -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 (file)
index 0000000..37e0ea6
--- /dev/null
@@ -0,0 +1,29 @@
+<?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']);
+    }
+}
diff --git a/src/Company.php b/src/Company.php
new file mode 100644 (file)
index 0000000..c44c6bd
--- /dev/null
@@ -0,0 +1,70 @@
+<?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']);
+    }
+}
diff --git a/src/User.php b/src/User.php
new file mode 100644 (file)
index 0000000..dd22cab
--- /dev/null
@@ -0,0 +1,86 @@
+<?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];
+    }
+}