def __init__(self, objecttable, objectid, contextInstanceID):
        if type(objectid) is not long:
            raise moodleObjects.moodleWarning("Invalid ObjectID provided")

        self.standardInit()

        # Get additional information required for this
        query = """SELECT  *
				 FROM %sdialogue_conversations c
				 WHERE c.id = '%s'""" % (config.MOODLE_PREFIX, objectid)
        self.cursor.execute(query)
        row = self.cursor.fetchone()

        if (row is None):
            self.setRemovedObject(objecttable, objectid, contextInstanceID)
        else:
            self.data = row
            self.data['type'] = self.TYPE_EN
            self.data[
                'url'] = config.BASE_URI + "/mod/dialogue/conversation.php?id=%s&conversationid=%s" % (
                    str(contextInstanceID), str(objectid))
            self.data['name'] = row['subject']
            self.data['intro'] = "A Moodle Conversation"

            # Build the additional grouping
            query = """SELECT p.*
					 FROM %(prefix)sdialogue_conversations c
					 	JOIN %(prefix)sdialogue p ON c.dialogueid = p.id

					 WHERE c.id = '%(oid)s';""" % {
                'prefix': config.MOODLE_PREFIX,
                'oid': objectid
            }
            self.cursor.execute(query)
            row = self.cursor.fetchone()
            row['url'] = config.BASE_URI + "/mod/dialogue/view.php?id=%s" % (
                str(contextInstanceID))
            row['type'] = self.TYPE
            row['intro'] = "A Moodle Dialogue"

            self.groupings.append({
                "id": row['url'],
                "definition": {
                    "name": tincan.LanguageMap({'en': row['name']}),
                    "type": self.TYPE,
                    "description": tincan.LanguageMap({'en': row['intro']}),
                    "extensions": {
                        "http://lrs.learninglocker.net/define/extensions/moodle_module":
                        row
                    }
                }
            })
    def __init__(self, objecttable, objectid, contextInstanceID):
        if type(objectid) is not long:
            raise moodleObjects.moodleWarning("Invalid ObjectID provided")

        self.standardInit()

        # Get additional information required for this
        query = """SELECT  *
				 FROM %sforum_discussions c
				 WHERE c.id = '%s'""" % (config.MOODLE_PREFIX, objectid)
        self.cursor.execute(query)
        row = self.cursor.fetchone()

        # if 'name' not in row: raise moodleObjects.moodleWarning("Failed to match record from " + objecttable + " with objectid " + str(objectid))

        if (row is None):
            self.setRemovedObject(objecttable, objectid, contextInstanceID)
        else:
            self.data = row
            self.data['type'] = self.TYPE_EN
            self.data[
                'url'] = config.BASE_URI + "/mod/forum/discuss.php?id=" + str(
                    objectid)
            self.data['intro'] = "A Moodle discussion."

            # Build the additional grouping
            query = """SELECT f.*
					 FROM %sforum f
					 WHERE f.id = '%s';""" % (config.MOODLE_PREFIX, self.data['forum'])
            self.cursor.execute(query)
            row = self.cursor.fetchone()
            row['url'] = config.BASE_URI + "/mod/forum/view.php?id=" + str(
                contextInstanceID)
            row['type'] = 'forum'

            self.groupings.append({
                "id": row['url'],
                "definition": {
                    "name": tincan.LanguageMap({'en': row['name']}),
                    "type":
                    "http://lrs.learninglocker.net/define/type/moodle/forum",
                    "description": tincan.LanguageMap({'en': row['intro']}),
                    "extensions": {
                        "http://lrs.learninglocker.net/define/extensions/moodle_module":
                        row
                    }
                }
            })
예제 #3
0
    def __init__(self, objecttable, objectid, relatedUserID):
        if type(objectid) is not long:
            raise moodleObjects.moodleWarning("Invalid ObjectID provided")

        self.standardInit()

        # Get additional information required for this
        query = """SELECT  *
				 FROM %sassign c
				 WHERE c.id = '%s'""" % (config.MOODLE_PREFIX, objectid)
        self.cursor.execute(query)
        row = self.cursor.fetchone()

        # if 'name' not in row: raise moodleObjects.moodleWarning("Failed to match record from " + objecttable + " with objectid " + str(objectid))

        if (row is None):
            self.setRemovedObject(objecttable, objectid, None)
        else:
            self.data = row
            self.data['type'] = self.TYPE_EN
            self.data[
                'url'] = config.BASE_URI + "/mod/assign/view.php?id=" + str(
                    objectid)

            self.groupings.append({
                "id": row['url'],
                "definition": {
                    "name": tincan.LanguageMap({'en': row['name']}),
                    "type": self.TYPE,
                    "description": tincan.LanguageMap({'en': row['intro']}),
                    "extensions": {
                        "http://lrs.learninglocker.net/define/extensions/moodle_module":
                        row
                    }
                }
            })

        # Get the result
        query = """SELECT (gg.rawgrade/gg.rawgrademax) as scaled, gg.rawgrade as raw, gg.rawgrademax as max, true as completion, gg.feedback as response
				 FROM %(prefix)sassign_grades ag
				 	JOIN %(prefix)sgrade_items gi ON gi.iteminstance = ag.assignment
				 	JOIN %(prefix)sgrade_grades gg ON gg.itemid = gi.id
				 WHERE gi.itemmodule = 'assign'
				 AND ag.id = '%(oid)s'
				 AND gg.userid = '%(ruid)s'""" % {
            'prefix': config.MOODLE_PREFIX,
            'oid': objectid,
            'ruid': relatedUserID
        }
        self.cursor.execute(query)
        row = self.cursor.fetchone()

        # Quick fix for a empty response (regex criticals)
        if row['response'] is None: row['response'] = ''
        for key in ['scaled', 'raw', 'max']:
            if row[key] is not None: row[key] = int(row[key])

        self.result = {
            "score": {
                "scaled": row['scaled'],
                "raw": row['raw'],
                "max": row['max']
            },
            "completion": row['completion'],
            "response": re.sub(
                r'[^\x00-\x7F]+', ' ', row['response']
            )  # Non-unicode characters, cannot be serialized so this replaces them with a space
        }
예제 #4
0
    def __init__(self, objecttable, objectid, contextInstanceID):
        if type(objectid) is not long:
            raise moodleObjects.moodleWarning("Invalid ObjectID provided")

        self.standardInit()

        # Get additional information required for this
        query = """SELECT  *
				 FROM %squiz_attempts qa
				 WHERE qa.id = '%s'""" % (config.MOODLE_PREFIX, objectid)
        self.cursor.execute(query)
        row = self.cursor.fetchone()

        # if 'name' not in row: raise moodleObjects.moodleWarning("Failed to match record from " + objecttable + " with objectid " + str(objectid))

        if (row is None):
            self.setRemovedObject(objecttable, objectid, contextInstanceID)
        else:
            self.data = row
            self.data['name'] = 'Attempt ' + str(objectid)
            self.data['type'] = self.TYPE_EN
            self.data[
                'url'] = config.BASE_URI + "/mod/quiz/attempt.php?id=" + str(
                    objectid)
            if 'sumgrades' in self.data and self.data['sumgrades'] is not None:
                self.data['sumgrades'] = int(row['sumgrades'])
            self.data['questions'] = {}

            # Add additional information to the object
            query = """SELECT qa.*
					 FROM %squestion_attempts qa
					 WHERE qa.questionusageid = '%s';""" % (config.MOODLE_PREFIX,
                                             row['uniqueid'])
            self.cursor.execute(query)
            questionAttempts = self.cursor.fetchall(
            )  # Yes this is bad. So is creating 3 connections to a db.
            for questionAttempt in questionAttempts:
                # Clean questionAttempt information
                questionAttempt['maxmark'] = int(questionAttempt['maxmark'])
                questionAttempt['maxfraction'] = int(
                    questionAttempt['maxfraction'])
                questionAttempt['minfraction'] = int(
                    questionAttempt['minfraction'])
                questionAttempt['steps'] = {}

                # Query the steps
                query = """SELECT *
						 FROM %squestion_attempt_steps
						 WHERE questionattemptid = '%s';""" % (config.MOODLE_PREFIX,
                                             questionAttempt['id'])
                self.cursor.execute(query)
                attemptSteps = self.cursor.fetchall(
                )  # Yes this is bad. So is creating 4 connections to a db.

                for step in attemptSteps:
                    if 'fraction' in step and step['fraction'] is not None:
                        step['fraction'] = int(step['fraction'])
                    # Query the data
                    query = """SELECT *
							 FROM %squestion_attempt_step_data
							 WHERE attemptstepid = '%s';""" % (config.MOODLE_PREFIX, step['id'])
                    self.cursor.execute(query)
                    stepData = self.cursor.fetchone()
                    step['data'] = stepData
                    questionAttempt['steps'][step['id']] = step

                self.data['questions'][questionAttempt['id']] = questionAttempt

            # Build the additional grouping
            query = """SELECT q.*
					 FROM %squiz q
					 WHERE q.id = '%s';""" % (config.MOODLE_PREFIX, self.data['quiz'])
            self.cursor.execute(query)
            row = self.cursor.fetchone()
            row['url'] = config.BASE_URI + "/mod/quiz/view.php?id=" + str(
                contextInstanceID)
            row['type'] = 'quiz'
            row['grade'] = int(row['grade'])
            row['sumgrades'] = int(row['sumgrades'])

            self.groupings.append({
                "id": row['url'],
                "definition": {
                    "name": tincan.LanguageMap({'en': row['name']}),
                    "type":
                    "http://lrs.learninglocker.net/define/type/moodle/quiz",
                    "description": tincan.LanguageMap({'en': row['intro']}),
                    "extensions": {
                        "http://lrs.learninglocker.net/define/extensions/moodle_module":
                        row
                    }
                }
            })