* @link https://TheTempusProject.com * @license https://opensource.org/licenses/MIT [MIT LICENSE] */ namespace TheTempusProject\Models; use TheTempusProject\Bedrock\Classes\Config; use TheTempusProject\Bedrock\Functions\Check; use TheTempusProject\Canary\Bin\Canary as Debug; use TheTempusProject\Classes\DatabaseModel; use TheTempusProject\Plugins\Feedback as Plugin; use TheTempusProject\TheTempusProject as App; class Inithistory extends DatabaseModel { public $tableName = 'feedback'; public $databaseMatrix = [ [ 'name', 'varchar', '128' ], [ 'time', 'int', '10' ], [ 'email', 'varchar', '128' ], [ 'ip', 'varchar', '64' ], [ 'feedback', 'text', '' ], ]; public $plugin; /** * The model constructor. */ public function __construct() { parent::__construct(); $this->plugin = new Plugin; } /** * Saves a feedback form to the db. * * @param string $name -the name on the form * @param string $email -the email provided * @param string $feedback -contents of the feedback form. * @return bool */ public function create( $name, $email, $feedback ) { if ( !$this->plugin->checkEnabled() ) { Debug::info( 'Feedback is disabled in the config.' ); return false; } $fields = [ 'name' => $name, 'email' => $email, 'feedback' => $feedback, 'time' => time(), 'ip' => $_SERVER['REMOTE_ADDR'], ]; if ( !self::$db->insert( $this->tableName, $fields ) ) { Debug::info( 'Feedback::create - failed to insert to db' ); return false; } return self::$db->lastId(); } /** * Function to clear feedback from the DB. * * @todo is there a way i could check for success here I'm pretty sure this is just a bad idea? * @return bool */ public function clear() { if ( empty( self::$log ) ) { self::$log = new Log; } self::$db->delete( $this->tableName, ['ID', '>=', '0'] ); self::$log->admin( 'Cleared Feedback' ); Debug::info( 'Feedback Cleared' ); return true; } public function userHistory( $limit = 0 ) { $whereClause = [ 'userID', '=', App::$activeUser->ID, 'AND', 'deletedAt', '=', '0', 'AND', 'expiresAt', '<', time(), ]; if ( empty( $limit ) ) { $notifications = self::$db->get( $this->tableName, $whereClause ); } else { $notifications = self::$db->get( $this->tableName, $whereClause, 'ID', 'DESC', [0, $limit] ); } if ( !$notifications->count() ) { Debug::info( 'No Notifications found.' ); return false; } return $this->filter( $notifications->results() ); } }