Skip to content

Commit

Permalink
MDL-77135 block_myoverview: Remove duplicated strings
Browse files Browse the repository at this point in the history
AMOS BEGIN
  CPY [zero_nopermission_title,block_myoverview],[zero_default_title,block_myoverview]
AMOS END
  • Loading branch information
Amaia Anabitarte committed Feb 24, 2023
1 parent 9ee4f8d commit 9f840c1
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 17 deletions.
38 changes: 29 additions & 9 deletions blocks/myoverview/classes/output/main.php
Expand Up @@ -504,7 +504,11 @@ public function export_for_zero_state_template(renderer_base $output) {
'post',
\single_button::BUTTON_PRIMARY
);
return $this->generate_zero_state_data($nocoursesimg, [$button], 'request');
return $this->generate_zero_state_data(
$nocoursesimg,
[$button],
['title' => 'zero_request_title', 'intro' => 'zero_request_intro']
);
}

$totalcourses = $DB->count_records_select('course', 'category > 0');
Expand All @@ -526,7 +530,11 @@ public function export_for_zero_state_template(renderer_base $output) {
\single_button::BUTTON_PRIMARY
);
$buttons[] = $createbutton->export_for_template($output);
return $this->generate_zero_state_data($nocoursesimg, $buttons, 'nocourses');
return $this->generate_zero_state_data(
$nocoursesimg,
$buttons,
['title' => 'zero_nocourses_title', 'intro' => 'zero_nocourses_intro']
);
}

if ($categorytocreate = \core_course_category::get_nearest_editable_subcategory($coursecat, ['create'])) {
Expand All @@ -544,24 +552,36 @@ public function export_for_zero_state_template(renderer_base $output) {
get_string('managecourses')
);
$buttons[] = $managebutton->export_for_template($output);
return $this->generate_zero_state_data($nocoursesimg, array_reverse($buttons), 'createcourses');
return $this->generate_zero_state_data(
$nocoursesimg,
array_reverse($buttons),
['title' => 'zero_default_title', 'intro' => 'zero_createcourses_intro']
);
}
return $this->generate_zero_state_data($nocoursesimg, $buttons, 'nomanagecourses');
return $this->generate_zero_state_data(
$nocoursesimg,
$buttons,
['title' => 'zero_default_title', 'intro' => 'zero_nomanagecourses_intro']
);
}
}

return $this->generate_zero_state_data($nocoursesimg, [], 'nopermission');
return $this->generate_zero_state_data(
$nocoursesimg,
[],
['title' => 'zero_default_title', 'intro' => 'zero_nopermission_intro']
);
}

/**
* Generate the state zero data.
*
* @param \moodle_url $imageurl The URL to the image to show
* @param \single_button[] $buttons
* @param string $scenario the scenario name (used to get title and intro strings)
* @param array $strings Title and intro strings for the zero state if needed.
* @return array Context variables for the template
*/
private function generate_zero_state_data(\moodle_url $imageurl, array $buttons, string $scenario) {
private function generate_zero_state_data(\moodle_url $imageurl, array $buttons, array $strings) {
global $CFG;
// Documentation data.
$dochref = new \moodle_url($CFG->docroot, ['lang' => current_language()]);
Expand All @@ -576,8 +596,8 @@ private function generate_zero_state_data(\moodle_url $imageurl, array $buttons,
];
return [
'nocoursesimg' => $imageurl->out(),
'title' => get_string("zero_{$scenario}_title", 'block_myoverview'),
'intro' => get_string("zero_{$scenario}_intro", 'block_myoverview', $docparams),
'title' => ($strings['title']) ? get_string($strings['title'], 'block_myoverview') : '',
'intro' => ($strings['intro']) ? get_string($strings['intro'], 'block_myoverview', $docparams) : '',
'buttons' => $buttons,
];
}
Expand Down
4 changes: 1 addition & 3 deletions blocks/myoverview/lang/en/block_myoverview.php
Expand Up @@ -88,15 +88,13 @@
$string['sortbyshortname'] = 'Sort by short name';
$string['privacy:request:preference:set'] = 'The value of the setting \'{$a->name}\' was \'{$a->value}\'';
$string['viewquickstart'] = 'View Quickstart guide';
$string['zero_nopermission_title'] = 'You\'re not enroled in any course';
$string['zero_default_title'] = 'You\'re not enrolled in any course';
$string['zero_nopermission_intro'] = 'Once you enrol in a course, it will appear here.';
$string['zero_request_title'] = 'Request your first course';
$string['zero_request_intro'] = 'Need help getting started? Check out the <a href="{$a->dochref}" title="{$a->doctitle}" target="{$a->doctarget}">Moodle documentation</a> or take your first steps with our <a href="{$a->quickhref}" title="{$a->quicktitle}" target="{$a->quicktarget}">Quickstart guide</a>.';
$string['zero_nocourses_title'] = 'Create your first course';
$string['zero_nocourses_intro'] = 'Need help getting started? Check out the <a href="{$a->dochref}" title="{$a->doctitle}" target="{$a->doctarget}">Moodle documentation</a> or take your first steps with our Quickstart guide.';
$string['zero_createcourses_title'] = 'You\'re not enroled in any course';
$string['zero_createcourses_intro'] = 'Once you enrol in a course, it will appear here. To view all courses on this site, go to Manage courses.';
$string['zero_nomanagecourses_title'] = 'You\'re not enroled in any course';
$string['zero_nomanagecourses_intro'] = 'Once you enrol in a course, it will appear here.';

// Deprecated since Moodle 4.0.
Expand Down
Expand Up @@ -35,7 +35,7 @@ Feature: My overview block pagination

Scenario: The pagination controls should be hidden if I am not enrolled in any courses
When I am on the "My courses" page logged in as "student1"
Then I should see "You're not enroled in any course" in the "Course overview" "block"
Then I should see "You're not enrolled in any course" in the "Course overview" "block"
And I should not see "Show" in the "Course overview" "block"
And ".block_myoverview .dropdown-menu.show" "css_element" should not be visible
And ".block_myoverview [data-control='next']" "css_element" should not be visible
Expand Down
Expand Up @@ -40,7 +40,7 @@ Feature: My overview block searching

Scenario: There is no search if I am not enrolled in any course
When I am on the "My courses" page logged in as "student2"
Then I should see "You're not enroled in any course" in the "Course overview" "block"
Then I should see "You're not enrolled in any course" in the "Course overview" "block"
And "Search courses" "field" should not exist in the "Course overview" "block"
And I log out

Expand Down
Expand Up @@ -15,7 +15,7 @@ Feature: Zero state on my overview block

Scenario: Users with no permissions don't see any CTA
Given I am on the "My courses" page logged in as "user"
When I should see "You're not enroled in any course"
When I should see "You're not enrolled in any course"
Then I should see "Once you enrol in a course, it will appear here"
And I should not see "Create course"
And I should not see "Request a course"
Expand Down Expand Up @@ -46,7 +46,7 @@ Feature: Zero state on my overview block
| fullname | Course 1 |
| shortname | C1 |
When I am on the "My courses" page logged in as "manager"
Then I should see "You're not enroled in any course"
Then I should see "You're not enrolled in any course"
Then I should see "To view all courses on this site, go to Manage courses."
And "Manage courses" "button" should exist
And "Create course" "button" should exist
Expand All @@ -64,7 +64,7 @@ Feature: Zero state on my overview block
| fullname | Course 1 |
| shortname | C1 |
When I am on the "My courses" page logged in as "manager"
Then I should see "You're not enroled in any course"
Then I should see "You're not enrolled in any course"
Then I should not see "To view all courses on this sie, go to Manage courses"
And "Manage courses" "button" should not exist
And "Create course" "button" should exist
Expand Down

0 comments on commit 9f840c1

Please sign in to comment.