@@ -497,44 +497,40 @@ function questions_get_expert_where_sql($user_guid = 0) {
497497 return false ;
498498 }
499499
500- $ site = elgg_get_site_entity ();
501-
502- $ wheres = [];
503-
504- // site expert
505- if ( questions_is_expert ( $ site, $ user )) {
506- // filter all non group questions
507- $ wheres [] = function ( QueryBuilder $ qb , $ main_alias ) {
500+ return function ( QueryBuilder $ qb , $ main_alias ) use ( $ user ) {
501+ $ site = elgg_get_site_entity ();
502+
503+ $ wheres = [];
504+
505+ // site expert
506+ if ( questions_is_expert ( $ site , $ user )) {
507+ // filter all non group questions
508508 $ sub = $ qb ->subquery ('entities ' )
509509 ->select ('guid ' )
510510 ->where ($ qb ->compare ('type ' , '= ' , 'group ' , ELGG_VALUE_STRING ))
511511 ->andWhere ($ qb ->compare ('enabled ' , '= ' , 'yes ' , ELGG_VALUE_STRING ));
512512
513- return $ qb ->compare ("{$ main_alias }.container_guid " , 'NOT IN ' , $ sub ->getSQL ());
514- };
515- }
516-
517- // fetch groups where user is expert
518- $ groups = elgg_get_entities ([
519- 'type ' => 'group ' ,
520- 'limit ' => false ,
521- 'relationship ' => QUESTIONS_EXPERT_ROLE ,
522- 'relationship_guid ' => $ user ->guid ,
523- 'callback ' => function ($ row ) {
524- return (int ) $ row ->guid ;
525- },
526- ]);
527- if (!empty ($ groups )) {
528- $ wheres [] = function (QueryBuilder $ qb , $ main_alias ) use ($ groups ) {
529- return $ qb ->compare ("{$ main_alias }.container_guid " , 'IN ' , $ groups );
530- };
531- }
532-
533- if (empty ($ wheres )) {
534- return false ;
535- }
536-
537- return function (QueryBuilder $ qb , $ main_alias ) use ($ wheres ) {
513+ $ wheres [] = $ qb ->compare ("{$ main_alias }.container_guid " , 'NOT IN ' , $ sub ->getSQL ());
514+ }
515+
516+ // fetch groups where user is expert
517+ $ groups = elgg_get_entities ([
518+ 'type ' => 'group ' ,
519+ 'limit ' => false ,
520+ 'relationship ' => QUESTIONS_EXPERT_ROLE ,
521+ 'relationship_guid ' => $ user ->guid ,
522+ 'callback ' => function ($ row ) {
523+ return (int ) $ row ->guid ;
524+ },
525+ ]);
526+ if (!empty ($ groups )) {
527+ $ wheres [] = $ qb ->compare ("{$ main_alias }.container_guid " , 'IN ' , $ groups );
528+ }
529+
530+ if (empty ($ wheres )) {
531+ return false ;
532+ }
533+
538534 return $ qb ->merge ($ wheres , 'OR ' );
539535 };
540536}
0 commit comments