This repository has been archived by the owner on Nov 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
poll.model.php
89 lines (71 loc) · 2.37 KB
/
poll.model.php
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
78
79
80
81
82
83
84
85
86
87
88
89
<?php
class Poll {
private $id = '';
private $adminId = '';
private $title = '';
private $details = '';
private $changed = '';
private $dates = array();
private $entries = array();
private $comments = array();
function __construct($id, $adminId, $title, $details, $changed) {
$this->id = $id ? $id : $this->id;
$this->adminId = $adminId ? $adminId : $this->adminId;
$this->title = $title ? $title : $this->title;
$this->details = $details ? $details : $this->details;
$this->changed = $changed ? $changed : $this->changed;
}
//// GETTERS ////
function getId(){ return $this->id; }
function getAdminId(){ return $this->adminId; }
function getTitle(){ return $this->title; }
function getDetails(){ return $this->details; }
function getChanged(){ return $this->changed; }
function getEntries(){ return $this->entries; }
function getComments(){ return $this->comments; }
function getDates(){ return $this->dates; }
function getDatesForDisplay(){
$preparedDates = array();
//sort by "sort"
usort($this->dates, function($a, $b) {
return $a["sort"] - $b["sort"];
});
$count = 0;
foreach ($this->dates as $date) {
$preparedDates[$count++] = array(
"date" => $date["date"],
"yes" => 0,
"maybe" => 0,
"no" => 0,
"total" => 0
);
}
return $preparedDates;
}
//// SETTERS ////
function setTitle($title){
$this->title = $title;
}
function setDetails($details){
$this->details = $details;
}
function setChanged($changed){
$this->changed = $changed;
}
function setDates($dates){
$this->dates = $dates;
}
function setEntries($entries){
$this->entries = array();
foreach ($entries as $entry) {
if (!isset($entry["name"])){
$this->entries[$entry["name"]] = array();
}
$this->entries[$entry["name"]][$entry["date"]] = $entry["value"];
}
}
function setComments($comments){
$this->comments = $comments;
}
}
?>