ObjList.php

  1. 6.x classes/ObjList.php
  2. 4.x classes/ObjList.php
  3. 5.x classes/ObjList.php

File

classes/ObjList.php
View source
  1. <?php
  2. class ObjList
  3. {
  4. public $array_list, $i, $is_empty, $count;
  5. function __construct()
  6. {
  7. $this->array_list = array();
  8. $this->i = 0;
  9. $this->count = 0;
  10. $this->is_empty = true;
  11. }
  12. function add($c, $bool_add_to_top = false)
  13. {
  14. // Adds courses to the list. Remember to perform
  15. // reset_counter before using this list, or the count
  16. // variable will be off!
  17. if ($bool_add_to_top == false)
  18. {
  19. $this->array_list[] = $c;
  20. //adminDebug(".....adding course");
  21. } else {
  22. // We are going to add this to the top of the array, pushing
  23. // everything else down.
  24. $temp_array = array();
  25. $temp_array[0] = $c;
  26. $new_array = array_merge($temp_array, $this->array_list);
  27. $this->array_list = $new_array;
  28. // adminDebug("adding to top...");
  29. }
  30. $this->is_empty = false;
  31. $this->count = count($this->array_list);
  32. }
  33. function index_of($obj_c)
  34. {
  35. // Find in the array an object.equals(objC), and return the
  36. // index.
  37. for ($t = 0; $t < count($this->array_list); $t++)
  38. {
  39. if ($this->array_list[$t]->equals($obj_c))
  40. {
  41. return $t;
  42. }
  43. }
  44. return -1;
  45. }
  46. function check_is_empty()
  47. {
  48. if (count($this->array_list) > 0)
  49. {
  50. $this->is_empty = false;
  51. }
  52. }
  53. function object_index_of($obj_c)
  54. {
  55. // This will return the array index of the exact object being requested.
  56. // Not the ->equals(), but rather an == of the object (the reference is the same)
  57. for ($t = 0; $t < count($this->array_list); $t++)
  58. {
  59. if ($this->array_list[$t] == $obj_c)
  60. {
  61. return $t;
  62. }
  63. }
  64. return -1;
  65. }
  66. function reset_counter()
  67. {
  68. $this->i = 0;
  69. $this->count = count($this->array_list);
  70. }
  71. function get_first()
  72. {
  73. if ($this->get_size() > 0)
  74. {
  75. return $this->get_element(0);
  76. } else {
  77. return false;
  78. }
  79. }
  80. function get_element($c)
  81. {
  82. return $this->array_list[$c];
  83. }
  84. function find_match($obj_c)
  85. { // This actually returns an object if it can find
  86. // it using index_of.
  87. $c = $this->index_of($obj_c);
  88. if ($c > -1)
  89. {
  90. return $this->get_element($c);
  91. } else {
  92. return false;
  93. }
  94. }
  95. function insert_after_index($new_i, $obj_c)
  96. {
  97. $rtn = new ObjList();
  98. for ($t = 0; $t < $new_i; $t++)
  99. {
  100. $rtn->add($this->array_list[$t]);
  101. }
  102. $rtn->add($obj_c);
  103. for ($t = $new_i; $t < count($this->array_list); $t++)
  104. {
  105. $rtn->add($this->array_list[$t]);
  106. }
  107. $this->array_list = $rtn->array_list;
  108. $this->count = count($this->array_list);
  109. }
  110. function find_all_matches(stdClass $obj_c)
  111. {
  112. // This will find all the matches of objC in the
  113. // array, and return an ObjList of matches.
  114. $rtn = new ObjList();
  115. $bool_no_matches = true;
  116. for ($t = 0; $t < $this->count; $t++)
  117. {
  118. if ($this->array_list[$t]->equals($obj_c))
  119. {
  120. $rtn->add($this->array_list[$t]);
  121. $bool_no_matches = false;
  122. }
  123. }
  124. if ($bool_no_matches == false)
  125. {
  126. return $rtn;
  127. } else {
  128. return false;
  129. }
  130. }
  131. function get_size()
  132. {
  133. return sizeof($this->array_list);
  134. }
  135. function to_string()
  136. {
  137. // Return a string of every obj in this list.
  138. $rtn = "";
  139. for ($t = 0; $t < $this->count; $t++)
  140. {
  141. $rtn .= $this->array_list[$t]->to_string();
  142. }
  143. return $rtn;
  144. }
  145. function refresh_indexes() {
  146. $new_array_list = array();
  147. foreach ($this->array_list as $obj) {
  148. $new_array_list[] = $obj;
  149. }
  150. $this->array_list = $new_array_list;
  151. $this->reset_counter();
  152. }
  153. function has_more()
  154. {
  155. //adminDebug("here " . count($this->array_list));
  156. if ($this->i < $this->count)
  157. {
  158. return true;
  159. } else {
  160. return false;
  161. }
  162. }
  163. function get_next()
  164. {
  165. $s = @$this->array_list[$this->i];
  166. $this->i++;
  167. return $s;
  168. }
  169. }

Classes

Namesort descending Description
ObjList