Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
moodle-tool_lifecycle
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elc
moodle-tool_lifecycle
Commits
c54dd9ba
Unverified
Commit
c54dd9ba
authored
8 years ago
by
Tobias Reischmann
Browse files
Options
Downloads
Patches
Plain Diff
Created a settings manager for saving and getting step settings
parent
18cec3ca
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
classes/manager/settings_manager.php
+103
-0
103 additions, 0 deletions
classes/manager/settings_manager.php
step/lib.php
+0
-22
0 additions, 22 deletions
step/lib.php
with
103 additions
and
22 deletions
classes/manager/settings_manager.php
0 → 100644
+
103
−
0
View file @
c54dd9ba
<?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/>.
/**
* Manager to retrive the local settings for each step subplugin.
*
* @package tool_cleanupcourses
* @copyright 2017 Tobias Reischmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace
tool_cleanupcourses\manager
;
defined
(
'MOODLE_INTERNAL'
)
||
die
();
class
settings_manager
{
/**
* Saves the local settings for a subplugin step instance.
* @param string $subpluginname name of the subplugin.
* @param mixed $data submitted data of the form.
* @throws \moodle_exception
*/
public
function
save_settings
(
$subpluginname
,
$data
)
{
global
$DB
;
$libmanager
=
new
lib_manager
();
$lib
=
$libmanager
->
get_step_lib
(
$subpluginname
);
$settingsfields
=
$lib
->
instance_settings
();
if
(
!
object_property_exists
(
$data
,
'id'
))
{
throw
new
\moodle_exception
(
'id of the step instance has to be set!'
);
}
$id
=
$data
->
id
;
foreach
(
$settingsfields
as
$setting
)
{
if
(
object_property_exists
(
$data
,
$setting
->
name
))
{
$value
=
$data
->
{
$setting
->
name
};
$cleanedvalue
=
clean_param
(
$value
,
$setting
->
paramtype
);
$record
=
$DB
->
get_record
(
'tool_cleanupcourses_settings'
,
array
(
'instanceid'
=>
$id
,
'name'
=>
$setting
->
name
)
);
if
(
$record
)
{
$record
->
value
=
$cleanedvalue
;
$DB
->
update_record
(
'tool_cleanupcourses_settings'
,
$record
);
}
else
{
$newrecord
=
new
\stdClass
();
$newrecord
->
instanceid
=
$id
;
$newrecord
->
name
=
$setting
->
name
;
$newrecord
->
value
=
$cleanedvalue
;
$DB
->
insert_record
(
'tool_cleanupcourses_settings'
,
$newrecord
);
}
}
}
}
/**
* Returns an array of local step settings for a given instance id
* @param int $instanceid id of the step instance
* @return array|null settings key-value pairs
*/
public
function
get_settings
(
$instanceid
)
{
global
$DB
;
$manager
=
new
step_manager
();
$stepinstance
=
$manager
->
get_step_instance
(
$instanceid
);
if
(
!
$stepinstance
)
{
return
null
;
}
$libmanager
=
new
lib_manager
();
$lib
=
$libmanager
->
get_step_lib
(
$stepinstance
->
subpluginname
);
if
(
$stepinstance
->
subpluginname
!==
$lib
->
get_subpluginname
())
{
return
null
;
}
$settingsvalues
=
array
();
foreach
(
$lib
->
instance_settings
()
as
$setting
)
{
$record
=
$DB
->
get_record
(
'tool_cleanupcourses_settings'
,
array
(
'instanceid'
=>
$instanceid
,
'name'
=>
$setting
->
name
));
if
(
$record
)
{
$value
=
clean_param
(
$record
->
value
,
$setting
->
paramtype
);
$settingsvalues
[
$setting
->
name
]
=
$value
;
}
}
return
$settingsvalues
;
}
}
This diff is collapsed.
Click to expand it.
step/lib.php
+
0
−
22
View file @
c54dd9ba
...
...
@@ -53,28 +53,6 @@ abstract class base {
return
array
();
}
public
function
get_settings
(
$instanceid
)
{
global
$DB
;
$manager
=
new
step_manager
();
$stepinstance
=
$manager
->
get_step_instance
(
$instanceid
);
if
(
!
$stepinstance
||
$stepinstance
->
subpluginname
!==
$this
->
get_subpluginname
())
{
return
null
;
}
$settingsvalues
=
array
();
foreach
(
$this
->
instance_settings
()
as
$setting
)
{
$record
=
$DB
->
get_record
(
'tool_cleanupcourses_settings'
,
array
(
'instanceid'
=>
$instanceid
,
'name'
=>
$setting
->
name
));
if
(
$record
)
{
$value
=
clean_param
(
$record
->
value
,
$setting
->
paramtype
);
$settingsvalues
[
$setting
->
name
]
=
$value
;
}
}
return
$settingsvalues
;
}
/**
* This method can be overriden, to add form elements to the form_step_instance.
* It is called in definition().
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment