DefaultController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
eloc 14
c 2
b 0
f 0
dl 0
loc 31
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A actionIndex() 0 19 3
1
<?php
2
3
namespace diecoding\pdfjs\controllers;
4
5
use Yii;
6
use yii\web\Controller;
7
8
/**
9
 * Default controller for the PdfJs Module.
10
 * 
11
 * @link [sugeng-sulistiyawan.github.io](sugeng-sulistiyawan.github.io)
12
 * @author Sugeng Sulistiyawan <[email protected]>
13
 * @copyright Copyright (c) 2024
14
 */
15
class DefaultController extends Controller
16
{
17
	/**
18
	 * @inheritDoc
19
	 */
20
	public $layout = 'main';
21
22
	/**
23
	 * Renders the index view for the module
24
	 * 
25
	 * @return string
26
	 */
27
	public function actionIndex($file)
28
	{
29
		$title = 'PDF Viewer';
30
		$sections = [];
31
		if (Yii::$app->request->getIsPost()) {
32
			/** @var array $sections */
33
			$sections = Yii::$app->request->post();
34
			$title = $sections['title'] ?? 'PDF Viewer: ' . $file;
35
			unset($sections[Yii::$app->request->csrfParam]);
36
			unset($sections['title']);
37
38
			foreach ($sections as $section => $show) {
39
				$sections[$section] = $show != 0;
40
			}
41
		}
42
43
		return $this->render('index', [
44
			'title' => $title,
45
			'sections' => $sections,
46
		]);
47
	}
48
}
49