diff --git a/include/class-Domain.php b/include/class-Domain.php index 5708b4e..6e7a6a9 100644 --- a/include/class-Domain.php +++ b/include/class-Domain.php @@ -1,100 +1,101 @@ . /** * A domain handled by the user */ class Domain extends Queried { const T = 'domain'; + const UID = 'domain_name'; public function __construct() { $this->integers( 'domain_ID' ); $this->booleans( 'domain_active' ); $this->dates( 'domain_born', 'domain_expiration' ); } /** * Get domain ID * * @return int */ public function getDomainID() { return $this->get( 'domain_ID' ); } /** * Get domain name * * @return string */ public function getDomainName() { return $this->get( 'domain_name' ); } /** * Get the domain edit URl * * @param boolean $absolute True for an absolute URL * @return string */ public function getDomainPermalink( $absolute = false ) { return Domain::permalink( $this->get( 'domain_name' ), $absolute ); } /** * Factory mailbox from this domain * * @return MailboxFullAPI */ public function factoryMailbox() { return ( new MailboxFullAPI() )->whereDomain( $this ); } /** * Factory e-mail forward from this domain * * @return MailforwardFullAPI */ public function factoryMailforwardfrom() { return ( new MailforwardfromAPI() )->whereDomain( $this ); } /** * Factory FTP users from this domain * * @return FTPAPI */ public function factoryFTP() { return ( new FTPAPI() )->whereDomain( $this ); } /** * Get the domain permalink * * @param string $domain_name Domain name * @param boolean $absolute True for an absolute URL */ public static function permalink( $domain_name = null, $absolute = false ) { $url = 'domain.php'; if( $domain_name ) { $url .= _ . $domain_name; } return site_page( $url, $absolute ); } } diff --git a/include/class-DomainAPI.php b/include/class-DomainAPI.php index dfb102f..4a4f2ac 100644 --- a/include/class-DomainAPI.php +++ b/include/class-DomainAPI.php @@ -1,101 +1,106 @@ . /** * Domain API */ class DomainAPI extends Query { const UID = 'name'; + /** + * Domain ID column name + */ + const DOMAIN_ID = 'domain.domain_ID'; + public function __construct() { parent::__construct(); $this->from( Domain::T ); $this->defaultClass( 'Domain' ); } /** * Where the domains are editable by me * * @return self */ public function whereDomainIsEditable() { if( ! has_permission( 'edit-domain-all' ) ) { $this->whereDomainUser(); } return $this; } /** * Limit to a certain user (or yourself) * * @param $user_ID int * @return self */ public function whereDomainUser( $user_ID = false ) { if( $user_ID === false ) { $user_ID = get_user( 'user_ID' ); } $this->joinDomainUser(); return $this->whereInt( 'domain_user.user_ID', $user_ID ); } /** * Limit to a certian domain name * * @param $domain_name string * @return self */ public function whereDomainName( $domain_name ) { return $this->whereStr( 'domain_name', $domain_name ); } /** * Constructor from a domain ID * * @param $domain_ID int * @return self */ public function whereDomainID( $domain_ID ) { - return $this->whereInt( 'domain.domain_ID', $domain_ID ); + return $this->whereInt( static::DOMAIN_ID, $domain_ID ); } /** * Constructor from a Domain object * * @param $domain object * @return self */ public function whereDomain( $domain ) { return $this->whereDomainID( $domain->getDomainID() ); } /** * Join domain and users (once) * * @return self */ public function joinDomainUser() { if( empty( $this->joinedDomainUser ) ) { $this->from( 'domain_user' ); $this->equals( 'domain_user.domain_ID', 'domain.domain_ID' ); $this->joinedDomainUser = true; } return $this; } } diff --git a/include/class-FTPAPI.php b/include/class-FTPAPI.php index cd47a1f..6eaa19a 100644 --- a/include/class-FTPAPI.php +++ b/include/class-FTPAPI.php @@ -1,65 +1,70 @@ . /** * FTP users API */ class FTPAPI extends DomainAPI { + /** + * @override + */ + const DOMAIN_ID = 'ftp.domain_ID'; + public function __construct() { Query::__construct(); $this->from( FTP::T ); $this->defaultClass( 'FTP' ); } /** * Join FTP and domain tables (once) * * @return self */ public function joinFTPDomain() { if( empty( $this->joinedFTPDomain ) ) { $this->joinedFTPDomain = true; $this->from( 'domain' ); $this->equals( 'domain.domain_ID', 'ftp.domain_ID' ); } return $this; } /** * Filter to a certain FTP login * * @param string $login * @return self */ public function whereFTPLogin( $login ) { return $this->whereStr( 'ftp_login', $login ); } /** - * Filter to a certain domain ID + * Limit to a specific FTP account * - * @param int $id int + * @param object $ftp FTP account * @return self - * @override */ - public function whereDomainID( $id ) { - return $this->whereInt( 'ftp.domain_ID', $id ); + public function whereFTP( $ftp ) { + return $this->whereDomain( $ftp ) + ->whereFTPLogin( $ftp->getFTPLogin() ); } } diff --git a/include/class-MailforwardAPI.php b/include/class-MailforwardAPI.php index 728dffa..a63158f 100644 --- a/include/class-MailforwardAPI.php +++ b/include/class-MailforwardAPI.php @@ -1,64 +1,63 @@ . /** * E-mail forwarding API */ class MailforwardfromAPI extends DomainAPI { + /** + * Domain ID column name + * + * @override + */ + const DOMAIN_ID = Mailforwardfrom::T . DOT . 'domain_ID'; + + /** + * @constructor + */ public function __construct() { Query::__construct(); $this->from( Mailforwardfrom::T ); $this->defaultClass( 'Mailforwardfrom' ); } /** * Join mailforwardes and domain (once) * * @return self */ public function joinMailforwardfromDomain() { if( empty( $this->joinedMailforwardfromDomain ) ) { $this->joinedMailforwardfromDomain = true; $this->from( 'domain' ); $this->equals( 'domain.domain_ID', 'mailforwardfrom.domain_ID' ); } return $this; } /** * Filter to a certain mail forwarding username * * @param mailforward_source string * @return self */ public function whereMailforwardfromUsername( $username ) { return $this->whereStr( 'mailforwardfrom_username', $username ); } - /** - * Filter to a certain domain ID - * - * @param $domain_ID int - * @return self - * @override - */ - public function whereDomainID( $domain_ID ) { - return $this->whereInt( 'mailforwardfrom.domain_ID', $domain_ID ); - } - }