/**
  * Displays a single model
  *
  * @param integer $id
  *
  * @return mixed
  */
 public function actionView($id)
 {
     $model = $this->findModel($id);
     if (isset($_POST['form-submitted'])) {
         ContentTemplateHasWidget::deleteAll(['content_template_id' => $id]);
         if (isset($_POST['sorted-widgets'])) {
             foreach ($_POST['sorted-widgets'] as $position => $widgets) {
                 $sorter = 0;
                 foreach ($widgets as $widgetId) {
                     $layoutWidget = new ContentTemplateHasWidget();
                     $layoutWidget->content_template_id = $id;
                     $layoutWidget->content_template_widget_id = $widgetId;
                     $layoutWidget->position = $position;
                     $layoutWidget->sorter = $sorter;
                     $layoutWidget->save(false);
                     $sorter++;
                 }
             }
         }
         Yii::$app->session->setFlash('success', ContentModule::t('app', 'Saved'));
         return $this->refresh();
     }
     return $this->renderIsAjax('view', compact('model'));
 }