= 5. * No error handling is performed; all expected XML nodes must be present. * @author James Ide * @version 1.0 */ class Member { // all instance variables are declared public for easy access public $number; public $name; public $year; public $major; public $semesterJoined; public $gcSemesters; public $projects = array(); public $biography; public $quote; public $cited; public $favoriteGame; public $favoriteIceCream; public $after; public $normalPhoto; public $normalPhotoFullSize; public $crazyPhoto; public $crazyPhotoFullSize; /** * Constructs a Member object that represents a member of GamesCrafters. * To load a Member from an XML file, a pathname pointing to the data file * may be specified. */ public function __construct($xmlFile = null, $photoPrefix = '') { // try to create a SimpleXMLElement object from the XML file if(($xmlFile != null) && ($member = simplexml_load_file($xmlFile))) { // populate the member's properties $attr = $member->attributes(); $this->number = (string)$attr['number']; $this->name = (string)$attr['name']; $this->year = (string)$member->year[0]; $this->major = (string)$member->major[0]; $this->semesterJoined = (string)$member->{'semester-joined'}[0]; $this->gcSemesters = (string)$member->{'gc-semesters'}[0]; foreach($member->projects[0]->project as $project) { $this->projects[] = (string)$project; } $this->biography = (string)$member->biography[0]; $this->quote = (string)$member->quote[0]; if ($member->quote[0]) { $attr = $member->quote[0]->attributes(); $this->cited = (string)$attr['cite']; } $this->favoriteGame = (string)$member->{'favorite-game'}[0]; $this->favoriteIceCream = (string)$member->{'favorite-ice-cream'}[0]; $this->after = (string)$member->{'after'}[0]; $this->normalPhoto = (string)$member->photographs[0]->normal[0]; $this->normalPhotoFullSize = (string)$member->photographs[0]->{'normal-fullsize'}[0]; $this->crazyPhoto = (string)$member->photographs[0]->crazy[0]; $this->crazyPhotoFullSize = (string)$member->photographs[0]->{'crazy-fullsize'}[0]; foreach($this as $var => $value) { if (empty($this->$var)) { if (strpos($var, 'Photo')) { $this->$var = 'alumni/OX.jpg'; } else { $this->$var = 'N/A'; } } if (strpos($var, 'Photo')) { $this->$var = $photoPrefix.$this->$var; } } } } public static function compare(Member $a, Member $b) { return $a->number - $b->number; } } ?>