~cypheon/nextcloud-chores-app

ref: d19a6603c01e63c7545582e5ff313ef4aec0bf9f nextcloud-chores-app/lib/Db/WorklogItem.php -rw-r--r-- 2.1 KiB
d19a6603 — Johann Rudloff Make overdue sidebar badge dynamic, switch badges to `CounterBubble` component 10 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
namespace OCA\Chores\Db;

use DateTimeImmutable;
use JsonSerializable;

use OCP\AppFramework\Db\Entity;

class WorklogItem extends Entity implements JsonSerializable {

  protected $teamId;
  protected $choreId;
  protected $doneTimestamp;
  protected $submitTimestamp;
  protected $memberUid;
  protected $name;
  protected $points;

  public function __construct() {
    $this->addType('id', 'string');
    $this->addType('teamId', 'integer');
    $this->addType('choreId', 'integer');
    $this->addType('doneTimestamp', 'datetimetz_immutable');
    $this->addType('submitTimestamp', 'datetimetz_immutable');
    $this->addType('memberUid', 'string');
    $this->addType('name', 'string');
    $this->addType('points', 'integer');
  }

  public function getSubmitTimestamp(): string {
    return $this->getSubmitTimestampDate()->format("c");
  }

  public function setSubmitTimestamp(string $submitTimestampStr) {
    $this->submitTimestamp = new DateTimeImmutable($submitTimestampStr);
    $this->markFieldUpdated("submitTimestamp");
  }

  public function getSubmitTimestampDate(): DateTimeImmutable {
    return $this->submitTimestamp;
  }

  public function setSubmitTimestampDate(DateTimeImmutable $submitTimestampDate) {
    $this->submitTimestamp = $submitTimestampDate;
    $this->markFieldUpdated("submitTimestamp");
  }

  public function getDoneTimestamp(): string {
    return $this->getDoneTimestampDate()->format("c");
  }

  public function setDoneTimestamp(string $doneTimestampStr) {
    $this->doneTimestamp = new DateTimeImmutable($doneTimestampStr);
    $this->markFieldUpdated("doneTimestamp");
  }

  public function getDoneTimestampDate(): DateTimeImmutable {
    return $this->doneTimestamp;
  }

  public function setDoneTimestampDate(DateTimeImmutable $doneTimestampDate) {
    $this->doneTimestamp = $doneTimestampDate;
    $this->markFieldUpdated("doneTimestamp");
  }


  public function jsonSerialize() {
    return [
      'id' => $this->id,
      'member' => $this->memberUid,
      'work_time' => $this->getDoneTimestamp(),
      'submit_time' => $this->getSubmitTimestamp(),
      'name' => $this->name,
      'points' => $this->points,
    ];
  }
}