Example #1
0
 public function actionSetupBlock($sectionId, $blockPath)
 {
     $query = new QueryBuilder();
     $query->select('MAX(' . Block::getDbDriver()->quoteName('order') . ')')->from(Block::getTableName())->where('section=:section')->params([':section' => $sectionId]);
     $maxOrder = (int) $this->app->db->default->query($query)->fetchScalar();
     $block = new Block();
     $block->section = $sectionId;
     $block->path = $blockPath;
     $block->template = '';
     $params = [];
     foreach ($this->app->config->blocks->{$blockPath}->options as $optionName => $options) {
         $params[$optionName] = $options->default;
     }
     $block->options = json_encode($params);
     $block->order = $maxOrder + 10;
     if (false !== $block->save()) {
         $this->data->id = $block->getPK();
         $this->data->result = true;
     } else {
         $this->data->result = false;
     }
 }