33namespace Expressionengine \Coilpack \Fieldtypes \Presenters ;
44
55use Expressionengine \Coilpack \FieldtypeManager ;
6+ use ExpressionEngine \Coilpack \Models \Category \Category ;
67use ExpressionEngine \Coilpack \Models \Channel \ChannelEntry ;
8+ use ExpressionEngine \Coilpack \Models \Channel \Scopes ;
79use Expressionengine \Coilpack \Models \FieldContent ;
810use Expressionengine \Coilpack \Support \Arguments \FilterArgument ;
911use Expressionengine \Coilpack \Support \Arguments \ListArgument ;
1012use Expressionengine \Coilpack \Support \Arguments \SearchArgument ;
13+ use Expressionengine \Coilpack \Support \Arguments \Term ;
1114use Expressionengine \Coilpack \Support \Parameter ;
1215use Expressionengine \Coilpack \Traits \HasArgumentsAndParameters ;
1316
1417class RelationshipPresenter extends Presenter
1518{
16- use HasArgumentsAndParameters;
19+ use HasArgumentsAndParameters, Traits \QueriesRelationships ;
1720
1821 private $ fieldtypeManager ;
1922
@@ -24,34 +27,7 @@ public function __construct()
2427
2528 public function present (FieldContent $ content , $ arguments )
2629 {
27- $ isGrid = $ content ->field ->field_type === 'grid ' ;
28- $ isFluid = $ content ->hasAttribute ('fluid_field ' );
29- $ fluidFieldId = ($ isFluid ) ? $ content ->fluid_field_data_id : 0 ;
30- $ this ->arguments ($ arguments );
31-
32- $ query = ChannelEntry::query ();
33-
34- if ($ content ->entry ->isPreview ()) {
35- $ query ->whereIn ('entry_id ' , $ content ->data ['data ' ] ?? [0 ]);
36- } else {
37- $ query ->select ('channel_titles.* ' )
38- ->join ('relationships ' , 'entry_id ' , '= ' , 'child_id ' )
39- ->when ($ isFluid , function ($ query ) use ($ fluidFieldId ) {
40- $ query ->where ('relationships.fluid_field_data_id ' , $ fluidFieldId );
41- }, function ($ query ) {
42- $ query ->where ('relationships.fluid_field_data_id ' , 0 );
43- })
44- ->when ($ isGrid , function ($ query ) use ($ content ) {
45- $ query ->where ('relationships.grid_field_id ' , $ content ->field ->field_id )
46- ->where ('relationships.grid_row_id ' , $ content ->grid_row_id )
47- ->where ('relationships.grid_col_id ' , $ content ->grid_col_id );
48- }, function ($ query ) use ($ content ) {
49- $ query ->where ('relationships.field_id ' , $ content ->field ->field_id )
50- ->where ('relationships.grid_field_id ' , 0 );
51- })
52- ->where ('relationships.parent_id ' , $ content ->entry_id )
53- ->orderBy ('order ' );
54- }
30+ $ query = $ this ->buildRelationshipQuery ($ content , new ChannelEntry , 'relationships ' );
5531
5632 // Author
5733 $ query ->when ($ this ->hasArgument ('author ' ), function ($ query ) {
0 commit comments