diff --git a/include/class-MailboxAPI.php b/include/class-MailboxAPI.php index bad385a..e06fa8c 100644 --- a/include/class-MailboxAPI.php +++ b/include/class-MailboxAPI.php @@ -1,118 +1,132 @@ . // load dependend traits class_exists( 'DomainAPI' ); /** * Methods for a MailboxAPI class */ trait MailboxAPITrait { use DomainAPITrait; /** * Limit to a specific mailbox * * @param object $mailbox Mailbox * @return self */ public function whereMailbox( $mailbox ) { - return $this->whereDomain( $mailbox ) - ->whereMailboxUsername( $mailbox->getMailboxUsername() ); + return $this->whereMailboxID( $mailbox->getMailboxID() ); + } + + /** + * Limit to a specific Mailbox ID + * + * @param int $id Mailbox ID + * @return self + */ + public function whereMailboxID( $id ) { + return $this->whereInt( $this->MAILBOX_ID, $id ); } /** * Filter a specific Mailbox username * * @param string $username Mailbox username (without domain name) * @return self */ public function whereMailboxUsername( $username ) { return $this->whereStr( 'mailbox_username', $username ); } /** * Where the Mailbox is Active (or not) * * @param boolean $active If you want the active, or the inactive * @return self */ public function whereMailboxIsActive( $active = true ) { return $this->whereInt( 'mailbox_active', $active ); } /** * Join mailboxes and domain (once) * * @return self */ public function joinMailboxDomain() { if( empty( $this->joinedMailboxDomain ) ) { $this->from( 'domain' ); $this->equals( 'domain.domain_ID', 'mailbox.domain_ID' ); $this->joinedMailboxDomain = true; } return $this; } /** * Check if I can edit this mailbox * * Actually it just checks if you can edit the whole domain. * * @return boolean */ public function whereMailboxIsEditable() { return $this->whereDomainIsEditable(); } } /** * Mailbox API */ class MailboxAPI extends Query { use MailboxAPITrait; /** * Univoque Domain ID column name * * Used by DomainAPITrait */ const DOMAIN_ID = 'mailbox.domain_ID'; /** * Univoque Plan ID column name */ - const PLAN_ID = 'domain.plan_ID'; + protected $PLAN_ID = 'domain.plan_ID'; + + /** + * Univoque column name to the Mailbox ID + */ + protected $MAILBOX_ID = 'mailbox.mailbox_ID'; /** * Constructor */ public function __construct( $db = null ) { // set database and class name parent::__construct( $db, Mailbox::class ); // set database table $this->from( Mailbox::T ); } } diff --git a/include/class-MailboxQuota.php b/include/class-MailboxQuota.php index b49529f..3606efe 100644 --- a/include/class-MailboxQuota.php +++ b/include/class-MailboxQuota.php @@ -1,81 +1,83 @@ . // load dependent traits class_exists( 'Mailbox' ); /** * Methods for a MailboxQuota class */ trait MailboxQuotaTrait { /** * Get the Mailbox quota date * * @return DateTime */ public function getMailboxQuotaDate() { return $this->get( 'mailboxquota_date' ); } /** * Get the Mailbox quota bytes * * @return int */ public function getMailboxQuotaBytes() { return $this->get( 'mailboxquota_bytes' ); } /** * Get the Mailbox quota size readable for humans * * @return string */ public function getMailboxQuotaHumanSize() { $size = $this->getMailboxQuotaBytes(); return human_filesize( $size ); } /** * Normalize a MailboxQuota object after being retrieved from database */ - protected static function normalizeMailboxQuota() { + protected function normalizeMailboxQuota() { $this->integers( 'mailboxquota_bytes' ); $this->datetimes( 'mailboxquota_date' ); } } /** * Rappresentation of a Mailbox quota size */ class MailboxQuota extends Queried { + use MailboxQuotaTrait; + /** * Table name */ const T = 'mailboxquota'; /** * Constructor */ public function __construct() { $this->normalizeMailboxQuota(); } } diff --git a/include/class-MailboxQuotaAPI.php b/include/class-MailboxQuotaAPI.php index 966fadd..e04e7f9 100644 --- a/include/class-MailboxQuotaAPI.php +++ b/include/class-MailboxQuotaAPI.php @@ -1,118 +1,54 @@ . // load dependend traits class_exists( 'MailboxAPI' ); /** * Methods for a MailboxQuotaAPI class */ trait MailboxQuotaAPITrait { use MailboxAPITrait; - /** - * Limit to a specific mailbox - * - * @param object $mailbox MailboxQuota - * @return self - */ - public function whereMailboxQuota( $mailbox ) { - return $this->whereDomain( $mailbox ) - ->whereMaiboxUsername( $mailbox->getMailboxQuotaUsername() ); - } - - /** - * Filter a specific MailboxQuota username - * - * @param string $username MailboxQuota username (without domain name) - * @return self - */ - public function whereMailboxQuotaUsername( $username ) { - return $this->whereStr( 'mailbox_username', $username ); - } - - /** - * Where the MailboxQuota is Active (or not) - * - * @param boolean $active If you want the active, or the inactive - * @return self - */ - public function whereMailboxQuotaIsActive( $active = true ) { - return $this->whereInt( 'mailbox_active', $active ); - } - - /** - * Join mailboxes and domain (once) - * - * @return self - */ - public function joinMailboxQuotaDomain() { - if( empty( $this->joinedMailboxQuotaDomain ) ) { - $this->from( 'domain' ); - $this->equals( 'domain.domain_ID', 'mailbox.domain_ID' ); - - $this->joinedMailboxQuotaDomain = true; - } - return $this; - } - - /** - * Check if I can edit this mailbox - * - * Actually it just checks if you can edit the whole domain. - * - * @return boolean - */ - public function whereMailboxQuotaIsEditable() { - return $this->whereDomainIsEditable(); - } - } /** * MailboxQuota API */ class MailboxQuotaAPI extends Query { use MailboxQuotaAPITrait; /** - * Univoque Domain ID column name - * - * Used by DomainAPITrait - */ - const DOMAIN_ID = 'mailbox.domain_ID'; - - /** - * Univoque Plan ID column name + * Univoque column name to the Mailbox ID */ - const PLAN_ID = 'domain.plan_ID'; + protected $MAILBOX_ID = 'mailboxquota.mailbox_ID'; /** * Constructor */ public function __construct( $db = null ) { // set database and class name parent::__construct( $db, MailboxQuota::class ); // set database table $this->from( MailboxQuota::T ); } }