<?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
  private $mentor;

  //------------------------
  // CONSTRUCTOR
  //------------------------

  public function __construct($aNumber, $aMentor)
  {
    $this->number = $aNumber;
    $didAddMentor = $this->setMentor($aMentor);
    if (!$didAddMentor)
    {
      throw new Exception("Unable to create student due to mentor. See https://manual.umple.org?RE002ViolationofAssociationMultiplicity.html");
    }
  }

  //------------------------
  // 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 setMentor($aNewMentor)
  {
    $wasSet = false;
    if ($aNewMentor == null)
    {
      //Unable to setMentor to null, as student must always be associated to a mentor
      return $wasSet;
    }
    
    $existingStudent = $aNewMentor->getStudent();
    if ($existingStudent != null && $this != $existingStudent)
    {
      //Unable to setMentor, the current mentor already has a student, which would be orphaned if it were re-assigned
      return $wasSet;
    }
    
    $anOldMentor = $this->mentor;
    $this->mentor = $aNewMentor;
    $this->mentor->setStudent($this);
    
    if ($anOldMentor != null)
    {
      $anOldMentor->setStudent(null);
    }
    $wasSet = true;
    return $wasSet;
  }

  public function equals($compareTo)
  {
    return $this == $compareTo;
  }

  public function delete()
  {
    $existingMentor = $this->mentor;
    $this->mentor = null;
    if ($existingMentor != null)
    {
      $existingMentor->setStudent(null);
    }
  }

}
?>
<?php
/*PLEASE DO NOT EDIT THIS CODE*/
/*This code was generated using the UMPLE 1.35.0.7523.c616a4dce modeling language!*/

class Mentor
{

  //------------------------
  // STATIC VARIABLES
  //------------------------

  private static $theInstance = null;

  //------------------------
  // MEMBER VARIABLES
  //------------------------

  //Mentor Attributes
  private $name;

  //Mentor Associations
  public $student; //until PHP 5.3 (setAccessible)

  //------------------------
  // CONSTRUCTOR
  //------------------------

  private function __construct()
  {
    $this->name = NULL;
  }

  public static function getInstance()
  {
    if(self::$theInstance == null)
    {
      self::$theInstance = new Mentor();
    }
    return self::$theInstance;
  }

  //------------------------
  // INTERFACE
  //------------------------

  public function setName($aName)
  {
    $wasSet = false;
    $this->name = $aName;
    $wasSet = true;
    return $wasSet;
  }

  public function getName()
  {
    return $this->name;
  }

  public function getStudent()
  {
    return $this->student;
  }

  public function hasStudent()
  {
    $has = $this->student != null;
    return $has;
  }

  public function setStudent($aNewStudent)
  {
    $wasSet = false;
    if ($this->student != null && $this->student != $aNewStudent && $this == $this->student->getMentor())
    {
      //Unable to setStudent, as existing student would become an orphan
      return $wasSet;
    }
    
    $this->student = $aNewStudent;
    $anOldMentor = $aNewStudent != null ? $aNewStudent->getMentor() : null;
    
    if ($this != $anOldMentor)
    {
      if ($anOldMentor != null)
      {
        $anOldMentor->student = null;
      }
      if ($this->student != null)
      {
        $this->student->setMentor($this);
      }
    }
    $wasSet = true;
    return $wasSet;
  }

  public function equals($compareTo)
  {
    return $this == $compareTo;
  }

  public function delete()
  {
    $existingStudent = $this->student;
    $this->student = null;
    if ($existingStudent != null)
    {
      $existingStudent->delete();
    }
  }

}
?>