| Current Path : /var/www/www.yekclass.com/public_html/components/com_droptables/ |
| Current File : /var/www/www.yekclass.com/public_html/components/com_droptables/controller.php |
<?php
/**
* Droptables
*
* We developed this code with our hearts and passion.
* We hope you found it useful, easy to understand and to customize.
* Otherwise, please feel free to contact us at contact@joomunited.com *
*
* @package Droptables
* @copyright Copyright (C) 2014 JoomUnited (http://www.joomunited.com). All rights reserved.
* @copyright Copyright (C) 2014 Damien Barrère (http://www.crac-design.com). All rights reserved.
* @license GNU General Public License version 2 or later; http://www.gnu.org/licenses/gpl-2.0.html
*/
//-- No direct access
defined('_JEXEC') || die('=;)');
jimport('joomla.application.component.controller');
/**
* Class droptablesController
*/
class droptablesController extends JControllerLegacy //phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps -- Class name not change
{
/**
* DroptablesController constructor.
*
* @param array $config Class name
*
* @return void
*/
public function __construct($config = array())
{
$view = JFactory::getApplication()->input->get('view');
//if(!preg_match('/^front.*/', $view)){
// $config['base_path'] = JPATH_COMPONENT_ADMINISTRATOR;
//}
parent::__construct($config);
}
/**
* Method to display the view.
*
* @param boolean $cachable If true, the view output will be cached
* @param boolean|array $urlparams An array of safe url parameters and their variable types,
* for valid values see {@link JFilterInput::clean()}.
*
* @return $this
*/
public function display($cachable = false, $urlparams = false)
{
// Load the submenu.
DroptablesHelper::addSubmenu(JRequest::getCmd('view', $this->default_view));
$vName = JRequest::getCmd('view', $this->default_view);
if ($vName === 'droptables') {
$view = $this->getView($vName, 'html');
$model = $this->getModel('category');
$view->setModel($model, false);
} elseif ($vName === 'frontfile' || $vName === 'frontfiles' || $vName === 'frontcategories') {
JLoader::register('DroptablesFilesHelper', JPATH_ADMINISTRATOR . '/components/com_droptables/helpers/files.php');
$view = $this->getView($vName, 'json');
$model = $this->getModel('frontcategory');
$view->setModel($model, false);
}
parent::display($cachable, $urlparams);
return $this;
}
/**
* Load data
*
* @return void
*/
public function loadData()
{
$input = JFactory::getApplication()->input;
$id = $input->getInt('id');
$page = $input->getInt('page');
$size = $input->getInt('size');
$filters = $input->get('filter', array(), 'Array');
$columns = $input->get('column', array(), 'Array');
$model = $this->getModel('table');
include(JPATH_COMPONENT_ADMINISTRATOR . DIRECTORY_SEPARATOR . 'models' . DIRECTORY_SEPARATOR . 'dbtable.php');
$dbmodel = new DroptablesModelDbtable();
$item = $model->getItem($id);
if ($item) {
$query = $item->datas;
$table_data = array();
$table_data['mysql_columns'] = $item->params['mysql_columns'];
$table_data['custom_titles'] = $item->params['custom_titles'];
$table_data['where_conditions'] = array();
if (isset($item->params['where_conditions'])) {
$table_data['where_conditions'] = $item->params['where_conditions'];
}
if (isset($item->params['join_rules'])) {
$table_data['join_rules'] = $item->params['join_rules'];
}
if (isset($item->params['grouping_rules'])) {
$table_data['grouping_rules'] = $item->params['grouping_rules'];
}
if (count($filters) > 0) {
foreach ($filters as $key => $v) {
$where_condition = array();
$where_condition['operator'] = 'plikep';
$where_condition['column'] = $table_data['mysql_columns'][$key];
$where_condition['value'] = $v;
$table_data['where_conditions'][] = $where_condition;
}
}
if (count($columns) > 0) {
$valueColumns = array_values($columns);
$keyColumns = array_keys($columns);
$columnIndex = $keyColumns[0];
$orderDir = (int) $valueColumns[0];
$table_data['default_ordering'] = $table_data['mysql_columns'][$columnIndex];
$table_data['default_ordering_dir'] = $orderDir ? 'asc' : 'desc';
}
// If there is any column filter or sorting then re-build the query
if (count($filters) || count($columns)) {
$generatedResult = $dbmodel->generateQueryAndPreviewdata($table_data);
$query = $generatedResult['query'];
}
$total_rows = $model->getTotalRows($query);
if ($size) {
$query .= ' LIMIT ' . $page * $size . ', ' . $size;
}
// echo $query; die();
$data = $model->getTableData($query);
$params = $item->params;
$headers = $params['custom_titles'];
$newData = array();
foreach ($data as $item) {
$row = array();
$i = 0;
foreach ($item as $k => $value) {
$row[$headers[$i]] = $value;
$i ++;
}
$newData[] = $row;
}
}
//$headers = array_keys($newData[0]);
$result = array('total_rows' => $total_rows, 'rows' => $newData, 'headers' => $headers);
echo json_encode($result);
die();
}
}