Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
moodle-local_sembasednav
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-local_sembasednav
Commits
1989a3be
Commit
1989a3be
authored
3 years ago
by
Julian Wendling
Browse files
Options
Downloads
Patches
Plain Diff
REMOVE Mutliple calls to get_course_metadata
parent
418f90a8
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib.php
+13
-33
13 additions, 33 deletions
lib.php
with
13 additions
and
33 deletions
lib.php
+
13
−
33
View file @
1989a3be
...
@@ -54,16 +54,22 @@ function local_sembasednav_extend_navigation(global_navigation $navigation)
...
@@ -54,16 +54,22 @@ function local_sembasednav_extend_navigation(global_navigation $navigation)
// Creates a new array with semesters that contain their courses
// Creates a new array with semesters that contain their courses
foreach
(
$courses
as
$c
)
{
foreach
(
$courses
as
$c
)
{
$c
->
semesterId
=
get_semester_id
((
int
)
$c
->
key
,
$semFieldName
);
$semesterCustomField
=
get_semester_customFields
((
int
)
$c
->
key
,
$semFieldName
);
$c
->
semesterName
=
get_semester_name
((
int
)
$c
->
key
,
$semFieldName
);
$semesterId
=
preg_replace
(
'/[^0-9]/'
,
''
,
$semesterCustomField
);
$semesterName
=
\customfield_semester\data_controller
::
get_name_for_semester
((
int
)
$semesterId
);
$c
->
semesterId
=
$semesterId
;
$c
->
semesterName
=
$semesterName
;
$courseName
=
empty
(
$CFG
->
navshowfullcoursenames
)
?
$c
->
shorttext
:
$c
->
title
;
$courseName
=
empty
(
$CFG
->
navshowfullcoursenames
)
?
$c
->
shorttext
:
$c
->
title
;
if
(
$c
->
semesterId
==
1
)
{
if
(
$c
->
semesterId
==
1
)
{
// Term-independent
$specialNodesList
[
$c
->
semesterId
][
"name"
]
=
$c
->
semesterName
;
$specialNodesList
[
$c
->
semesterId
][
"name"
]
=
$c
->
semesterName
;
$specialNodesList
[
$c
->
semesterId
][
"courses"
][]
=
$c
;
$specialNodesList
[
$c
->
semesterId
][
"courses"
][]
=
$c
;
$
myCoursesNode
->
children
->
remove
(
$c
->
key
)
;
$
c
->
showinflatnavigation
=
false
;
}
else
{
}
else
{
// Normal semesters
$mySemesters
[
$c
->
semesterId
][
"name"
]
=
$c
->
semesterName
;
$mySemesters
[
$c
->
semesterId
][
"name"
]
=
$c
->
semesterName
;
$mySemesters
[
$c
->
semesterId
][
"courses"
][]
=
$c
;
$mySemesters
[
$c
->
semesterId
][
"courses"
][]
=
$c
;
$c
->
showinflatnavigation
=
false
;
$c
->
showinflatnavigation
=
false
;
...
@@ -124,9 +130,9 @@ function add_semester_nodes(array $semesterList, $parentNode)
...
@@ -124,9 +130,9 @@ function add_semester_nodes(array $semesterList, $parentNode)
// Assign courses to their semester in the navigation
// Assign courses to their semester in the navigation
foreach
(
$value
[
"courses"
]
as
$c
)
{
foreach
(
$value
[
"courses"
]
as
$c
)
{
$parentNode
->
children
->
remove
(
$c
->
key
);
$parentNode
->
children
->
remove
(
$c
->
key
);
$c
->
showinflatnavigation
=
true
;
$c
->
add_class
(
'p-l-3'
);
$c
->
add_class
(
'p-l-3'
);
$c
->
set_parent
(
$semesterNode
);
$c
->
set_parent
(
$semesterNode
);
$c
->
showinflatnavigation
=
true
;
if
(
!
$semesterNode
->
forceopen
)
if
(
!
$semesterNode
->
forceopen
)
$c
->
add_class
(
'localboostnavigationcollapsedchild'
);
$c
->
add_class
(
'localboostnavigationcollapsedchild'
);
...
@@ -208,45 +214,19 @@ function create_node_key(string $semesterName)
...
@@ -208,45 +214,19 @@ function create_node_key(string $semesterName)
}
}
/**
/**
* Returns semester name of given course id.
* Gets the custom fields of a given course id
* If no semester is found, return no semester assigned name.
* @param int $id
* @param int $id
* @return string
* @return string
*/
*/
function
get_semester_name
(
int
$id
,
$semFieldName
)
function
get_semester_customFields
(
int
$id
,
$semFieldName
)
{
{
$noSemesterAssigned
=
get_config
(
'sembasednav'
,
'setting_nosemestername'
);
$semesterName
=
''
;
try
{
try
{
$allCustomFields
=
get_course_metadata
(
$id
);
$allCustomFields
=
get_course_metadata
(
$id
);
$semesterField
=
$allCustomFields
[
$semFieldName
->
shortname
];
$semesterField
=
$allCustomFields
[
$semFieldName
->
shortname
];
$semesterValue
=
preg_replace
(
'/[^0-9]/'
,
''
,
$semesterField
);
// extract semester int from string
$semesterName
=
\customfield_semester\data_controller
::
get_name_for_semester
((
int
)
$semesterValue
);
}
catch
(
Exception
$e
)
{
echo
$e
->
getMessage
();
}
return
empty
(
$semesterName
)
||
$semesterName
===
''
?
$noSemesterAssigned
:
$semesterName
;
}
/**
return
$semesterField
;
* @param int $id
* @return string
*/
function
get_semester_id
(
int
$id
,
$semFieldName
)
{
$semesterValue
=
''
;
try
{
$allCustomFields
=
get_course_metadata
(
$id
);
$semesterField
=
$allCustomFields
[
$semFieldName
->
shortname
];
$semesterValue
=
preg_replace
(
'/[^0-9]/'
,
''
,
$semesterField
);
// extract semester int from string
}
catch
(
Exception
$e
)
{
}
catch
(
Exception
$e
)
{
echo
$e
->
getMessage
();
echo
$e
->
getMessage
();
}
}
return
empty
(
$semesterValue
)
||
$semesterValue
===
''
?
0
:
$semesterValue
;
}
}
// https://docs.moodle.org/dev/Custom_fields_API#Example_code_for_course_custom_fields
// https://docs.moodle.org/dev/Custom_fields_API#Example_code_for_course_custom_fields
...
...
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