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 "tests" table
20 if (!defined('TR_INCLUDE_PATH')) exit;
22 require_once(TR_INCLUDE_PATH. 'classes/DAO/DAO.class.php');
23 require_once(TR_INCLUDE_PATH. 'classes/Utility.class.php');
25 class TestsDAO extends DAO {
31 * @return true, if successful
32 * false and add error into global var $msg, if unsuccessful
35 public function Create($course_id, $title, $description)
39 $title = Utility::validateLength($addslashes(trim($title)), 100);
40 $description = $addslashes(trim($description));
42 if ($this->isFieldsValid($title))
44 $sql = "INSERT INTO ".TABLE_PREFIX."tests " .
45 "(course_id, title, description)" .
46 "VALUES ($course_id, '$title', '$description')";
48 if (!$this->execute($sql))
50 $msg->addError('DB_NOT_UPDATED');
55 return mysql_insert_id();
65 * Update an existing user record
67 * @param testID, title, description
68 * @return user id, if successful
69 * false and add error into global var $msg, if unsuccessful
72 public function Update($testID, $title, $description)
76 $title = Utility::validateLength($addslashes(trim($title)), 100);
77 $description = $addslashes(trim($description));
79 if ($this->isFieldsValid($title))
81 $sql = "UPDATE ".TABLE_PREFIX."tests " .
83 description='$description'
84 WHERE test_id=$testID";
86 return $this->execute($sql);
94 * @return true, if successful
95 * false and add error into global var $msg, if unsuccessful
98 public function Delete($testID)
100 $sql = "DELETE FROM ".TABLE_PREFIX."tests WHERE test_id = ".$testID;
101 return $this->execute($sql);
105 * Return content information by given content id
109 * @author Cindy Qi Li
111 public function get($testID)
113 $sql = 'SELECT * FROM '.TABLE_PREFIX.'tests WHERE test_id='.$testID;
114 if ($rows = $this->execute($sql))
122 * Return max ordering based on given course id and content parent id
126 * @author Cindy Qi Li
128 public function getByCourseID($courseID)
131 FROM ".TABLE_PREFIX."tests
132 WHERE course_id=$courseID";
133 return $this->execute($sql);
137 * Validates fields preparing for insert and update
142 * $pass_score_checkbox
145 * @return true if update successfully
146 * false if update unsuccessful
147 * @author Cindy Qi Li
149 private function isFieldsValid($title)
153 $missing_fields = array();
156 $missing_fields[] = _AT('title');
159 if ($missing_fields) {
160 $missing_fields = implode(', ', $missing_fields);
161 $msg->addError(array('EMPTY_FIELDS', $missing_fields));
164 if (!$msg->containsErrors()) return true;