Roberto Santini 3 anos atrás
pai
commit
0d3ee0af27

+ 1
- 0
app/Http/Controllers/LoginController.php Ver arquivo

@@ -43,6 +43,7 @@ class LoginController extends Controller
43 43
         if($user == null){
44 44
           $user = new User;
45 45
           $user->redmine_id = $redmineUser->id;
46
+          $user->azienda()->associate($azienda);
46 47
           $user->save();
47 48
         }
48 49
 

+ 10
- 0
app/Models/AbstractModels/AbstractAzienda.php Ver arquivo

@@ -57,4 +57,14 @@ abstract class AbstractAzienda extends Model
57 57
         'created_at',
58 58
         'updated_at'
59 59
     ];
60
+    
61
+    public function configs()
62
+    {
63
+        return $this->hasMany('\App\Models\Config', 'azienda_id', 'id');
64
+    }
65
+    
66
+    public function users()
67
+    {
68
+        return $this->hasMany('\App\Models\User', 'azienda_id', 'id');
69
+    }
60 70
 }

+ 10
- 15
app/Models/AbstractModels/AbstractConfig.php Ver arquivo

@@ -17,26 +17,12 @@ abstract class AbstractConfig extends Model
17 17
      */
18 18
     protected $table = 'config';
19 19
     
20
-    /**  
21
-     * Primary key name.
22
-     * 
23
-     * @var string
24
-     */
25
-    public $primaryKey = 'key';
26
-    
27 20
     /**  
28 21
      * Primary key type.
29 22
      * 
30 23
      * @var string
31 24
      */
32
-    protected $keyType = 'string';
33
-    
34
-    /**  
35
-     * Primary key is non-autoincrementing.
36
-     * 
37
-     * @var bool
38
-     */
39
-    public $incrementing = false;
25
+    protected $keyType = 'bigInteger';
40 26
     
41 27
     /**  
42 28
      * The attributes that should be cast to native types.
@@ -44,6 +30,8 @@ abstract class AbstractConfig extends Model
44 30
      * @var array
45 31
      */
46 32
     protected $casts = [
33
+        'id' => 'integer',
34
+        'azienda_id' => 'integer',
47 35
         'key' => 'string',
48 36
         'group' => 'string',
49 37
         'display_name' => 'string',
@@ -60,6 +48,8 @@ abstract class AbstractConfig extends Model
60 48
      * @var array
61 49
      */
62 50
     protected $fillable = [
51
+        'id',
52
+        'azienda_id',
63 53
         'key',
64 54
         'group',
65 55
         'display_name',
@@ -69,4 +59,9 @@ abstract class AbstractConfig extends Model
69 59
         'created_at',
70 60
         'updated_at'
71 61
     ];
62
+    
63
+    public function azienda()
64
+    {
65
+        return $this->belongsTo('\App\Models\Azienda', 'azienda_id', 'id');
66
+    }
72 67
 }

+ 7
- 0
app/Models/AbstractModels/AbstractUser.php Ver arquivo

@@ -32,6 +32,7 @@ abstract class AbstractUser extends Model
32 32
     protected $casts = [
33 33
         'id' => 'integer',
34 34
         'redmine_id' => 'integer',
35
+        'azienda_id' => 'integer',
35 36
         'firma' => 'string',
36 37
         'created_at' => 'datetime',
37 38
         'updated_at' => 'datetime'
@@ -45,8 +46,14 @@ abstract class AbstractUser extends Model
45 46
     protected $fillable = [
46 47
         'id',
47 48
         'redmine_id',
49
+        'azienda_id',
48 50
         'firma',
49 51
         'created_at',
50 52
         'updated_at'
51 53
     ];
54
+    
55
+    public function azienda()
56
+    {
57
+        return $this->belongsTo('\App\Models\Azienda', 'azienda_id', 'id');
58
+    }
52 59
 }

+ 1
- 1
app/Models/Config.php Ver arquivo

@@ -18,7 +18,7 @@ class Config extends \App\Models\AbstractModels\AbstractConfig
18 18
 
19 19
   public static function getValue($key){
20 20
     try{
21
-      return Config::find($key)->value;
21
+      return Config::where([['key', $key], ['azienda_id', session('azienda')->id]])->first()->value;
22 22
     }catch(\Exception $e){
23 23
       return 0;
24 24
     }

+ 3
- 2
app/Models/Issue.php Ver arquivo

@@ -8,7 +8,7 @@ use Illuminate\Support\Facades\Log;
8 8
 
9 9
 class Issue{
10 10
 
11
-  public static function getCollection(array $status = []){
11
+  public static function getCollection($status = []){
12 12
     $redmineUser = session('redmine_user');
13 13
     $collection = new Collection();
14 14
 
@@ -16,7 +16,7 @@ class Issue{
16 16
     $issueResponse = Http::get(session('azienda')->redmine_url.'/issues.json', [
17 17
       'key' => $redmineUser->api_key,
18 18
       'assigned_to_id' => $redmineUser->id,
19
-      'status_id' => count($status)>0?implode('|', $status):'open',
19
+      'status_id' => ($status!=null && count($status)>0)?implode('|', $status):'open',
20 20
       'limit' => 100,
21 21
     ]);
22 22
 
@@ -40,6 +40,7 @@ class Issue{
40 40
         $issueResponse = Http::get(session('azienda')->redmine_url.'/issues.json', [
41 41
           'key' => $redmineUser->api_key,
42 42
           'assigned_to_id' => $group->id,
43
+          'status_id' => ($status!=null && count($status)>0)?implode('|', $status):'open',
43 44
           'limit' => 100,
44 45
         ]);
45 46
 

+ 0
- 42
database/migrations/2022_03_18_100151_skipper_migrations_2022031810015198.php Ver arquivo

@@ -1,42 +0,0 @@
1
-<?php
2
-/* 
3
- * Migrations generated by: Skipper (http://www.skipper18.com)
4
- * Migration id: 389c4dec-5f41-4008-a12d-91fe5ebf4b24
5
- * Migration datetime: 2022-03-18 10:01:51.987239
6
- */ 
7
-
8
-use Illuminate\Support\Facades\Schema;
9
-use Illuminate\Database\Schema\Blueprint;
10
-use Illuminate\Database\Migrations\Migration;
11
-
12
-class SkipperMigrations2022031810015198 extends Migration
13
-{
14
-    /**
15
-     * Run the migrations.
16
-     *
17
-     * @return void
18
-     */
19
-    public function up()
20
-    {
21
-        Schema::create('config', function (Blueprint $table) {
22
-            $table->string('key');
23
-            $table->string('group')->nullable(true);
24
-            $table->string('display_name')->nullable(true);
25
-            $table->longText('value')->nullable(true);
26
-            $table->integer('order')->nullable(true);
27
-            $table->string('type')->nullable(true);
28
-            $table->timestamp('created_at')->nullable(true);
29
-            $table->timestamp('updated_at')->nullable(true);
30
-            $table->primary(['key']);
31
-        });
32
-    }
33
-    /**
34
-     * Reverse the migrations.
35
-     *
36
-     * @return void
37
-     */
38
-    public function down()
39
-    {
40
-        Schema::dropIfExists('config');
41
-    }
42
-}

+ 0
- 38
database/migrations/2022_03_18_104703_skipper_migrations_2022031810470316.php Ver arquivo

@@ -1,38 +0,0 @@
1
-<?php
2
-/* 
3
- * Migrations generated by: Skipper (http://www.skipper18.com)
4
- * Migration id: 81cb22a4-03b7-4566-9925-9af06de59d8c
5
- * Migration datetime: 2022-03-18 10:47:03.168319
6
- */ 
7
-
8
-use Illuminate\Support\Facades\Schema;
9
-use Illuminate\Database\Schema\Blueprint;
10
-use Illuminate\Database\Migrations\Migration;
11
-
12
-class SkipperMigrations2022031810470316 extends Migration
13
-{
14
-    /**
15
-     * Run the migrations.
16
-     *
17
-     * @return void
18
-     */
19
-    public function up()
20
-    {
21
-        Schema::create('user', function (Blueprint $table) {
22
-            $table->bigInteger('id')->autoIncrement()->unsigned();
23
-            $table->integer('redmine_id')->nullable(true);
24
-            $table->text('firma')->nullable(true);
25
-            $table->timestamp('created_at')->nullable(true);
26
-            $table->timestamp('updated_at')->nullable(true);
27
-        });
28
-    }
29
-    /**
30
-     * Reverse the migrations.
31
-     *
32
-     * @return void
33
-     */
34
-    public function down()
35
-    {
36
-        Schema::dropIfExists('user');
37
-    }
38
-}

+ 0
- 36
database/migrations/2022_03_18_122155_skipper_migrations_2022031812215528.php Ver arquivo

@@ -1,36 +0,0 @@
1
-<?php
2
-/* 
3
- * Migrations generated by: Skipper (http://www.skipper18.com)
4
- * Migration id: 4e7662d1-1f4b-45d7-9b1e-50073955d166
5
- * Migration datetime: 2022-03-18 12:21:55.286492
6
- */ 
7
-
8
-use Illuminate\Support\Facades\Schema;
9
-use Illuminate\Database\Schema\Blueprint;
10
-use Illuminate\Database\Migrations\Migration;
11
-
12
-class SkipperMigrations2022031812215528 extends Migration
13
-{
14
-    /**
15
-     * Run the migrations.
16
-     *
17
-     * @return void
18
-     */
19
-    public function up()
20
-    {
21
-        Schema::table('user', function (Blueprint $table) {
22
-            $table->binary('firma')->nullable(true)->after('redmine_id')->change();
23
-        });
24
-    }
25
-    /**
26
-     * Reverse the migrations.
27
-     *
28
-     * @return void
29
-     */
30
-    public function down()
31
-    {
32
-        Schema::table('user', function (Blueprint $table) {
33
-            $table->text('firma')->nullable(true)->after('redmine_id')->change();
34
-        });
35
-    }
36
-}

+ 68
- 0
database/migrations/2022_03_18_142224_skipper_migrations_2022031814222440.php Ver arquivo

@@ -0,0 +1,68 @@
1
+<?php
2
+/* 
3
+ * Migrations generated by: Skipper (http://www.skipper18.com)
4
+ * Migration id: 46c0a901-82c6-46b0-b5b2-c384b35596e4
5
+ * Migration datetime: 2022-03-18 14:22:24.400151
6
+ */ 
7
+
8
+use Illuminate\Support\Facades\Schema;
9
+use Illuminate\Database\Schema\Blueprint;
10
+use Illuminate\Database\Migrations\Migration;
11
+
12
+class SkipperMigrations2022031814222440 extends Migration
13
+{
14
+    /**
15
+     * Run the migrations.
16
+     *
17
+     * @return void
18
+     */
19
+    public function up()
20
+    {
21
+        Schema::create('config', function (Blueprint $table) {
22
+            $table->bigInteger('id')->autoIncrement()->unsigned();
23
+            $table->bigInteger('azienda_id')->nullable(true)->unsigned();
24
+            $table->string('key')->nullable(true);
25
+            $table->string('group')->nullable(true);
26
+            $table->string('display_name')->nullable(true);
27
+            $table->longText('value')->nullable(true);
28
+            $table->integer('order')->nullable(true);
29
+            $table->string('type')->nullable(true);
30
+            $table->timestamp('created_at')->nullable(true);
31
+            $table->timestamp('updated_at')->nullable(true);
32
+        });
33
+        Schema::create('user', function (Blueprint $table) {
34
+            $table->bigInteger('id')->autoIncrement()->unsigned();
35
+            $table->integer('redmine_id')->nullable(true);
36
+            $table->bigInteger('azienda_id')->nullable(true)->unsigned();
37
+            $table->binary('firma')->nullable(true);
38
+            $table->timestamp('created_at')->nullable(true);
39
+            $table->timestamp('updated_at')->nullable(true);
40
+        });
41
+        Schema::table('config', function (Blueprint $table) {
42
+            $table->foreign('azienda_id')->references('id')->on('azienda')->onDelete('cascade');
43
+        });
44
+        Schema::table('user', function (Blueprint $table) {
45
+            $table->foreign('azienda_id')->references('id')->on('azienda')->onDelete('cascade');
46
+        });
47
+    }
48
+    /**
49
+     * Reverse the migrations.
50
+     *
51
+     * @return void
52
+     */
53
+    public function down()
54
+    {
55
+        if (Schema::hasTable('user')) {
56
+            Schema::table('user', function (Blueprint $table) {
57
+                $table->dropForeign(['azienda_id']);
58
+            });
59
+        }
60
+        if (Schema::hasTable('config')) {
61
+            Schema::table('config', function (Blueprint $table) {
62
+                $table->dropForeign(['azienda_id']);
63
+            });
64
+        }
65
+        Schema::dropIfExists('user');
66
+        Schema::dropIfExists('config');
67
+    }
68
+}

+ 16
- 11
database/seeders/ConfigSeeder.php Ver arquivo

@@ -4,6 +4,7 @@ namespace Database\Seeders;
4 4
 
5 5
 use Illuminate\Database\Seeder;
6 6
 use App\Models\Config;
7
+use App\Models\Azienda;
7 8
 
8 9
 class ConfigSeeder extends Seeder
9 10
 {
@@ -15,17 +16,21 @@ class ConfigSeeder extends Seeder
15 16
   public function run()
16 17
   {
17 18
     // Configurazione
18
-    foreach(Config::getConfig() as $key => $group){
19
-      $order = 1;
20
-      foreach($group as $key2 => $c){
21
-        $config = Config::find($c['key']);
22
-        if($config == null){
23
-          $config = new Config;
24
-          $config->fill($c);
25
-          $config->order = $order;
26
-          $config->group = $key;
27
-          $config->save();
28
-          $order++;
19
+    foreach(Azienda::all() as $azienda){
20
+      foreach(Config::getConfig() as $key => $group){
21
+        $order = 1;
22
+        foreach($group as $key2 => $c){
23
+          $config = Config::where([['key', $c['key']], ['azienda_id', $azienda->id]])->first();
24
+          if($config == null){
25
+            $config = new Config;
26
+            $config->fill($c);
27
+            $config->order = $order;
28
+            $config->group = $key;
29
+            $config->key = $c['key'];
30
+            $config->azienda()->associate($azienda);
31
+            $config->save();
32
+            $order++;
33
+          }
29 34
         }
30 35
       }
31 36
     }

+ 10
- 10
resources/views/config/index.blade.php Ver arquivo

@@ -36,26 +36,26 @@ thead select{
36 36
           @foreach(Config::groupBy('group')->pluck('group')->toarray() as $group)
37 37
 
38 38
           <h2 style="margin-top: 20px;">{{ $group }}</h2>
39
-          @foreach(Config::where('group', $group)->orderBy('order', 'ASC')->get() as $config)
39
+          @foreach(Config::where([['group', $group], ['azienda_id', session('azienda')->id]])->orderBy('order', 'ASC')->get() as $config)
40 40
 
41 41
           <div class="form-row">
42 42
             <div class="form-group col">
43
-              {!! Form::hidden('key['.$config->key.']', $config->key) !!}
44
-              {!! Form::label('key['.$config->key.']', $config->display_name) !!}
43
+              {!! Form::hidden('key['.$config->id.']', $config->id) !!}
44
+              {!! Form::label('key['.$config->id.']', $config->display_name) !!}
45 45
               @switch($config->type)
46 46
               @case('boolean')
47 47
               <br>
48
-              {!! Form::radio('value['.$config->key.']', 1, $config->value==true, ['class' => '']) !!} SI
49
-              {!! Form::radio('value['.$config->key.']', 0, $config->value==false, ['class' => '']) !!} NO
48
+              {!! Form::radio('value['.$config->id.']', 1, $config->value==true, ['class' => '']) !!} SI
49
+              {!! Form::radio('value['.$config->id.']', 0, $config->value==false, ['class' => '']) !!} NO
50 50
               @break
51 51
 
52 52
               @case('textarea')
53 53
               <br>
54
-              {!! Form::textarea('value['.$config->key.']', $config->value, ['class' => 'form-control']) !!}
54
+              {!! Form::textarea('value['.$config->id.']', $config->value, ['class' => 'form-control']) !!}
55 55
               @break
56 56
 
57 57
               @case('password')
58
-              {!! Form::password('value['.$config->key.']', ['class' => 'form-control']) !!}
58
+              {!! Form::password('value['.$config->id.']', ['class' => 'form-control']) !!}
59 59
               @break
60 60
 
61 61
               @case('array_status')
@@ -63,7 +63,7 @@ thead select{
63 63
               <?php
64 64
               $checked = json_decode($config->value);
65 65
               foreach(Issue::getStati() as $status_id => $status_label){
66
-                echo Form::checkbox('value['.$config->key.'][]', $status_id, $checked!=null?in_array($status_id, $checked):false, [])." ".$status_label."<br>";
66
+                echo Form::checkbox('value['.$config->id.'][]', $status_id, $checked!=null?in_array($status_id, $checked):false, [])." ".$status_label."<br>";
67 67
               }
68 68
               ?>
69 69
               @break
@@ -71,7 +71,7 @@ thead select{
71 71
               @case('file')
72 72
               <div class="form-row">
73 73
                 <div class="form-group col">
74
-                  {!! Form::file('value['.$config->key.']', null, ['class' => 'form-control']) !!}
74
+                  {!! Form::file('value['.$config->id.']', null, ['class' => 'form-control']) !!}
75 75
                 </div>
76 76
                 <div class="form-group col">
77 77
                   <p>Logo attuale</p>
@@ -85,7 +85,7 @@ thead select{
85 85
               @break
86 86
 
87 87
               @default
88
-              {!! Form::text('value['.$config->key.']', $config->value, ['class' => 'form-control']) !!}
88
+              {!! Form::text('value['.$config->id.']', $config->value, ['class' => 'form-control']) !!}
89 89
               @endswitch
90 90
             </div>
91 91
           </div>

Carregando…
Cancelar
Salvar