| Conditions | 5 |
| Paths | 9 |
| Total Lines | 98 |
| Code Lines | 81 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 161 | private function createForumXml(array $forumData, string $forumDir): void |
||
| 162 | { |
||
| 163 | // ----- intro with category hints (mirrors UrlExport) ----- |
||
| 164 | $intro = (string) $forumData['description']; |
||
| 165 | if (!empty($forumData['category_id'])) { |
||
| 166 | $intro .= "\n<!-- CHAMILO2:forum_category_id:{$forumData['category_id']} -->"; |
||
| 167 | if (!empty($forumData['category_title'])) { |
||
| 168 | $intro .= "\n<!-- CHAMILO2:forum_category_title:". |
||
| 169 | htmlspecialchars((string) $forumData['category_title']).' -->'; |
||
| 170 | } |
||
| 171 | } |
||
| 172 | $introCdata = '<![CDATA['.$intro.']]>'; |
||
| 173 | |||
| 174 | $xml = '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL; |
||
| 175 | $xml .= '<activity id="'.$forumData['id'].'" moduleid="'.$forumData['moduleid'].'" modulename="forum" contextid="'.$forumData['contextid'].'">'.PHP_EOL; |
||
| 176 | $xml .= ' <forum id="'.$forumData['id'].'">'.PHP_EOL; |
||
| 177 | $xml .= ' <type>general</type>'.PHP_EOL; |
||
| 178 | $xml .= ' <name>'.htmlspecialchars((string) $forumData['name']).'</name>'.PHP_EOL; |
||
| 179 | $xml .= ' <intro>'.$introCdata.'</intro>'.PHP_EOL; |
||
| 180 | $xml .= ' <introformat>1</introformat>'.PHP_EOL; |
||
| 181 | $xml .= ' <duedate>0</duedate>'.PHP_EOL; |
||
| 182 | $xml .= ' <cutoffdate>0</cutoffdate>'.PHP_EOL; |
||
| 183 | $xml .= ' <assessed>0</assessed>'.PHP_EOL; |
||
| 184 | $xml .= ' <assesstimestart>0</assesstimestart>'.PHP_EOL; |
||
| 185 | $xml .= ' <assesstimefinish>0</assesstimefinish>'.PHP_EOL; |
||
| 186 | $xml .= ' <scale>100</scale>'.PHP_EOL; |
||
| 187 | $xml .= ' <maxbytes>512000</maxbytes>'.PHP_EOL; |
||
| 188 | $xml .= ' <maxattachments>9</maxattachments>'.PHP_EOL; |
||
| 189 | $xml .= ' <forcesubscribe>0</forcesubscribe>'.PHP_EOL; |
||
| 190 | $xml .= ' <trackingtype>1</trackingtype>'.PHP_EOL; |
||
| 191 | $xml .= ' <rsstype>0</rsstype>'.PHP_EOL; |
||
| 192 | $xml .= ' <rssarticles>0</rssarticles>'.PHP_EOL; |
||
| 193 | $xml .= ' <timemodified>'.$forumData['timemodified'].'</timemodified>'.PHP_EOL; |
||
| 194 | $xml .= ' <warnafter>0</warnafter>'.PHP_EOL; |
||
| 195 | $xml .= ' <blockafter>0</blockafter>'.PHP_EOL; |
||
| 196 | $xml .= ' <blockperiod>0</blockperiod>'.PHP_EOL; |
||
| 197 | $xml .= ' <completiondiscussions>0</completiondiscussions>'.PHP_EOL; |
||
| 198 | $xml .= ' <completionreplies>0</completionreplies>'.PHP_EOL; |
||
| 199 | $xml .= ' <completionposts>0</completionposts>'.PHP_EOL; |
||
| 200 | $xml .= ' <displaywordcount>0</displaywordcount>'.PHP_EOL; |
||
| 201 | $xml .= ' <lockdiscussionafter>0</lockdiscussionafter>'.PHP_EOL; |
||
| 202 | $xml .= ' <grade_forum>0</grade_forum>'.PHP_EOL; |
||
| 203 | |||
| 204 | // Discussions |
||
| 205 | $xml .= ' <discussions>'.PHP_EOL; |
||
| 206 | foreach ($forumData['threads'] as $thread) { |
||
| 207 | $xml .= ' <discussion id="'.$thread['id'].'">'.PHP_EOL; |
||
| 208 | $xml .= ' <name>'.htmlspecialchars((string) $thread['title']).'</name>'.PHP_EOL; |
||
| 209 | $xml .= ' <firstpost>'.(int) $thread['firstpost'].'</firstpost>'.PHP_EOL; |
||
| 210 | $xml .= ' <userid>'.$thread['userid'].'</userid>'.PHP_EOL; |
||
| 211 | $xml .= ' <groupid>-1</groupid>'.PHP_EOL; |
||
| 212 | $xml .= ' <assessed>0</assessed>'.PHP_EOL; |
||
| 213 | $xml .= ' <timemodified>'.$thread['timemodified'].'</timemodified>'.PHP_EOL; |
||
| 214 | $xml .= ' <usermodified>'.$thread['usermodified'].'</usermodified>'.PHP_EOL; |
||
| 215 | $xml .= ' <timestart>0</timestart>'.PHP_EOL; |
||
| 216 | $xml .= ' <timeend>0</timeend>'.PHP_EOL; |
||
| 217 | $xml .= ' <pinned>0</pinned>'.PHP_EOL; |
||
| 218 | $xml .= ' <timelocked>0</timelocked>'.PHP_EOL; |
||
| 219 | |||
| 220 | // Posts |
||
| 221 | $xml .= ' <posts>'.PHP_EOL; |
||
| 222 | foreach ($thread['posts'] as $post) { |
||
| 223 | $xml .= ' <post id="'.$post['id'].'">'.PHP_EOL; |
||
| 224 | $xml .= ' <parent>'.(int) $post['parent'].'</parent>'.PHP_EOL; |
||
| 225 | $xml .= ' <userid>'.$post['userid'].'</userid>'.PHP_EOL; |
||
| 226 | $xml .= ' <created>'.$post['created'].'</created>'.PHP_EOL; |
||
| 227 | $xml .= ' <modified>'.$post['modified'].'</modified>'.PHP_EOL; |
||
| 228 | $xml .= ' <mailed>'.(int) $post['mailed'].'</mailed>'.PHP_EOL; |
||
| 229 | $xml .= ' <subject>'.htmlspecialchars((string) $post['subject']).'</subject>'.PHP_EOL; |
||
| 230 | $xml .= ' <message>'.htmlspecialchars((string) $post['message']).'</message>'.PHP_EOL; |
||
| 231 | $xml .= ' <messageformat>1</messageformat>'.PHP_EOL; |
||
| 232 | $xml .= ' <messagetrust>0</messagetrust>'.PHP_EOL; |
||
| 233 | $xml .= ' <attachment></attachment>'.PHP_EOL; |
||
| 234 | $xml .= ' <totalscore>0</totalscore>'.PHP_EOL; |
||
| 235 | $xml .= ' <mailnow>0</mailnow>'.PHP_EOL; |
||
| 236 | $xml .= ' <privatereplyto>0</privatereplyto>'.PHP_EOL; |
||
| 237 | $xml .= ' <ratings>'.PHP_EOL; |
||
| 238 | $xml .= ' </ratings>'.PHP_EOL; |
||
| 239 | $xml .= ' </post>'.PHP_EOL; |
||
| 240 | } |
||
| 241 | $xml .= ' </posts>'.PHP_EOL; |
||
| 242 | |||
| 243 | // Subscriptions (basic placeholder) |
||
| 244 | $xml .= ' <discussion_subs>'.PHP_EOL; |
||
| 245 | $xml .= ' <discussion_sub id="'.$thread['id'].'">'.PHP_EOL; |
||
| 246 | $xml .= ' <userid>'.$thread['userid'].'</userid>'.PHP_EOL; |
||
| 247 | $xml .= ' <preference>'.$thread['timemodified'].'</preference>'.PHP_EOL; |
||
| 248 | $xml .= ' </discussion_sub>'.PHP_EOL; |
||
| 249 | $xml .= ' </discussion_subs>'.PHP_EOL; |
||
| 250 | |||
| 251 | $xml .= ' </discussion>'.PHP_EOL; |
||
| 252 | } |
||
| 253 | $xml .= ' </discussions>'.PHP_EOL; |
||
| 254 | |||
| 255 | $xml .= ' </forum>'.PHP_EOL; |
||
| 256 | $xml .= '</activity>'; |
||
| 257 | |||
| 258 | $this->createXmlFile('forum', $xml, $forumDir); |
||
| 259 | } |
||
| 261 |