-
Notifications
You must be signed in to change notification settings - Fork 4
/
Article.php
84 lines (66 loc) · 1.6 KB
/
Article.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
<?php
namespace akademija;
class Article{
protected $title;
protected $price;
protected $anotation;
protected $date;
protected $state;
protected $bids = array();
public function __construct($title, $price, $anotation, $date){
$this->title = $title;
$this->price = $price;
$this->anotation = $anotation;
$this->date = $date;
$this->state = true;
}
public function getTitle(){
return $this->title;
}
public function setTitle($newTitle){
$this->title = $newTitle;
}
public function getPrice(){
return $this->price;
}
public function setPrice($newPrice){
$this->price = $newPrice;
}
public function getDate(){
return $this->date;
}
//get date from string as timestamp for precision
public function getDateAsTimestamp(){
$timestamp = strtotime($this->date);
return $timestamp;
}
public function setDate($newDate){
$this->date = $newDate;
}
public function getAnotation(){
return $this->anotation;
}
public function setAnotation($newAnotation){
$this->anotation = $newAnotation;
}
public function addBid(Bid $bid){
$this->bids[] = $bid;
}
public function getBids(){
return $this->bids;
}
//custom compare function for sorting by date, descending order
public function compareByDate($a, $b) {
if($a->getDateAsTimestamp()==$b->getDateAsTimestamp()) return 0;
return $a->getDateAsTimestamp() < $b->getDateAsTimestamp()?1:-1;
}
//sort bids by date
public function sortBids(){
echo "sort";
usort($this->bids, array($this, "compareByDate"));
return $this->bids;
}
public function changeState($state){
$this->state = $state;
}
}