diff --git a/include/class-MailboxSizeAPI.php b/include/class-MailboxSizeAPI.php index 60a4ab7..4b9e9ab 100644 --- a/include/class-MailboxSizeAPI.php +++ b/include/class-MailboxSizeAPI.php @@ -1,89 +1,89 @@ . // load dependend traits class_exists( 'MailboxAPI' ); /** * Methods for a MailboxSizeAPI class */ trait MailboxSizeAPITrait { use MailboxAPITrait; /** * Select the MAX Mailbox quota date * * @return self */ public function selectMaxMailboxSizeDate() { return $this->select( 'MAX( mailboxsize_date ) AS max_mailboxsize_date' ) - ->groupBy( 'mailboxsize_date' ); + ->groupBy( 'mailbox_ID' ); } /** * Assure that this is only the more updated Mailbox quota * * @return self */ public function whereMailboxSizeIsLast() { // subquery with a maximum constraint $max = ( new MailboxSizeAPI( null, false ) ) ->fromCustom( DB::instance()->getTable( 'mailboxsize', 'mailboxsize_sub' ) ) ->equals( 'mailboxsize.mailbox_ID', 'mailboxsize_sub.mailbox_ID' ) ->selectMaxMailboxSizeDate() ->getQuery(); return $this->where( sprintf( 'mailboxsize_date = (%s)', $max ) ); } } /** * MailboxSize API */ class MailboxSizeAPI extends Query { use MailboxSizeAPITrait; /** * Univoque column name to the Mailbox ID */ protected $MAILBOX_ID = 'mailboxsize.mailbox_ID'; /** * Constructor * * @param object $db Database * @param mixed $from Set to false to avoid to use the default FROM */ public function __construct( $db = null, $from = true ) { // set database and class name parent::__construct( $db, MailboxSize::class ); /** * Set database table (sometime the standard alias it's not useful) * * See MailboxSizeAPI class. */ if( $from ) { $this->from( MailboxSize::T ); } } }