Skip to content

Commit

Permalink
Merge branch 'w16_MDL-41101_m27_assign' of git://github.com/skodak/mo…
Browse files Browse the repository at this point in the history
…odle
  • Loading branch information
marinaglancy committed Apr 17, 2014
2 parents 127daca + 0202d43 commit 0b10dfc
Show file tree
Hide file tree
Showing 38 changed files with 3,206 additions and 1,084 deletions.
72 changes: 43 additions & 29 deletions mod/assign/classes/event/all_submissions_downloaded.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,33 @@
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class all_submissions_downloaded extends \core\event\base {
class all_submissions_downloaded extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;

/**
* Legacy log data.
* Create instance of event.
*
* @var array
* @since Moodle 2.7
*
* @param \assign $assign
* @return all_submissions_downloaded
*/
protected $legacylogdata;
public static function create_from_assign(\assign $assign) {
$data = array(
'context' => $assign->get_context(),
'objectid' => $assign->get_instance()->id
);
self::$preventcreatecall = false;
/** @var submission_graded $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
return $event;
}

/**
* Returns description of what happened.
Expand All @@ -52,52 +71,47 @@ public function get_description() {
return "User {$this->userid} has downloaded all the submissions.";
}

/**
* Return legacy data for add_to_log().
*
* @return array
*/
protected function get_legacy_logdata() {
return $this->legacylogdata;
}

/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('event_all_submissions_downloaded', 'mod_assign');
return get_string('eventallsubmissionsdownloaded', 'mod_assign');
}

/**
* Get URL related to the action.
* Init method.
*
* @return \moodle_url
* @return void
*/
public function get_url() {
return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_TEACHING;
$this->data['objecttable'] = 'assign';
}

/**
* Sets the legacy event log data.
* Return legacy data for add_to_log().
*
* @param \stdClass $legacylogdata legacy log data.
* @return void
* @return array
*/
public function set_legacy_logdata($legacylogdata) {
$this->legacylogdata = $legacylogdata;
protected function get_legacy_logdata() {
$this->set_legacy_logdata('download all submissions', get_string('downloadall', 'assign'));
return parent::get_legacy_logdata();
}

/**
* Init method.
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_TEACHING;
$this->data['objecttable'] = 'assign';
}
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call all_submissions_downloaded::create() directly, use all_submissions_downloaded::create_from_assign() instead.');
}

parent::validate_data();
}
}
68 changes: 35 additions & 33 deletions mod/assign/classes/event/assessable_submitted.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,31 @@
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class assessable_submitted extends \core\event\assessable_submitted {

class assessable_submitted extends base {
/**
* Legacy log data.
* Create instance of event.
*
* @since Moodle 2.7
*
* @var array
* @param \assign $assign
* @param \stdClass $submission
* @param bool $editable
* @return assessable_submitted
*/
protected $legacylogdata;
public static function create_from_submission(\assign $assign, \stdClass $submission, $editable) {
$data = array(
'context' => $assign->get_context(),
'objectid' => $submission->id,
'other' => array(
'submission_editable' => $editable,
),
);
/** @var assessable_submitted $event */
$event = self::create($data);
$event->set_assign($assign);
$event->add_record_snapshot('assign_submission', $submission);
return $event;
}

/**
* Returns description of what happened.
Expand Down Expand Up @@ -83,51 +100,35 @@ public static function get_legacy_eventname() {
return 'assessable_submitted';
}

/**
* Return legacy data for add_to_log().
*
* @return array
*/
protected function get_legacy_logdata() {
return $this->legacylogdata;
}

/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('event_assessable_submitted', 'mod_assign');
return get_string('eventassessablesubmitted', 'mod_assign');
}

/**
* Get URL related to the action
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
}

/**
* Sets the legacy event log data.
* Init method.
*
* @param \stdClass $legacylogdata legacy log data.
* @return void
*/
public function set_legacy_logdata($legacylogdata) {
$this->legacylogdata = $legacylogdata;
protected function init() {
$this->data['objecttable'] = 'assign_submission';
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
}

/**
* Init method.
* Return legacy data for add_to_log().
*
* @return void
* @return array
*/
protected function init() {
parent::init();
$this->data['objecttable'] = 'assign_submission';
protected function get_legacy_logdata() {
$submission = $this->get_record_snapshot('assign_submission', $this->objectid);
$this->set_legacy_logdata('submit for grading', $this->assign->format_submission_for_log($submission));
return parent::get_legacy_logdata();
}

/**
Expand All @@ -138,6 +139,7 @@ protected function init() {
*/
protected function validate_data() {
parent::validate_data();

if (!isset($this->other['submission_editable'])) {
throw new \coding_exception('Other must contain the key submission_editable.');
}
Expand Down
131 changes: 131 additions & 0 deletions mod/assign/classes/event/base.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* The mod_assign abstract base class.
*
* Most events can extend this class.
*
* @package mod_assign
* @since Moodle 2.7
* @copyright 2014 Mark Nelson
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace mod_assign\event;

defined('MOODLE_INTERNAL') || die();

abstract class base extends \core\event\base {
/** @var \assign */
protected $assign;

/**
* Legacy log data.
*
* @var array
*/
protected $legacylogdata;

/**
* Set assign instance for this event.
* @param \assign $assign
* @throws \coding_exception
*/
public function set_assign(\assign $assign) {
if ($this->is_triggered()) {
throw new \coding_exception('set_assign() must be done before triggerring of event');
}
if ($assign->get_context()->id != $this->get_context()->id) {
throw new \coding_exception('Invalid assign isntance supplied!');
}
$this->assign = $assign;
}

/**
* Get assign instance.
*
* NOTE: to be used from observers only.
*
* @return \assign
*/
public function get_assign() {
if ($this->is_restored()) {
throw new \coding_exception('get_assign() is intended for event observers only');
}
if (!isset($this->assign)) {
debugging('assign property should be initialised in each event', DEBUG_DEVELOPER);
global $CFG;
require_once($CFG->dirroot . '/mod/assign/locallib.php');
$cm = get_coursemodule_from_id('assign', $this->contextinstanceid, 0, false, MUST_EXIST);
$course = get_course($cm->course);
$this->assign = new \assign($this->get_context(), $cm, $course);
}
return $this->assign;
}


/**
* Returns relevant URL.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
}

/**
* Sets the legacy event log data.
*
* @param string $action The current action
* @param string $info A detailed description of the change. But no more than 255 characters.
* @param string $url The url to the assign module instance.
*/
public function set_legacy_logdata($action = '', $info = '', $url = '') {
$fullurl = 'view.php?id=' . $this->contextinstanceid;
if ($url != '') {
$fullurl .= '&' . $url;
}

$this->legacylogdata = array($this->courseid, 'assign', $action, $fullurl, $info, $this->contextinstanceid);
}

/**
* Return legacy data for add_to_log().
*
* @return array
*/
protected function get_legacy_logdata() {
if (isset($this->legacylogdata)) {
return $this->legacylogdata;
}

return null;
}

/**
* Custom validation.
*
* @throws \coding_exception
*/
protected function validate_data() {
parent::validate_data();

if ($this->contextlevel != CONTEXT_MODULE) {
throw new \coding_exception('Context passed must be module context.');
}
}
}
Loading

0 comments on commit 0b10dfc

Please sign in to comment.