'id', 'fields' => [ 'Sekce' => ['field' => 'title', 'render' => 'getTitle', 'size' => 4], 'Popis' => ['field' => 'descr', 'render' => 'renderHTML', 'class' => 'getDescriptionClass', 'size' => 6], 'Zobrazuje se' => ['field' => 'figure', 'render' => 'renderFigure', 'class' => 'alignRight hidden-label', 'size' => 2], ], 'class' => null, ]; public function getTitle($values, $column) { return [ HTML::create('span') ->class('drag-drop-mover') ->tag('i') ->class('bi bi-arrows-move handle') ->end(), HTML::create('span') ->class('bi bi-dash-circle opener '.(count($values['submenu']) > 0 ? '' : 'disabled')), HTML::create('strong') ->attr('class', 'text-dark') ->text($this->getListRowValue($values, $column['field'])), ]; } public function renderFigure($values, $column) { return $values['figure'] === 'N' ? $this->renderBadge(translate('figureN', 'menulinks'), 'badge-pastel-default', 'eye-slash-fill m-r-1') : ''; } public function getDescriptionClass($values) { return 'columnDescription'; } public function getQuery() { return sqlQueryBuilder(); } public function handleDrag() { $tree = getVal('tree'); if ($tree) { $id_topsection = getVal('target', $tree); if (!$id_topsection) { $id_topsection = null; } // update sqlQueryBuilder() ->update('articles_branches') ->set('position', 'position+1') ->where(\Query\Operator::equalsNullable(['top_branch' => $id_topsection])) ->andWhere('position >= :position') ->setParameter('position', $tree['position']) ->execute(); sqlQueryBuilder() ->update('articles_branches') ->directValues([ 'top_branch' => $id_topsection, 'position' => $tree['position'], ]) ->where(\Query\Operator::equalsNullable(['id' => $tree['id']])) ->execute(); self::orderTreeLevel($id_topsection); clearCache('article-sections-', true); exit('OK'); } exit('Err'); } public static function orderTreeLevel($id_topsection) { $SQL = sqlQueryBuilder() ->select('id, position') ->from('articles_branches') ->where(\Query\Operator::equalsNullable(['top_branch' => $id_topsection])) ->orderBy('position, name', 'ASC') ->execute(); foreach ($SQL as $index => $row) { if ($row['position'] === null || $row['position'] != $index) { sqlQuery("UPDATE articles_branches SET position={$index} WHERE id={$row['id']}"); } } } public function getSQL(Query\QueryBuilder $qb) { return ['SQL' => $this->articlesSections(null)]; } public function articlesSections($topCat) { $data = []; /*$SQL = sqlQuery('SELECT ab.id, ab.name, ab.descr, ab.figure FROM '.getTableName('articles_branches')." AS ab WHERE ab.top_branch='".$topCat."' ORDER BY ab.name ASC");*/ $SQL = sqlQueryBuilder() ->select('ab.id', 'ab.name', 'ab.descr', 'ab.figure') ->from('articles_branches', 'ab') ->where(\Query\Operator::equalsNullable(['ab.top_branch' => $topCat])) ->orderBy('ab.position, ab.name', 'ASC')->execute(); foreach ($SQL as $key => $row) { $data[$key]['id'] = $row['id']; $data[$key]['descr'] = $row['descr']; $data[$key]['figure'] = $row['figure']; $data[$key]['level'] = $topCat; $data[$key]['title'] = $row['name']; $data[$key]['submenu'] = $this->articlesSections($row['id']); } return $data; } }