MDL-39956 cohort: Event clean up and made ready for integration

* Added more PHP Documentation
* Localised strings for get_name()
* get_legacy_eventname() is now static
* get_legacy_eventdata() is now protected
* Testing legacy event data
* Added missing defined('MOODLE_INTERNAL') checks
* Added missing call to add_record_snapshot()
This commit is contained in:
Frederic Massart 2013-08-13 17:26:35 +08:00
parent 4fece33d9a
commit 25a66af722
8 changed files with 160 additions and 75 deletions

View file

@ -14,19 +14,34 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace core\event;
/**
* Cohort created event.
* Cohort updated event.
*
* @package core
* @copyright 2013 Dan Poltawski <dan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\event;
defined('MOODLE_INTERNAL') || die();
/**
* Cohort created event class.
*
* @package core
* @copyright 2013 Dan Poltawski <dan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class cohort_created extends base {
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'c';
// TODO MDL-41040.
$this->data['level'] = 50;
$this->data['objecttable'] = 'cohort';
}
@ -34,25 +49,24 @@ class cohort_created extends base {
/**
* Returns localised general event name.
*
* @return string|\lang_string
* @return string
*/
public static function get_name() {
//TODO: localise
return 'Cohort created';
return get_string('event_cohort_created', 'core_cohort');
}
/**
* Returns localised description of what happened.
* Returns description of what happened.
*
* @return string|\lang_string
* @return string
*/
public function get_description() {
//TODO: localise
return 'Cohort '.$this->objectid.' was created by '.$this->userid.' at context '.$this->contextid;
}
/**
* Returns relevant URL.
*
* @return \moodle_url
*/
public function get_url() {
@ -60,20 +74,20 @@ class cohort_created extends base {
}
/**
* Does this event replace legacy event?
* Return legacy event name.
*
* @return null|string legacy event name
* @return string legacy event name
*/
public function get_legacy_eventname() {
public static function get_legacy_eventname() {
return 'cohort_added';
}
/**
* Legacy event data if get_legacy_eventname() is not empty.
* Return legacy event data.
*
* @return mixed
* @return stdClass
*/
public function get_legacy_eventdata() {
protected function get_legacy_eventdata() {
return $this->get_record_snapshot('cohort', $this->objectid);
}
}

View file

@ -14,8 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace core\event;
/**
* Cohort deleted event.
*
@ -24,9 +22,26 @@ namespace core\event;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\event;
defined('MOODLE_INTERNAL') || die();
/**
* Cohort deleted event class.
*
* @package core
* @copyright 2013 Dan Poltawski <dan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class cohort_deleted extends base {
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'd';
// TODO MDL-41040.
$this->data['level'] = 50;
$this->data['objecttable'] = 'cohort';
}
@ -34,25 +49,24 @@ class cohort_deleted extends base {
/**
* Returns localised general event name.
*
* @return string|\lang_string
* @return string
*/
public static function get_name() {
//TODO: localise
return 'Cohort deleted';
return get_string('event_core_deleted', 'core_cohort');
}
/**
* Returns localised description of what happened.
* Returns description of what happened.
*
* @return string|\lang_string
* @return string
*/
public function get_description() {
//TODO: localise
return 'Cohort '.$this->objectid.' was deleted by '.$this->userid.' from context '.$this->contextid;
}
/**
* Returns relevant URL.
*
* @return \moodle_url
*/
public function get_url() {
@ -60,20 +74,20 @@ class cohort_deleted extends base {
}
/**
* Does this event replace legacy event?
* Return legacy event name.
*
* @return null|string legacy event name
*/
public function get_legacy_eventname() {
public static function get_legacy_eventname() {
return 'cohort_deleted';
}
/**
* Legacy event data if get_legacy_eventname() is not empty.
* Return legacy event data.
*
* @return mixed
* @return stdClass
*/
public function get_legacy_eventdata() {
protected function get_legacy_eventdata() {
return $this->get_record_snapshot('cohort', $this->objectid);
}
}

View file

@ -14,19 +14,34 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace core\event;
/**
* User added to a cohort
* User added to a cohort event.
*
* @package core
* @copyright 2013 Dan Poltawski <dan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\event;
defined('MOODLE_INTERNAL') || die();
/**
* User added to a cohort event class.
*
* @package core
* @copyright 2013 Dan Poltawski <dan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class cohort_member_added extends base {
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'c';
// TODO MDL-41040.
$this->data['level'] = 50;
$this->data['objecttable'] = 'cohort';
}
@ -34,25 +49,24 @@ class cohort_member_added extends base {
/**
* Returns localised general event name.
*
* @return string|\lang_string
* @return string
*/
public static function get_name() {
//TODO: localise
return 'User added to a cohort';
return get_string('event_cohort_member_added', 'core_cohort');
}
/**
* Returns localised description of what happened.
* Returns description of what happened.
*
* @return string|\lang_string
* @return string
*/
public function get_description() {
//TODO: localise
return 'User '.$this->relateduserid.' was added to cohort '.$this->objectid.' by:'.$this->userid;
return 'User '.$this->relateduserid.' was added to cohort '.$this->objectid.' by user '.$this->userid;
}
/**
* Returns relevant URL.
*
* @return \moodle_url
*/
public function get_url() {
@ -60,20 +74,20 @@ class cohort_member_added extends base {
}
/**
* Does this event replace legacy event?
* Return legacy event name.
*
* @return null|string legacy event name
* @return string legacy event name.
*/
public function get_legacy_eventname() {
public static function get_legacy_eventname() {
return 'cohort_member_added';
}
/**
* Legacy event data if get_legacy_eventname() is not empty.
* Return legacy event data.
*
* @return mixed
* @return stdClass
*/
public function get_legacy_eventdata() {
protected function get_legacy_eventdata() {
$data = new \stdClass();
$data->cohortid = $this->objectid;
$data->userid = $this->relateduserid;

View file

@ -14,10 +14,19 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* User removed from a cohort event.
*
* @package core
* @copyright 2013 Dan Poltawski <dan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\event;
defined('MOODLE_INTERNAL') || die();
/**
* User removed from a cohort
* User removed from a cohort event class.
*
* @package core
* @copyright 2013 Dan Poltawski <dan@moodle.com>
@ -25,8 +34,15 @@ namespace core\event;
*/
class cohort_member_removed extends base {
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'c';
$this->data['crud'] = 'd';
// TODO MDL-41040.
$this->data['level'] = 50;
$this->data['objecttable'] = 'cohort';
}
@ -34,25 +50,24 @@ class cohort_member_removed extends base {
/**
* Returns localised general event name.
*
* @return string|\lang_string
* @return string
*/
public static function get_name() {
//TODO: localise
return 'User removed from a cohort';
return get_string('event_cohort_member_removed', 'core_cohort');
}
/**
* Returns localised description of what happened.
* Returns description of what happened.
*
* @return string|\lang_string
* @return string
*/
public function get_description() {
//TODO: localise
return 'User '.$this->relateduserid.' was removed from cohort '.$this->objectid.' by: '.$this->userid;
return 'User '.$this->relateduserid.' was removed from cohort '.$this->objectid.' by user '.$this->userid;
}
/**
* Returns relevant URL.
*
* @return \moodle_url
*/
public function get_url() {
@ -60,20 +75,20 @@ class cohort_member_removed extends base {
}
/**
* Does this event replace legacy event?
* Return legacy event name.
*
* @return null|string legacy event name
* @return string legacy event name.
*/
public function get_legacy_eventname() {
public static function get_legacy_eventname() {
return 'cohort_member_removed';
}
/**
* Legacy event data if get_legacy_eventname() is not empty.
* Return legacy event data.
*
* @return mixed
* @return stdClass
*/
public function get_legacy_eventdata() {
protected function get_legacy_eventdata() {
$data = new \stdClass();
$data->cohortid = $this->objectid;
$data->userid = $this->relateduserid;

View file

@ -14,8 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace core\event;
/**
* Cohort updated event.
*
@ -24,9 +22,26 @@ namespace core\event;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\event;
defined('MOODLE_INTERNAL') || die();
/**
* Cohort updated event class.
*
* @package core
* @copyright 2013 Dan Poltawski <dan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class cohort_updated extends base {
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'u';
// TODO MDL-41040.
$this->data['level'] = 50;
$this->data['objecttable'] = 'cohort';
}
@ -34,25 +49,24 @@ class cohort_updated extends base {
/**
* Returns localised general event name.
*
* @return string|\lang_string
* @return string
*/
public static function get_name() {
//TODO: localise
return 'Cohort updated';
return get_string('event_cohort_updated', 'core_cohort');
}
/**
* Returns localised description of what happened.
* Returns description of what happened.
*
* @return string|\lang_string
* @return string
*/
public function get_description() {
//TODO: localise
return 'Cohort '.$this->objectid.' was updated by '.$this->userid.' at context '.$this->contextid;
}
/**
* Returns relevant URL.
*
* @return \moodle_url
*/
public function get_url() {
@ -60,20 +74,20 @@ class cohort_updated extends base {
}
/**
* Does this event replace legacy event?
* Return legacy event name.
*
* @return null|string legacy event name
* @return string legacy event name.
*/
public function get_legacy_eventname() {
public static function get_legacy_eventname() {
return 'cohort_updated';
}
/**
* Legacy event data if get_legacy_eventname() is not empty.
* Return legacy event data.
*
* @return mixed
* @return stdClass
*/
public function get_legacy_eventdata() {
protected function get_legacy_eventdata() {
return $this->get_record_snapshot('cohort', $this->objectid);
}
}