This repository has been archived by the owner on Nov 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Chapter.php
executable file
·161 lines (151 loc) · 5.16 KB
/
Chapter.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
/**
* @version $Id$
* @author Brian Smith <[email protected]>
* @package ABS
*/
class ABS_Chapter extends ABS_Base {
/**
* The name of the XML element in the response that defines the object.
*
* @var string
*/
const XML_RESPONSE_ELEMENT = 'chapter';
function __construct(ABS_Api $api) {
parent::__construct($api, self::XML_RESPONSE_ELEMENT);
}
/*
* Method to return the appropriate URL ending based on the method being executed
*
* @param string $method
* @return string
* @throws ABS_Exception
*/
protected function getUrl($method) {
switch($method) {
case 'verses':
return implode('',array('chapters/',
$this->_version_id,
':',
$this->_book_id,
'.',
$this->_chapter,
'/verses.xml',
)
);
break;
case 'list':
return implode('',array('books/',
$this->_version_id,
':',
$this->_book_id,
'/chapters.xml'
)
);
break;
case 'show':
return implode('',array('chapters/',
$this->_version_id,
':',
$this->_book_id,
'.',
$this->_chapter,
'.xml'
)
);
break;
default:
throw new ABS_Exception('Invalid method ' . $method);
}
}
/*
* Use this if you have received a ChapterID from a previous api call to set the version, book and chapter.
*/
public function setFromReceivedChapterID($ID) {
if ( strpos( $ID, ':') !== false && strpos ( $ID, '.' ) !== false ) {
$parts = explode(':', $ID);
if ( count( $parts ) == 2 ) {
$this->_version_id = $parts[0];
$parts = explode('.', $parts[1]);
if ( count( $parts ) == 2 ) {
$this->_book_id = $parts[0];
$this->_chapter = 0 + $parts[1]; // Easy way to force this to be an int
}
elseif ( count ( $parts ) == 3 ) {
$this->_book_id = $parts[0].'.'.$parts[1];
$this->_chapter = 0 + $parts[2];
}
else {
throw new ABS_Exception( 'Invalid Chapter ID' . $ID );
}
}
else {
throw new ABS_Exception( 'Invalid Chapter ID' . $ID );
}
}
else {
throw new ABS_Exception( 'Invalid Chapter ID' . $ID );
}
}
/*
* Method to list all verses of a chapter of the Bible
*
* @return xml SimpleXML object
*/
public function verses($chapter = '') {
$this->__setXpath('chapter/verses/verse');
if (empty($this->_version_id) || is_null($this->_version_id)) {
throw new ABS_Exception('The Version cannot be null or empty');
}
if (empty($chapter)) {
if (empty($this->_chapter) || is_null($this->_chapter)) {
throw new ABS_Exception('The Chapter cannot be null or empty');
}
} else {
$this->setChapter($chapter);
}
if (empty($this->_book_id) || is_null($this->_book_id)) {
throw new ABS_Exception('The Book cannot be null or empty');
}
return $this->requestXml('verses');
}
/*
* Method to list a group of verses from a specific version, chapter, and book
*
* @return xml SimpleXML object
*/
public function references($chapter = '', $start = '', $end = '') {
$this->addParam('start',$start);
$this->addParam('end',$end);
return $this->verses($chapter);
}
/*
* Method to list all books of the Bible
*
* @return xml SimpleXML object
*/
public function listChapters($version = '', $book = '') {
if ( ! empty( $version ) ) {
$this->setVersion( $version );
}
if ( ! empty( $book ) ) {
$this->setBook( $book );
}
return $this->requestXml('list');
}
/*
* Method to list show the details of a specific Bookof the Bible
*
* @param string $book
* @return xml SimpleXML object
*/
public function show($chapter = '') {
$this->setChapter($chapter);
$this->__validateChapter();
$this->__validateBook();
$this->__validateVersion();
$this->setChapter($chapter);
$xml = $this->requestXml('show');
return $xml;
}
}