def insertQuestion(self, courseId, question): db = dbc() query = "INSERT INTO questions (course_id, question) VALUES ({0}, '{1}')" query = query.format(courseId, question) db.execute(query) questionId = db.getLastId() return questionId
def getUserCourses(self, userId): db = dbc() query = "SELECT title, type, date_log FROM courses_taken as A JOIN courses as B ON A.course_id = B.course_id WHERE user_id={0} ORDER BY date_log DESC".format( userId) courses = db.resultDict(query) return courses
def insertCourse(self, userId, title, type): db = dbc() query = "INSERT INTO courses (author_id, title, type, date) VALUES ({0}, '{1}', '{2}', NOW())".format( userId, title, type) db.execute(query) id = db.getLastId() return id
def getNewestCourse(self): db = dbc() newestCourseQuery = "SELECT * FROM courses ORDER BY date DESC LIMIT 1" result = db.resultDict(newestCourseQuery) if result: return result[0] return False
def getUserData(self, userId): db = dbc() query = "SELECT email, username FROM users WHERE user_id={0}".format( userId) userData = db.resultDict(query) return userData
def checkUser(self, name, email): db = dbc() selectQuery = "SELECT username, email FROM users WHERE username='******' OR email='{1}'".format( name, email) result = dict(db.resultTuple(selectQuery)) usersCount = len(result) return usersCount
def insertDescription(self, courseId, description): db = dbc() query = "UPDATE courses SET description='{0}' WHERE course_id='{1}'".format(description, courseId) db.execute(query)
def insertCourse(self, userId, title, type): db = dbc() query = "INSERT INTO courses (author_id, title, type, date) VALUES ({0}, '{1}', '{2}', NOW())".format(userId, title, type) db.execute(query) id = db.getLastId() return id
def insertDescription(self, courseId, description): db = dbc() query = "UPDATE courses SET description='{0}' WHERE course_id='{1}'".format( description, courseId) db.execute(query)
def getCourseTypes(self): db = dbc() query = "SELECT type FROM course_types" types = db.resultDict(query) return types
def getUserData(self, userId): db = dbc() query = "SELECT email, username FROM users WHERE user_id={0}".format(userId) userData = db.resultDict(query) return userData
def getAnswers(self, questionId): db = dbc() answersQuery = "SELECT answer_id, answer, correct FROM answers WHERE question_id={0}".format(questionId) answers = db.resultDict(answersQuery) return answers
def insertAnswer(self, questionId, answer, correct): db = dbc() answQuery = "INSERT INTO answers (question_id, answer, correct) VALUES({0}, '{1}', {2})" answQuery = answQuery.format(questionId, answer, correct) db.execute(answQuery)
def courseTaken(self, userId, courseId): db = dbc() query = "INSERT INTO courses_taken (user_id, course_id, date_log) VALUES({0}, {1}, NOW()) ".format( userId, courseId) db.execute(query)
def getAnswers(self, questionId): db = dbc() answersQuery = "SELECT answer_id, answer, correct FROM answers WHERE question_id={0}".format( questionId) answers = db.resultDict(answersQuery) return answers
def getQuestions(self, courseId): db = dbc() questionsQuery = "SELECT question_id, question FROM questions WHERE course_id={0}".format( courseId) questions = db.resultDict(questionsQuery) return questions
def getQuestions(self, courseId): db = dbc() questionsQuery = "SELECT question_id, question FROM questions WHERE course_id={0}".format(courseId) questions = db.resultDict(questionsQuery) return questions
def courseTaken(self, userId, courseId): db = dbc() query = "INSERT INTO courses_taken (user_id, course_id, date_log) VALUES({0}, {1}, NOW()) ".format(userId, courseId) db.execute(query)
def searchCourses(self, courseType): db = dbc() query = "SELECT course_id, title FROM courses WHERE type='{0}'".format( courseType) courses = db.resultDict(query) return courses
def getUserCourses(self, userId): db = dbc() query = "SELECT title, type, date_log FROM courses_taken as A JOIN courses as B ON A.course_id = B.course_id WHERE user_id={0} ORDER BY date_log DESC".format(userId) courses = db.resultDict(query) return courses
def getDescription(self, courseId): db = dbc() query = "SELECT description FROM courses WHERE course_id={0}".format( courseId) descr = db.resultDict(query) return descr
def searchCourses(self, courseType): db = dbc() query = "SELECT course_id, title FROM courses WHERE type='{0}'".format(courseType) courses = db.resultDict(query) return courses
def createUser(self, name, email, password): db = dbc() query = "INSERT INTO users (username, email, password) VALUES('{0}', '{1}', '{2}')".format( name, email, password) db.execute(query)
def getDescription(self, courseId): db = dbc() query = "SELECT description FROM courses WHERE course_id={0}".format(courseId) descr = db.resultDict(query) return descr
def getUserInfo(self, email, password): db = dbc() query = "SELECT user_id, role FROM users WHERE email = '{0}' AND password = '******'".format( email, password) result = db.resultDict(query) return result