Esempio n. 1
0
 /**
  * Delete course
  * @access  public
  * @param   course ID
  * @return  true, if successful
  *          false and add error into global var $msg, if unsuccessful
  * @author  Cindy Qi Li
  */
 public function Delete($courseID)
 {
     require_once TR_INCLUDE_PATH . 'classes/FileUtility.class.php';
     require_once TR_INCLUDE_PATH . 'classes/DAO/ContentDAO.class.php';
     require_once TR_INCLUDE_PATH . 'classes/DAO/ForumsCoursesDAO.class.php';
     $contentDAO = new ContentDAO();
     $forumsCoursesDAO = new ForumsCoursesDAO();
     unset($_SESSION['s_cid']);
     // delete course content dir
     $content_dir = TR_CONTENT_DIR . $courseID . '/';
     FileUtility::clr_dir($content_dir);
     // delete tests and tests related data
     $sql = "DELETE FROM " . TABLE_PREFIX . "content_tests_assoc\n\t\t         WHERE content_id in (SELECT content_id FROM " . TABLE_PREFIX . "content WHERE course_id = " . $courseID . ")";
     $this->execute($sql);
     $sql = "DELETE FROM " . TABLE_PREFIX . "tests_questions_categories WHERE course_id = " . $courseID;
     $this->execute($sql);
     $sql = "DELETE FROM " . TABLE_PREFIX . "tests_questions_assoc \n\t\t         WHERE test_id in (SELECT test_id FROM " . TABLE_PREFIX . "tests WHERE course_id = " . $courseID . ")";
     $this->execute($sql);
     $sql = "DELETE FROM " . TABLE_PREFIX . "tests_questions WHERE course_id = " . $courseID;
     $this->execute($sql);
     $sql = "DELETE FROM " . TABLE_PREFIX . "tests WHERE course_id = " . $courseID;
     $this->execute($sql);
     // delete forums that are associated with this course
     $forumsCoursesDAO->DeleteByCourseID($courseID);
     // loop thru content to delete using ContentDAO->Delete(), which deletes a4a objects as well
     $content_rows = $contentDAO->getContentByCourseID($courseID);
     if (is_array($content_rows)) {
         foreach ($content_rows as $content) {
             $contentDAO->Delete($content['content_id']);
         }
     }
     $sql = "DELETE FROM " . TABLE_PREFIX . "content WHERE course_id = " . $courseID;
     $this->execute($sql);
     // delete user <-> course association
     $sql = "DELETE FROM " . TABLE_PREFIX . "user_courses WHERE course_id = " . $courseID;
     $this->execute($sql);
     // delete the course
     $sql = "DELETE FROM " . TABLE_PREFIX . "courses WHERE course_id = " . $courseID;
     return $this->execute($sql);
 }