diff --git a/includes/class-QuerySharable.php b/includes/class-QuerySharable.php index 51cef94..2b1dbe9 100644 --- a/includes/class-QuerySharable.php +++ b/includes/class-QuerySharable.php @@ -1,157 +1,156 @@ . // require dependent traits class_exists( QueryEvent::class, true ); /** * Methods related to a QuerySharable class */ trait QuerySharableTrait { /** * Where the Sharable is... * * @param object $event Sharable * @return self */ public function whereSharable( $event ) { return $this->whereSharableID( $event->getSharableID() ); } /** * Where the Sharable ID is... * * @param int $id Sharable ID * @return self */ public function whereSharableID( $id ) { return $this->whereInt( $this->SHARABLE_ID, $id ); } /** * Where the Sharable type is * * @param string $type * @return self */ public function whereSharableType( $type ) { return $this->whereStr( Sharable::TYPE, $type ); } /** * Where the Sharable has a parent * * @param boolean $has Set to false to have not a parent * @return self */ public function whereSharableHasParent( $has = true ) { // it has the parent if it's not NULL $verb = $has ? 'IS NOT' : 'IS'; return $this->compare( Sharable::PARENT, $verb, 'NULL' ); } /** * Where the Sharable has not a parent * * @param boolean $has Set to false to have not a parent * @return self */ public function whereSharableIsRoot() { return $this->whereSharableHasParent( false ); } /** * Where the Sharable has a parent and it's this one * * @param Sharable $sharable * @return self */ public function whereSharableParent( $sharable ) { return $this->whereSharableParentID( $sharable->getSharableID() ); } /** * Where the Sharable has a parent and it's this one * * @param int $id Sharable ID * @return self */ public function whereSharableParentID( $id ) { return $this->whereInt( Sharable::PARENT, $id ); } /** * Select a field called 'has_sharable_children' * * @return self */ public function selectSharableHasChildren( $alias = 'sharable_has_children' ) { // check if it exists another Sharable with this row as its parent $temp_subquery_alias = 'sharable_children'; $subquery = ( new QuerySharable( null, $temp_subquery_alias ) ) - ->equals( $temp_subquery_alias . DOT . Sharable::PARENT, Sharable::ID_ ) - ->getQuery(); + ->equals( $temp_subquery_alias . DOT . Sharable::PARENT, Sharable::ID_ ); - return $this->select( "EXISTS( $subquery ) $alias"); + return $this->selectExists( $subquery, $alias ); } } /** * Utility used to Query a Sharable. */ class QuerySharable extends Query { use QuerySharableTrait; use QueryEventTrait; /** * Univoque Sharable ID column name * * @var */ protected $SHARABLE_ID = 'sharable.sharable_ID'; /** * Univoque Event ID column name * * @var */ protected $EVENT_ID = 'sharable.event_ID'; /** * Constructor * * @param DB $db Database or NULL for the default one * @param string $alias Table alias */ public function __construct( $db = null, $alias = true ) { // initialize Query parent::__construct(); // select default table $this->fromAlias( Sharable::T, $alias ); // select default result class name $this->defaultClass( Sharable::class ); } }