2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2010 */
6 /* Inclusive Design Institute */
8 /* This program is free software. You can redistribute it and/or */
9 /* modify it under the terms of the GNU General Public License */
10 /* as published by the Free Software Foundation. */
11 /************************************************************************/
14 * DAO for "content_forums_assoc" table
20 if (!defined('TR_INCLUDE_PATH')) exit;
22 require_once(TR_INCLUDE_PATH. 'classes/DAO/DAO.class.php');
24 class ContentForumsAssocDAO extends DAO {
29 * @param content_id, forum_id
30 * @return true / false
33 function Create($content_id, $forum_id)
35 $sql = 'INSERT INTO ' . TABLE_PREFIX . 'content_forums_assoc' .
36 '(content_id, forum_id) ' .
37 'VALUES (' . $content_id . ", $forum_id)";
38 if ($this->execute($sql)) {
39 // update the courses.modified_date to the current timestamp
40 include_once(TR_INCLUDE_PATH.'classes/DAO/CoursesDAO.class.php');
41 $coursesDAO = new CoursesDAO();
42 $coursesDAO->updateModifiedDate($content_id, "content_id");
45 $msg->addError('DB_NOT_UPDATED');
51 * Delete row by content ID
54 * @return true or false
57 function DeleteByContentID($contentID)
59 $sql = "DELETE FROM ".TABLE_PREFIX."content_forums_assoc
60 WHERE content_id = ".$contentID."";
61 if ($this->execute($sql)) {
62 // update the courses.modified_date to the current timestamp
63 include_once(TR_INCLUDE_PATH.'classes/DAO/CoursesDAO.class.php');
64 $coursesDAO = new CoursesDAO();
65 $coursesDAO->updateModifiedDate($contentID, "content_id");
68 $msg->addError('DB_NOT_UPDATED');
74 * Delete row by forum ID
77 * @return true or false
80 function DeleteByForumID($forumID)
82 $sql = "DELETE FROM ".TABLE_PREFIX."content_forums_assoc
83 WHERE forum_id = ".$forumID."";
84 if ($this->execute($sql)) {
85 // update the courses.modified_date to the current timestamp
86 include_once(TR_INCLUDE_PATH.'classes/DAO/ForumsCoursesDAO.class.php');
87 include_once(TR_INCLUDE_PATH.'classes/DAO/CoursesDAO.class.php');
89 $forumsCoursesDAO = new ForumsCoursesDAO();
90 $course_rows = $forumsCoursesDAO->getByForum($forumID);
92 if (is_array($course_rows)) {
93 foreach ($course_rows as $row) {
94 $coursesDAO = new CoursesDAO();
95 $coursesDAO->updateModifiedDate($row['course_id']);
100 $msg->addError('DB_NOT_UPDATED');
106 * Return rows by content ID
110 * @author Cindy Qi Li
112 function getByContent($content_id)
114 $sql = "SELECT f.forum_id, f.title, f.description
115 FROM ".TABLE_PREFIX."content_forums_assoc cfa, ".TABLE_PREFIX."forums f
116 WHERE cfa.content_id = '".$content_id."'
117 AND cfa.forum_id = f.forum_id";
118 return $this->execute($sql);