1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: User |
5
|
|
|
* Date: 1/26/2019 |
6
|
|
|
* Time: 6:00 PM |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace crocodicstudio\crudbooster\types; |
10
|
|
|
|
11
|
|
|
use crocodicstudio\crudbooster\controllers\scaffolding\traits\DefaultOption; |
12
|
|
|
use crocodicstudio\crudbooster\controllers\scaffolding\traits\Join; |
13
|
|
|
use crocodicstudio\crudbooster\models\ColumnModel; |
14
|
|
|
use crocodicstudio\crudbooster\types\select\SelectModel; |
15
|
|
|
use Illuminate\Support\Facades\DB; |
16
|
|
|
|
17
|
|
|
class Select |
18
|
|
|
{ |
19
|
|
|
use DefaultOption, Join; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param string $field_name |
23
|
|
|
* @return $this |
24
|
|
|
*/ |
25
|
|
|
public function foreignKey($field_name) |
26
|
|
|
{ |
27
|
|
|
$data = columnSingleton()->getColumn($this->index); |
28
|
|
|
/** @var SelectModel $data */ |
29
|
|
|
$data->setForeignKey($field_name); |
30
|
|
|
columnSingleton()->setColumn($this->index, $data); |
31
|
|
|
|
32
|
|
|
return $this; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param $table string|Model |
|
|
|
|
37
|
|
|
* @param $key_field string |
38
|
|
|
* @param $display_field string |
39
|
|
|
* @param $SQLCondition string|callable |
40
|
|
|
* @return $this |
41
|
|
|
*/ |
42
|
|
|
public function optionsFromTable($table, $key_field, $display_field, $SQLCondition = null) { |
43
|
|
|
|
44
|
|
|
if(strpos($table,"App\Models")!==false) { |
45
|
|
|
$table = new $table(); |
46
|
|
|
$table = $table::$tableName; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$data = DB::table($table); |
50
|
|
|
if($SQLCondition && is_callable($SQLCondition)) { |
51
|
|
|
$data = call_user_func($SQLCondition, $data); |
52
|
|
|
}elseif ($SQLCondition && is_string($SQLCondition)) { |
53
|
|
|
$data->whereRaw($SQLCondition); |
54
|
|
|
} |
55
|
|
|
$data = $data->get(); |
56
|
|
|
$options = []; |
57
|
|
|
foreach ($data as $d) { |
58
|
|
|
$options[ $d->$key_field ] = $d->$display_field; |
59
|
|
|
} |
60
|
|
|
$data = columnSingleton()->getColumn($this->index); |
61
|
|
|
/** @var $data SelectModel */ |
62
|
|
|
$data->setOptionsFromTable(["table"=>$table,"key_field"=>$key_field,"display_field"=>$display_field,"sql_condition"=>$SQLCondition]); |
63
|
|
|
columnSingleton()->setColumn($this->index, $data); |
64
|
|
|
|
65
|
|
|
$this->options($options); |
66
|
|
|
|
67
|
|
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function optionsFromQuery(callable $query) { |
71
|
|
|
$data = columnSingleton()->getColumn($this->index); |
72
|
|
|
/** @var $data SelectModel */ |
73
|
|
|
$data->setOptionsFromQuery($query); |
74
|
|
|
|
75
|
|
|
columnSingleton()->setColumn($this->index, $data); |
76
|
|
|
|
77
|
|
|
$result = call_user_func($query); |
78
|
|
|
if($result) { |
79
|
|
|
$options = []; |
80
|
|
|
foreach($result as $r) { |
81
|
|
|
$options[ $r->key ] = $r->label; |
82
|
|
|
} |
83
|
|
|
$this->options($options); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
return $this; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function options($data_options) { |
90
|
|
|
$data = columnSingleton()->getColumn($this->index); |
91
|
|
|
/** @var $data SelectModel */ |
92
|
|
|
$data->setOptions($data_options); |
93
|
|
|
|
94
|
|
|
columnSingleton()->setColumn($this->index, $data); |
95
|
|
|
|
96
|
|
|
return $this; |
97
|
|
|
} |
98
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths