Your IP : 216.73.216.240


Current Path : /home/juvelize/saulnois/tmp/install_695d2cf0b4957/src/Model/
Upload File :
Current File : /home/juvelize/saulnois/tmp/install_695d2cf0b4957/src/Model/TfModelExport.php

<?php
/*
* @package		Tech Fry Library
* @license		https://www.gnu.org/licenses/gpl-3.0.en.html
*/

namespace TechFry\Library\Model;

defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Form\FormFactoryInterface;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\Registry\Registry;
use Joomla\CMS\Form\Form;
use TechFry\Library\Model\Back\TfModelForm;

class TfModelExport extends TfModelForm
{
    public function __construct($config = [], ?MVCFactoryInterface $factory = null, ?FormFactoryInterface $formFactory = null)
	{
	    parent::__construct($config, $factory, $formFactory);
	    
	    $this->basic_fields = [];
	    
	    $this->loadData = false;
	}
    
    public function getForm($data = [], $loadData = true)
    {
        $this->form = Form::getInstance($this->option . '.' . $this->getName(), JPATH_LIBRARIES . '/techfry/forms/' . $this->getName() . '.xml', array("control" => "jform"));
        
        if (empty($this->form))
        {
            return false;
        }

        $db_table = $this->input->get('type', '');
        if ($db_table)
        {
            $this->form->setFieldAttribute('db_table', 'default', $db_table);
            $this->form->setFieldAttribute('db_table', 'readonly', 'true');

            $this->set_column_fields($db_table);
        }

        // Set custom fields field
        $element = '<field name="custom_fields" type="text" label="Custom Field IDs" />';
        $this->set_field($element, 'general');
        
        return $this->form;
    }

    public function set_column_fields($db_table)
    {
        $table_name = '#__' . $db_table;
        
        $db = Factory::getDbo();
        $cols = $db->getTableColumns($table_name);
        
        $element = '<field name="select_fields" type="list" label="COM_TF_COLUMNS" layout="joomla.form.field.list-fancy-select" multiple="true">';
        $json_element = '<field name="json_fields" type="list" label="JSON Fields" layout="joomla.form.field.list-fancy-select" multiple="true">';
        
        foreach ($cols as $col_name => $col_type)
        {
            $element .= '<option value="' . $col_name . '">' . $col_name . '</option>';
            $json_element .= '<option value="' . $col_name . '">' . $col_name . '</option>';
        }
        
        $element .= '</field>';
        $json_element .= '</field>';
	    
        $this->set_field($element, 'general');
        $this->set_field($json_element, 'general');
    }
}