89 lines
2.9 KiB
PHP
89 lines
2.9 KiB
PHP
<?php
|
|
/**
|
|
* app/plugins/contacts/models/contact.php
|
|
*
|
|
* This class is used for the manipulation of the contacts database table.
|
|
*
|
|
* @package TP Contacts
|
|
* @version 3.0
|
|
* @author Joey Kimsey <Joey@thetempusproject.com>
|
|
* @link https://TheTempusProject.com
|
|
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
|
*/
|
|
namespace TheTempusProject\Models;
|
|
|
|
use TheTempusProject\Canary\Canary as Debug;
|
|
use TheTempusProject\Classes\DatabaseModel;
|
|
use TheTempusProject\TheTempusProject as App;
|
|
|
|
class Contact extends DatabaseModel {
|
|
public $tableName = 'contacts';
|
|
|
|
public $databaseMatrix = [
|
|
[ 'avatar', 'text', ''],
|
|
[ 'first_name', 'varchar', '128'],
|
|
[ 'middle_name', 'varchar', '128'],
|
|
[ 'last_name', 'varchar', '128'],
|
|
[ 'nickname', 'varchar', '128'],
|
|
[ 'company', 'varchar', '128'],
|
|
[ 'job_title', 'varchar', '128'],
|
|
[ 'email', 'varchar', '128'],
|
|
[ 'email_2', 'varchar', '128'],
|
|
[ 'phone', 'varchar', '128'],
|
|
[ 'phone_2', 'varchar', '128'],
|
|
[ 'address_1_primary', 'varchar', '128'],
|
|
[ 'address_1_secondary', 'varchar', '128'],
|
|
[ 'city', 'varchar', '128'],
|
|
[ 'state', 'varchar', '128'],
|
|
[ 'zipcode', 'varchar', '128'],
|
|
[ 'country', 'varchar', '128'],
|
|
[ 'address_2_primary', 'varchar', '128'],
|
|
[ 'address_2_secondary', 'varchar', '128'],
|
|
[ 'city_2', 'varchar', '128'],
|
|
[ 'state_2', 'varchar', '128'],
|
|
[ 'zipcode_2', 'varchar', '128'],
|
|
[ 'country_2', 'varchar', '128'],
|
|
[ 'notes', 'text', ''],
|
|
[ 'color', 'varchar', '48' ],
|
|
[ 'icon', 'varchar', '48' ],
|
|
[ 'createdAt', 'int', '11'],
|
|
[ 'createdBy', 'int', '11'],
|
|
[ 'phonebookID', 'int', '11'],
|
|
];
|
|
|
|
/**
|
|
* The model constructor.
|
|
*/
|
|
public function __construct() {
|
|
parent::__construct();
|
|
}
|
|
|
|
public function byUser( $limit = null ) {
|
|
$whereClause = [ 'createdBy', '=', App::$activeUser->ID ];
|
|
if ( empty( $limit ) ) {
|
|
$phonebooks = self::$db->get( $this->tableName, $whereClause );
|
|
} else {
|
|
$phonebooks = self::$db->get( $this->tableName, $whereClause, 'ID', 'DESC', [0, $limit] );
|
|
}
|
|
if ( !$phonebooks->count() ) {
|
|
Debug::info( 'No Phonebooks found.' );
|
|
return false;
|
|
}
|
|
return $this->filter( $phonebooks->results() );
|
|
}
|
|
|
|
public function byPhonebook( $phonebookID, $limit = null ) {
|
|
$whereClause = [ 'phonebookID', '=', $phonebookID ];
|
|
if ( empty( $limit ) ) {
|
|
$phonebooks = self::$db->get( $this->tableName, $whereClause );
|
|
} else {
|
|
$phonebooks = self::$db->get( $this->tableName, $whereClause, 'ID', 'DESC', [0, $limit] );
|
|
}
|
|
if ( !$phonebooks->count() ) {
|
|
Debug::info( 'No Phonebooks found.' );
|
|
return false;
|
|
}
|
|
return $this->filter( $phonebooks->results() );
|
|
}
|
|
}
|