public function actionRenderGraph()
 {
     $stages = array_reduce(OrderStage::find()->asArray()->all(), function ($arr, $i) {
         $parent = OrderStageLeaf::find()->select(['stage_from_id'])->where(['stage_to_id' => $i['id']])->scalar();
         $arr[] = [['v' => $i['id'], 'f' => $i['name_frontend']], $parent ? $parent : '', $i['event_name']];
         return $arr;
     });
     return $this->render('render-graph', ['stages' => $stages]);
 }
 public function actionLeafEdit($id = null)
 {
     $model = null;
     if (null !== $id) {
         $model = OrderStageLeaf::findOne(['id' => $id]);
     }
     if (Yii::$app->request->isPost) {
         if (empty($model)) {
             $model = new OrderStageLeaf();
             $model->loadDefaultValues();
         }
         if ($model->load(Yii::$app->request->post())) {
             if ($model->validate() && $model->save()) {
                 return $this->redirect(Url::to(['', 'id' => $model->id]));
             } else {
                 Yii::$app->session->setFlash('error', 'Error saving data.');
             }
         } else {
             Yii::$app->session->setFlash('error', 'Error loading data.');
         }
     }
     if (empty($model)) {
         $model = new OrderStageLeaf();
         $model->loadDefaultValues();
     }
     $stages = array_reduce(OrderStage::find()->all(), function ($result, $item) {
         $result[$item->id] = $item->name;
         return $result;
     }, []);
     $events = array_reduce(Events::find()->all(), function ($result, $item) {
         /** @var Events $item */
         $result[$item->event_name] = $item->event_name;
         return $result;
     }, ['' => '']);
     return $this->render('leaf-edit', ['model' => $model, 'stages' => $stages, 'events' => $events]);
 }