/
AtomSourceAdapter.php
125 lines (103 loc) · 3.55 KB
/
AtomSourceAdapter.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
require_once 'ExtensibleAtomAdapter.php';
require_once 'SimpleAtomAdapter.php';
require_once 'AtomTextConstructAdapter.php';
require_once 'AtomLinkAdapter.php';
require_once 'AtomPersonConstructAdapter.php';
require_once 'AtomDateConstructAdapter.php';
require_once 'AtomCategoryAdapter.php';
class AtomSourceAdapter extends ExtensibleAtomAdapter {
protected $_author;
protected $_category;
protected $_id;
protected $_link;
protected $_title;
protected $_updated;
public function addAuthor() {
$newAuthor = $this->_addElement(AtomNS::NAMESPACE, AtomNS::AUTHOR_ELEMENT);
return $this->_author[] = new AtomPersonConstructAdapter(AtomNS::AUTHOR_ELEMENT, $newAuthor);
}
public function addCategory() {
$newCategory = $this->_addElement(AtomNS::NAMESPACE, AtomNS::CATEGORY_ELEMENT);
return $this->_category[] = new AtomCategoryAdapter($newCategory);
}
public function addLink() {
$newLink = $this->_addElement(AtomNS::NAMESPACE, AtomNS::LINK_ELEMENT);
return $this->_link[] = new AtomLinkAdapter($newLink);
}
public function getAuthor() {
return $this->_author;
}
public function getCategory() {
return $this->_category;
}
public function getId() {
return $this->_id;
}
public function getLink() {
return $this->_link;
}
public function getTitle() {
return $this->_title;
}
public function getUpdated() {
return $this->_updated;
}
public function setId($value) {
if (!isset($this->_id)) {
$id = $this->_addElement(AtomNS::NAMESPACE, AtomNS::ID_ELEMENT, $value);
$this->_id = new SimpleAtomAdapter(AtomNS::ID_ELEMENT, $id);
return;
}
$this->_id->value = $value;
}
public function setTitle($value) {
if (!isset($this->_title)) {
$title = $this->_addElement(AtomNS::NAMESPACE, AtomNS::TITLE_ELEMENT, $value);
$this->_title = new AtomTextConstructAdapter(AtomNS::TITLE_ELEMENT, $title);
return;
}
$this->_title->value = $value;
}
public function setUpdated($value) {
if (!isset($this->_updated)) {
$updated = $this->_addElement(AtomNS::NAMESPACE, AtomNS::UPDATED_ELEMENT, $value);
$this->_updated = new AtomDateConstructAdapter(AtomNS::UPDATED_ELEMENT, $updated);
return;
}
$this->_updated->value = $value;
}
public function __construct($adapterType, $data, $data_is_url=false) {
parent::__construct($adapterType, $data, $data_is_url);
$this->_init();
}
protected function _init() {
if (isset($this->_element[AtomNS::TITLE_ELEMENT][0])) {
$this->_title = new AtomTextConstructAdapter(AtomNS::TITLE_ELEMENT, $this->_element[AtomNS::TITLE_ELEMENT][0]);
}
if (isset($this->_element[AtomNS::ID_ELEMENT][0])) {
$this->_id = new SimpleAtomAdapter(AtomNS::ID_ELEMENT, $this->_element[AtomNS::ID_ELEMENT][0]);
}
$this->_link = array();
if (isset($this->_element[AtomNS::LINK_ELEMENT])) {
foreach ($this->_element[AtomNS::LINK_ELEMENT] as $link) {
$this->_link[] = new AtomLinkAdapter($link);
}
}
$this->_category = array();
if (isset($this->_element[AtomNS::CATEGORY_ELEMENT])) {
foreach ($this->_element[AtomNS::CATEGORY_ELEMENT] as $category) {
$this->_category[] = new AtomCategoryAdapter($category);
}
}
$this->_author = array();
if (isset($this->_element[AtomNS::AUTHOR_ELEMENT])) {
foreach ($this->_element[AtomNS::AUTHOR_ELEMENT] as $author) {
$this->_author[] = new AtomPersonConstructAdapter(AtomNS::AUTHOR_ELEMENT, $author);
}
}
if (isset($this->_element[AtomNS::UPDATED_ELEMENT][0])) {
$this->_updated = new AtomDateConstructAdapter(AtomNS::UPDATED_ELEMENT,$this->_element[AtomNS::UPDATED_ELEMENT][0]);
}
}
}