lp_item.lib.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class lp_item
  5. * made to manipulate data of lp_item table.
  6. *
  7. * This class is still incomplete
  8. * You can add lp_item database manipulation function here
  9. */
  10. class LpItem
  11. {
  12. public $c_id = 0;
  13. public $id = 0;
  14. public $lp_id = 0;
  15. public $item_type = '';
  16. public $ref = '';
  17. public $title = '';
  18. public $description = '';
  19. public $path = '';
  20. public $min_score = 0;
  21. public $max_score = 0;
  22. public $mastery_score = 0;
  23. public $parent_item_id = 0;
  24. public $previous_item_id = 0;
  25. public $next_item_id = 0;
  26. public $display_order = 0;
  27. public $prerequisite = '';
  28. public $parameters = '';
  29. public $launch_data = '';
  30. public $max_time_allowed = '';
  31. public $terms = '';
  32. public $search_did = 0;
  33. public $audio = '';
  34. /**
  35. * LpItem constructor.
  36. *
  37. * @param int $in_c_id
  38. * @param int $in_id
  39. */
  40. public function __construct($in_c_id = 0, $in_id = 0)
  41. {
  42. if ($in_c_id > 0 && $in_id > 0) {
  43. $item_view_table = Database::get_course_table(TABLE_LP_ITEM);
  44. $sql = "SELECT * FROM $item_view_table
  45. WHERE
  46. c_id=".intval($in_c_id)." AND
  47. iid=".intval($in_id);
  48. $res = Database::query($sql);
  49. $data = Database::fetch_array($res);
  50. if (Database::num_rows($res) > 0) {
  51. $this->c_id = $data['c_id'];
  52. $this->id = $data['id'];
  53. $this->lp_id = $data['lp_id'];
  54. $this->item_type = $data['item_type'];
  55. $this->ref = $data['ref'];
  56. $this->title = $data['title'];
  57. $this->description = $data['description'];
  58. $this->path = $data['path'];
  59. $this->min_score = $data['min_score'];
  60. $this->max_score = $data['max_score'];
  61. $this->mastery_score = $data['mastery_score'];
  62. $this->parent_item_id = $data['parent_item_id'];
  63. $this->previous_item_id = $data['previous_item_id'];
  64. $this->next_item_id = $data['next_item_id'];
  65. $this->display_order = $data['display_order'];
  66. $this->prerequisite = $data['prerequisite'];
  67. $this->parameters = $data['parameters'];
  68. $this->launch_data = $data['launch_data'];
  69. $this->max_time_allowed = $data['max_time_allowed'];
  70. $this->terms = $data['terms'];
  71. $this->search_did = $data['search_did'];
  72. $this->audio = $data['audio'];
  73. }
  74. }
  75. }
  76. /**
  77. * Update in database.
  78. */
  79. public function update()
  80. {
  81. $table = Database::get_course_table(TABLE_LP_ITEM);
  82. if ($this->c_id > 0 && $this->id > 0) {
  83. $sql = "UPDATE $table SET
  84. lp_id = '".intval($this->lp_id)."' ,
  85. item_type = '".Database::escape_string($this->item_type)."' ,
  86. ref = '".Database::escape_string($this->ref)."' ,
  87. title = '".Database::escape_string($this->title)."' ,
  88. description = '".Database::escape_string($this->description)."' ,
  89. path = '".Database::escape_string($this->path)."' ,
  90. min_score = '".Database::escape_string($this->min_score)."' ,
  91. max_score = '".Database::escape_string($this->max_score)."' ,
  92. mastery_score = '".Database::escape_string($this->mastery_score)."' ,
  93. parent_item_id = '".Database::escape_string($this->parent_item_id)."' ,
  94. previous_item_id = '".Database::escape_string($this->previous_item_id)."' ,
  95. next_item_id = '".Database::escape_string($this->next_item_id)."' ,
  96. display_order = '".Database::escape_string($this->display_order)."' ,
  97. prerequisite = '".Database::escape_string($this->prerequisite)."' ,
  98. parameters = '".Database::escape_string($this->parameters)."' ,
  99. launch_data = '".Database::escape_string($this->launch_data)."' ,
  100. max_time_allowed = '".Database::escape_string($this->max_time_allowed)."' ,
  101. terms = '".Database::escape_string($this->terms)."' ,
  102. search_did = '".Database::escape_string($this->search_did)."' ,
  103. audio = '".Database::escape_string($this->audio)."'
  104. WHERE c_id=".$this->c_id." AND id=".$this->id;
  105. Database::query($sql);
  106. }
  107. }
  108. /**
  109. * Create extra field for learning path item.
  110. *
  111. * @param string $variable
  112. * @param int $fieldType
  113. * @param string $displayText
  114. * @param string|null $default Optional.
  115. * @param bool $changeable Optional.
  116. * @param bool $visibleToSelf Optional.
  117. * @param bool $visibleToOthers Optional.
  118. *
  119. * @return bool|int
  120. */
  121. public static function createExtraField(
  122. $variable,
  123. $fieldType,
  124. $displayText,
  125. $default = null,
  126. $changeable = false,
  127. $visibleToSelf = false,
  128. $visibleToOthers = false
  129. ) {
  130. $extraField = new ExtraField('lp_item');
  131. $params = [
  132. 'variable' => $variable,
  133. 'field_type' => $fieldType,
  134. 'display_text' => $displayText,
  135. 'default_value' => $default,
  136. 'changeable' => $changeable,
  137. 'visible_to_self' => $visibleToSelf,
  138. 'visible_to_others' => $visibleToOthers,
  139. ];
  140. return $extraField->save($params);
  141. }
  142. }