-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserParse.class.php
More file actions
77 lines (71 loc) · 2.19 KB
/
Copy pathUserParse.class.php
File metadata and controls
77 lines (71 loc) · 2.19 KB
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
<?php
require_once("BooksParse.class.php");
/**
* Class dedicated to parsing the userdata xml.
*/
class UserParse
{
private $username;
private $fullname;
private $books;
private $image;
private $numbooks;
private $color;
private $domdoc;
/**
* Create a UserParse instance
*/
public function __construct( $username )
{
$this->domdoc = new DomDocument;
$this->domdoc->load('users.xml');
$users = $this->domdoc->getElementsByTagName('user');
foreach($users as $user)
{
if($user->getElementsByTagName("username")->item(0)->nodeValue == $username)
{
$this->username = $username;
$this->fullname = $user->getElementsByTagName("name")->item(0)->nodeValue;
$this->books = $user->getElementsByTagName("books")->item(0)->nodeValue;
$this->image = $user->getElementsByTagName("pic")->item(0)->nodeValue;
$this->color = $user->getElementsByTagName("color")->item(0)->nodeValue;
}
}
}
/**
* Return user image.
*/
public function get_image()
{
return "<img src='".$this->image."' style='border-color:". $this->color." ' />";
}
/**
* Return user's fullname
*/
public function get_fullname()
{
return $this->fullname;
}
/**
* Get user's book list
*/
public function get_booklist()
{
$mybooks = new BooksParse("bookdata/".$this->username.".xml");
return $mybooks->display_books(3);
}
/**
* Get user's number of books.
*/
public function get_numbooks(){
$mybooks = new BooksParse("bookdata/".$this->username.".xml");
return $mybooks->get_numBooks();
}
/**
* Retrieve the user's color preference.
*/
public function get_color(){
return $this->color;
}
}
?>