1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace MySociety\TheyWorkForYou\DataClass\Regmem; |
6
|
|
|
|
7
|
|
|
use MySociety\TheyWorkForYou\DataClass\BaseModel; |
8
|
|
|
|
9
|
|
|
class InfoEntry extends BaseModel { |
10
|
|
|
public ?string $id = null; |
11
|
|
|
public ?string $comparable_id = null; |
12
|
|
|
public string $item_hash; |
13
|
|
|
public string $content = ""; |
14
|
|
|
public string $content_format = "string"; |
15
|
|
|
public string $info_type = "entry"; |
16
|
|
|
public bool $null_entry = false; |
17
|
|
|
public ?string $date_registered = null; |
18
|
|
|
public ?string $date_published = null; |
19
|
|
|
public ?string $date_updated = null; |
20
|
|
|
public ?string $date_received = null; |
21
|
|
|
public ?AnnotationList $annotations = null; |
22
|
|
|
public ?DetailGroup $details = null; |
23
|
|
|
public ?EntryList $sub_entries = null; |
24
|
|
|
|
25
|
|
|
public function isNew(string $register_date): ?bool { |
26
|
|
|
// This is for flagging new entries in a given register |
27
|
|
|
// if we can't know, return None |
28
|
|
|
|
29
|
|
|
// if there are sub_entries, check them first and return a true if we find one |
30
|
|
|
if ($this->sub_entries !== null) { |
31
|
|
|
foreach ($this->sub_entries as $sub_entry) { |
32
|
|
|
if ($sub_entry->isNew($register_date)) { |
33
|
|
|
return true; |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
$latest_date = $this->date_published ?? $this->date_updated; |
39
|
|
|
if ($latest_date === null) { |
40
|
|
|
return null; |
41
|
|
|
} |
42
|
|
|
$latest_date = new \DateTime($latest_date); |
43
|
|
|
$register_date = new \DateTime($register_date); |
44
|
|
|
$diff = $register_date->diff($latest_date); |
45
|
|
|
return $diff->days <= 14; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function hasEntries(): bool { |
49
|
|
|
return $this->sub_entries !== null && ($this->sub_entries->isEmpty() === false); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function hasDetails(): bool { |
53
|
|
|
return $this->details !== null && ($this->details->isEmpty() === false); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function hasEntryOrDetail(): bool { |
57
|
|
|
return $this->hasEntries() || $this->hasDetails(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function get_detail(string $slug): ?Detail { |
61
|
|
|
// given a slug, return the detail object |
62
|
|
|
foreach ($this->details as $detail) { |
63
|
|
|
if ($detail->slug === $slug) { |
64
|
|
|
return $detail; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
return null; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
} |
71
|
|
|
|