forked from FMCorz/moodle-block_xp
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
182 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
class block_xp_filter_course extends block_xp_filter { | ||
|
||
|
||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
class block_xp_filter_default extends block_xp_filter { | ||
|
||
public function load($filter_object) { | ||
$this->ruledata = $filter_object->ruledata; | ||
$this->points = $filter_object->points; | ||
$this->sortorder = $filter_object->sortorder; | ||
} | ||
|
||
public function save() { | ||
$record = (object) array( | ||
'ruledata' => $this->ruledata, | ||
'points' => $this->points, | ||
'sortorder' => $this->sortorder, | ||
); | ||
|
||
$this->insert_or_update('block_xp_default_filters', $record); | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
abstract class block_xp_filters { | ||
|
||
protected $filters; | ||
|
||
public abstract function create_filter(); | ||
|
||
public abstract function load(); | ||
|
||
public function save() { | ||
foreach($this->filters as $filter) { | ||
$filter->save(); | ||
} | ||
} | ||
|
||
public function import($filters_object) { | ||
|
||
if (!method_exists($this, 'create_filter')) { | ||
throw new coding_exception(get_class($this) , " can't import filters"); | ||
} | ||
|
||
unset($this->filters); | ||
|
||
foreach($filters_object->filters as $filter) { | ||
$cloned_filter = $this->create_filter(); | ||
$cloned_filter->load($filter); | ||
$this->filters[] = $cloned_filter; | ||
} | ||
|
||
$this->save(); | ||
} | ||
|
||
public function get() { | ||
return $this->filters; | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
class block_xp_course_filters extends block_xp_filters { | ||
|
||
protected $courseid; | ||
|
||
public function __construct($id) { | ||
$this->$courseid = $id; | ||
} | ||
public function load() { | ||
throw new coding_exception('not implemented.'); | ||
} | ||
|
||
public function save() { | ||
throw new coding_exception('not implemented.'); | ||
} | ||
|
||
public function create_filter() { | ||
return new block_xp_filter_course($this->courseid); | ||
} | ||
|
||
|
||
|
||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
class block_xp_filters_default extends block_xp_filters { | ||
|
||
public function load() { | ||
throw new coding_exception('not implemented.'); | ||
} | ||
|
||
public function create_filter() { | ||
return new block_xp_filter_default(); | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
class block_xp_filters_static extends block_xp_filters { | ||
|
||
public function create_filter() { | ||
throw new coding_exception('Static filters cannot be modified.'); | ||
} | ||
|
||
public function __construct() { | ||
$this->filters = array(); | ||
$this->load(); | ||
} | ||
|
||
public function load() { | ||
if (empty($this->filters)) { | ||
$this->load_set_1(); | ||
} | ||
} | ||
|
||
public function save() { | ||
throw new \coding_exception("Static filters cannot be saved."); | ||
} | ||
|
||
private function load_set_1() { | ||
$d = new block_xp_rule_property(block_xp_rule_base::EQ, 'd', 'crud'); | ||
$c = new block_xp_rule_property(block_xp_rule_base::EQ, 'c', 'crud'); | ||
$r = new block_xp_rule_property(block_xp_rule_base::EQ, 'r', 'crud'); | ||
$u = new block_xp_rule_property(block_xp_rule_base::EQ, 'u', 'crud'); | ||
|
||
// Skip those as they duplicate other more low level actions. | ||
$bcmv = new block_xp_rule_event('\mod_book\event\course_module_viewed'); | ||
$dsc = new block_xp_rule_event('\mod_forum\event\discussion_subscription_created'); | ||
$sc = new block_xp_rule_event('\mod_forum\event\subscription_created'); | ||
$as = new block_xp_rule_property(block_xp_rule_base::CT, 'assessable_submitted', 'eventname'); | ||
$au = new block_xp_rule_property(block_xp_rule_base::CT, 'assessable_uploaded', 'eventname'); | ||
|
||
$ruleset = new block_xp_ruleset(array($bcmv, $dsc, $sc, $as, $au), block_xp_ruleset::ANY); | ||
$data = array('rule' => $ruleset, 'points' => 0, 'editable' => true); | ||
$this->filters[] = block_xp_filter::load_from_data($data); | ||
|
||
$data = array('rule' => $c, 'points' => 45, 'editable' => true); | ||
$this->filters[] = block_xp_filter::load_from_data($data); | ||
|
||
$data = array('rule' => $r, 'points' => 9, 'editable' => true); | ||
$this->filters[] = block_xp_filter::load_from_data($data); | ||
|
||
$data = array('rule' => $u, 'points' => 3, 'editable' => true); | ||
$this->filters[] = block_xp_filter::load_from_data($data); | ||
|
||
$data = array('rule' => $d, 'points' => 0, 'editable' => true); | ||
$this->filters[] = block_xp_filter::load_from_data($data); | ||
} | ||
} | ||
|
||
?> |