Completed
Push — master ( 534aa6...b0bf1d )
by Andreas
17:36
created

net_nehmer_blog_handler_create::_handler_create()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 28
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 4.0218

Importance

Changes 0
Metric Value
cc 4
eloc 17
nc 2
nop 3
dl 0
loc 28
ccs 16
cts 18
cp 0.8889
crap 4.0218
rs 9.7
c 0
b 0
f 0
1
<?php
2
/**
3
 * @package net.nehmer.blog
4
 * @author The Midgard Project, http://www.midgard-project.org
5
 * @copyright The Midgard Project, http://www.midgard-project.org
6
 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
7
 */
8
9
use midcom\datamanager\datamanager;
10
use midcom\datamanager\controller;
11
use Symfony\Component\HttpFoundation\Request;
12
13
/**
14
 * n.n.blog create page handler
15
 *
16
 * @package net.nehmer.blog
17
 */
18
class net_nehmer_blog_handler_create extends midcom_baseclasses_components_handler
19
{
20
    /**
21
     * The article which has been created
22
     *
23
     * @var midcom_db_article
24
     */
25
    private $article;
26
27
    /**
28
     * Displays an article create view.
29
     *
30
     * If create privileges apply, we relocate to the created article
31
     *
32
     * @param Request $request The request object
33
     * @param array $args The argument list.
34
     * @param array $data The local request data.
35
     */
36 1
    public function _handler_create(Request $request, array $args, array &$data)
37
    {
38 1
        $this->_topic->require_do('midgard:create');
39
40 1
        $schema_name = $args[0];
41 1
        $schemadb = $data['schemadb'];
42 1
        if (   $this->_config->get('simple_name_handling')
43 1
            && !midcom::get()->auth->can_user_do('midcom:urlname')) {
44
            foreach ($schemadb->all() as $schema) {
45
                $schema->get_field('name')['readonly'] = true;
46
            }
47
        }
48
49 1
        $this->article = new midcom_db_article();
50 1
        $this->article->topic = $this->_topic->id;
51
52 1
        $dm = new datamanager($schemadb);
53 1
        $data['controller'] = $dm->set_storage($this->article, $schema_name)
54 1
            ->get_controller();
55
56 1
        midcom::get()->head->set_pagetitle(sprintf($this->_l10n_midcom->get('create %s'), $this->_l10n->get($schemadb->get($schema_name)->get('description'))));
57
58 1
        $workflow = $this->get_workflow('datamanager', [
59 1
            'controller' => $data['controller'],
60 1
            'save_callback' => [$this, 'save_callback']
61
        ]);
62
63 1
        return $workflow->run($request);
64
    }
65
66 1
    public function save_callback(controller $controller)
67
    {
68
        // Reindex the article
69 1
        $indexer = midcom::get()->indexer;
70 1
        net_nehmer_blog_viewer::index($controller->get_datamanager(), $indexer, $this->_topic);
71
72 1
        if ($this->_config->get('callback_function')) {
73
            if ($this->_config->get('callback_snippet')) {
74
                midcom_helper_misc::include_snippet_php($this->_config->get('callback_snippet'));
0 ignored issues
show
Bug introduced by
It seems like $this->_config->get('callback_snippet') can also be of type false; however, parameter $path of midcom_helper_misc::include_snippet_php() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

74
                midcom_helper_misc::include_snippet_php(/** @scrutinizer ignore-type */ $this->_config->get('callback_snippet'));
Loading history...
75
            }
76
77
            $callback = $this->_config->get('callback_function');
78
            $callback($this->article, $this->_topic);
79
        }
80 1
    }
81
}
82