-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make default rules editable (#26) #59
Changes from 1 commit
2f56bf4
20d0e52
a33bbcc
f3b01e5
b174f18
32dc4f0
c4cb5eb
76c8ba4
f5f0aa5
590a5a3
8edd6cf
e6559cb
1592295
70b547c
374a614
a22c0ea
9600918
ae568c8
cee1259
da4e569
a877742
11380d8
fb29ddd
9d7c4a9
a6a4a54
a6b9b88
ce43806
8c81559
4c2f17b
d303018
776c042
7ae003a
ae4c262
fe57237
e11d003
1c1e15c
23555f6
547ba24
9e3342e
b584083
149f652
55127a9
716ba0e
468f6a8
1176abd
a7859f5
f2c18bd
2e55685
9e12b04
08aad6d
97118ff
ac6f77f
d6d199e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…ing...
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,20 +33,17 @@ | |
*/ | ||
class block_xp_filter_manager { | ||
|
||
/** | ||
* The block XP manager. | ||
* | ||
* @var block_xp_manager. | ||
*/ | ||
protected $manager; | ||
protected $courseid; | ||
|
||
protected $filterset; | ||
/** | ||
* Constructor. | ||
* | ||
* @param block_xp_manager $manager The XP manager. | ||
*/ | ||
public function __construct(block_xp_manager $manager) { | ||
$this->manager = $manager; | ||
public function __construct($courseid) { | ||
$this->courseid = $courseid; | ||
$this->filterset = new block_xp_filterset_course($courseid); | ||
} | ||
|
||
/** | ||
|
@@ -58,7 +55,7 @@ public function __construct(block_xp_manager $manager) { | |
*/ | ||
public function get_all_filters() { | ||
$cache = cache::make('block_xp', 'filters'); | ||
$key = 'filters_' . $this->manager->get_courseid(); | ||
$key = 'filters_' . $this->get_courseid(); | ||
if (false === ($filters = $cache->get($key))) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because this method is |
||
$filters = $this->get_course_filters(); | ||
$cache->set($key, $filters); | ||
|
@@ -72,7 +69,7 @@ public function get_all_filters() { | |
* @return course id | ||
*/ | ||
public function get_courseid() { | ||
return $this->manager->get_courseid(); | ||
return $this->courseid; | ||
} | ||
|
||
|
||
|
@@ -97,10 +94,7 @@ public function get_points_for_event(\core\event\base $event) { | |
* @return array Of filter objects. | ||
*/ | ||
public static function get_static_filters() { | ||
$staticfilters = new block_xp_filterset_static(); | ||
$staticfilters->load(); | ||
|
||
return $staticfilters->get(); | ||
return (new block_xp_filterset_static())->get(); | ||
} | ||
|
||
/** | ||
|
@@ -109,15 +103,7 @@ public static function get_static_filters() { | |
* @return array of filter data from the DB, though properties is already json_decoded. | ||
*/ | ||
public function get_course_filters() { | ||
global $DB; | ||
$results = $DB->get_recordset('block_xp_filters', array('courseid' => $this->get_courseid()), | ||
'sortorder ASC, id ASC'); | ||
$filters = array(); | ||
foreach ($results as $key => $filter) { | ||
$filters[$filter->id] = block_xp_filter::load_from_data($filter); | ||
} | ||
$results->close(); | ||
return $filters; | ||
return $this->filterset->get(); | ||
} | ||
|
||
/** | ||
|
@@ -137,21 +123,33 @@ public function get_user_filters() { | |
public static function save_default_filters() { | ||
$staticfilters = new block_xp_filterset_static(); | ||
$defaultfilters = new block_xp_filterset_default(); | ||
|
||
$defaultfilters->import($staticfilters); | ||
} | ||
|
||
/** | ||
* Used when adding block to course | ||
* | ||
* @return void */ | ||
public function copy_default_filters_to_course() { | ||
public function copy_default_filters() { | ||
$defaultfilters = new block_xp_filterset_default(); | ||
$coursefilters = new block_xp_filterset_course($this->get_courseid()); | ||
print_object("--REGLAS DEFECTO DENTRO ANTES APPEND --"); | ||
print_object($defaultfilters->get()); | ||
$this->filterset->append($defaultfilters); | ||
print_object("--REGLAS DEFECTO DENTRO DESPUES APPEND --"); | ||
print_object($defaultfilters->get()); | ||
|
||
if ($coursefilters->empty()) { | ||
$coursefilters->import($defaultfilters); | ||
} | ||
|
||
} | ||
|
||
public static function copy_default_filters_to_course($courseid) { | ||
$defaultfilters = new block_xp_filterset_default(); | ||
$coursefilters = new block_xp_filterset_course($courseid); | ||
print_object("--REGLAS DEFECTO DENTRO ANTES APPEND --"); | ||
print_object($defaultfilters->get()); | ||
|
||
$coursefilters->append($defaultfilters); | ||
print_object("--REGLAS DEFECTO DENTRO DESPUES APPEND --"); | ||
print_object($defaultfilters->get()); | ||
} | ||
|
||
/** | ||
|
@@ -164,4 +162,8 @@ public function invalidate_filters_cache() { | |
$cache->delete('filters_' . $this->get_courseid()); | ||
} | ||
|
||
public function get_filterset() { | ||
return $this->filterset; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would add the default rules again, and again, if the block was remove, then re-added. Notice in
instance_delete
I do not remove anything form the database, I simple update the block to be disabled. That is another improvement we could make at a later stage.