PageRenderTime 47ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/testbed_php/src-gen-umple/MentorAD.php

http://umple.googlecode.com/
PHP | 246 lines | 202 code | 31 blank | 13 comment | 34 complexity | 62a03af1fbf2c87e79ebefd3cd051bd4 MD5 | raw file
Possible License(s): MIT, LGPL-2.1, BSD-3-Clause, GPL-2.0
  1. <?php
  2. /*PLEASE DO NOT EDIT THIS CODE*/
  3. /*This code was generated using the UMPLE 1.16.0.2388 modeling language!*/
  4. class MentorAD
  5. {
  6. //------------------------
  7. // MEMBER VARIABLES
  8. //------------------------
  9. //MentorAD Attributes
  10. private $name;
  11. //MentorAD Associations
  12. private $students;
  13. private $program;
  14. //------------------------
  15. // CONSTRUCTOR
  16. //------------------------
  17. public function __construct($aName)
  18. {
  19. $this->name = $aName;
  20. $this->students = array();
  21. }
  22. //------------------------
  23. // INTERFACE
  24. //------------------------
  25. public function setName($aName)
  26. {
  27. $wasSet = false;
  28. $this->name = $aName;
  29. $wasSet = true;
  30. return $wasSet;
  31. }
  32. public function getName()
  33. {
  34. return $this->name;
  35. }
  36. public function getStudent($index)
  37. {
  38. $aStudent = $this->students[$index];
  39. return $aStudent;
  40. }
  41. public function getStudents()
  42. {
  43. $newStudents = $this->students;
  44. return $newStudents;
  45. }
  46. public function numberOfStudents()
  47. {
  48. $number = count($this->students);
  49. return $number;
  50. }
  51. public function hasStudents()
  52. {
  53. $has = $this->numberOfStudents() > 0;
  54. return $has;
  55. }
  56. public function indexOfStudent($aStudent)
  57. {
  58. $wasFound = false;
  59. $index = 0;
  60. foreach($this->students as $student)
  61. {
  62. if ($student->equals($aStudent))
  63. {
  64. $wasFound = true;
  65. break;
  66. }
  67. $index += 1;
  68. }
  69. $index = $wasFound ? $index : -1;
  70. return $index;
  71. }
  72. public function getProgram()
  73. {
  74. return $this->program;
  75. }
  76. public static function minimumNumberOfStudents()
  77. {
  78. return 0;
  79. }
  80. public static function maximumNumberOfStudents()
  81. {
  82. return 2;
  83. }
  84. public function addStudent($aStudent)
  85. {
  86. $wasAdded = false;
  87. if ($this->indexOfStudent($aStudent) !== -1) { return false; }
  88. if ($this->numberOfStudents() >= self::maximumNumberOfStudents())
  89. {
  90. return $wasAdded;
  91. }
  92. $this->students[] = $aStudent;
  93. if ($aStudent->indexOfMentor($this) != -1)
  94. {
  95. $wasAdded = true;
  96. }
  97. else
  98. {
  99. $wasAdded = $aStudent->addMentor($this);
  100. if (!$wasAdded)
  101. {
  102. array_pop($this->students);
  103. }
  104. }
  105. return $wasAdded;
  106. }
  107. public function removeStudent($aStudent)
  108. {
  109. $wasRemoved = false;
  110. if ($this->indexOfStudent($aStudent) == -1)
  111. {
  112. return $wasRemoved;
  113. }
  114. $oldIndex = $this->indexOfStudent($aStudent);
  115. unset($this->students[$oldIndex]);
  116. if ($aStudent->indexOfMentor($this) == -1)
  117. {
  118. $wasRemoved = true;
  119. }
  120. else
  121. {
  122. $wasRemoved = $aStudent->removeMentor($this);
  123. if (!$wasRemoved)
  124. {
  125. $this->students[$oldIndex] = $aStudent;
  126. ksort($this->students);
  127. }
  128. }
  129. $this->students = array_values($this->students);
  130. return $wasRemoved;
  131. }
  132. public function addStudentAt($aStudent, $index)
  133. {
  134. $wasAdded = false;
  135. if($this->addStudent($aStudent))
  136. {
  137. if($index < 0 ) { $index = 0; }
  138. if($index > $this->numberOfStudents()) { $index = $this->numberOfStudents() - 1; }
  139. array_splice($this->students, $this->indexOfStudent($aStudent), 1);
  140. array_splice($this->students, $index, 0, array($aStudent));
  141. $wasAdded = true;
  142. }
  143. return $wasAdded;
  144. }
  145. public function addOrMoveStudentAt($aStudent, $index)
  146. {
  147. $wasAdded = false;
  148. if($this->indexOfStudent($aStudent) !== -1)
  149. {
  150. if($index < 0 ) { $index = 0; }
  151. if($index > $this->numberOfStudents()) { $index = $this->numberOfStudents() - 1; }
  152. array_splice($this->students, $this->indexOfStudent($aStudent), 1);
  153. array_splice($this->students, $index, 0, array($aStudent));
  154. $wasAdded = true;
  155. }
  156. else
  157. {
  158. $wasAdded = $this->addStudentAt($aStudent, $index);
  159. }
  160. return $wasAdded;
  161. }
  162. public function setProgram($newProgram)
  163. {
  164. $wasSet = false;
  165. if ($newProgram == null)
  166. {
  167. $existingProgram = $this->program;
  168. $this->program = null;
  169. if ($existingProgram != null && $existingProgram->getMentor() != null)
  170. {
  171. $existingProgram->setMentor(null);
  172. }
  173. $wasSet = true;
  174. return $wasSet;
  175. }
  176. $currentProgram = $this->getProgram();
  177. if ($currentProgram != null && $currentProgram != $newProgram)
  178. {
  179. $currentProgram->setMentor(null);
  180. }
  181. $this->program = $newProgram;
  182. $existingMentor = $newProgram->getMentor();
  183. if ($this != $existingMentor)
  184. {
  185. $newProgram->setMentor($this);
  186. }
  187. $wasSet = true;
  188. return $wasSet;
  189. }
  190. public function equals($compareTo)
  191. {
  192. return $this == $compareTo;
  193. }
  194. public function delete()
  195. {
  196. $copyOfStudents = $this->students;
  197. $this->students = array();
  198. foreach ($copyOfStudents as $aStudent)
  199. {
  200. if ($aStudent->numberOfMentors() <= StudentAD::minimumNumberOfMentors())
  201. {
  202. $aStudent->delete();
  203. }
  204. else
  205. {
  206. $aStudent->removeMentor($this);
  207. }
  208. }
  209. if ($this->program != null)
  210. {
  211. $this->program->setMentor(null);
  212. }
  213. }
  214. }
  215. ?>