<?php


/**
 * @package     pkg_dearflip
 * @subpackage  com_dearflip
 * @since       1.0.0
 * @copyright   Copyright © 2007 Free Software Foundation, Inc. All rights reserved.
 * @license   GNU General Public License version 3 or later; see https://www.gnu.org/licenses/gpl-3.0.en.html
 */

// No direct access to this file
defined( '_JEXEC' ) or die( 'Restricted access' );

/**
 * Dearflip Model
 *
 * @since  0.0.1
 */
class DearflipModelDearflipsetting extends JModelAdmin {
    /**
     * Method to get a table object, load it if necessary.
     *
     * @param string $type The table name. Optional.
     * @param string $prefix The class prefix. Optional.
     * @param array $config Configuration array for model. Optional.
     *
     * @return  JTable  A JTable object
     *
     * @since   1.6
     */
    public function getTable( $type = 'Dearflipsetting', $prefix = 'DearflipTable', $config = array() ) {
        return JTable::getInstance( $type, $prefix, $config );
    }

    /**
     * Method to get the record form.
     *
     * @param array $data Data for the form.
     * @param boolean $loadData True if the form is to load its own data (default case), false if not.
     *
     * @return  mixed    A JForm object on success, false on failure
     *
     * @since   1.6
     */
    public function getForm( $data = array(), $loadData = true ) {
        // Get the form.
        $form = $this->loadForm(
            'com_dearflip.dearflipsetting',
            'dearflipsetting',
            array(
                'control'   => 'jform',
                'load_data' => $loadData
            )

        );


        if ( empty( $form ) ) {
            return false;
        }

        return $form;
    }

    /**
     * Method to get the data that should be injected in the form.
     *
     * @return  mixed  The data for the form.
     *
     * @since   1.6
     */
    protected function loadFormData() {
        // Check the session for previously entered form data.
        $data = JFactory::getApplication()->getUserState(
            'com_dearflip.edit.dearflipsetting.data',
            array()
        );

        if ( empty( $data ) ) {
            $data = $this->getItem();
        }

        return $data;
    }
}