Dokeos PHP Cross Reference Learning Management Systems

Source: /main/coursecopy/classes/CourseBuilder.class.php - 716 lines - 27515 bytes - Summary - Text - Print

   1  <?php
   2  /* For licensing terms, see /dokeos_license.txt */
   3  
   4  require_once  'Course.class.php';
   5  require_once  'Event.class.php';
   6  require_once  'Link.class.php';
   7  require_once  'ToolIntro.class.php';
   8  require_once  'Document.class.php';
   9  require_once  'ScormDocument.class.php';
  10  require_once  'LinkCategory.class.php';
  11  require_once  'CourseDescription.class.php';
  12  require_once  'ForumPost.class.php';
  13  require_once  'ForumTopic.class.php';
  14  require_once  'Forum.class.php';
  15  require_once  'ForumCategory.class.php';
  16  require_once  'Quiz.class.php';
  17  require_once  'QuizQuestion.class.php';
  18  require_once  'Learnpath.class.php';
  19  require_once  'Survey.class.php';
  20  require_once  'SurveyQuestion.class.php';
  21  require_once  'Glossary.class.php';
  22  require_once  'CourseSession.class.php';
  23  require_once  'wiki.class.php';
  24  
  25  /**
  26   * Class which can build a course-object from a Dokeos-course.
  27   * @author Bart Mollet <bart.mollet@hogent.be>
  28   * @package dokeos.backup
  29   */
  30  class CourseBuilder
  31  {
  32      /**
  33       * The course
  34       */
  35      var $course;
  36      
  37      /**
  38       * Create a new CourseBuilder
  39       */
  40  	function CourseBuilder($type='')
  41      {
  42          global $_course;
  43          $this->course = new Course();
  44          $this->course->code = $_course['official_code'];
  45          $this->course->type = $type;
  46          $this->course->path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/';
  47          $this->course->backup_path = api_get_path(SYS_COURSE_PATH).$_course['path'];
  48          $this->course->encoding = api_get_system_encoding(); //current platform encoding
  49      }
  50      /**
  51       * Get the created course
  52       * @return course The course
  53       */
  54  	function get_course()
  55      {
  56          return $this->course;
  57      }
  58      /**
  59       * Build the course-object
  60       */
  61  	function build($session_id = 0,$course_code = '')
  62      {
  63  
  64          if (!empty($session_id) && !empty($course_code)) {
  65              $course_info = api_get_course_info($course_code);
  66              $table_link = Database :: get_course_table(TABLE_LINKED_RESOURCES,$course_info['dbName']);
  67              $table_properties = Database :: get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']);
  68  
  69              $this->build_documents($session_id,$course_code);
  70              $this->build_quizzes($session_id,$course_code);
  71              $this->build_glossary($session_id,$course_code);
  72              $this->build_learnpaths($session_id,$course_code);
  73              $this->build_links($session_id,$course_code);
  74              $this->build_course_descriptions($session_id,$course_code);
  75              $this->build_wiki();
  76  
  77          } else {
  78  
  79              $table_link = Database :: get_course_table(TABLE_LINKED_RESOURCES);
  80              $table_properties = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  81  
  82              $this->build_events();
  83              $this->build_announcements();
  84              $this->build_links();
  85              $this->build_tool_intro();
  86              $this->build_documents();
  87              $this->build_course_descriptions();
  88              $this->build_wiki();
  89              $this->build_quizzes();
  90              $this->build_learnpaths();
  91              $this->build_surveys();
  92              $this->build_glossary();
  93              
  94          }
  95  
  96          //TABLE_LINKED_RESOURCES is the "resource" course table, which is deprecated, apparently
  97  
  98          foreach ($this->course->resources as $type => $resources) {
  99              foreach ($resources as $id => $resource) {
 100                  $sql = "SELECT * FROM ".$table_link." WHERE source_type = '".$resource->get_type()."' AND source_id = '".$resource->get_id()."'";
 101                  $res = Database::query($sql, __FILE__, __LINE__);
 102                  while ($link = Database::fetch_object($res)) {
 103                      $this->course->resources[$type][$id]->add_linked_resource($link->resource_type, $link->resource_id);
 104                  }
 105              }
 106          }
 107  
 108          foreach ($this->course->resources as $type => $resources)
 109          {
 110              foreach ($resources as $id => $resource)
 111              {
 112                  $tool = $resource->get_tool();
 113                  if ($tool != null)
 114                  {
 115                      $sql = "SELECT * FROM $table_properties WHERE TOOL = '".$tool."' AND ref='".$resource->get_id()."'";
 116                      $res = Database::query($sql,__FILE__,__LINE__);
 117                      $all_properties = array ();
 118                      while ($item_property = Database::fetch_array($res))
 119                      {
 120                          $all_properties[] = $item_property;
 121                      }
 122                      $this->course->resources[$type][$id]->item_properties = $all_properties;
 123                  }
 124              }
 125          }
 126          return $this->course;
 127      }
 128      /**
 129       * Build the documents
 130       */
 131  	function build_documents($session_id = 0,$course_code = '')
 132      {
 133  
 134          if (!empty($course_code) && !empty($session_id)) {
 135              $course_info = api_get_course_info($course_code);
 136              $table_doc = Database :: get_course_table(TABLE_DOCUMENT,$course_info['dbName']);
 137              $table_prop = Database :: get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']);
 138  
 139              $session_id = intval($session_id);
 140  
 141              if (!empty($this->course->type) && $this->course->type=='partial') {
 142                  $sql = 'SELECT * FROM '.$table_doc.' d, '.$table_prop.' p WHERE tool = \''.TOOL_DOCUMENT.'\' AND p.ref = d.id AND p.visibility != 2 AND path NOT LIKE \'/images/gallery%\' AND session_id = '.$session_id.' ORDER BY path';
 143              } else {
 144                  $sql = 'SELECT * FROM '.$table_doc.' d, '.$table_prop.' p WHERE tool = \''.TOOL_DOCUMENT.'\' AND p.ref = d.id AND p.visibility != 2 AND session_id = '.$session_id.' ORDER BY path';
 145              }
 146  
 147              $db_result = Database::query($sql, __FILE__, __LINE__);
 148              while ($obj = Database::fetch_object($db_result))
 149              {
 150                  $doc = new Document($obj->id, $obj->path, $obj->comment, $obj->title, $obj->filetype, $obj->size);
 151                  $this->course->add_resource($doc);
 152              }
 153  
 154          } else {
 155              $table_doc = Database :: get_course_table(TABLE_DOCUMENT);
 156              $table_prop = Database :: get_course_table(TABLE_ITEM_PROPERTY);
 157  
 158              if (!empty($this->course->type) && $this->course->type=='partial')
 159              $sql = 'SELECT * FROM '.$table_doc.' d, '.$table_prop.' p WHERE tool = \''.TOOL_DOCUMENT.'\' AND p.ref = d.id AND p.visibility != 2 AND path NOT LIKE \'/images/gallery%\' ORDER BY path';
 160              else
 161                  $sql = 'SELECT * FROM '.$table_doc.' d, '.$table_prop.' p WHERE tool = \''.TOOL_DOCUMENT.'\' AND p.ref = d.id AND p.visibility != 2 ORDER BY path';
 162  
 163              $db_result = Database::query($sql, __FILE__, __LINE__);
 164              while ($obj = Database::fetch_object($db_result))
 165              {
 166                  $doc = new Document($obj->id, $obj->path, $obj->comment, $obj->title, $obj->filetype, $obj->size);
 167                  $this->course->add_resource($doc);
 168              }
 169          }
 170  
 171  
 172      }
 173      /**
 174       * Build the forums
 175       */
 176  	function build_forums()
 177      {
 178          $table = Database :: get_course_table(TABLE_FORUM);
 179          $sql = 'SELECT * FROM '.$table;
 180          $db_result = Database::query($sql, __FILE__, __LINE__);
 181          while ($obj = Database::fetch_object($db_result))
 182          {
 183              $forum = new Forum($obj->forum_id, $obj->forum_title, $obj->forum_comment, $obj->forum_category, $obj->forum_last_post, $obj->forum_threads, $obj->forum_posts, $obj->allow_anonymous, $obj->allow_edit, $obj->approval_direct_post, $obj->allow_attachements, $obj->allow_new_threads, $obj->default_view, $obj->forum_of_group, $obj->forum_group_public_private, $obj->forum_order, $obj->locked, $obj->session_id, $obj->forum_image);
 184              $this->course->add_resource($forum);
 185              $this->build_forum_category($obj->forum_category);
 186          }
 187          $this->build_forum_topics();
 188          $this->build_forum_posts();
 189      }
 190      /**
 191       * Build a forum-category
 192       */
 193  	function build_forum_category($id)
 194      {
 195          $table = Database :: get_course_table(TABLE_FORUM_CATEGORY);
 196          $sql = 'SELECT * FROM '.$table.' WHERE cat_id = '.$id;
 197          $db_result = Database::query($sql, __FILE__, __LINE__);
 198          while ($obj = Database::fetch_object($db_result))
 199          {
 200              $forum_category = new ForumCategory($obj->cat_id, $obj->cat_title, $obj->cat_comment, $obj->cat_order, $obj->locked, $obj->session_id);
 201              $this->course->add_resource($forum_category);
 202          }
 203      }
 204      /**
 205       * Build the forum-topics
 206       */
 207  	function build_forum_topics()
 208      {
 209          $table = Database :: get_course_table(TABLE_FORUM_THREAD);
 210          $sql = 'SELECT * FROM '.$table;
 211          $db_result = Database::query($sql, __FILE__, __LINE__);
 212          while ($obj = Database::fetch_object($db_result))
 213          {
 214              $forum_topic = new ForumTopic($obj->thread_id, $obj->thread_title, $obj->thread_date, $obj->thread_poster_id, $obj->thread_poster_name, $obj->forum_id, $obj->thread_last_post, $obj->thread_replies, $obj->thread_views, $obj->thread_sticky, $obj->locked, $obj->thread_close_date, $obj->thread_weight, $obj->thread_title_qualify, $obj->thread_qualify_max);
 215              $this->course->add_resource($forum_topic);
 216          }
 217      }
 218      /**
 219       * Build the forum-posts
 220       * TODO: All tree structure of posts should be built, attachments for example.
 221       */
 222  	function build_forum_posts()
 223      {
 224          $table_post = Database :: get_course_table(TABLE_FORUM_POST);
 225          $sql = 'SELECT * FROM '.$table_post;
 226          $db_result = Database::query($sql, __FILE__, __LINE__);
 227          while ($obj = Database::fetch_object($db_result))
 228          {
 229              $forum_post = new ForumPost($obj->post_id, $obj->post_title, $obj->post_text, $obj->post_date, $obj->poster_id, $obj->poster_name, $obj->post_notification, $obj->post_parent_id, $obj->thread_id, $obj->forum_id, $obj->visible);
 230              $this->course->add_resource($forum_post);
 231          }
 232      }
 233      /**
 234       * Build the links
 235       */
 236  	function build_links($session_id = 0,$course_code = '')
 237      {
 238  
 239          if (!empty($session_id) && !empty($course_code)) {
 240              $course_info = api_get_course_info($course_code);
 241              $table = Database :: get_course_table(TABLE_LINK,$course_info['dbName']);
 242              $table_prop = Database :: get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']);
 243              $session_id = intval($session_id);
 244              $sql = "SELECT * FROM $table l, $table_prop p WHERE p.ref=l.id AND p.tool = '".TOOL_LINK."' AND p.visibility != 2  AND session_id = '$session_id' ORDER BY l.display_order";
 245          } else {
 246              $table = Database :: get_course_table(TABLE_LINK);
 247              $table_prop = Database :: get_course_table(TABLE_ITEM_PROPERTY);
 248              $sql = "SELECT * FROM $table l, $table_prop p WHERE p.ref=l.id AND p.tool = '".TOOL_LINK."' AND p.visibility != 2  ORDER BY l.display_order";
 249          }
 250  
 251          $db_result = Database::query($sql, __FILE__, __LINE__);
 252          while ($obj = Database::fetch_object($db_result))
 253          {
 254              $link = new Link($obj->id, $obj->title, $obj->url, $obj->description, $obj->category_id, $obj->on_homepage);
 255              $this->course->add_resource($link);
 256  
 257              if (!empty($course_code)) {
 258                  $res = $this->build_link_category($obj->category_id,$course_code);
 259              } else {
 260                  $res = $this->build_link_category($obj->category_id);
 261              }
 262  
 263              if($res > 0)
 264              {
 265                  $this->course->resources[RESOURCE_LINK][$obj->id]->add_linked_resource(RESOURCE_LINKCATEGORY, $obj->category_id);
 266              }
 267          }
 268      }
 269      /**
 270       * Build tool intro
 271       */
 272  	function build_tool_intro()
 273      {
 274          $table = Database :: get_course_table(TABLE_TOOL_INTRO);
 275          $sql = 'SELECT * FROM '.$table;
 276          $db_result = Database::query($sql, __FILE__, __LINE__);
 277          while ($obj = Database::fetch_object($db_result))
 278          {
 279              $tool_intro = new ToolIntro($obj->id, $obj->intro_text);
 280              $this->course->add_resource($tool_intro);
 281          }
 282      }
 283      /**
 284       * Build a link category
 285       */
 286  	function build_link_category($id, $course_code = '')
 287      {
 288          if (!empty($course_code)) {
 289              $course_info = api_get_course_info($course_code);
 290              $link_cat_table = Database :: get_course_table(TABLE_LINK_CATEGORY, $course_info['dbName']);
 291          } else {
 292              $link_cat_table = Database :: get_course_table(TABLE_LINK_CATEGORY);
 293          }
 294  
 295          $sql = 'SELECT * FROM '.$link_cat_table.' WHERE id = '.$id;
 296          $db_result = Database::query($sql, __FILE__, __LINE__);
 297          while ($obj = Database::fetch_object($db_result))
 298          {
 299              $link_category = new LinkCategory($obj->id, $obj->category_title, $obj->description, $obj->display_order);
 300              $this->course->add_resource($link_category);
 301              return $id;
 302          }
 303          return 0;
 304      }
 305      /**
 306       * Build the Quizzes
 307       */
 308  	function build_quizzes($session_id = 0,$course_code = '')
 309      {
 310          if (!empty($course_code) && !empty($session_id)) {
 311              $course_info = api_get_course_info($course_code);
 312              $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST, $course_info['dbName']);
 313              $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION, $course_info['dbName']);
 314              $table_doc = Database :: get_course_table(TABLE_DOCUMENT, $course_info['dbName']);
 315              $session_id = intval($session_id);
 316              $sql = 'SELECT * FROM '.$table_qui.' WHERE active >=0 AND session_id = '.$session_id; //select only quizzes with active = 0 or 1 (not -1 which is for deleted quizzes)
 317          } else {
 318              $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
 319              $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
 320              $table_doc = Database :: get_course_table(TABLE_DOCUMENT);
 321              $sql = 'SELECT * FROM '.$table_qui.' WHERE active >=0'; //select only quizzes with active = 0 or 1 (not -1 which is for deleted quizzes)
 322          }
 323  
 324          $db_result = Database::query($sql, __FILE__, __LINE__);
 325          while ($obj = Database::fetch_object($db_result))
 326          {
 327              if (strlen($obj->sound) > 0)
 328              {
 329                  $doc = Database::fetch_object(Database::query("SELECT id FROM ".$table_doc." WHERE path = '/audio/".$obj->sound."'"));
 330                  $obj->sound = $doc->id;
 331              }
 332              $quiz = new Quiz($obj->id, $obj->title, $obj->description, $obj->random, $obj->type, $obj->active, $obj->sound, $obj->max_attempt, $obj->results_disabled, $obj->access_condition, $obj->start_time, $obj->end_time, $obj->feedback_type);
 333              $sql = 'SELECT * FROM '.$table_rel.' WHERE exercice_id = '.$obj->id;
 334              $db_result2 = Database::query($sql, __FILE__, __LINE__);
 335              while ($obj2 = Database::fetch_object($db_result2))
 336              {
 337                  $quiz->add_question($obj2->question_id, $obj2->question_order);
 338              }
 339              $this->course->add_resource($quiz);
 340          }
 341  
 342          if (!empty($course_code)) {
 343              $this->build_quiz_questions($course_code);
 344          } else {
 345              $this->build_quiz_questions();
 346          }
 347  
 348  
 349      }
 350      /**
 351       * Build the Quiz-Questions
 352       */
 353  	function build_quiz_questions($course_code = '')
 354      {
 355  
 356          if (!empty($course_code)) {
 357              $course_info = api_get_course_info($course_code);
 358              $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST,$course_info['dbName']);
 359              $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION,$course_info['dbName']);
 360              $table_que = Database :: get_course_table(TABLE_QUIZ_QUESTION,$course_info['dbName']);
 361              $table_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER,$course_info['dbName']);
 362          } else {
 363              $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
 364              $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
 365              $table_que = Database :: get_course_table(TABLE_QUIZ_QUESTION);
 366              $table_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER);
 367          }
 368  
 369          // Building normal tests.
 370          $sql = 'SELECT * FROM '.$table_que;
 371          $db_result = Database::query($sql, __FILE__, __LINE__);
 372          while ($obj = Database::fetch_object($db_result))
 373          {
 374              $question = new QuizQuestion($obj->id, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture,$obj->level);
 375              $sql = 'SELECT * FROM '.$table_ans.' WHERE question_id = '.$obj->id;
 376              $db_result2 = Database::query($sql, __FILE__, __LINE__);
 377              while ($obj2 = Database::fetch_object($db_result2))
 378              {
 379                  $question->add_answer($obj2->answer, $obj2->correct, $obj2->comment, $obj2->ponderation, $obj2->position, $obj2->hotspot_coordinates, $obj2->hotspot_type);
 380              }
 381              $this->course->add_resource($question);
 382          }
 383  
 384          // Building a fictional test for collecting orphan questions.
 385          $build_orphan_questions = !empty($_POST['recycle_option']); // When a course is emptied this option should be activated (true).
 386          $sql = 'SELECT * FROM '.$table_que.
 387              ' as questions LEFT JOIN '.$table_rel.' as quizz_questions ON questions.id=quizz_questions.question_id LEFT JOIN '.$table_qui.
 388              ' as exercices ON exercice_id=exercices.id WHERE quizz_questions.exercice_id IS NULL OR exercices.active = -1'; // active = -1 means "deleted" test.
 389          $db_result = Database::query($sql, __FILE__, __LINE__);
 390          if (Database::num_rows($db_result) > 0)
 391          {
 392              $build_orphan_questions = true;
 393              while ($obj = Database::fetch_object($db_result))
 394              {
 395                  $question = new QuizQuestion($obj->id, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture,$obj->level);
 396                  $sql = 'SELECT * FROM '.$table_ans.' WHERE question_id = '.(int)$obj->id;
 397                  $db_result2 = Database::query($sql, __FILE__, __LINE__);
 398                  while ($obj2 = Database::fetch_object($db_result2))
 399                  {
 400                      $question->add_answer($obj2->answer, $obj2->correct, $obj2->comment, $obj2->ponderation, $obj2->position, $obj2->hotspot_coordinates, $obj2->hotspot_type);
 401                  }
 402                  $this->course->add_resource($question);
 403              }
 404          }
 405          if ($build_orphan_questions)
 406          {
 407              $this->course->add_resource(new Quiz(-1, get_lang('OrphanQuestions', ''), '', 0, 0, 1, '', 0));
 408          }
 409      }
 410      /**
 411       * Build the orphan questions
 412       */
 413  	function build_quiz_orphan_questions()
 414      {
 415          $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
 416          $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
 417          $table_que = Database :: get_course_table(TABLE_QUIZ_QUESTION);
 418          $table_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER);
 419  
 420          $sql = 'SELECT * FROM '.$table_que.
 421              ' as questions LEFT JOIN '.$table_rel.' as quizz_questions ON questions.id=quizz_questions.question_id LEFT JOIN '.$table_qui.
 422              ' as exercices ON exercice_id=exercices.id WHERE quizz_questions.exercice_id IS NULL OR exercices.active = -1';
 423          $db_result = Database::query($sql, __FILE__, __LINE__);
 424          if (Database::num_rows($db_result) > 0)
 425          {
 426              $orphan_questions = new Quiz(-1, get_lang('OrphanQuestions', ''), '', 0, 0, 1, '', 0); // Tjis is the fictional test for collecting orphan questions.
 427              $this->course->add_resource($orphan_questions);
 428              while ($obj = Database::fetch_object($db_result))
 429              {
 430                  $question = new QuizQuestion($obj->id, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture,$obj->level);
 431                  $sql = 'SELECT * FROM '.$table_ans.' WHERE question_id = '.$obj->id;
 432                  $db_result2 = Database::query($sql, __FILE__, __LINE__);
 433                  while ($obj2 = Database::fetch_object($db_result2))
 434                  {
 435                      $question->add_answer($obj2->answer, $obj2->correct, $obj2->comment, $obj2->ponderation, $obj2->position, $obj2->hotspot_coordinates, $obj2->hotspot_type);
 436                  }
 437                  $this->course->add_resource($question);
 438              }
 439          }
 440      }
 441      /**
 442       * Build the Surveys
 443       */
 444  	function build_surveys()
 445      {
 446          $table_survey = Database :: get_course_table(TABLE_SURVEY);
 447          $table_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
 448          $sql = 'SELECT * FROM '.$table_survey;
 449          $db_result = Database::query($sql, __FILE__, __LINE__);
 450          while ($obj = Database::fetch_object($db_result))
 451          {
 452              $survey = new Survey($obj->survey_id, $obj->code,$obj->title,
 453                                  $obj->subtitle, $obj->author, $obj->lang,
 454                                  $obj->avail_from, $obj->avail_till, $obj->is_shared,
 455                                  $obj->template, $obj->intro, $obj->surveythanks,
 456                                  $obj->creation_date, $obj->invited, $obj->answered,
 457                                  $obj->invite_mail, $obj->reminder_mail);
 458              $sql = 'SELECT * FROM '.$table_question.' WHERE survey_id = '.$obj->survey_id;
 459              $db_result2 = Database::query($sql, __FILE__, __LINE__);
 460              while ($obj2 = Database::fetch_object($db_result2))
 461              {
 462                  $survey->add_question($obj2->question_id);
 463              }
 464              $this->course->add_resource($survey);
 465          }
 466          $this->build_survey_questions();
 467      }
 468      /**
 469       * Build the Survey Questions
 470       */
 471  	function build_survey_questions()
 472      {
 473          $table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION);
 474          $table_opt = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
 475          $sql = 'SELECT * FROM '.$table_que;
 476          $db_result = Database::query($sql, __FILE__, __LINE__);
 477          while ($obj = Database::fetch_object($db_result))
 478          {
 479              $question = new SurveyQuestion($obj->question_id, $obj->survey_id,
 480                                              $obj->survey_question, $obj->survey_question_comment,
 481                                              $obj->type, $obj->display, $obj->sort,
 482                                              $obj->shared_question_id, $obj->max_value);
 483              $sql = 'SELECT * FROM '.$table_opt.' WHERE question_id = '."'".$obj->question_id."'";
 484              $db_result2 = Database::query($sql, __FILE__, __LINE__);
 485              while ($obj2 = Database::fetch_object($db_result2))
 486              {
 487                  $question->add_answer($obj2->option_text, $obj2->sort);
 488              }
 489              $this->course->add_resource($question);
 490          }
 491      }
 492      /**
 493       * Build the announcements
 494       */
 495  	function build_announcements()
 496      {
 497          $table = Database :: get_course_table(TABLE_ANNOUNCEMENT);
 498          $sql = 'SELECT * FROM '.$table;
 499          $db_result = Database::query($sql, __FILE__, __LINE__);
 500          while ($obj = Database::fetch_object($db_result))
 501          {
 502              $announcement = new Announcement($obj->id, $obj->title, $obj->content, $obj->end_date,$obj->display_order,$obj->email_sent);
 503              $this->course->add_resource($announcement);
 504          }
 505      }
 506      /**
 507       * Build the events
 508       */
 509  	function build_events()
 510      {
 511          $table = Database :: get_course_table(TABLE_AGENDA);
 512          $sql = 'SELECT * FROM '.$table;
 513          $db_result = Database::query($sql, __FILE__, __LINE__);
 514          while ($obj = Database::fetch_object($db_result))
 515          {
 516              $event = new Event($obj->id, $obj->title, $obj->content, $obj->start_date, $obj->end_date);
 517              $this->course->add_resource($event);
 518          }
 519      }
 520      /**
 521       * Build the course-descriptions
 522       */
 523  	function build_course_descriptions($session_id = 0,$course_code = '')
 524      {
 525          if (!empty($session_id) && !empty($course_code)) {
 526              $course_info = api_get_course_info($course_code);
 527              $table = Database :: get_course_table(TABLE_COURSE_DESCRIPTION,$course_info['dbName']);
 528              $session_id = intval($session_id);
 529              $sql = 'SELECT * FROM '.$table. ' WHERE session_id ='.$session_id;
 530          } else {
 531              $table = Database :: get_course_table(TABLE_COURSE_DESCRIPTION);
 532              $sql = 'SELECT * FROM '.$table;
 533          }
 534  
 535          $db_result = Database::query($sql, __FILE__, __LINE__);
 536          while ($obj = Database::fetch_object($db_result))
 537          {
 538              $cd = new CourseDescription($obj->id, $obj->title, $obj->content, $obj->description_type);
 539              $this->course->add_resource($cd);
 540          }
 541      }
 542      /**
 543       * Build the learnpaths
 544       */
 545  	function build_learnpaths($session_id = 0,$course_code = '')
 546      {
 547  
 548          if (!empty($session_id) && !empty($course_code)) {
 549              $course_info     = api_get_course_info($course_code);
 550              $table_main     = Database :: get_course_table(TABLE_LP_MAIN,$course_info['dbName']);
 551              $table_item     = Database :: get_course_table(TABLE_LP_ITEM,$course_info['dbName']);
 552              $table_tool     = Database::get_course_table(TABLE_TOOL_LIST,$course_info['dbName']);
 553  
 554              $sql = 'SELECT * FROM '.$table_main.' WHERE session_id = '.$session_id;
 555          } else {
 556              $table_main     = Database :: get_course_table(TABLE_LP_MAIN);
 557              $table_item     = Database :: get_course_table(TABLE_LP_ITEM);
 558              $table_tool     = Database::get_course_table(TABLE_TOOL_LIST);
 559  
 560              $sql = 'SELECT * FROM '.$table_main;
 561          }
 562  
 563          $db_result = Database::query($sql, __FILE__, __LINE__);
 564  
 565          while ($obj = Database::fetch_object($db_result))
 566          {
 567              $items = array();
 568              $sql_items = "SELECT * FROM ".$table_item." WHERE lp_id = ".$obj->id."";
 569              $db_items = Database::query($sql_items);
 570              while ($obj_item = Database::fetch_object($db_items))
 571              {
 572                  $item['id'] = $obj_item->id;
 573                  $item['item_type'] = $obj_item->item_type;
 574                  $item['ref'] = $obj_item->ref;
 575                  $item['title'] = $obj_item->title;
 576                  $item['description'] = $obj_item->description;
 577                  $item['path'] = $obj_item->path;
 578                  $item['min_score'] = $obj_item->min_score;
 579                  $item['max_score'] = $obj_item->max_score;
 580                  $item['mastery_score'] = $obj_item->mastery_score;
 581                  $item['parent_item_id'] = $obj_item->parent_item_id;
 582                  $item['previous_item_id'] = $obj_item->previous_item_id;
 583                  $item['next_item_id'] = $obj_item->next_item_id;
 584                  $item['display_order'] = $obj_item->display_order;
 585                  $item['prerequisite'] = $obj_item->prerequisite;
 586                  $item['parameters'] = $obj_item->parameters;
 587                  $item['launch_data'] = $obj_item->launch_data;
 588                  $items[] = $item;
 589              }
 590  
 591              $sql_tool = "SELECT id FROM ".$table_tool." WHERE (link LIKE '%lp_controller.php%lp_id=".$obj->id."%' and image='scormbuilder.gif') AND visibility='1'";
 592              $db_tool = Database::query($sql_tool);
 593  
 594              if(Database::num_rows($db_tool))
 595              {
 596                  $visibility='1';
 597              }
 598              else
 599              {
 600                  $visibility='0';
 601              }
 602  
 603              $lp = new Learnpath($obj->id,
 604                                  $obj->lp_type,
 605                                  $obj->name,
 606                                  $obj->path,
 607                                  $obj->ref,
 608                                  $obj->description,
 609                                  $obj->content_local,
 610                                  $obj->default_encoding,
 611                                  $obj->default_view_mod,
 612                                  $obj->prevent_reinit,
 613                                  $obj->force_commit,
 614                                  $obj->content_maker,
 615                                  $obj->display_order,
 616                                  $obj->js_lib,
 617                                  $obj->content_license,
 618                                  $obj->debug,
 619                                  $visibility,
 620                                  $items);
 621  
 622              $this->course->add_resource($lp);
 623          }
 624  
 625          //save scorm directory (previously build_scorm_documents())
 626          $i = 1;
 627          if($dir=@opendir($this->course->backup_path.'/scorm'))
 628          {
 629              while($file=readdir($dir))
 630              {
 631                  if(is_dir($this->course->backup_path.'/scorm/'.$file) && !in_array($file,array('.','..')))
 632                  {
 633                      $doc = new ScormDocument($i++, '/'.$file, $file);
 634                      $this->course->add_resource($doc);
 635                  }
 636              }
 637  
 638              closedir($dir);
 639          }
 640      }
 641  
 642      /**
 643       * Build the glossarys
 644       */
 645  	function build_glossary($session_id = 0, $course_code = '') {
 646  
 647          if (!empty($session_id) && !empty($course_code)) {
 648              $course_info = api_get_course_info($course_code);
 649              $table_glossary = Database :: get_course_table(TABLE_GLOSSARY,$course_info['dbName']);
 650              $session_id = intval($session_id);
 651              if (!empty($this->course->type) && $this->course->type=='partial') {
 652                  $sql = 'SELECT * FROM '.$table_glossary.' g WHERE session_id = '.$session_id;
 653              } else {
 654                  $sql = 'SELECT * FROM '.$table_glossary.' g WHERE session_id = '.$session_id;
 655              }
 656          } else {
 657              $table_glossary = Database :: get_course_table(TABLE_GLOSSARY);
 658              if (!empty($this->course->type) && $this->course->type=='partial') {
 659                  $sql = 'SELECT * FROM '.$table_glossary.' g ';
 660              } else {
 661                  $sql = 'SELECT * FROM '.$table_glossary.' g ';
 662              }
 663          }
 664  
 665          $db_result = Database::query($sql, __FILE__, __LINE__);
 666          while ($obj = Database::fetch_object($db_result))
 667          {
 668              $doc = new Glossary($obj->glossary_id, $obj->name, $obj->description, $obj->display_order);
 669              $this->course->add_resource($doc);
 670          }
 671      }
 672  
 673      /*
 674       * build session course by jhon
 675       * */
 676  	function build_session_course(){
 677          $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
 678          $tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
 679          $list_course = Database::get_course_list();
 680          $list = array();
 681          foreach($list_course as $_course) {
 682              $this->course = new Course();
 683              $this->course->code = $_course['code'];
 684              $this->course->type = 'partial';
 685              $this->course->path = api_get_path(SYS_COURSE_PATH).$_course['directory'].'/';
 686              $this->course->backup_path = api_get_path(SYS_COURSE_PATH).$_course['directory'];
 687              $this->course->encoding = api_get_system_encoding(); //current platform encoding
 688              $code_course = $_course['code'];
 689              $sql_session = "SELECT id, name, course_code  FROM $tbl_session_course
 690                  INNER JOIN  $tbl_session ON id_session = id
 691                  WHERE course_code = '$code_course' ";
 692              $query_session = Database::query($sql_session, __FILE__, __LINE__);
 693              while($rows_session = mysql_fetch_assoc($query_session)) {
 694                  $session = new CourseSession($rows_session['id'], $rows_session['name']);
 695                  $this->course->add_resource($session);
 696              }
 697              $list[] = $this->course;
 698          }
 699          return $list;
 700      }
 701      
 702  	function build_wiki() 
 703      {
 704          // Database table definition
 705          $tbl_wiki = Database::get_course_table('wiki');
 706  
 707           $sql = 'SELECT * FROM ' . $tbl_wiki . ' INNER JOIN (SELECT MAX(id) as wikiid FROM ' . $tbl_wiki . ' GROUP BY page_id)ids ON id=ids.wikiid ORDER BY dtime DESC, group_id, reflink';
 708  
 709          $db_result = api_sql_query($sql, __FILE__, __LINE__);
 710          while ($obj = mysql_fetch_object($db_result))
 711          {
 712              $wiki = new Wiki($obj->page_id, $obj->reflink, $obj->title, $obj->content, $obj->user_id, $obj->group_id, $obj->dtime);
 713              $this->course->add_resource($wiki);
 714          }
 715      }    
 716  }

title

Description

title

Description

title

Description

title

title

Body