@@ -485,4 +485,115 @@ public function refresh() {
485
485
return false ;
486
486
}
487
487
488
+ public function save () {
489
+ if (!isset (Common::$ database )) {
490
+ Common::$ database = DatabaseDriver::getDatabaseObject ();
491
+ }
492
+ try {
493
+ $ stmt = Common::$ database ->prepare ("
494
+ UPDATE
495
+ `packets`
496
+ SET
497
+ `created_datetime` = :created_dt,
498
+ `edited_count` = :edited_count,
499
+ `edited_datetime` = :edited_dt,
500
+ `options_bitmask` = :options,
501
+ `packet_application_layer_id` = :application_layer_id,
502
+ `packet_direction_id` = :direction_id,
503
+ `packet_format` = :format,
504
+ `packet_name` = :name,
505
+ `packet_remarks` = :remarks,
506
+ `packet_transport_layer_id` = :transport_layer_id,
507
+ `user_id` = :user_id
508
+ WHERE
509
+ `id` = :id
510
+ LIMIT 1;
511
+ " );
512
+ $ stmt ->bindParam (
513
+ ":application_layer_id " , $ this ->packet_application_layer_id ,
514
+ PDO ::PARAM_INT
515
+ );
516
+ $ stmt ->bindParam (":created_dt " , $ this ->created_datetime , PDO ::PARAM_INT );
517
+ $ stmt ->bindParam (":edited_count " , $ this ->edited_count , PDO ::PARAM_INT );
518
+ $ stmt ->bindParam (":edited_dt " , $ this ->edited_datetime , PDO ::PARAM_INT );
519
+ $ stmt ->bindParam (
520
+ ":direction_id " , $ this ->packet_direction_id , PDO ::PARAM_INT
521
+ );
522
+ $ stmt ->bindParam (":format " , $ this ->packet_format , PDO ::PARAM_STR );
523
+ $ stmt ->bindParam (":id " , $ this ->id , PDO ::PARAM_INT );
524
+ $ stmt ->bindParam (":name " , $ this ->packet_name , PDO ::PARAM_STR );
525
+ $ stmt ->bindParam (":options " , $ this ->options_bitmask , PDO ::PARAM_INT );
526
+ $ stmt ->bindParam (":remarks " , $ this ->packet_remarks , PDO ::PARAM_STR );
527
+ $ stmt ->bindParam (
528
+ ":transport_layer_id " , $ this ->packet_transport_layer_id ,
529
+ PDO ::PARAM_INT
530
+ );
531
+ $ stmt ->bindParam (":user_id " , $ this ->user_id , PDO ::PARAM_INT );
532
+ if (!$ stmt ->execute ()) {
533
+ throw new QueryException ("Cannot save document " );
534
+ }
535
+ $ stmt ->closeCursor ();
536
+
537
+ $ object = new StdClass ();
538
+ $ object ->created_datetime = $ this ->created_datetime ;
539
+ $ object ->edited_count = $ this ->edited_count ;
540
+ $ object ->edited_datetime = $ this ->edited_datetime ;
541
+ $ object ->id = $ this ->id ;
542
+ $ object ->options_bitmask = $ this ->options_bitmask ;
543
+ $ object ->packet_application_layer_id = $ this ->packet_application_layer_id ;
544
+ $ object ->packet_direction_id = $ this ->packet_direction_id ;
545
+ $ object ->packet_format = $ this ->packet_format ;
546
+ $ object ->packet_id = $ this ->packet_id ;
547
+ $ object ->packet_name = $ this ->packet_name ;
548
+ $ object ->packet_remarks = $ this ->packet_remarks ;
549
+ $ object ->packet_transport_layer_id = $ this ->packet_transport_layer_id ;
550
+ $ object ->user_id = $ this ->user_id ;
551
+
552
+ $ cache_key = "bnetdocs-packet- " . $ this ->id ;
553
+ Common::$ cache ->set ($ cache_key , serialize ($ object ), 300 );
554
+ Common::$ cache ->delete ("bnetdocs-packets " );
555
+
556
+ return true ;
557
+ } catch (PDOException $ e ) {
558
+ throw new QueryException ("Cannot save packet " , $ e );
559
+ }
560
+ return false ;
561
+ }
562
+
563
+ public function setEditedCount ($ value ) {
564
+ $ this ->edited_count = $ value ;
565
+ }
566
+
567
+ public function setEditedDateTime (\DateTime $ value ) {
568
+ $ this ->edited_datetime = $ value ->format ("Y-m-d H:i:s " );
569
+ }
570
+
571
+ public function setMarkdown ($ value ) {
572
+ if ($ value ) {
573
+ $ this ->options_bitmask |= self ::OPTION_MARKDOWN ;
574
+ } else {
575
+ $ this ->options_bitmask &= ~self ::OPTION_MARKDOWN ;
576
+ }
577
+ }
578
+
579
+ public function setPacketFormat ($ value ) {
580
+ $ this ->packet_format = $ value ;
581
+ }
582
+
583
+ public function setPacketName ($ value ) {
584
+ $ this ->packet_name = $ value ;
585
+ }
586
+
587
+ public function setPacketRemarks ($ value ) {
588
+ $ this ->packet_remarks = $ value ;
589
+ }
590
+
591
+ public function setPublished ($ value ) {
592
+ if ($ value ) {
593
+ $ this ->options_bitmask |= self ::OPTION_PUBLISHED ;
594
+ } else {
595
+ $ this ->options_bitmask &= ~self ::OPTION_PUBLISHED ;
596
+ }
597
+ }
598
+
488
599
}
0 commit comments