46d3ff2a143ff124fa129cfcddcbb78fa1440a87
[acontent.git] / docs / include / classes / DAO / ContentTestsAssocDAO.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_tests_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 ContentTestsAssocDAO extends DAO {
25
26         /**
27         * Insert a new row
28         * @access  public
29         * @param   content_id, test_id
30         * @return  true / false
31         * @author  Cindy Qi Li
32         */
33         function Create($content_id, $test_id)
34         {
35                 $sql =  'INSERT INTO ' . TABLE_PREFIX . 'content_tests_assoc' . 
36                                 '(content_id, test_id) ' .
37                                 'VALUES (' . $content_id . ", $test_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_tests_assoc 
60                      WHERE content_id = ".$contentID."";
61                 
62             if ($this->execute($sql)) {
63                         // update the courses.modified_date to the current timestamp
64                         include_once(TR_INCLUDE_PATH.'classes/DAO/CoursesDAO.class.php');
65                         $coursesDAO = new CoursesDAO();
66                         $coursesDAO->updateModifiedDate($contentID, "content_id");
67                         return true;
68                 } else {
69                         $msg->addError('DB_NOT_UPDATED');
70                         return false;
71                 }
72         }
73         
74         /**
75         * Delete row by test ID
76         * @access  public
77         * @param   testID
78         * @return  true or false
79         * @author  Cindy Qi Li
80         */
81         function DeleteByTestID($testID)
82         {
83             $sql = "DELETE FROM ".TABLE_PREFIX."content_tests_assoc 
84                      WHERE test_id = ".$testID."";
85                 if ($this->execute($sql)) {
86                         // update the courses.modified_date to the current timestamp
87                         include_once(TR_INCLUDE_PATH.'classes/DAO/TestsDAO.class.php');
88                         include_once(TR_INCLUDE_PATH.'classes/DAO/CoursesDAO.class.php');
89                         $testsDAO = new TestsDAO();
90                         $test_rows = $testsDAO->get($testID);
91                         
92                         if ($test_rows['course_id'] > 0) {
93                                 $coursesDAO = new CoursesDAO();
94                                 $coursesDAO->updateModifiedDate($test_rows['course_id']);
95                         }
96                         return true;
97                 } else {
98                         $msg->addError('DB_NOT_UPDATED');
99                         return false;
100                 }
101         }
102         
103         /**
104         * Return rows by content ID
105         * @access  public
106         * @param   name
107         * @return  table rows
108         * @author  Cindy Qi Li
109         */
110         function getByContent($content_id)
111         {
112             $sql = "SELECT * FROM ".TABLE_PREFIX."content_tests_assoc WHERE content_id = '".$content_id."'";
113             return $this->execute($sql);
114         }
115 }
116 ?>