1 | <?php |
||
12 | class save_block extends base_action |
||
13 | { |
||
14 | /** @var \blitze\sitemaker\model\blocks\mapper\blocks */ |
||
15 | protected $block_mapper; |
||
16 | |||
17 | 4 | public function execute($style_id) |
|
18 | { |
||
19 | 4 | $block_id = $this->request->variable('id', 0); |
|
20 | 4 | $update_similar = $this->request->variable('similar', false); |
|
21 | |||
22 | 4 | $this->block_mapper = $this->mapper_factory->create('blocks', 'blocks'); |
|
23 | |||
24 | 4 | if (($entity = $this->block_mapper->load(array('bid' => $block_id))) === null) |
|
25 | 4 | { |
|
26 | 1 | throw new \blitze\sitemaker\exception\out_of_bounds('BLOCK_NOT_FOUND'); |
|
27 | } |
||
28 | |||
29 | 3 | $old_hash = $entity->get_hash(); |
|
30 | |||
31 | 3 | $cfg_handler = $this->phpbb_container->get('blitze.sitemaker.blocks.cfg_handler'); |
|
32 | 3 | $block_instance = $this->block_factory->get_block($entity->get_name()); |
|
33 | 3 | $default_settings = $block_instance->get_config(array()); |
|
34 | 3 | $submitted_settings = $cfg_handler->get_submitted_settings($default_settings); |
|
35 | |||
36 | 3 | $entity->set_permission($this->request->variable('permission', array(0))) |
|
37 | 3 | ->set_class($this->request->variable('class', '')) |
|
38 | 3 | ->set_hide_title($this->request->variable('hide_title', 0)) |
|
39 | 3 | ->set_status($this->request->variable('status', 0)) |
|
40 | 3 | ->set_type($this->request->variable('type', 0)) |
|
41 | 3 | ->set_no_wrap($this->request->variable('no_wrap', 0)) |
|
42 | 3 | ->set_settings($submitted_settings); |
|
43 | 3 | $entity = $this->block_mapper->save($entity); |
|
44 | |||
45 | 3 | $new_hash = $entity->get_hash(); |
|
46 | 3 | $updated_blocks = array(); |
|
47 | 3 | $updated_blocks[$entity->get_bid()] = $this->render_block($entity); |
|
48 | |||
49 | 3 | if ($update_similar && $new_hash !== $old_hash) |
|
50 | 3 | { |
|
51 | 1 | $updated_blocks += $this->_update_similar($old_hash, $new_hash, $submitted_settings); |
|
52 | 1 | } |
|
53 | |||
54 | 3 | return $updated_blocks; |
|
55 | } |
||
56 | |||
57 | 1 | private function _update_similar($old_hash, $new_hash, $settings) |
|
76 | } |
||
77 |