diff --git a/include/class-FTPAPI.php b/include/class-FTPAPI.php index 6eaa19a..bc7ccef 100644 --- a/include/class-FTPAPI.php +++ b/include/class-FTPAPI.php @@ -1,70 +1,97 @@ . /** - * FTP users API + * Methods related to an FTPAPI class */ -class FTPAPI extends DomainAPI { - - /** - * @override - */ - const DOMAIN_ID = 'ftp.domain_ID'; - - public function __construct() { - Query::__construct(); - $this->from( FTP::T ); - $this->defaultClass( 'FTP' ); - } +trait FTPAPITrait { /** * 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 ); } /** * Limit to a specific FTP account * * @param object $ftp FTP account * @return self */ public function whereFTP( $ftp ) { return $this->whereDomain( $ftp ) ->whereFTPLogin( $ftp->getFTPLogin() ); } + /** + * Join whatever table with the FTP users table + * + * @param object + * @return self + */ + public function joinFTP() { + return $this->joinOn( 'INNER', 'ftp', static::FTP_ID, 'ftp.ftp_ID' ); + } + +} + +// assure load of dependent traits +class_exists( 'DomainAPI', true ); + +/** + * FTP users API + */ +class FTPAPI extends Query { + + use FTPAPITrait; + use DomainAPITrait; + + /** + * Univoque domain ID column name + * + * @override + */ + const DOMAIN_ID = 'ftp.domain_ID'; + + public function __construct( $db = null ) { + // set database and class + parent::__construct( $db, 'FTP' ); + + // set table name + $this->from( FTP::T ); + } + }