Conditions | 12 |
Paths | 12 |
Total Lines | 106 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
46 | public function preparePage() |
||
47 | { |
||
48 | $this->P = new \HaaseIT\HCSF\CorePage($this->serviceManager, [], 'admin/base.twig'); |
||
49 | $this->P->cb_pagetype = 'content'; |
||
50 | $this->P->cb_subnav = 'admin'; |
||
51 | |||
52 | $this->P->cb_customcontenttemplate = 'textcatadmin'; |
||
53 | |||
54 | $return = ''; |
||
55 | |||
56 | $getaction = filter_input(INPUT_GET, 'action'); |
||
57 | if (empty($getaction)) { |
||
58 | $aData = $this->textcats->getCompleteTextcatForCurrentLang(); |
||
59 | |||
60 | $aListSetting = [ |
||
61 | ['title' => $this->hardcodedtextcats->get('textcatadmin_list_title_key'), 'key' => 'tc_key', 'width' => '20%', 'linked' => false,], |
||
62 | ['title' => $this->hardcodedtextcats->get('textcatadmin_list_title_text'), 'key' => 'tcl_text', 'width' => '80%', 'linked' => false, 'escapehtmlspecialchars' => true,], |
||
63 | [ |
||
64 | 'title' => $this->hardcodedtextcats->get('textcatadmin_list_title_edit'), |
||
65 | 'key' => 'tc_id', |
||
66 | 'width' => 35, |
||
67 | 'linked' => true, |
||
68 | 'ltarget' => '/_admin/textcatadmin.html', |
||
69 | 'lkeyname' => 'id', |
||
70 | 'lgetvars' => [ |
||
71 | 'action' => 'edit', |
||
72 | ], |
||
73 | ], |
||
74 | ]; |
||
75 | $return .= Tools::makeListtable($aListSetting, $aData, $this->serviceManager->get('twig')); |
||
76 | } elseif ($getaction === 'edit' || $getaction === 'delete') { |
||
77 | $getid = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT); |
||
78 | if ($getaction === 'delete' && filter_input(INPUT_POST, 'delete') === 'do') { |
||
79 | $this->textcats->deleteText($getid); |
||
80 | $this->P->cb_customdata['deleted'] = true; |
||
81 | } else { |
||
82 | $this->P->cb_customdata['edit'] = true; |
||
83 | |||
84 | $this->textcats->initTextIfVoid($getid); |
||
85 | |||
86 | // if post:edit is set, update |
||
87 | if (filter_input(INPUT_POST, 'edit') === 'do') { |
||
88 | $this->textcats->purifier = false; |
||
89 | if ($this->config->getCore('textcat_enable_purifier')) { |
||
90 | $this->textcats->purifier = $this->helper->getPurifier('textcat'); |
||
91 | } |
||
92 | $this->textcats->saveText( |
||
93 | filter_input(INPUT_POST, 'lid', FILTER_SANITIZE_NUMBER_INT), |
||
94 | filter_input(INPUT_POST, 'text') |
||
95 | ); |
||
96 | $this->P->cb_customdata['updated'] = true; |
||
97 | } |
||
98 | |||
99 | $aData = $this->textcats->getSingleTextByID($getid); |
||
100 | $this->P->cb_customdata['editform'] = [ |
||
101 | 'id' => $aData['tc_id'], |
||
102 | 'lid' => $aData['tcl_id'], |
||
103 | 'key' => $aData['tc_key'], |
||
104 | 'lang' => $aData['tcl_lang'], |
||
105 | 'text' => $aData['tcl_text'], |
||
106 | ]; |
||
107 | |||
108 | // show archived versions of this textcat |
||
109 | $dbal = $this->serviceManager->get('dbal'); |
||
110 | |||
111 | /** @var \Doctrine\DBAL\Query\QueryBuilder $queryBuilder */ |
||
112 | $queryBuilder = $dbal->createQueryBuilder(); |
||
113 | $queryBuilder |
||
114 | ->select('*') |
||
115 | ->from('textcat_lang_archive') |
||
116 | ->where('tcl_id = ?') |
||
117 | ->andWhere('tcl_lang = ?') |
||
118 | ->setParameter(0, $aData['tcl_id']) |
||
119 | ->setParameter(1, $this->config->getLang()) |
||
120 | ->orderBy('tcla_timestamp', 'DESC') |
||
121 | ; |
||
122 | $statement = $queryBuilder->execute(); |
||
123 | $iArchivedRows = $statement->rowCount(); |
||
124 | |||
125 | if ($iArchivedRows > 0) { |
||
126 | $aListSetting = [ |
||
127 | ['title' => 'tcla_timestamp', 'key' => 'tcla_timestamp', 'width' => '15%', 'linked' => false,], |
||
128 | ['title' => 'tcl_text', 'key' => 'tcl_text', 'width' => '85%', 'linked' => false, 'escapehtmlspecialchars' => true,], |
||
129 | ]; |
||
130 | $aData = $statement->fetchAll(); |
||
131 | $this->P->cb_customdata['archived_list'] = Tools::makeListtable($aListSetting, |
||
132 | $aData, $this->serviceManager->get('twig')); |
||
133 | } |
||
134 | } |
||
135 | } elseif ($getaction === 'add') { |
||
136 | $this->P->cb_customdata['add'] = true; |
||
137 | if (filter_input(INPUT_POST, 'add') === 'do') { |
||
138 | $postkey = filter_input(INPUT_POST, 'key', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); |
||
139 | $this->P->cb_customdata['err'] = $this->textcats->verifyAddTextKey($postkey); |
||
140 | |||
141 | if (count($this->P->cb_customdata['err']) == 0) { |
||
142 | $this->P->cb_customdata['addform'] = [ |
||
143 | 'key' => $postkey, |
||
144 | 'id' => $this->textcats->addTextKey($postkey), |
||
145 | ]; |
||
146 | } |
||
147 | } |
||
148 | } |
||
149 | |||
150 | $this->P->oPayload->cl_html = $return; |
||
151 | } |
||
152 | } |
||
153 |