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_tests_assoc" table
20 if (!defined('TR_INCLUDE_PATH')) exit;
22 require_once(TR_INCLUDE_PATH. 'classes/DAO/DAO.class.php');
24 class ContentTestsAssocDAO extends DAO {
29 * @param content_id, test_id
30 * @return true / false
33 function Create($content_id, $test_id)
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");
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_tests_assoc
60 WHERE content_id = ".$contentID."";
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");
69 $msg->addError('DB_NOT_UPDATED');
75 * Delete row by test ID
78 * @return true or false
81 function DeleteByTestID($testID)
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);
92 if ($test_rows['course_id'] > 0) {
93 $coursesDAO = new CoursesDAO();
94 $coursesDAO->updateModifiedDate($test_rows['course_id']);
98 $msg->addError('DB_NOT_UPDATED');
104 * Return rows by content ID
108 * @author Cindy Qi Li
110 function getByContent($content_id)
112 $sql = "SELECT * FROM ".TABLE_PREFIX."content_tests_assoc WHERE content_id = '".$content_id."'";
113 return $this->execute($sql);