scormOrganization.class.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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,$scorm_charset='UTF-8') {
  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($tmp_children->length==1 and $child->firstChild->nodeValue != '' )
  108. {
  109. $this->title = html_entity_decode(html_entity_decode($child->firstChild->nodeValue,ENT_QUOTES,$scorm_charset));
  110. }
  111. break;
  112. }
  113. break;
  114. case XML_TEXT_NODE:
  115. break;
  116. }
  117. }
  118. if($element->hasAttributes()){
  119. $attributes = $element->attributes;
  120. //$keep_href = '';
  121. foreach($attributes as $attrib)
  122. {
  123. switch($attrib->name){
  124. case 'identifier':
  125. $this->identifier = $attrib->value;
  126. break;
  127. case 'structure':
  128. $this->structure = $attrib->value;
  129. break;
  130. }
  131. }
  132. }
  133. return true;
  134. }
  135. }else{
  136. //cannot parse because not PHP4 nor PHP5... We should not even be here anyway...
  137. return false;
  138. }
  139. }
  140. return false;
  141. }
  142. /**
  143. * Get a flat list of items in the organization
  144. * @return array Array containing an ordered list of all items with their level and all information related to each item
  145. */
  146. function get_flat_items_list()
  147. {
  148. $list = array();
  149. $i = 1;
  150. foreach($this->items as $id=>$dummy)
  151. {
  152. $abs_order = 0;
  153. $this->items[$id]->get_flat_list($list,$abs_order,$i,0); //passes the array as a pointer so it is modified in $list directly
  154. $i++;
  155. }
  156. return $list;
  157. }
  158. /**
  159. * Name getter
  160. * @return string Name or empty string
  161. */
  162. function get_name()
  163. {
  164. if(!empty($this->title)){
  165. return mysql_real_escape_string($this->title);
  166. }else{
  167. return '';
  168. }
  169. }
  170. /**
  171. * Reference identifier getter
  172. * @return string Identifier or empty string
  173. */
  174. function get_ref()
  175. {
  176. if(!empty($this->identifier)){
  177. return mysql_real_escape_string($this->identifier);
  178. }else{
  179. return '';
  180. }
  181. }
  182. /**
  183. * Sets the title element
  184. * @param string New title to set
  185. */
  186. function set_name($title){
  187. if(!empty($title)){
  188. $this->title = mysql_real_escape_string($title);
  189. }
  190. }
  191. }
  192. ?>