scormOrganization.class.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <?php //$id:$
  2. /**
  3. * Container for the scormOrganization class
  4. * @package scorm.learnpath
  5. * @author Yannick Warnier <ywarnier@beeznest.org>
  6. */
  7. /**
  8. * Class defining the <organization> tag in an imsmanifest.xml file
  9. */
  10. class scormOrganization {
  11. var $identifier = '';
  12. var $structure = '';
  13. var $title = '';
  14. var $items = array();
  15. var $metadata;
  16. /**
  17. * Class constructor. Depending of the type of construction called ('db' or 'manifest'), will create a scormOrganization
  18. * object from database records or from the DOM element given as parameter
  19. * @param string Type of construction needed ('db' or 'manifest', default = 'manifest')
  20. * @param mixed Depending on the type given, DB id for the lp_item or reference to the DOM element
  21. */
  22. function scormOrganization($type='manifest',&$element) {
  23. if(isset($element))
  24. {
  25. $v = substr(phpversion(),0,1);
  26. if($v == 4){
  27. switch($type){
  28. case 'db':
  29. //TODO implement this way of metadata object creation
  30. return false;
  31. case 'manifest': //do the same as the default
  32. default:
  33. //if($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function
  34. $children = $element->children();
  35. foreach($children as $a => $dummy)
  36. {
  37. $child =& $children[$a];
  38. switch($child->type)
  39. {
  40. case XML_ELEMENT_NODE:
  41. switch($child->tagname){
  42. case 'item':
  43. $oItem = new scormItem('manifest',$child);
  44. if($oItem->identifier != ''){
  45. $this->items[$oItem->identifier] = $oItem;
  46. }
  47. break;
  48. case 'metadata':
  49. $this->metadata = new scormMetadata('manifest',$child);
  50. break;
  51. case 'title':
  52. $tmp_children = $child->children();
  53. if(count($tmp_children)==1 and $tmp_children[0]->content!='' )
  54. {
  55. $this->title = $tmp_children[0]->content;
  56. }
  57. break;
  58. }
  59. break;
  60. case XML_TEXT_NODE:
  61. break;
  62. }
  63. }
  64. $attributes = $element->attributes();
  65. //$keep_href = '';
  66. foreach($attributes as $a1 => $dummy)
  67. {
  68. $attrib =& $attributes[$a1];
  69. switch($attrib->name){
  70. case 'identifier':
  71. $this->identifier = $attrib->value;
  72. break;
  73. case 'structure':
  74. $this->structure = $attrib->value;
  75. break;
  76. }
  77. }
  78. return true;
  79. }
  80. }elseif($v == 5){
  81. //parsing using PHP5 DOMXML methods
  82. switch($type){
  83. case 'db':
  84. //TODO implement this way of metadata object creation
  85. return false;
  86. case 'manifest': //do the same as the default
  87. default:
  88. //if($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function
  89. $children = $element->childNodes;
  90. foreach($children as $child)
  91. {
  92. switch($child->nodeType)
  93. {
  94. case XML_ELEMENT_NODE:
  95. switch($child->tagName){
  96. case 'item':
  97. $oItem = new scormItem('manifest',$child);
  98. if($oItem->identifier != ''){
  99. $this->items[$oItem->identifier] = $oItem;
  100. }
  101. break;
  102. case 'metadata':
  103. $this->metadata = new scormMetadata('manifest',$child);
  104. break;
  105. case 'title':
  106. $tmp_children = $child->childNodes;
  107. //if(count($tmp_children)==1 and $tmp_children[0]->textContent != '' )
  108. if($tmp_children->length==1 and $child->firstChild->nodeValue != '' )
  109. {
  110. $this->title = $tmp_children->firstChild->nodeValue;
  111. }
  112. break;
  113. }
  114. break;
  115. case XML_TEXT_NODE:
  116. break;
  117. }
  118. }
  119. if($element->hasAttributes()){
  120. $attributes = $element->attributes;
  121. //$keep_href = '';
  122. foreach($attributes as $attrib)
  123. {
  124. switch($attrib->name){
  125. case 'identifier':
  126. $this->identifier = $attrib->value;
  127. break;
  128. case 'structure':
  129. $this->structure = $attrib->value;
  130. break;
  131. }
  132. }
  133. }
  134. return true;
  135. }
  136. }else{
  137. //cannot parse because not PHP4 nor PHP5... We should not even be here anyway...
  138. return false;
  139. }
  140. }
  141. return false;
  142. }
  143. /**
  144. * Get a flat list of items in the organization
  145. * @return array Array containing an ordered list of all items with their level and all information related to each item
  146. */
  147. function get_flat_items_list()
  148. {
  149. $list = array();
  150. $i = 1;
  151. foreach($this->items as $id=>$dummy)
  152. {
  153. $item =& stripslashes($this->items[$id]);
  154. $abs_order = 0;
  155. $this->items[$id]->get_flat_list($list,$abs_order,$i,0); //passes the array as a pointer so it is modified in $list directly
  156. $i++;
  157. }
  158. return $list;
  159. }
  160. /**
  161. * Name getter
  162. * @return string Name or empty string
  163. */
  164. function get_name()
  165. {
  166. if(!empty($this->title)){
  167. return mysql_real_escape_string($this->title);
  168. }else{
  169. return '';
  170. }
  171. }
  172. /**
  173. * Reference identifier getter
  174. * @return string Identifier or empty string
  175. */
  176. function get_ref()
  177. {
  178. if(!empty($this->identifier)){
  179. return mysql_real_escape_string($this->identifier);
  180. }else{
  181. return '';
  182. }
  183. }
  184. /**
  185. * Sets the title element
  186. * @param string New title to set
  187. */
  188. function set_name($title){
  189. if(!empty($title)){
  190. $this->title = mysql_real_escape_string($title);
  191. }
  192. }
  193. }
  194. ?>