Passed
Push — develop ( f5d3ab...1cfb3a )
by Jens
03:36
created

documents.php ➔ renderDocument()   C

Complexity

Conditions 7
Paths 16

Size

Total Lines 33
Code Lines 25

Duplication

Lines 8
Ratio 24.24 %

Importance

Changes 0
Metric Value
cc 7
eloc 25
nc 16
nop 3
dl 8
loc 33
rs 6.7272
c 0
b 0
f 0
1
<script>window.onload=function(){History.init();History.replaceState(null, 'Cloud Control CMS', '/<?=$request::$subfolders . $cmsPrefix?>/documents?path=/');};</script>
2
<section class="documents">
3
	<h2><i class="fa fa-file-text-o"></i> Documents</h2>
4
	<nav class="actions">
5
		<ul>
6
			<li>
7
				<a class="btn" onmousedown="this.setAttribute('href', '<?=\library\cc\Request::$subfolders?><?=$cmsPrefix?>/documents/new-document?path=' + getParameterByName('path'));" href="<?=\library\cc\Request::$subfolders?><?=$cmsPrefix?>/documents/new-document" title="New Document">
8
					+ <i class="fa fa-file-text-o"></i>
9
				</a>
10
				<a class="btn" onmousedown="this.setAttribute('href', '<?=\library\cc\Request::$subfolders?><?=$cmsPrefix?>/documents/new-folder?path=' + getParameterByName('path'));" href="<?=\library\cc\Request::$subfolders?><?=$cmsPrefix?>/documents/new-folder" title="New Folder">
11
					+ <i class="fa fa-folder-o"></i>
12
				</a>
13
			</li>
14
		</ul>
15
	</nav>
16
	<? if (isset($documents)) : ?>
17
		<ul class="documents grid-wrapper">
18
			<li class="grid-container">
19
				<div class="grid-box-12">
20
					<i class="fa fa-terminal" title="Path"></i>
21
					<i id="pathHolder">/</i>
22
				</div>
23
			</li>
24
			<? foreach ($documents as $document) : ?>
25
				<li class="grid-container">
26
					<? if ($document->type == 'document') : ?>
27
						<?renderDocument($document, $cmsPrefix);?>
28
					<? elseif ($document->type == 'folder') : ?>
29
						<?renderFolder($document, $cmsPrefix, '', true);?>
30
					<? endif ?>
31
				</li>
32
33
			<? endforeach ?>
34
		</ul>
35
	<? endif ?>
36
</section>
37
<? function renderDocument($document, $cmsPrefix, $slugPrefix = '') {?>
38
<div class="grid-box-10">
39
	<h3>
40
		<a class="btn documentTitle" href="<?=\library\cc\Request::$subfolders?><?=$cmsPrefix?>/documents/edit-document?slug=<?=$slugPrefix . $document->slug?>" title="Edit">
41
			<i class="fa fa-file-text-o"></i>
42
            <small class="state <?=strtolower($document->state)?>"><i class="fa <?=$document->state == 'published' ? 'fa-check-circle-o' : 'fa-times-circle-o' ?>"></i></small>
43
            <?=$document->title?>
44
		</a>
45
        <? if ($document->unpublishedChanges) : ?><small class="small unpublished-changes">Unpublished Changes</small><? endif ?>
46
		<small class="small documentType"><?=$document->documentType?></small>
47
		<small class="small lastModified" title="<?=date('r', $document->lastModificationDate)?>">
48
			<span class="label">Modified:</span>
49
			<?=\library\cc\StringUtil::timeElapsedString($document->lastModificationDate)?>
50
		</small>
51
		<small class="small lastModifiedBy">
52
			<span class="label">By:</span>
53
			<?=$document->lastModifiedBy?>
54
		</small>
55
	</h3>
56
</div>
57
<div class="documentActions grid-box-2">
58 View Code Duplication
    <? if (strtolower($document->state) == 'unpublished' || $document->unpublishedChanges) : ?>
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
59
        <a class="btn publish" title="Publish" href="<?=\library\cc\Request::$subfolders?><?=$cmsPrefix?>/documents/publish-document?slug=<?=$slugPrefix . $document->slug?>"><i class="fa fa-check"></i></a>
60
    <? endif ?>
61
    <? if (strtolower($document->state) == 'published') : ?>
62
        <a class="btn unpublish" title="Unpublish" href="<?=\library\cc\Request::$subfolders?><?=$cmsPrefix?>/documents/unpublish-document?slug=<?=$slugPrefix . $document->slug?>"><i class="fa fa-times"></i></a>
63
    <? endif ?>
64
	<a class="btn" href="<?=\library\cc\Request::$subfolders?><?=$cmsPrefix?>/documents/edit-document?slug=<?=$slugPrefix . $document->slug?>" title="Edit"><i class="fa fa-pencil"></i></a>
65 View Code Duplication
	<? if (strtolower($document->state) == 'unpublished') : ?>
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
66
	<a onclick="return confirm('Are you sure you want to delete this item?');" class="btn error" href="<?=\library\cc\Request::$subfolders?><?=$cmsPrefix?>/documents/delete-document?slug=<?=$slugPrefix . $document->slug?>" title="Delete"><i class="fa fa-trash"></i></a>
67
    <? endif ?>
68
</div>
69
<?}?>
70
<? function renderFolder($document, $cmsPrefix, $slugPrefix ='', $root = false) {?>
71
<div class="grid-box-8">
72
	<h3>
73
		<a class="btn documentTitle openFolder" data-slug="<?=$slugPrefix . $document->slug?>" title="Open">
74
			<i class="fa fa-folder-o "></i> <?=$document->title?>
75
		</a>
76
	</h3>
77
</div>
78
<div class="documentActions grid-box-4">
79
	<a class="btn" href="<?=\library\cc\Request::$subfolders?><?=$cmsPrefix?>/documents/edit-folder?slug=<?=$slugPrefix . $document->slug?>" title="Edit"><i class="fa fa-pencil"></i></a>
80
	<a onclick="return confirm('Are you sure you want to delete this item?');" class="btn error" href="<?=\library\cc\Request::$subfolders?><?=$cmsPrefix?>/documents/delete-folder?slug=<?=$slugPrefix . $document->slug?>" title="Delete"><i class="fa fa-trash"></i></a>
81
</div>
82
<ul class="documents grid-wrapper nested<?=$root ? ' root' : '' ?>">
83
	<? foreach ($document->content as $subDocument) : ?>
84
		<li class="grid-container">
85
			<? if ($subDocument->type == 'document') : ?>
86
				<?renderDocument($subDocument, $cmsPrefix, $slugPrefix . $document->slug . '/');?>
87
			<? elseif ($subDocument->type == 'folder') : ?>
88
				<?renderFolder($subDocument, $cmsPrefix, $slugPrefix . $document->slug . '/');?>
89
			<? endif ?>
90
		</li>
91
	<? endforeach ?>
92
	<? if (count($document->content) == 0) : ?>
93
		<li class="grid-container">
94
			<div class="grid-box-12">
95
				<i class="fa fa-ellipsis-h empty"></i>
96
				<i>Empty</i>
97
			</div>
98
		</li>
99
	<? endif ?>
100
</ul>
101
<?}?>
102