<?php

/** 
 *------------------------------------------------------------------------------
 * @package       T4 Page Builder for Joomla!
 *------------------------------------------------------------------------------
 * @copyright     Copyright (C) 2004-2020 JoomlArt.com. All Rights Reserved.
 * @license       GNU General Public License version 2 or later; see LICENSE.txt
 * @authors       JoomlArt
 * @forum:		  https://www.joomlart.com/forums/t/t4-builder
 * @Link:         https://demo.t4-builder.joomlart.com/
 *------------------------------------------------------------------------------
 */
namespace JPB\Editor\Action;
defined('_JEXEC') or die;

use Joomla\CMS\Table\Table;
use JPB\Helper\Table AS JPBTable;

class Alias extends Base {
	public function run() {
		$data = json_decode(file_get_contents('php://input'), true);
		$alias = $data['alias'];
		$table = $data['tables'];
		switch ($table) {
			case 'menu':
				$result = self::checkAliasMenu($alias);
				break;
			
			default:
				$result = ['data' => true];
				break;
		}
		return $result;
	}
	public static function checkAliasMenu($alias){
		$tables = Table::getInstance('Menu', 'JTable');
		if ($tables->load(array('alias' => $alias)))
		{
			return ['data' => false];
		}
		return ['data' => true];
	}

}
