<?php /*PLEASE DO NOT EDIT THIS CODE*/ /*This code was generated using the UMPLE 1.35.0.7523.c616a4dce modeling language!*/ class Mentor { //------------------------ // MEMBER VARIABLES //------------------------ //Mentor Attributes private $name; //Mentor Associations private $students; //------------------------ // CONSTRUCTOR //------------------------ public function __construct($aName, $allStudents) { $this->name = $aName; $this->students = array(); $didAddStudents = $this->setStudents($allStudents); if (!$didAddStudents) { throw new Exception("Unable to create Mentor, must have 3 students. See https://manual.umple.org?RE002ViolationofAssociationMultiplicity.html"); } } //------------------------ // INTERFACE //------------------------ public function setName($aName) { $wasSet = false; $this->name = $aName; $wasSet = true; return $wasSet; } public function getName() { return $this->name; } public function getStudent_index($index) { $aStudent = $this->students[$index]; return $aStudent; } public function getStudents() { $newStudents = $this->students; return $newStudents; } public function numberOfStudents() { $number = count($this->students); return $number; } public function hasStudents() { $has = $this->numberOfStudents() > 0; return $has; } public function indexOfStudent($aStudent) { $wasFound = false; $index = 0; foreach($this->students as $student) { if ($student->equals($aStudent)) { $wasFound = true; break; } $index += 1; } $index = $wasFound ? $index : -1; return $index; } public static function requiredNumberOfStudents() { return 3; } public static function minimumNumberOfStudents() { return 3; } public static function maximumNumberOfStudents() { return 3; } public function setStudents($newStudents) { $wasSet = false; $checkNewStudents = array(); foreach ($newStudents as $aStudent) { if (array_search($aStudent,$checkNewStudents) !== false) { return $wasSet; } else if ($aStudent->getMentor() != null && $this !== $aStudent->getMentor()) { return $wasSet; } $checkNewStudents[] = $aStudent; } if (count($checkNewStudents) != self::minimumNumberOfStudents()) { return $wasSet; } foreach ($this->students as $orphan) { $wasFound = false; foreach ($checkNewStudents as $fosterCare) { if ($orphan == $fosterCare) { $wasFound = true; break; } } if (!$wasFound) { $this->setMentor($orphan, null); } } $this->students = array(); foreach ($newStudents as $aStudent) { $this->setMentor($aStudent, $this); $this->students[] = $aStudent; } $wasSet = true; return $wasSet; } private function setMentor($aStudent, $aMentor) { $aStudent->mentor = $aMentor; //$prop = new ReflectionProperty($aStudent, 'mentor'); //$prop->setAccessible(true); //$prop->setValue($aStudent,$aMentor); //$prop->setAccessible(false); } public function equals($compareTo) { return $this == $compareTo; } public function delete() { foreach ($this->students as $aStudent) { $this->setMentor($aStudent,null); } $this->students = array(); } } ?> <?php /*PLEASE DO NOT EDIT THIS CODE*/ /*This code was generated using the UMPLE 1.35.0.7523.c616a4dce modeling language!*/ class Student { //------------------------ // MEMBER VARIABLES //------------------------ //Student Attributes private $number; //Student Associations public $mentor; //until PHP 5.3 (setAccessible) //------------------------ // CONSTRUCTOR //------------------------ public function __construct($aNumber) { $this->number = $aNumber; } //------------------------ // INTERFACE //------------------------ public function setNumber($aNumber) { $wasSet = false; $this->number = $aNumber; $wasSet = true; return $wasSet; } public function getNumber() { return $this->number; } public function getMentor() { return $this->mentor; } public function hasMentor() { $has = $this->mentor != null; return $has; } public function equals($compareTo) { return $this == $compareTo; } public function delete() { if ($this->mentor != null) { $this->mentor->delete(); } } } ?>