<?php
/**
 * app/plugins/suggestions/forms.php
 *
 * This houses all of the form checking functions for this plugin.
 *
 * @package TP Suggest
 * @version 3.0
 * @author  Joey Kimsey <Joey@thetempusproject.com>
 * @link    https://TheTempusProject.com
 * @license https://opensource.org/licenses/MIT [MIT LICENSE]
 */
namespace TheTempusProject\Plugins\Suggestions;

use TheTempusProject\Bedrock\Functions\Input;
use TheTempusProject\Classes\Forms;

class SuggestionForms extends Forms {
    /**
     * Adds these functions to the form list.
     */
    public function __construct() {
        self::addHandler( 'newSuggestion', __CLASS__, 'newSuggestion' );
        self::addHandler( 'editSuggestion', __CLASS__, 'editSuggestion' );
    }

    /**
     * Validates the suggestion create form.
     *
     * @return {bool}
     */
    public static function newSuggestion() {
        if ( !Input::exists( 'title' ) ) {
            self::addUserError( 'You must specify title' );
            return false;
        }
        if ( !Input::exists( 'suggestion' ) ) {
            self::addUserError( 'You must write a Suggestion' );
            return false;
        }
        if ( !self::token() ) {
            return false;
        }
        return true;
    }

    /**
     * Validates the suggestion create form.
     *
     * @return {bool}
     */
    public static function editSuggestion() {
        if ( !Input::exists( 'title' ) ) {
            self::addUserError( 'You must specify title' );
            return false;
        }
        if ( !Input::exists( 'suggestion' ) ) {
            self::addUserError( 'You must write a Suggestion' );
            return false;
        }
        if ( !self::token() ) {
            return false;
        }
        return true;
    }
}

new SuggestionForms;
