Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Stud.IP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jan-Hendrik Willms
Stud.IP
Commits
0bb23f9d
Commit
0bb23f9d
authored
6 months ago
by
Jan-Hendrik Willms
Browse files
Options
Downloads
Patches
Plain Diff
restore logging of institute changes and insert home institut back into seminar_inst, fixes #4751
Closes #4751 Merge request
studip/studip!3546
parent
24bbb999
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/controllers/course/basicdata.php
+11
-13
11 additions, 13 deletions
app/controllers/course/basicdata.php
lib/models/Course.php
+86
-0
86 additions, 0 deletions
lib/models/Course.php
with
97 additions
and
13 deletions
app/controllers/course/basicdata.php
+
11
−
13
View file @
0bb23f9d
...
...
@@ -130,12 +130,11 @@ class Course_BasicdataController extends AuthenticatedController
'locked'
=>
LockRules
::
Check
(
$course
->
id
,
'Institut_id'
)
];
$institute_ids
=
$course
->
institutes
->
pluck
(
'id'
);
$this
->
institutional
[]
=
[
'title'
=>
_
(
'beteiligte Einrichtungen'
),
'name'
=>
'related_institutes[]'
,
'type'
=>
'nested-select'
,
'value'
=>
$institute_ids
,
'value'
=>
array_diff
(
$course
->
institutes
->
pluck
(
'id'
),
[
$course
->
institut_id
])
,
'choices'
=>
$this
->
instituteChoices
(
$institutes
),
'locked'
=>
LockRules
::
Check
(
$course
->
id
,
'seminar_inst'
),
'multiple'
=>
true
,
...
...
@@ -488,19 +487,18 @@ class Course_BasicdataController extends AuthenticatedController
}
else
{
$invalid_datafields
[]
=
$datafield
->
getName
();
}
}
else
if
(
$field
[
'name'
]
==
'related_institutes[]'
)
{
}
else
if
(
$field
[
'name'
]
==
=
'related_institutes[]'
)
{
// only related_institutes supported for now
$related_institute_ids
=
Request
::
optionArray
(
'related_institutes'
);
if
(
is_array
(
$related_institute_ids
))
{
$institutes
=
Institute
::
findMany
(
$related_institute_ids
);
if
(
$institutes
)
{
$course
->
institutes
=
$institutes
;
$changemade
=
$course
->
store
();
}
else
{
$this
->
msg
[
'error'
][]
=
_
(
'Es muss mindestens ein Institut angegeben werden.'
);
}
}
else
{
$this
->
msg
[
'error'
][]
=
_
(
'Es muss mindestens ein Institut angegeben werden.'
);
$current_institute_ids
=
$course
->
institutes
->
pluck
(
'id'
);
$current_institute_ids
=
array_diff
(
$current_institute_ids
,
[
$course
->
institut_id
]);
$institutes_changed
=
count
(
$related_institute_ids
)
!==
count
(
$current_institute_ids
)
||
count
(
array_diff
(
$current_institute_ids
,
$related_institute_ids
))
>
0
;
if
(
$institutes_changed
)
{
$course
->
institutes
=
Institute
::
findMany
(
$related_institute_ids
);
$changemade
=
true
;
}
}
else
{
// format of input element name is "course_xxx"
...
...
This diff is collapsed.
Click to expand it.
lib/models/Course.php
+
86
−
0
View file @
0bb23f9d
...
...
@@ -89,6 +89,11 @@ class Course extends SimpleORMap implements Range, PrivacyObject, StudipItem, Fe
*/
protected
$initial_end_semester
;
/**
* @var array|null Currently assigned institutes, used for tracking changes
*/
protected
$currently_assigned_institutes
=
null
;
protected
static
function
configure
(
$config
=
[])
{
$config
[
'db_table'
]
=
'seminare'
;
...
...
@@ -305,6 +310,7 @@ class Course extends SimpleORMap implements Range, PrivacyObject, StudipItem, Fe
$config
[
'i18n_fields'
][
'ort'
]
=
true
;
$config
[
'registered_callbacks'
][
'before_store'
][]
=
'logStore'
;
$config
[
'registered_callbacks'
][
'before_store'
][]
=
'handleInstitutes'
;
$config
[
'registered_callbacks'
][
'after_create'
][]
=
'setDefaultTools'
;
$config
[
'registered_callbacks'
][
'after_delete'
][]
=
function
(
Course
$course
)
{
CourseAvatar
::
getAvatar
(
$course
->
id
)
->
reset
();
...
...
@@ -377,6 +383,12 @@ class Course extends SimpleORMap implements Range, PrivacyObject, StudipItem, Fe
parent
::
initRelation
(
$relation
);
$this
->
initial_start_semester
=
$this
->
getStartSemester
();
$this
->
initial_end_semester
=
$this
->
getEndSemester
();
}
elseif
(
$relation
===
'institutes'
&&
$this
->
currently_assigned_institutes
===
null
)
{
parent
::
initRelation
(
$relation
);
$this
->
currently_assigned_institutes
=
array_filter
(
$this
->
relations
[
'institutes'
]
->
pluck
(
'id'
),
fn
(
$inst_id
)
=>
$inst_id
!==
$this
->
getPristineValue
(
'institut_id'
)
);
}
parent
::
initRelation
(
$relation
);
}
...
...
@@ -392,6 +404,7 @@ class Course extends SimpleORMap implements Range, PrivacyObject, StudipItem, Fe
//Reset the flags for the start and end semester:
$this
->
initial_start_semester
=
null
;
$this
->
initial_end_semester
=
null
;
$this
->
currently_assigned_institutes
=
null
;
}
/**
...
...
@@ -2141,6 +2154,79 @@ class Course extends SimpleORMap implements Range, PrivacyObject, StudipItem, Fe
][
$this
->
completion
]
??
_
(
'undefiniert'
);
}
public
function
setValue
(
$field
,
$value
)
{
if
(
strtolower
(
$field
)
===
'institut_id'
)
{
$this
->
institutes
=
$this
->
institutes
->
filter
(
function
(
Institute
$institute
)
{
return
$institute
->
id
!==
$this
->
institut_id
;
});
}
elseif
(
strtolower
(
$field
)
===
'institutes'
)
{
$this
->
initRelation
(
$field
);
}
return
parent
::
setValue
(
$field
,
$value
);
}
/**
* Handle all things related to storing the institutes
*/
protected
function
handleInstitutes
():
void
{
if
(
$this
->
isFieldDirty
(
'institut_id'
))
{
StudipLog
::
log
(
'CHANGE_INSTITUTE_DATA'
,
$this
->
id
,
$this
->
institut_id
,
"Die Heimateinrichtung wurde zu
\"
{
$this
->
home_institut
->
name
}
\"
geändert."
);
}
if
(
$this
->
currently_assigned_institutes
!==
null
)
{
$assigned_ids
=
$this
->
institutes
->
pluck
(
'id'
);
// Deleted
$deleted_ids
=
array_diff
(
$this
->
currently_assigned_institutes
,
$assigned_ids
);
Institute
::
findEachMany
(
function
(
Institute
$institute
)
{
StudipLog
::
log
(
'CHANGE_INSTITUTE_DATA'
,
$this
->
id
,
$institute
->
id
,
"Die beteiligte Einrichtung
\"
{
$institute
->
name
}
\"
wurde gelöscht."
);
NotificationCenter
::
postNotification
(
'SeminarInstitutionDidDelete'
,
$institute
->
id
,
$this
->
id
);
},
$deleted_ids
);
// Added
$added_ids
=
array_diff
(
$assigned_ids
,
$this
->
currently_assigned_institutes
);
Institute
::
findEachMany
(
function
(
Institute
$institute
)
{
StudipLog
::
log
(
'CHANGE_INSTITUTE_DATA'
,
$this
->
id
,
$institute
->
id
,
"Die beteiligte Einrichtung
\"
{
$institute
->
name
}
\"
wurde hinzugefügt."
);
NotificationCenter
::
postNotification
(
'SeminarInstitutionDidCreate'
,
$institute
->
id
,
$this
->
id
);
},
$added_ids
);
if
(
count
(
$deleted_ids
)
>
0
||
count
(
$added_ids
)
>
0
)
{
NotificationCenter
::
postNotification
(
'CourseDidChangeInstitutes'
,
$this
);
}
}
if
(
$this
->
institut_id
&&
!
$this
->
institutes
->
find
(
$this
->
institut_id
)
)
{
$this
->
institutes
[]
=
$this
->
home_institut
;
}
}
/**
* Generates a general log entry if the course were changed.
* Furthermore, this method emits notifications when the
...
...
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