public function actionOrder($id = null, $ordering = null, $direction = null) { if ($id != null || $ordering != null || $direction != null) { $sess = Yii::$app->session->get('sessMenus'); if ($direction == "up") { $newSortOrder = $ordering - 1; } else { if ($direction == "down") { $newSortOrder = $ordering + 1; } } $parent = Menus::find($id); $where = array(); $where[] = "ordering = '{$newSortOrder}'"; $where[] = "langs = '" . $sess['langs'] . "'"; $where[] = "parent_id = '" . $parent->parent_id . "'"; $connection = Yii::$app->db; $sql = "SELECT id FROM tbl_menus " . (count($where) ? "\n WHERE " . implode(' AND ', $where) : ''); $command = $connection->createCommand($sql); $reader = $command->query(); foreach ($reader as $row) { $otherId = $row["id"]; } $where = array(); $where[] = "id = '{$id}'"; $where[] = "langs = '" . $sess['langs'] . "'"; $where[] = "parent_id = '" . $parent->parent_id . "'"; $sql = 'UPDATE tbl_menus SET ordering = "' . $newSortOrder . '" ' . (count($where) ? "\n WHERE " . implode(' AND ', $where) : ''); $command = $connection->createCommand($sql); $command->execute(); if ($reader->getRowCount() > 0) { $where = array(); $where[] = "id = '{$otherId}'"; $where[] = "langs = '" . $sess['langs'] . "'"; $where[] = "parent_id = '" . $parent->parent_id . "'"; $sql = 'UPDATE tbl_menus SET ordering = "' . $ordering . '"' . (count($where) ? "\n WHERE " . implode(' AND ', $where) : ''); $command = $connection->createCommand($sql); $command->execute(); } return $this->redirect(['index']); } }
public function listCategorySub($parent, $space = '|---') { global $arr; $children = Menus::find()->where(['parent_id' => $parent])->orderBy('ordering')->all(); foreach ($children as $child) { $data = array(); $data['id'] = $child->id; $data['names'] = $space . ' ' . $child->names; $data['published'] = $child->published; $data['ordering'] = $child->ordering; $data['min'] = $this->orderMin($child->langs, $child->type, $child->parent_id); $data['max'] = $this->orderMax($child->langs, $child->type, $child->parent_id); $arr[] = $data; Menus::listCategorySub($child->id, $space . '---'); } }
</div> <div class="col_one_fifth col_last"> <?php $r3 = $rows[3]; ?> <div class="widget widget_links clearfix"> <h4><?php echo $r3->names; ?> </h4> <ul> <?php $que = \app\models\Menus::find()->where(['parent_id' => $r3->id, 'published' => 1])->orderBy('ordering'); $row = $que->all(); foreach ($row as $s) { ?> <li><a href="<?php echo $s->urls; ?> "><?php echo $s->names; ?> </a></li> <?php } ?> </ul> </div>
public function listMenusSub($parent, $space = '|---') { global $arr; $children = Menus::find()->where(['parent_id' => $parent])->orderBy('ordering')->all(); foreach ($children as $child) { $data = array(); $data['id'] = $child->id; $data['name'] = $space . ' ' . $child->names; $arr[] = $data; $this->listMenusSub($child->id, $space . ' ---'); } }