Copy a students previous attempt to a new attempt.

@param int $assignmentid
@return array of warnings to indicate any errors.
@since Moodle 2.6
498571
public static function copy_previous_attempt($assignmentid) {

        $params = self::validate_parameters(self::copy_previous_attempt_parameters(),
                                            array('assignmentid' => $assignmentid));

        list($assignment, $course, $cm, $context) = self::validate_assign($params['assignmentid']);

        $notices = array();

        $assignment->copy_previous_attempt($notices);

        $warnings = array();
        foreach ($notices as $notice) {
            $warnings[] = self::generate_warning($assignmentid,
                                                 'couldnotcopyprevioussubmission',
                                                 $notice);
        }

        return $warnings;
    }
318030
def get_assignment(self, assignment_id):
        
        try:
            response = self.mturk.get_assignment(AssignmentId=assignment_id)
        except ClientError as ex:
            if "does not exist" in str(ex):
                return None
            raise
        return self._translate_assignment(response["Assignment"])
1343189
protected function getAssignedAddOns() {
        if (!$this->_assignedAddOns) {
            $this->_assignedAddOns = new AssignedAddOnList(
                $this->version,
                $this->solution['accountSid'],
                $this->solution['sid']
            );
        }

        return $this->_assignedAddOns;
    }
810679
public function getVariationForExperiment($experimentId)
    {
        $decision = $this->getDecisionForExperiment($experimentId);
        if (!is_null($decision)) {
            return $decision->getVariationId();
        }

        return null;
    }
901889
public static function get_blockids_from_courseid($courseid) {
        global $DB;

        // Get the context of the course
        $contextid = context_course::instance($courseid)->id;

        // Get all the block instances which parentcontextid is the course contextid
        $blockids = array();
        $instances = $DB->get_records('block_instances', array('parentcontextid' => $contextid), '', 'id');
        foreach ($instances as $instance) {
            $blockids[] = $instance->id;
        }
        return $blockids;
    }
386109
public static function list_course_competencies($courseid) {
        global $DB;

        $sql = 'SELECT coursecomp.*
                  FROM {' . self::TABLE . '} coursecomp
                  JOIN {' . competency::TABLE . '} comp
                    ON coursecomp.competencyid = comp.id
                 WHERE coursecomp.courseid = ?';
        $params = array($courseid);

        $sql .= ' ORDER BY coursecomp.sortorder ASC';
        $results = $DB->get_recordset_sql($sql, $params);
        $instances = array();
        foreach ($results as $result) {
            array_push($instances, new course_competency(0, $result));
        }
        $results->close();

        return $instances;
    }
955045
public static function reveal_identities($assignmentid) {
        global $CFG, $USER;

        $params = self::validate_parameters(self::reveal_identities_parameters(),
                                            array('assignmentid' => $assignmentid));

        list($assignment, $course, $cm, $context) = self::validate_assign($params['assignmentid']);

        $warnings = array();
        if (!$assignment->reveal_identities()) {
            $detail = 'User id: ' . $USER->id . ', Assignment id: ' . $params['assignmentid'];
            $warnings[] = self::generate_warning($params['assignmentid'],
                                                 'couldnotrevealidentities',
                                                 $detail);
        }

        return $warnings;
    }
231114
public static function unlock_submissions($assignmentid, $userids) {
        global $CFG;

        $params = self::validate_parameters(self::unlock_submissions_parameters(),
                        array('assignmentid' => $assignmentid,
                              'userids' => $userids));

        list($assignment, $course, $cm, $context) = self::validate_assign($params['assignmentid']);

        $warnings = array();
        foreach ($params['userids'] as $userid) {
            if (!$assignment->unlock_submission($userid)) {
                $detail = 'User id: ' . $userid . ', Assignment id: ' . $params['assignmentid'];
                $warnings[] = self::generate_warning($params['assignmentid'],
                                                     'couldnotunlock',
                                                     $detail);
            }
        }

        return $warnings;
    }
352436
public function getBBCodes($setId = 1)
    {
        $set = $this->getSet($setId);
        $bbcodes = $set->getCodes();
        return $bbcodes;
    }
217652
public function duplicate_page($pageid) {
        global $PAGE;
        $cm = get_coursemodule_from_instance('lesson', $this->properties->id, $this->properties->course);
        $context = context_module::instance($cm->id);
        // Load the page.
        $page = $this->load_page($pageid);
        $properties = $page->properties();
        // The create method checks to see if these properties are set and if not sets them to zero, hence the unsetting here.
        if (!$properties->qoption) {
            unset($properties->qoption);
        }
        if (!$properties->layout) {
            unset($properties->layout);
        }
        if (!$properties->display) {
            unset($properties->display);
        }

        $properties->pageid = $pageid;
        // Add text and format into the format required to create a new page.
        $properties->contents_editor = array(
            'text' => $properties->contents,
            'format' => $properties->contentsformat
        );
        $answers = $page->get_answers();
        // Answers need to be added to $properties.
        $i = 0;
        $answerids = array();
        foreach ($answers as $answer) {
            // Needs to be rearranged to work with the create function.
            $properties->answer_editor[$i] = array(
                'text' => $answer->answer,
                'format' => $answer->answerformat
            );

            $properties->response_editor[$i] = array(
              'text' => $answer->response,
              'format' => $answer->responseformat
            );
            $answerids[] = $answer->id;

            $properties->jumpto[$i] = $answer->jumpto;
            $properties->score[$i] = $answer->score;

            $i++;
        }
        // Create the duplicate page.
        $newlessonpage = lesson_page::create($properties, $this, $context, $PAGE->course->maxbytes);
        $newanswers = $newlessonpage->get_answers();
        // Copy over the file areas as well.
        $this->copy_page_files('page_contents', $pageid, $newlessonpage->id, $context->id);
        $j = 0;
        foreach ($newanswers as $answer) {
            if (isset($answer->answer) && strpos($answer->answer, '@@PLUGINFILE@@') !== false) {
                $this->copy_page_files('page_answers', $answerids[$j], $answer->id, $context->id);
            }
            if (isset($answer->response) && !is_array($answer->response) && strpos($answer->response, '@@PLUGINFILE@@') !== false) {
                $this->copy_page_files('page_responses', $answerids[$j], $answer->id, $context->id);
            }
            $j++;
        }
    }
190312
public static function get_sections_from_courseid($courseid) {
        global $DB;

        // Get all sections belonging to requested course
        $sectionsarr = array();
        $sections = $DB->get_records('course_sections', array('course' => $courseid), 'section');
        foreach ($sections as $section) {
            $sectionsarr[] = $section->id;
        }
        return $sectionsarr;
    }
874419
public static function list_competencies($courseid) {
        global $DB;

        $sql = 'SELECT comp.*
                  FROM {' . competency::TABLE . '} comp
                  JOIN {' . self::TABLE . '} coursecomp
                    ON coursecomp.competencyid = comp.id
                 WHERE coursecomp.courseid = ?';
        $params = array($courseid);

        $sql .= ' ORDER BY coursecomp.sortorder ASC';
        $results = $DB->get_recordset_sql($sql, $params);
        $instances = array();
        foreach ($results as $result) {
            $comp = new competency(0, $result);
            $instances[$comp->get('id')] = $comp;
        }
        $results->close();

        return $instances;
    }
1182086
public static function move_up_competency($id) {
        static::require_enabled();
        $current = new competency($id);

        // First we do a permissions check.
        require_capability('moodle/competency:competencymanage', $current->get_context());

        $sortorder = $current->get('sortorder');
        if ($sortorder == 0) {
            return false;
        }

        $sortorder = $sortorder - 1;
        $current->set('sortorder', $sortorder);

        $filters = array('parentid' => $current->get('parentid'),
                         'competencyframeworkid' => $current->get('competencyframeworkid'),
                         'sortorder' => $sortorder);
        $children = self::list_competencies($filters, 'id');
        foreach ($children as $needtoswap) {
            $needtoswap->set('sortorder', $sortorder + 1);
            $needtoswap->update();
        }

        // OK - all set.
        $result = $current->update();

        return $result;
    }
122642
protected function get_sample_courseid($sampleid) {
        global $DB;

        if (empty($this->samplecourses[$sampleid])) {
            $course = enrol_get_course_by_user_enrolment_id($sampleid);
            $this->samplecourses[$sampleid] = $course->id;
        }

        return $this->samplecourses[$sampleid];
    }
179524
protected static function validate_quiz($quizid) {
        global $DB;

        // Request and permission validation.
        $quiz = $DB->get_record('quiz', array('id' => $quizid), '*', MUST_EXIST);
        list($course, $cm) = get_course_and_cm_from_instance($quiz, 'quiz');

        $context = context_module::instance($cm->id);
        self::validate_context($context);

        return array($quiz, $course, $cm, $context);
    }
305476
public function copy($raterid, $itemid) {
        global $DB;
        $instanceid = parent::copy($raterid, $itemid);
        $currentgrade = $this->get_rubric_filling();
        foreach ($currentgrade['criteria'] as $criterionid => $record) {
            $params = array('instanceid' => $instanceid, 'criterionid' => $criterionid,
                'levelid' => $record['levelid'], 'remark' => $record['remark'], 'remarkformat' => $record['remarkformat']);
            $DB->insert_record('gradingform_rubric_fillings', $params);
        }
        return $instanceid;
    }
1006261
protected function getNewInstance($sessionId)
    {
        $className = $this->repository->getClassName();
        $session = new $className();

        $session->setSessionId($sessionId);

        return $session;
    }