'); if (!$name) { $name = parse_config($config, ''); $user = parse_config($config, ''); $passwd = parse_config($config, ''); $host = parse_config($config, ''); } else { $user = parse_config($config, ''); $passwd = parse_config($config, ''); $host = parse_config($config, ''); } if ($host == null) { $host = "localhost"; } $instance = new DbConn(); $retval = $instance->init_conn($user, $passwd, $host, $name); if (!$retval) return null; } return $instance; } static function escape_string($string) { $db = self::get(); return $db->base_escape_string($string); } } class BoltUser { static $cache; static function lookup_userid($id) { $db = BoltDb::get(); return $db->lookup('bolt_user', 'BoltUser', "user_id=$id"); } static function insert($clause) { $db = BoltDb::get(); return $db->insert('bolt_user', $clause); } static function lookup(&$user) { if (!$user) return; if (isset($user->bolt)) return; if (isset(self::$cache[$user->id])) { $bolt = self::$cache[$user->id]; } else { $bolt = self::lookup_userid($user->id); if (!$bolt) { self::insert("(user_id) values ($user->id)"); $bolt = self::lookup_userid($user->id); } self::$cache[$user->id] = $bolt; } $user->bolt = $bolt; } function update($clause) { $db = BoltDb::get(); $clause = "$clause where user_id=$this->user_id"; return $db->update_aux('bolt_user', $clause); } } class BoltCourse { static function insert($clause) { $db = BoltDb::get(); $ret = $db->insert('bolt_course', $clause); if (!$ret) return $ret; return $db->insert_id(); } static function lookup_id($id) { $db = BoltDb::get(); return $db->lookup_id($id, 'bolt_course', 'BoltCourse'); } static function lookup_name($name) { $db = BoltDb::get(); return $db->lookup('bolt_course', 'BoltCourse', "short_name='$name'"); } static function enum() { $db = BoltDb::get(); return $db->enum('bolt_course', 'BoltCourse'); } function update($clause) { $db = BoltDb::get(); return $db->update($this, 'bolt_course', $clause); } } class BoltEnrollment { static function insert($clause) { $db = BoltDb::get(); return $db->insert('bolt_enrollment', $clause); } function lookup($user_id, $course_id) { $db = BoltDb::get(); return $db->lookup('bolt_enrollment', 'BoltEnrollment', "user_id=$user_id and course_id=$course_id"); } function update($clause) { $db = BoltDb::get(); $db->update_aux('bolt_enrollment', "$clause where user_id=$this->user_id and course_id=$this->course_id"); } function delete($user_id, $course_id) { $db = BoltDb::get(); $db->delete_aux('bolt_enrollment', "user_id=$user_id and course_id=$course_id"); } } class BoltView { static function insert($clause) { $db = BoltDb::get(); $ret = $db->insert('bolt_view', $clause); if (!$ret) return null; return $db->insert_id(); } static function lookup_id($id) { $db = BoltDb::get(); return $db->lookup_id($id, 'bolt_view', 'BoltView'); } function update($clause) { $db = BoltDb::get(); $db->update($this, 'bolt_view', $clause); } static function enum($clause) { $db = BoltDb::get(); return $db->enum('bolt_view', 'BoltView', $clause); } } class BoltResult { static function insert($clause) { $db = BoltDb::get(); $ret = $db->insert('bolt_result', $clause); if (!$ret) return null; return $db->insert_id(); } static function lookup_id($id) { $db = BoltDb::get(); return $db->lookup_id($id, 'bolt_result', 'BoltResult'); } static function enum($clause) { $db = BoltDb::get(); return $db->enum('bolt_result', 'BoltResult', $clause); } } class BoltXsetResult { static function lookup_id($id) { $db = BoltDb::get(); return $db->lookup_id($id, 'bolt_xset_result', 'BoltXsetResult'); } static function insert($clause) { $db = BoltDb::get(); $ret = $db->insert('bolt_xset_result', $clause); if (!$ret) return null; return $db->insert_id(); } static function enum($clause) { $db = BoltDb::get(); return $db->enum('bolt_xset_result', 'BoltXsetResult', $clause); } } class BoltRefreshRec { static function lookup_id($id) { $db = BoltDb::get(); return $db->lookup_id($id, 'bolt_refresh', 'BoltRefreshRec'); } function lookup($clause) { $db = BoltDb::get(); return $db->lookup('bolt_refresh', 'BoltRefreshRec', $clause); } static function replace($clause) { $db = BoltDb::get(); return $db->replace('bolt_refresh', $clause); } static function insert($clause) { $db = BoltDb::get(); $ret = $db->insert('bolt_refresh', $clause); if (!$ret) return null; return $db->insert_id(); } static function enum($clause) { $db = BoltDb::get(); return $db->enum('bolt_refresh', 'BoltRefreshRec', $clause); } function update($clause) { $db = BoltDb::get(); $db->update($this, 'bolt_refresh', $clause); } } class BoltSelectFinished { static function insert($clause) { $db = BoltDb::get(); return $db->insert('bolt_select_finished', $clause); } static function enum($clause) { $db = BoltDb::get(); return $db->enum('bolt_select_finished', 'BoltSelectFinished', $clause); } } class BoltQuestion { static function insert($clause) { $db = BoltDb::get(); return $db->insert('bolt_question', $clause); } static function enum($clause) { $db = BoltDb::get(); return $db->enum('bolt_question', 'BoltQuestion', $clause); } } // TODO: move this somewhere else, and think about whether it's correct // function bolt_course_status($course_id, $user_id) { $e = BoltEnrollment::lookup($user_id, $course_id); if (!$e) return BOLT_COURSE_NOT_STARTED; $view = BoltView::lookup_id($e->last_view_id); if ($view->fraction_done == 1) return BOLT_COURSE_FINISHED; return BOLT_COURSE_STARTED; } ?>