Your IP : 216.73.216.68


Current Path : /home/jeromecohp/www/tmp/yooessentials/modules/core/src/
Upload File :
Current File : /home/jeromecohp/www/tmp/yooessentials/modules/core/src/CoreController.php

<?php
/**
 * @package   Essentials YOOtheme Pro (Freemium) 1.6.8
 * @author    ZOOlanders https://www.zoolanders.com
 * @copyright Copyright (C) Joolanders, SL
 * @license   http://www.gnu.org/licenses/gpl.html GNU/GPL
 */

namespace ZOOlanders\YOOessentials;

use YOOtheme\File;
use YOOtheme\Http\Request;
use YOOtheme\Http\Response;

class CoreController
{
    public const GET_CHANGELOG_URL = 'yooessentials/changelog';

    public const GET_TABLE_COLUMNS_ENDPOINT = 'yooessentials/core/table/columns';

    public function getChangelog(Response $response)
    {
        return $response->withFile(File::get('~yooessentials/CHANGELOG.md'));
    }

    public function getTableColumns(Request $request, Response $response, Config $config, DatabaseManager $database)
    {
        $config = $request->getParam('form') ?? [];
        $table = $request->getParam('table') ?? '';

        if (!$table) {
            return $request->abort(400, 'Table must be specified.');
        }

        try {
            $options = array_filter(Util\Prop::filterByPrefix($config, 'db_'));
            $options['external'] = $config['external'] ?? false;

            $columns = $database->initialize($options)->fetchAll("SHOW FULL COLUMNS FROM $table");

            return $response->withJson(compact('columns'), 200);
        } catch (\Exception $e) {
            return $request->abort(400, $e->getMessage());
        }
    }
}