Skip to content

Commit 79d1593

Browse files
committed
Add recently edited documents/packets to site nav
1 parent 4c77cef commit 79d1593

File tree

3 files changed

+111
-10
lines changed

3 files changed

+111
-10
lines changed

src/libraries/Document.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,45 @@ public static function getAllDocuments( $order = null ) {
141141
return null;
142142
}
143143

144+
public static function getDocumentsByLastEdited(int $count)
145+
{
146+
if (!isset(Common::$database))
147+
{
148+
Common::$database = DatabaseDriver::getDatabaseObject();
149+
}
150+
151+
$stmt = Common::$database->prepare(
152+
'SELECT
153+
`content`,
154+
`created_datetime`,
155+
`edited_count`,
156+
`edited_datetime`,
157+
`id`,
158+
`options_bitmask`,
159+
`title`,
160+
`user_id`
161+
FROM `documents`
162+
ORDER BY IFNULL(`edited_datetime`, `created_datetime`) DESC
163+
LIMIT ' . $count . ';'
164+
);
165+
166+
$r = $stmt->execute();
167+
if (!$r)
168+
{
169+
throw new QueryException('Cannot refresh documents');
170+
return $r;
171+
}
172+
173+
$r = [];
174+
while ($row = $stmt->fetch(PDO::FETCH_OBJ))
175+
{
176+
$r[] = new self($row);
177+
}
178+
179+
$stmt->closeCursor();
180+
return $r;
181+
}
182+
144183
public function getContent($prepare) {
145184
if (!$prepare) {
146185
return $this->content;

src/libraries/Packet.php

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
class Packet implements JsonSerializable {
2323

24+
const DATE_SQL = 'Y-m-d H:i:s';
25+
2426
const DIRECTION_CLIENT_SERVER = 1;
2527
const DIRECTION_SERVER_CLIENT = 2;
2628
const DIRECTION_PEER_TO_PEER = 3;
@@ -172,6 +174,49 @@ public static function &getAllPackets(
172174
return null;
173175
}
174176

177+
public static function getPacketsByLastEdited(int $count)
178+
{
179+
if (!isset(Common::$database))
180+
{
181+
Common::$database = DatabaseDriver::getDatabaseObject();
182+
}
183+
184+
$stmt = Common::$database->prepare('
185+
SELECT `created_datetime`,
186+
`edited_count`,
187+
`edited_datetime`,
188+
`id`,
189+
`options_bitmask`,
190+
`packet_application_layer_id`,
191+
`packet_direction_id`,
192+
`packet_format`,
193+
`packet_id`,
194+
`packet_name`,
195+
`packet_remarks`,
196+
`packet_transport_layer_id`,
197+
`user_id`
198+
FROM `packets`
199+
ORDER BY IFNULL(`edited_datetime`, `created_datetime`) DESC
200+
LIMIT ' . $count . '
201+
');
202+
203+
$r = $stmt->execute();
204+
if (!$r)
205+
{
206+
throw new QueryException('Cannot get packets by date');
207+
return $r;
208+
}
209+
210+
$r = [];
211+
while ($row = $stmt->fetch(PDO::FETCH_OBJ))
212+
{
213+
$r[] = new self($row);
214+
}
215+
216+
$stmt->closeCursor();
217+
return $r;
218+
}
219+
175220
public static function getAllPacketsBySearch($query) {
176221

177222
if ( !isset( Common::$database )) {
@@ -257,6 +302,14 @@ public function getId() {
257302
return $this->id;
258303
}
259304

305+
public function getName() {
306+
return sprintf('%s %s %s',
307+
$this->getPacketDirectionTag(),
308+
$this->getPacketId(true),
309+
$this->getPacketName()
310+
);
311+
}
312+
260313
public function getOptionsBitmask() {
261314
return $this->options_bitmask;
262315
}
@@ -614,8 +667,9 @@ public function setEditedCount( $value ) {
614667
$this->edited_count = $value;
615668
}
616669

617-
public function setEditedDateTime( DateTime $value ) {
618-
$this->edited_datetime = $value->format( 'Y-m-d H:i:s' );
670+
public function setEditedDateTime(DateTime $value)
671+
{
672+
$this->edited_datetime = $value->format(self::DATE_SQL);
619673
}
620674

621675
public function setInResearch( $value ) {

src/templates/header.inc.phtml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace BNETDocs\Templates;
33
use \BNETDocs\Libraries\Authentication;
44
use \BNETDocs\Libraries\Document;
55
use \BNETDocs\Libraries\Logger;
6+
use \BNETDocs\Libraries\Packet;
67
use \BNETDocs\Libraries\User;
78
use \BNETDocs\Libraries\VersionInfo;
89
use \CarlBennett\MVC\Libraries\Common;
@@ -37,7 +38,8 @@ if (isset(Authentication::$user))
3738
$_header_user_url = null;
3839
$_header_staff = null;
3940
}
40-
$_header_documents = Document::getAllDocuments(['title', 'ASC']);
41+
$_header_documents = Document::getDocumentsByLastEdited(10);
42+
$_header_packets = Packet::getPacketsByLastEdited(10);
4143
$_header_navigation_config = Common::$config->bnetdocs->navigation;
4244
$_header_user_register_disabled = Common::$config->bnetdocs->user_register_disabled;
4345
$_unique_asset = (
@@ -128,27 +130,33 @@ $_campaign_vultr = (
128130
</li>
129131
<? } ?>
130132
<li class="nav-item<?=_header_active('/document/', false)?> dropdown">
131-
<a class="nav-link dropdown-toggle" href="#" id="navbarObjectsDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Documents</a>
132-
<div class="dropdown-menu" aria-labelledby="navbarObjectsDropdown">
133+
<a class="nav-link dropdown-toggle" href="#" id="navbarDocumentsDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Documents</a>
134+
<div class="dropdown-menu" aria-labelledby="navbarDocumentsDropdown">
133135
<a class="dropdown-item<?=_header_active('/document/index', false)?> text-info" href="<?=Common::relativeUrlToAbsolute('/document/index')?>">All Documents<?=_header_active('/document/index', true)?></a>
134136
<? if ($_header_staff) { ?>
135137
<div class="dropdown-divider"></div>
136138
<a class="dropdown-item<?=_header_active('/document/create', false)?> text-success" href="<?=Common::relativeUrlToAbsolute('/document/create')?>">Create Document<?=_header_active('/document/create', true)?></a>
137139
<div class="dropdown-divider"></div>
138-
<? }
139-
foreach ($_header_documents as $doc) { $doc_url_part = '/document/' . $doc->getId(); ?>
140-
<a class="dropdown-item<?=_header_active($doc_url_part, false)?>" href="<?=Common::relativeUrlToAbsolute($doc->getURI())?>"><?=filter_var($doc->getTitle(), FILTER_SANITIZE_FULL_SPECIAL_CHARS)?><?=_header_active($doc_url_part, true)?></a>
140+
<? }?>
141+
<div class="dropdown-header">Recently Edited Documents</div>
142+
<? foreach ($_header_documents as $doc) { $doc_url_part = '/document/' . $doc->getId(); ?>
143+
<a class="dropdown-item<?=_header_active($doc_url_part, false)?>" href="<?=$doc->getURI()?>"><?=filter_var($doc->getTitle(), FILTER_SANITIZE_FULL_SPECIAL_CHARS)?><?=_header_active($doc_url_part, true)?></a>
141144
<? } ?>
142145
</div>
143146
</li>
144147
<li class="nav-item<?=_header_active('/packet/', false)?> dropdown">
145-
<a class="nav-link dropdown-toggle" href="#" id="navbarObjectsDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Packets</a>
146-
<div class="dropdown-menu" aria-labelledby="navbarObjectsDropdown">
148+
<a class="nav-link dropdown-toggle" href="#" id="navbarPacketsDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Packets</a>
149+
<div class="dropdown-menu" aria-labelledby="navbarPacketsDropdown">
147150
<a class="dropdown-item<?=_header_active('/packet/index', false)?> text-info" href="<?=Common::relativeUrlToAbsolute('/packet/index')?>">All Packets<?=_header_active('/packet/index', true)?></a>
148151
<? if ($_header_staff) { ?>
149152
<div class="dropdown-divider"></div>
150153
<a class="dropdown-item<?=_header_active('/packet/create', false)?> text-success" href="<?=Common::relativeUrlToAbsolute('/packet/create')?>">Create Packet<?=_header_active('/packet/create', true)?></a>
154+
<div class="dropdown-divider"></div>
151155
<? }?>
156+
<div class="dropdown-header">Recently Edited Packets</div>
157+
<? foreach ($_header_packets as $pkt) { $pkt_url_part = '/packet/' . $pkt->getId(); ?>
158+
<a class="dropdown-item<?=_header_active($pkt_url_part, false)?>" href="<?=$pkt->getURI()?>"><?=filter_var($pkt->getName(), FILTER_SANITIZE_FULL_SPECIAL_CHARS)?><?=_header_active($pkt_url_part, true)?></a>
159+
<? } ?>
152160
</div>
153161
</li>
154162
</ul>

0 commit comments

Comments
 (0)