skeeks\cms\controllers\AdminTreeController::actionResort PHP Method

actionResort() public method

TODO пока что циклом меняем приоритеты всех нод
public actionResort ( )
    public function actionResort()
    {
        $response = ['success' => false];
        Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
        if (\Yii::$app->request->isPost) {
            $tree = new Tree();
            $post = \Yii::$app->request->post();
            //$ids = array_reverse(array_filter($post['ids']));
            $ids = array_filter($post['ids']);
            $priority = 100;
            foreach ($ids as $id) {
                $node = $tree->find()->where(['id' => $id])->one();
                $node->priority = $priority;
                $node->save(false);
                $priority += 100;
            }
            $response['success'] = true;
        }
        /*
        if (\Yii::$app->request->isPost)
        {
            $tree = new Tree();
        
            $post = \Yii::$app->request->post();
        
            $resortIds = array_filter($post['ids']);
            $changeId = intval($post['changeId']);
        
            $changeNode = $tree->find()->where(['id' => $changeId])->one();
        
            $nodes = $tree->find()->where(['pid' =>$changeNode->pid])->orderBy(["priority" => SORT_DESC])->all();
            $origIds = [];
            foreach($nodes as $node)
            {
                $origIds[] = $node->id;
            }
        
            $origPos = array_search($changeId, $origIds);
            $resortPos = array_search($changeId, $resortIds);
        
            if($origPos > $resortPos)
            {
                $origIds = array_reverse($origIds);
                $offset = count($origIds) - 1;
                $origPos = $offset - $origPos;
                $resortPos = $offset - $resortPos;
            }
        
            for($i = $origPos+1; $i <= $resortPos; $i++)
            {
                $id = $origIds[$i];
                $node = $tree->find()->where(['id'=>$id])->one();
                $changeNode->swapPriorities($node);
            }
        
            $response['success'] = true;
        }
        */
        return $response;
    }