AC_4897, AC_4898, AC_4899: Multifile uploader fixes.
[acontent.git] / include / classes / DAO / ContentForumsAssocDAO.class.php
1 <?php
2 /************************************************************************/
3 /* AContent                                                             */
4 /************************************************************************/
5 /* Copyright (c) 2010                                                   */
6 /* Inclusive Design Institute                                           */
7 /*                                                                      */
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 /************************************************************************/
12
13 /**
14 * DAO for "content_forums_assoc" table
15 * @access       public
16 * @author       Cindy Qi Li
17 * @package      DAO
18 */
19
20 if (!defined('TR_INCLUDE_PATH')) exit;
21
22 require_once(TR_INCLUDE_PATH. 'classes/DAO/DAO.class.php');
23
24 class ContentForumsAssocDAO extends DAO {
25
26         /**
27         * Insert a new row
28         * @access  public
29         * @param   content_id, forum_id
30         * @return  true / false
31         * @author  Cindy Qi Li
32         */
33         function Create($content_id, $forum_id)
34         {
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");
43                         return true;
44                 } else {
45                         $msg->addError('DB_NOT_UPDATED');
46                         return false;
47                 }
48         }
49         
50         /**
51         * Delete row by content ID
52         * @access  public
53         * @param   contentID
54         * @return  true or false
55         * @author  Cindy Qi Li
56         */
57         function DeleteByContentID($contentID)
58         {
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");
66                         return true;
67                 } else {
68                         $msg->addError('DB_NOT_UPDATED');
69                         return false;
70                 }
71         }
72         
73         /**
74         * Delete row by forum ID
75         * @access  public
76         * @param   forumID
77         * @return  true or false
78         * @author  Cindy Qi Li
79         */
80         function DeleteByForumID($forumID)
81         {
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');
88                         
89                         $forumsCoursesDAO = new ForumsCoursesDAO();
90                         $course_rows = $forumsCoursesDAO->getByForum($forumID);
91                         
92                         if (is_array($course_rows)) {
93                                 foreach ($course_rows as $row) {
94                                         $coursesDAO = new CoursesDAO();
95                                         $coursesDAO->updateModifiedDate($row['course_id']);
96                                 }
97                         }
98                         return true;
99                 } else {
100                         $msg->addError('DB_NOT_UPDATED');
101                         return false;
102                 }
103         }
104         
105         /**
106         * Return rows by content ID
107         * @access  public
108         * @param   name
109         * @return  table rows
110         * @author  Cindy Qi Li
111         */
112         function getByContent($content_id)
113         {
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);
119         }
120 }
121 ?>