1 <?php
2 class ZoteroEntry
3 {
4 	const AUTHOR_PLACEHOLDER = "AUTHOR";
5 	const TITLE_PLACEHOLDER = "TITLE";
6 	const DATE_PLACEHOLDER = "DATE";
7 
8 	private $zoteroId;
9 	private $citeKey;
10 	private $title;
11 	private $author;
12 	private $date;
13 
14 	public function __construct($zoteroId)
15 	{
16 		$this->zoteroId = $zoteroId;
17 	}
18 
19 	public function getZoteroId()
20 	{
21 		return $this->zoteroId;
22 	}
23 
24 	public function setCiteKey($value)
25 	{
26 		$this->citeKey = $value;
27 	}
28 
29 	public function getCiteKey()
30 	{
31 		return $this->citeKey;
32 	}
33 
34 	public function setTitle($value)
35 	{
36 		$this->title = $value;
37 	}
38 
39 	public function getTitle()
40 	{
41 		return $this->title;
42 	}
43 
44 	public function setAuthor($value)
45 	{
46 		$this->author = $value;
47 	}
48 
49 	public function getAuthor()
50 	{
51 		return $this->author;
52 	}
53 
54 	public function setDate($value)
55 	{
56 		$this->date = $value;
57 	}
58 
59 	public function getDate()
60 	{
61 		return $this->date;
62 	}
63 
64   	public function getYear()
65 	{
66 		$year = 0;
67 		$matches = array();
68 		if (preg_match("/([0-9]{4})/", $this->getDate(), $matches))
69 		{
70 			return $matches[1];
71 		}
72 		return $year;
73 	}
74 
75 	public function getShortInfo($format = "")
76 	{
77 		$date = $this->getYear();
78 		if ($date === 0)
79 		{
80 			$date = $this->getDate();
81 		}
82 
83 		if ($format == "")
84 		{
85 			return $this->getAuthor() . ": " . $this->getTitle() . " (" . $date . ")";
86 		}
87 		else
88 		{
89 			$title = str_replace(self::AUTHOR_PLACEHOLDER, $this->getAuthor(), $format);
90 			$title = str_replace(self::TITLE_PLACEHOLDER, $this->getTitle(), $title);
91 			$title = str_replace(self::DATE_PLACEHOLDER, $date, $title);
92 			return $title;
93 		}
94 	}
95 
96 	public function __toString()
97 	{
98 		return $this->getShortInfo();
99 	}
100 
101 	public function equals(ZoteroEntry $other)
102 	{
103 		return $this->getZoteroId() === $other->getZoteroId()
104 			&& $this->getCiteKey() === $other->getCiteKey()
105 			&& $this->getAuthor() === $other->getAuthor()
106 			&& $this->getDate() === $other->getDate()
107 			&& $this->getTitle() === $other->getTitle();
108 	}
109 }
110 ?>