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
277bae6f
Commit
277bae6f
authored
3 years ago
by
Ron Lucke
Committed by
Elmar Ludwig
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
fix #229
parent
bffdb471
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/controllers/course/courseware.php
+36
-14
36 additions, 14 deletions
app/controllers/course/courseware.php
with
36 additions
and
14 deletions
app/controllers/course/courseware.php
+
36
−
14
View file @
277bae6f
...
...
@@ -2,6 +2,7 @@
use
Courseware\StructuralElement
;
use
Courseware\Instance
;
use
Courseware\UserProgress
;
/**
* @property ?string $entry_element_id
...
...
@@ -42,7 +43,7 @@ class Course_CoursewareController extends AuthenticatedController
]);
}
// load courseware for
seminar
// load courseware for
course
if
(
!
$this
->
entry_element_id
||
!
$struct
||
!
$struct
->
canRead
(
$GLOBALS
[
'user'
]))
{
$course
=
Course
::
find
(
Context
::
getId
());
...
...
@@ -110,9 +111,20 @@ class Course_CoursewareController extends AuthenticatedController
$data
=
[];
$cid
=
Context
::
getId
();
$course
=
Course
::
find
(
$cid
);
$course_members
=
$course
->
getMembersWithStatus
(
'autor'
);
$course_member_ids
=
array_column
(
$course_members
,
'user_id'
);
$elements
=
StructuralElement
::
findBySQL
(
'range_id = ?'
,
[
$cid
]);
if
(
$course_progress
)
{
$cw_user_progresses
=
UserProgress
::
findBySQL
(
'user_id IN (?)'
,
[
$course_member_ids
]);
}
else
{
$cw_user_progresses
=
UserProgress
::
findBySQL
(
'user_id = ?'
,
[
$GLOBALS
[
'user'
]
->
id
,
]);
}
foreach
(
$elements
as
$element
)
{
$el
=
[
'id'
=>
$element
->
id
,
...
...
@@ -121,7 +133,7 @@ class Course_CoursewareController extends AuthenticatedController
'parent_name'
=>
$element
->
parent
->
title
,
'children'
=>
$this
->
getChildren
(
$element
->
children
),
];
$el
[
'progress'
]
=
$this
->
getProgress
(
$element
,
$course_progress
);
$el
[
'progress'
]
=
$this
->
getProgress
(
$course
,
$element
,
$course_progress
,
$cw_user_progresses
,
$course_member_ids
);
array_push
(
$data
,
$el
);
}
...
...
@@ -156,16 +168,15 @@ class Course_CoursewareController extends AuthenticatedController
return
$data
;
}
private
function
getProgress
(
StructuralElement
$element
,
bool
$course_progress
=
false
):
array
private
function
getProgress
(
Course
$course
,
StructuralElement
$element
,
bool
$course_progress
=
false
,
array
$cw_user_progresses
,
array
$course_member_ids
):
array
{
$descendants
=
$element
->
findDescendants
();
$count
=
count
(
$descendants
);
$progress
=
0
;
$own_progress
=
0
;
$course
=
Seminar
::
GetInstance
(
Context
::
getId
());
foreach
(
$descendants
as
$el
)
{
$block
=
$this
->
getBlocks
(
$el
->
id
,
$course_progress
,
$c
ourse
);
$block
=
$this
->
getBlocks
(
$el
->
id
,
$course_progress
,
$c
w_user_progresses
,
$course
,
$course_member_ids
);
if
(
$block
[
'counter'
]
>
0
)
{
$progress
+=
$block
[
'progress'
]
/
$block
[
'counter'
];
}
else
{
...
...
@@ -173,7 +184,7 @@ class Course_CoursewareController extends AuthenticatedController
}
}
$own_blocks
=
$this
->
getBlocks
(
$element
->
id
,
$course_progress
,
$c
ourse
);
$own_blocks
=
$this
->
getBlocks
(
$element
->
id
,
$course_progress
,
$c
w_user_progresses
,
$course
,
$course_member_ids
);
if
(
$own_blocks
[
'counter'
]
>
0
)
{
$own_progress
=
$own_blocks
[
'progress'
]
/
$own_blocks
[
'counter'
];
...
...
@@ -191,7 +202,7 @@ class Course_CoursewareController extends AuthenticatedController
return
[
'total'
=>
round
(
$progress
,
2
)
*
100
,
'current'
=>
round
(
$own_progress
,
2
)
*
100
];
}
private
function
getBlocks
(
string
$element_id
,
bool
$course_progress
=
false
,
$course
):
array
private
function
getBlocks
(
string
$element_id
,
bool
$course_progress
=
false
,
array
$cw_user_progresses
,
Course
$course
,
array
$course_member_ids
):
array
{
$containers
=
Courseware\Container
::
findBySQL
(
'structural_element_id = ?'
,
[
intval
(
$element_id
)]);
$blocks
=
[];
...
...
@@ -201,16 +212,22 @@ class Course_CoursewareController extends AuthenticatedController
foreach
(
$containers
as
$container
)
{
$counter
=
$container
->
countBlocks
();
$blocks
[
'counter'
]
+=
$counter
;
if
(
$counter
>
0
)
{
$blks
=
Courseware\Block
::
findBySQL
(
'container_id = ?'
,
[
$container
->
id
]);
foreach
(
$blks
as
$item
)
{
if
(
$course_progress
)
{
if
(
$users_counter
>
0
)
{
$progresses
=
Courseware\UserProgress
::
findBySQL
(
'block_id = ?'
,
[
$item
->
id
]);
$progresses
=
array_filter
(
$cw_user_progresses
,
function
(
$progress
)
use
(
$item
)
{
if
(
$progress
->
block_id
===
$item
->
id
)
{
return
true
;
}
});
$users_progress
=
0
;
foreach
(
$progresses
as
$prog
)
{
if
(
array
_key_exists
(
$prog
->
user_id
,
$course
->
getMembersWithStatus
(
'autor'
)
))
{
if
(
in_
array
(
$prog
->
user_id
,
$course
_member_ids
))
{
$users_progress
+=
$prog
->
grade
;
}
}
...
...
@@ -218,11 +235,16 @@ class Course_CoursewareController extends AuthenticatedController
$blocks
[
'progress'
]
+=
$users_progress
/
$users_counter
;
}
}
else
{
$progress
=
Courseware\UserProgress
::
findOneBySQL
(
'user_id = ? and block_id = ?'
,
[
$GLOBALS
[
'user'
]
->
id
,
$item
->
id
,
]);
$blocks
[
'progress'
]
+=
$progress
->
grade
;
$uid
=
$GLOBALS
[
'user'
]
->
id
;
$progresses
=
array_filter
(
$cw_user_progresses
,
function
(
$progress
)
use
(
$item
,
$uid
)
{
if
(
$progress
->
block_id
===
$item
->
id
&&
$progress
->
user_id
===
$uid
)
{
return
true
;
}
});
$progress
=
reset
(
$progresses
);
if
(
$progress
!==
null
)
{
$blocks
[
'progress'
]
+=
intval
(
$progress
->
grade
);
}
}
}
}
...
...
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