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
1a0bd8ab
Commit
1a0bd8ab
authored
7 years ago
by
Tobias Reischmann
Browse files
Options
Downloads
Patches
Plain Diff
Adjusted step_manager to new workflow model
Removed followedby functions Added functions for changing sortindex
parent
f5cd3095
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
classes/manager/step_manager.php
+70
-46
70 additions, 46 deletions
classes/manager/step_manager.php
lib.php
+4
-3
4 additions, 3 deletions
lib.php
with
74 additions
and
49 deletions
classes/manager/step_manager.php
+
70
−
46
View file @
1a0bd8ab
...
@@ -56,9 +56,8 @@ class step_manager extends subplugin_manager {
...
@@ -56,9 +56,8 @@ class step_manager extends subplugin_manager {
if
(
$subplugin
->
id
)
{
if
(
$subplugin
->
id
)
{
$DB
->
update_record
(
'tool_cleanupcourses_step'
,
$subplugin
);
$DB
->
update_record
(
'tool_cleanupcourses_step'
,
$subplugin
);
}
else
{
}
else
{
$subplugin
->
sortindex
=
self
::
count_steps_of_workflow
(
$subplugin
->
worflowid
)
+
1
;
$subplugin
->
id
=
$DB
->
insert_record
(
'tool_cleanupcourses_step'
,
$subplugin
);
$subplugin
->
id
=
$DB
->
insert_record
(
'tool_cleanupcourses_step'
,
$subplugin
);
$record
=
$DB
->
get_record
(
'tool_cleanupcourses_step'
,
array
(
'id'
=>
$subplugin
->
id
));
$subplugin
=
step_subplugin
::
from_record
(
$record
);
}
}
$transaction
->
allow_commit
();
$transaction
->
allow_commit
();
}
}
...
@@ -71,22 +70,71 @@ class step_manager extends subplugin_manager {
...
@@ -71,22 +70,71 @@ class step_manager extends subplugin_manager {
global
$DB
;
global
$DB
;
$transaction
=
$DB
->
start_delegated_transaction
();
$transaction
=
$DB
->
start_delegated_transaction
();
if
(
$record
=
$DB
->
get_record
(
'tool_cleanupcourses_step'
,
array
(
'id'
=>
$stepinstanceid
)))
{
if
(
$record
=
$DB
->
get_record
(
'tool_cleanupcourses_step'
,
array
(
'id'
=>
$stepinstanceid
)))
{
$step
=
step_subplugin
::
from_record
(
$record
);
self
::
remove_from_sortindex
(
$step
);
$DB
->
delete_records
(
'tool_cleanupcourses_step'
,
(
array
)
$step
);
}
$transaction
->
allow_commit
();
}
$othersteps
=
$DB
->
get_records
(
'tool_cleanupcourses_step'
,
array
(
'followedby'
=>
$stepinstanceid
));
/**
foreach
(
$othersteps
as
$steprecord
)
{
* Removes a subplugin from the sortindex of a workflow and adjusts all other indizes.
$step
=
step_subplugin
::
from_record
(
$steprecord
);
* @param step_subplugin $toberemoved
$step
->
followedby
=
null
;
*/
self
::
insert_or_update
(
$step
);
private
static
function
remove_from_sortindex
(
&
$toberemoved
)
{
global
$DB
;
$transaction
=
$DB
->
start_delegated_transaction
();
if
(
isset
(
$toberemoved
->
sortindex
))
{
$subplugins
=
$DB
->
get_records_select
(
'tool_cleanupcourses_step'
,
"sortindex >
$toberemoved->sortindex
"
,
array
(
'workflowid'
=>
$toberemoved
->
worflowid
));
foreach
(
$subplugins
as
$record
)
{
$subplugin
=
step_subplugin
::
from_record
(
$record
);
$subplugin
->
sortindex
--
;
self
::
insert_or_update
(
$subplugin
);
}
$toberemoved
->
sortindex
=
null
;
self
::
insert_or_update
(
$toberemoved
);
}
$transaction
->
allow_commit
();
}
}
$othertrigger
=
$DB
->
get_records
(
'tool_cleanupcourses_trigger'
,
array
(
'followedby'
=>
$stepinstanceid
));
/**
foreach
(
$othertrigger
as
$triggerrecord
)
{
* Changes the sortindex of a step by swapping it with another.
$trigger
=
trigger_subplugin
::
from_record
(
$triggerrecord
);
* @param int $stepid id of the step
$trigger
->
followedby
=
null
;
* @param bool $up tells if the step should be set up or down
trigger_manager
::
insert_or_update
(
$trigger
);
*/
public
static
function
change_sortindex
(
$stepid
,
$up
)
{
global
$DB
;
$step
=
self
::
get_step_instance
(
$stepid
);
// Prevent first entry to be put up even more.
if
(
$step
->
sortindex
==
1
&&
$up
)
{
return
;
}
// Prevent last entry to be put down even more.
if
(
$step
->
sortindex
==
self
::
count_steps_of_workflow
(
$step
->
worflowid
)
&&
!
$up
)
{
return
;
}
}
$DB
->
delete_records
(
'tool_cleanupcourses_step'
,
(
array
)
$record
);
$index
=
$step
->
sortindex
;
if
(
$up
)
{
$otherindex
=
$index
-
1
;
}
else
{
$otherindex
=
$index
+
1
;
}
}
$transaction
=
$DB
->
start_delegated_transaction
();
$otherrecord
=
$DB
->
get_record
(
'tool_cleanupcourses_step'
,
array
(
'sortindex'
=>
$otherindex
,
'workflowid'
=>
$step
->
worflowid
)
);
$otherstep
=
step_subplugin
::
from_record
(
$otherrecord
);
$step
->
sortindex
=
$otherindex
;
$otherstep
->
sortindex
=
$index
;
self
::
insert_or_update
(
$step
);
self
::
insert_or_update
(
$otherstep
);
$transaction
->
allow_commit
();
$transaction
->
allow_commit
();
}
}
...
@@ -131,44 +179,20 @@ class step_manager extends subplugin_manager {
...
@@ -131,44 +179,20 @@ class step_manager extends subplugin_manager {
return
$result
;
return
$result
;
}
}
/**
* Changes the followedby of a trigger.
* @param int $subpluginid id of the trigger
* @param int $followedby id of the step
*/
public
static
function
change_followedby
(
$subpluginid
,
$followedby
)
{
global
$DB
;
$transaction
=
$DB
->
start_delegated_transaction
();
$step
=
self
::
get_step_instance
(
$subpluginid
);
if
(
!
$step
)
{
return
;
// TODO: Throw error.
}
$followedby
=
self
::
get_step_instance
(
$followedby
);
// If step is not defined clear followedby.
if
(
$followedby
)
{
$step
->
followedby
=
$followedby
->
id
;
}
else
{
$step
->
followedby
=
null
;
}
self
::
insert_or_update
(
$step
);
$transaction
->
allow_commit
();
}
/**
/**
* Handles an action of the subplugin_settings.
* Handles an action of the subplugin_settings.
* @param string $action action to be executed
* @param string $action action to be executed
* @param int $subplugin id of the subplugin
* @param int $subplugin
id
id of the subplugin
*/
*/
public
static
function
handle_action
(
$action
,
$subplugin
)
{
public
static
function
handle_action
(
$action
,
$subpluginid
)
{
if
(
$action
===
ACTION_FOLLOWEDBY_STEP
)
{
if
(
$action
===
ACTION_UP_STEP
)
{
self
::
change_followedby
(
$subplugin
,
optional_param
(
'followedby'
,
null
,
PARAM_INT
));
self
::
change_sortindex
(
$subpluginid
,
true
);
}
if
(
$action
===
ACTION_DOWN_STEP
)
{
self
::
change_sortindex
(
$subpluginid
,
false
);
}
}
if
(
$action
===
ACTION_STEP_INSTANCE_DELETE
)
{
if
(
$action
===
ACTION_STEP_INSTANCE_DELETE
)
{
self
::
remove
(
$subplugin
);
self
::
remove
(
$subplugin
id
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
lib.php
+
4
−
3
View file @
1a0bd8ab
...
@@ -24,9 +24,10 @@ defined('MOODLE_INTERNAL') || die();
...
@@ -24,9 +24,10 @@ defined('MOODLE_INTERNAL') || die();
define
(
'ACTION_ENABLE_TRIGGER'
,
'enable'
);
define
(
'ACTION_ENABLE_TRIGGER'
,
'enable'
);
define
(
'ACTION_DISABLE_TRIGGER'
,
'disable'
);
define
(
'ACTION_DISABLE_TRIGGER'
,
'disable'
);
define
(
'ACTION_UP_TRIGGER'
,
'up'
);
define
(
'ACTION_UP_TRIGGER'
,
'up
_trigger
'
);
define
(
'ACTION_DOWN_TRIGGER'
,
'down'
);
define
(
'ACTION_DOWN_TRIGGER'
,
'down
_trigger
'
);
define
(
'ACTION_WORKFLOW_TRIGGER'
,
'workflow_trigger'
);
define
(
'ACTION_WORKFLOW_TRIGGER'
,
'workflow_trigger'
);
define
(
'ACTION_FOLLOWEDBY_STEP'
,
'followedby_step'
);
define
(
'ACTION_UP_STEP'
,
'up_step'
);
define
(
'ACTION_DOWN_STEP'
,
'down_step'
);
define
(
'ACTION_STEP_INSTANCE_FORM'
,
'step_instance_form'
);
define
(
'ACTION_STEP_INSTANCE_FORM'
,
'step_instance_form'
);
define
(
'ACTION_STEP_INSTANCE_DELETE'
,
'step_instance_delete'
);
define
(
'ACTION_STEP_INSTANCE_DELETE'
,
'step_instance_delete'
);
\ No newline at end of file
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