Passed
Push — develop ( b22d40...c9190c )
by Jens
03:28
created

getPublishDocumentLink()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 4
dl 0
loc 2
rs 10
1
<?php
2
/**
3
 * @param \CloudControl\Cms\storage\entities\Document $document
4
 * @param string $path
5
 * @param \CloudControl\Cms\cc\Request $request
6
 * @param string $cmsPrefix
7
 */
8
function renderDocument($document, $path, $request, $cmsPrefix)
9
{ ?>
10
  <td class="icon" title="<?= $document->type ?>">
11
    <i class="fa fa-file-text-o"></i>
12
  </td>
13
  <td class="icon" title="<?= $document->state ?>">
14
    <i class="fa <?= $document->state === 'published' ? 'fa-check-circle-o' : 'fa-times-circle-o' ?>"></i>
15
  </td>
16
  <td>
17
    <a href="<?= getEditDocumentLink($request, $cmsPrefix, $path, $document) ?>"><?= $document->title ?></a>
18
      <?php if ($document->unpublishedChanges) : ?>
19
        <small class="small unpublished-changes">Unpublished Changes</small>
20
      <?php endif ?>
21
    <small class="small document-type"><?= $document->documentType ?></small>
22
    <div class="details">
23
      <table>
24
        <tr>
25
          <th>Document Type</th>
26
          <td><?= $document->documentType ?></td>
27
          <th>Last Modified By</th>
28
          <td><?= $document->lastModifiedBy ?></td>
29
        </tr>
30
        <tr>
31
          <th>Created</th>
32
          <td title="<?= date('d-m-Y H:i:s',
33
              $document->creationDate) ?>"><?= \CloudControl\Cms\util\StringUtil::timeElapsedString($document->creationDate) ?></td>
34
          <th>Last Modified</th>
35
          <td title="<?= date('d-m-Y H:i:s',
36
              $document->lastModificationDate) ?>"><?= \CloudControl\Cms\util\StringUtil::timeElapsedString($document->lastModificationDate) ?></td>
37
        </tr>
38
        <tr>
39
          <td colspan="2">&nbsp;</td>
40
          <th>Published</th>
41
            <?php if ($document->state === 'published') : ?>
42
              <td title="<?= date('d-m-Y H:i:s',
43
                  $document->publicationDate) ?>"><?= \CloudControl\Cms\util\StringUtil::timeElapsedString($document->publicationDate) ?></td>
44
            <?php else : ?>
45
              <td>Not yet</td>
46
            <?php endif ?>
47
        </tr>
48
      </table>
49
    </div>
50
  </td>
51
  <td class="icon context-menu-container">
52
    <div class="context-menu">
53
      <i class="fa fa-ellipsis-v"></i>
54
      <ul>
55
        <li>
56
          <a href="<?= getEditDocumentLink($request, $cmsPrefix, $path, $document) ?>">
57
            <i class="fa fa-pencil"></i>
58
            Edit
59
          </a>
60
        </li>
61
          <?php if ($document->state === 'unpublished' || $document->unpublishedChanges) : ?>
62
            <li>
63
              <a href="<?= getPublishDocumentLink($request, $cmsPrefix, $path, $document) ?>">
64
                <i class="fa fa-check"></i>
65
                Publish
66
              </a>
67
            </li>
68
          <?php endif ?>
69
          <?php if ($document->state === 'published') : ?>
70
            <li>
71
              <a href="<?= getUnpublishDocumentLink($request, $cmsPrefix, $path, $document) ?>">
72
                <i class="fa fa-times"></i>
73
                Unpublish
74
              </a>
75
            </li>
76
          <?php endif ?>
77
          <?php if ($document->state === 'unpublished') : ?>
78
            <li>
79
              <a href="<?= getDeleteDocumentLink($request, $cmsPrefix, $path, $document) ?>" onclick="return confirm('Are you sure you want to delete this document?');">
80
                <i class="fa fa-trash"></i>
81
                Delete
82
              </a>
83
            </li>
84
          <?php endif ?>
85
        <li>
86
          <a href="#" onclick="return showDocumentDetails(this);">
87
            <i class="fa fa-list-alt"></i>
88
            Details
89
          </a>
90
        </li>
91
      </ul>
92
    </div>
93
  </td>
94
<?php }
95
96
function getDocumentSlug($path, $document) {
97
    return substr($path, 1) . ($path === '/' ? '' : '/') . $document->slug;
98
}
99
100
function getEditDocumentLink($request, $cmsPrefix, $path, $document) {
101
    return $request::$subfolders . $cmsPrefix . '/documents/edit-document?slug=' . getDocumentSlug($path, $document);
102
}
103
104
function getDeleteDocumentLink($request, $cmsPrefix, $path, $document) {
105
    return $request::$subfolders . $cmsPrefix . '/documents/delete-document?slug=' . getDocumentSlug($path, $document);
106
}
107
108
function getPublishDocumentLink($request, $cmsPrefix, $path, $document) {
109
    return $request::$subfolders . $cmsPrefix . '/documents/publish-document?slug=' . getDocumentSlug($path, $document);
110
}
111
112
function getUnpublishDocumentLink($request, $cmsPrefix, $path, $document) {
113
    return $request::$subfolders . $cmsPrefix . '/documents/unpublish-document?slug=' . getDocumentSlug($path, $document);
114
}?>
115